Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 89198200 authored by Olav Haugan's avatar Olav Haugan Committed by Liam Mark
Browse files

staging: zram: Rate limit memory allocation errors



If an error occurs allocating memory for zram we will not be able to
fullfill the request to store the page in zram. The swap subsystem still
continues to try to swap out pages to zram even when this error occurs
since there is currently no facility to stop the swap subsystem from
swapping out during such errors. This can cause the system to be
overflowed with logging errors.

Reduce the amount of logging to prevent the kernel log from being filled
with these error messages

Change-Id: I54b920337749ece59d9ca78fa8b29345ec7b976b
Signed-off-by: default avatarOlav Haugan <ohaugan@codeaurora.org>
parent 099e9fc7
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -41,6 +41,12 @@ static DEFINE_MUTEX(zram_index_mutex);
static int zram_major;
static const char *default_compressor = "lzo";

/*
 * We don't need to see memory allocation errors more than once every 1
 * second to know that a problem is occurring.
 */
#define ALLOC_ERROR_LOG_RATE_MS 1000

/* Module params (documentation at end) */
static unsigned int num_devices = 1;

@@ -668,6 +674,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
	struct zram_meta *meta = zram->meta;
	struct zcomp_strm *zstrm = NULL;
	unsigned long alloced_pages;
	static unsigned long zram_rs_time;

	page = bvec->bv_page;
	if (is_partial_io(bvec)) {
@@ -761,6 +768,8 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
		if (handle)
			goto compress_again;

		if (printk_timed_ratelimit(&zram_rs_time,
					   ALLOC_ERROR_LOG_RATE_MS))
			pr_err("Error allocating memory for compressed page: %u, size=%u\n",
			       index, clen);
		ret = -ENOMEM;