summaryrefslogtreecommitdiffstats
path: root/drivers/md
diff options
context:
space:
mode:
authorMikulas Patocka <mpatocka@redhat.com>2017-04-30 17:32:28 -0400
committerMike Snitzer <snitzer@redhat.com>2017-05-16 15:12:08 -0400
commit13840d38016203f0095cd547b90352812d24b787 (patch)
tree0f45c88b71acfc0a69ebdbf0736746b046faf076 /drivers/md
parentf98e0eb68008aff9824d1c4dad7276c8bab83ca5 (diff)
dm bufio: make the parameter "retain_bytes" unsigned long
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. Cc: stable@vger.kernel.org Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Diffstat (limited to 'drivers/md')
-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 5db11a405129..cd8139593ccd 100644
--- a/drivers/md/dm-bufio.c
+++ b/drivers/md/dm-bufio.c
@@ -218,7 +218,7 @@ static DEFINE_SPINLOCK(param_spinlock);
218 * Buffers are freed after this timeout 218 * Buffers are freed after this timeout
219 */ 219 */
220static unsigned dm_bufio_max_age = DM_BUFIO_DEFAULT_AGE_SECS; 220static unsigned dm_bufio_max_age = DM_BUFIO_DEFAULT_AGE_SECS;
221static unsigned dm_bufio_retain_bytes = DM_BUFIO_DEFAULT_RETAIN_BYTES; 221static unsigned long dm_bufio_retain_bytes = DM_BUFIO_DEFAULT_RETAIN_BYTES;
222 222
223static unsigned long dm_bufio_peak_allocated; 223static unsigned long dm_bufio_peak_allocated;
224static unsigned long dm_bufio_allocated_kmem_cache; 224static unsigned long dm_bufio_allocated_kmem_cache;
@@ -1558,10 +1558,10 @@ static bool __try_evict_buffer(struct dm_buffer *b, gfp_t gfp)
1558 return true; 1558 return true;
1559} 1559}
1560 1560
1561static unsigned get_retain_buffers(struct dm_bufio_client *c) 1561static unsigned long get_retain_buffers(struct dm_bufio_client *c)
1562{ 1562{
1563 unsigned retain_bytes = ACCESS_ONCE(dm_bufio_retain_bytes); 1563 unsigned long retain_bytes = ACCESS_ONCE(dm_bufio_retain_bytes);
1564 return retain_bytes / c->block_size; 1564 return retain_bytes >> (c->sectors_per_block_bits + SECTOR_SHIFT);
1565} 1565}
1566 1566
1567static unsigned long __scan(struct dm_bufio_client *c, unsigned long nr_to_scan, 1567static unsigned long __scan(struct dm_bufio_client *c, unsigned long nr_to_scan,
@@ -1571,7 +1571,7 @@ static unsigned long __scan(struct dm_bufio_client *c, unsigned long nr_to_scan,
1571 struct dm_buffer *b, *tmp; 1571 struct dm_buffer *b, *tmp;
1572 unsigned long freed = 0; 1572 unsigned long freed = 0;
1573 unsigned long count = nr_to_scan; 1573 unsigned long count = nr_to_scan;
1574 unsigned retain_target = get_retain_buffers(c); 1574 unsigned long retain_target = get_retain_buffers(c);
1575 1575
1576 for (l = 0; l < LIST_SIZE; l++) { 1576 for (l = 0; l < LIST_SIZE; l++) {
1577 list_for_each_entry_safe_reverse(b, tmp, &c->lru[l], lru_list) { 1577 list_for_each_entry_safe_reverse(b, tmp, &c->lru[l], lru_list) {
@@ -1794,8 +1794,8 @@ static bool older_than(struct dm_buffer *b, unsigned long age_hz)
1794static void __evict_old_buffers(struct dm_bufio_client *c, unsigned long age_hz) 1794static void __evict_old_buffers(struct dm_bufio_client *c, unsigned long age_hz)
1795{ 1795{
1796 struct dm_buffer *b, *tmp; 1796 struct dm_buffer *b, *tmp;
1797 unsigned retain_target = get_retain_buffers(c); 1797 unsigned long retain_target = get_retain_buffers(c);
1798 unsigned count; 1798 unsigned long count;
1799 LIST_HEAD(write_list); 1799 LIST_HEAD(write_list);
1800 1800
1801 dm_bufio_lock(c); 1801 dm_bufio_lock(c);
@@ -1955,7 +1955,7 @@ MODULE_PARM_DESC(max_cache_size_bytes, "Size of metadata cache");
1955module_param_named(max_age_seconds, dm_bufio_max_age, uint, S_IRUGO | S_IWUSR); 1955module_param_named(max_age_seconds, dm_bufio_max_age, uint, S_IRUGO | S_IWUSR);
1956MODULE_PARM_DESC(max_age_seconds, "Max age of a buffer in seconds"); 1956MODULE_PARM_DESC(max_age_seconds, "Max age of a buffer in seconds");
1957 1957
1958module_param_named(retain_bytes, dm_bufio_retain_bytes, uint, S_IRUGO | S_IWUSR); 1958module_param_named(retain_bytes, dm_bufio_retain_bytes, ulong, S_IRUGO | S_IWUSR);
1959MODULE_PARM_DESC(retain_bytes, "Try to keep at least this many bytes cached in memory"); 1959MODULE_PARM_DESC(retain_bytes, "Try to keep at least this many bytes cached in memory");
1960 1960
1961module_param_named(peak_allocated_bytes, dm_bufio_peak_allocated, ulong, S_IRUGO | S_IWUSR); 1961module_param_named(peak_allocated_bytes, dm_bufio_peak_allocated, ulong, S_IRUGO | S_IWUSR);