Re: [PATCH 8/9] bcache: use kvmalloc

2017-01-30 Thread Michal Hocko
On Mon 30-01-17 17:47:31, Vlastimil Babka wrote:
> On 01/30/2017 10:49 AM, Michal Hocko wrote:
> > From: Michal Hocko 
> > 
> > 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
> 
> I don't see why separate patch, some of the conversions in 5/9 were quite
> similar (except comparing with PAGE_SIZE, not 64*PAGE_SIZE), but nevermind.

I just found it later so I kept it separate. It can be folded to 5/9 if
that makes more sense.
 
> > Cc: Kent Overstreet 
> > Signed-off-by: Michal Hocko 
> 
> Acked-by: Vlastimil Babka 

Thanks!

> > ---
> >  drivers/md/bcache/super.c | 8 ++--
> >  1 file changed, 2 insertions(+), 6 deletions(-)
> > 
> > diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
> > index 3a19cbc8b230..4cb6b88a1465 100644
> > --- a/drivers/md/bcache/super.c
> > +++ b/drivers/md/bcache/super.c
> > @@ -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;
> > 
> > 

-- 
Michal Hocko
SUSE Labs


Re: [PATCH 8/9] bcache: use kvmalloc

2017-01-30 Thread Vlastimil Babka

On 01/30/2017 10:49 AM, Michal Hocko wrote:

From: Michal Hocko 

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


I don't see why separate patch, some of the conversions in 5/9 were quite 
similar (except comparing with PAGE_SIZE, not 64*PAGE_SIZE), but nevermind.



Cc: Kent Overstreet 
Signed-off-by: Michal Hocko 


Acked-by: Vlastimil Babka 


---
 drivers/md/bcache/super.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index 3a19cbc8b230..4cb6b88a1465 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -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;






[PATCH 8/9] bcache: use kvmalloc

2017-01-30 Thread Michal Hocko
From: Michal Hocko 

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

Cc: Kent Overstreet 
Signed-off-by: Michal Hocko 
---
 drivers/md/bcache/super.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index 3a19cbc8b230..4cb6b88a1465 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -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;
 
-- 
2.11.0