aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikulas Patocka <mpatocka@redhat.com>2017-04-30 17:32:28 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-05-25 09:44:33 -0400
commiteeaf13394d32763d75d3314ca47264e5078076cd (patch)
treee50a1dc2191a70137c01623e4bbed9b1175d154c
parente69242436b6b086a6f342f715c68389596a9a7ac (diff)
dm bufio: make the parameter "retain_bytes" unsigned long
commit 13840d38016203f0095cd547b90352812d24b787 upstream. Change the type of the parameter "retain_bytes" from unsigned to unsigned long, so that on 64-bit machines the user can set more than 4GiB of data to be retained. Also, change the type of the variable "count" in the function "__evict_old_buffers" to unsigned long. The assignment "count = c->n_buffers[LIST_CLEAN] + c->n_buffers[LIST_DIRTY];" could result in unsigned long to unsigned overflow and that could result in buffers not being freed when they should. While at it, avoid division in get_retain_buffers(). Division is slow, we can change it to shift because we have precalculated the log2 of block size. Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/md/dm-bufio.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
index c805fd9184bf..8bf9667ff46b 100644
--- a/drivers/md/dm-bufio.c
+++ b/drivers/md/dm-bufio.c
@@ -215,7 +215,7 @@ static DEFINE_SPINLOCK(param_spinlock);
215 * Buffers are freed after this timeout 215 * Buffers are freed after this timeout
216 */ 216 */
217static unsigned dm_bufio_max_age = DM_BUFIO_DEFAULT_AGE_SECS; 217static unsigned dm_bufio_max_age = DM_BUFIO_DEFAULT_AGE_SECS;
218static unsigned dm_bufio_retain_bytes = DM_BUFIO_DEFAULT_RETAIN_BYTES; 218static unsigned long dm_bufio_retain_bytes = DM_BUFIO_DEFAULT_RETAIN_BYTES;
219 219
220static unsigned long dm_bufio_peak_allocated; 220static unsigned long dm_bufio_peak_allocated;
221static unsigned long dm_bufio_allocated_kmem_cache; 221static unsigned long dm_bufio_allocated_kmem_cache;
@@ -1541,10 +1541,10 @@ static bool __try_evict_buffer(struct dm_buffer *b, gfp_t gfp)
1541 return true; 1541 return true;
1542} 1542}
1543 1543
1544static unsigned get_retain_buffers(struct dm_bufio_client *c) 1544static unsigned long get_retain_buffers(struct dm_bufio_client *c)
1545{ 1545{
1546 unsigned retain_bytes = ACCESS_ONCE(dm_bufio_retain_bytes); 1546 unsigned long retain_bytes = ACCESS_ONCE(dm_bufio_retain_bytes);
1547 return retain_bytes / c->block_size; 1547 return retain_bytes >> (c->sectors_per_block_bits + SECTOR_SHIFT);
1548} 1548}
1549 1549
1550static unsigned long __scan(struct dm_bufio_client *c, unsigned long nr_to_scan, 1550static unsigned long __scan(struct dm_bufio_client *c, unsigned long nr_to_scan,
@@ -1554,7 +1554,7 @@ static unsigned long __scan(struct dm_bufio_client *c, unsigned long nr_to_scan,
1554 struct dm_buffer *b, *tmp; 1554 struct dm_buffer *b, *tmp;
1555 unsigned long freed = 0; 1555 unsigned long freed = 0;
1556 unsigned long count = nr_to_scan; 1556 unsigned long count = nr_to_scan;
1557 unsigned retain_target = get_retain_buffers(c); 1557 unsigned long retain_target = get_retain_buffers(c);
1558 1558
1559 for (l = 0; l < LIST_SIZE; l++) { 1559 for (l = 0; l < LIST_SIZE; l++) {
1560 list_for_each_entry_safe_reverse(b, tmp, &c->lru[l], lru_list) { 1560 list_for_each_entry_safe_reverse(b, tmp, &c->lru[l], lru_list) {
@@ -1780,8 +1780,8 @@ static bool older_than(struct dm_buffer *b, unsigned long age_hz)
1780static void __evict_old_buffers(struct dm_bufio_client *c, unsigned long age_hz) 1780static void __evict_old_buffers(struct dm_bufio_client *c, unsigned long age_hz)
1781{ 1781{
1782 struct dm_buffer *b, *tmp; 1782 struct dm_buffer *b, *tmp;
1783 unsigned retain_target = get_retain_buffers(c); 1783 unsigned long retain_target = get_retain_buffers(c);
1784 unsigned count; 1784 unsigned long count;
1785 LIST_HEAD(write_list); 1785 LIST_HEAD(write_list);
1786 1786
1787 dm_bufio_lock(c); 1787 dm_bufio_lock(c);
@@ -1941,7 +1941,7 @@ MODULE_PARM_DESC(max_cache_size_bytes, "Size of metadata cache");
1941module_param_named(max_age_seconds, dm_bufio_max_age, uint, S_IRUGO | S_IWUSR); 1941module_param_named(max_age_seconds, dm_bufio_max_age, uint, S_IRUGO | S_IWUSR);
1942MODULE_PARM_DESC(max_age_seconds, "Max age of a buffer in seconds"); 1942MODULE_PARM_DESC(max_age_seconds, "Max age of a buffer in seconds");
1943 1943
1944module_param_named(retain_bytes, dm_bufio_retain_bytes, uint, S_IRUGO | S_IWUSR); 1944module_param_named(retain_bytes, dm_bufio_retain_bytes, ulong, S_IRUGO | S_IWUSR);
1945MODULE_PARM_DESC(retain_bytes, "Try to keep at least this many bytes cached in memory"); 1945MODULE_PARM_DESC(retain_bytes, "Try to keep at least this many bytes cached in memory");
1946 1946
1947module_param_named(peak_allocated_bytes, dm_bufio_peak_allocated, ulong, S_IRUGO | S_IWUSR); 1947module_param_named(peak_allocated_bytes, dm_bufio_peak_allocated, ulong, S_IRUGO | S_IWUSR);