From b8a2bd16924eebba1f5cf10a54c20eac981fa3cd Mon Sep 17 00:00:00 2001 From: Olav Haugan Date: Thu, 31 Oct 2013 17:53:41 -0700 Subject: 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: Olav Haugan --- drivers/staging/zram/zram_drv.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'drivers/staging') diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c index 72fbf05f169..6063c11375a 100644 --- a/drivers/staging/zram/zram_drv.c +++ b/drivers/staging/zram/zram_drv.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "zram_drv.h" @@ -39,6 +40,12 @@ static int zram_major; static struct zram *zram_devices; +/* + * 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; @@ -400,6 +407,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, struct page *page; unsigned char *user_mem, *cmem, *src, *uncmem = NULL; struct zram_meta *meta = zram->meta; + static unsigned long zram_rs_time; page = bvec->bv_page; src = meta->compress_buffer; @@ -473,8 +481,10 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, handle = zs_malloc(meta->mem_pool, clen); if (!handle) { - pr_info("Error allocating memory for compressed page: %u, size=%zu\n", - index, clen); + if (printk_timed_ratelimit(&zram_rs_time, + ALLOC_ERROR_LOG_RATE_MS)) + pr_info("Error allocating memory for compressed page: %u, size=%zu\n", + index, clen); ret = -ENOMEM; goto out; } -- cgit v1.2.3