dm bufio: change percent to ratio The default values were expressed in percent, change it to ratio. The problem with percents is that it can't represent values smaller than 100 and changing it to per milles would introduce the risk of integer overflow. Signed-off-by: Mikulas Patocka Cc: stable@vger.kernel.org # 3.2+ --- drivers/md/dm-bufio.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) Index: linux-3.17/drivers/md/dm-bufio.c =================================================================== --- linux-3.17.orig/drivers/md/dm-bufio.c 2014-10-08 19:06:52.000000000 +0200 +++ linux-3.17/drivers/md/dm-bufio.c 2014-10-08 19:06:54.000000000 +0200 @@ -19,16 +19,16 @@ /* * Memory management policy: - * Limit the number of buffers to DM_BUFIO_MEMORY_PERCENT of main memory - * or DM_BUFIO_VMALLOC_PERCENT of vmalloc memory (whichever is lower). + * Limit the number of buffers to DM_BUFIO_MEMORY_RATIO of main memory + * or DM_BUFIO_VMALLOC_RATIO of vmalloc memory (whichever is lower). * Always allocate at least DM_BUFIO_MIN_BUFFERS buffers. * Start background writeback when there are DM_BUFIO_WRITEBACK_PERCENT * dirty buffers. */ #define DM_BUFIO_MIN_BUFFERS 8 -#define DM_BUFIO_MEMORY_PERCENT 2 -#define DM_BUFIO_VMALLOC_PERCENT 25 +#define DM_BUFIO_MEMORY_RATIO 50 +#define DM_BUFIO_VMALLOC_RATIO 4 #define DM_BUFIO_WRITEBACK_PERCENT 75 /* @@ -1745,8 +1745,8 @@ static int __init dm_bufio_init(void) memset(&dm_bufio_caches, 0, sizeof dm_bufio_caches); memset(&dm_bufio_cache_names, 0, sizeof dm_bufio_cache_names); - mem = (__u64)((totalram_pages - totalhigh_pages) * - DM_BUFIO_MEMORY_PERCENT / 100) << PAGE_SHIFT; + mem = (__u64)((totalram_pages - totalhigh_pages) / + DM_BUFIO_MEMORY_RATIO) << PAGE_SHIFT; if (mem > ULONG_MAX) mem = ULONG_MAX; @@ -1756,8 +1756,8 @@ static int __init dm_bufio_init(void) * Get the size of vmalloc space the same way as VMALLOC_TOTAL * in fs/proc/internal.h */ - if (mem > (VMALLOC_END - VMALLOC_START) * DM_BUFIO_VMALLOC_PERCENT / 100) - mem = (VMALLOC_END - VMALLOC_START) * DM_BUFIO_VMALLOC_PERCENT / 100; + if (mem > (VMALLOC_END - VMALLOC_START) / DM_BUFIO_VMALLOC_RATIO) + mem = (VMALLOC_END - VMALLOC_START) / DM_BUFIO_VMALLOC_RATIO; #endif dm_bufio_default_cache_size = mem;