drivers/md/bcache/super.c: use kvmalloc
authorMichal Hocko <mhocko@suse.com>
Mon, 8 May 2017 22:57:37 +0000 (15:57 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 9 May 2017 00:15:13 +0000 (17:15 -0700)
bcache_device_init uses kmalloc for small requests and vmalloc for those
which are larger than 64 pages.  This alone is a strange criterion.
Moreover kmalloc can fallback to vmalloc on the failure.  Let's simply
use kvmalloc instead as it knows how to handle the fallback properly

Link: http://lkml.kernel.org/r/20170306103327.2766-5-mhocko@kernel.org
Signed-off-by: Michal Hocko <mhocko@suse.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Cc: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/md/bcache/super.c

index 85e3f21c251485ecfd56780110896c05c8429cef..e57353e39168120dccdfe34965ac9360b58fd2db 100644 (file)
@@ -767,16 +767,12 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size,
        }
 
        n = d->nr_stripes * sizeof(atomic_t);
-       d->stripe_sectors_dirty = n < PAGE_SIZE << 6
-               ? kzalloc(n, GFP_KERNEL)
-               : vzalloc(n);
+       d->stripe_sectors_dirty = kvzalloc(n, GFP_KERNEL);
        if (!d->stripe_sectors_dirty)
                return -ENOMEM;
 
        n = BITS_TO_LONGS(d->nr_stripes) * sizeof(unsigned long);
-       d->full_dirty_stripes = n < PAGE_SIZE << 6
-               ? kzalloc(n, GFP_KERNEL)
-               : vzalloc(n);
+       d->full_dirty_stripes = kvzalloc(n, GFP_KERNEL);
        if (!d->full_dirty_stripes)
                return -ENOMEM;