2018-07-23 14:14:44

by Jia-Ju Bai

[permalink] [raw]
Subject: [PATCH] block: zram: Replace GFP_ATOMIC with GFP_KERNEL

read_from_bdev_async() and write_to_bdev() are never called in atomic
context. They call bio_alloc() with GFP_ATOMIC, which is not necessary.
GFP_ATOMIC can be replaced with GFP_KERNEL.

This is found by a static analysis tool named DCNS written by myself.

Signed-off-by: Jia-Ju Bai <[email protected]>
---
drivers/block/zram/zram_drv.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 0f3fadd71230..b958ed0b8c35 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -450,7 +450,7 @@ static int read_from_bdev_async(struct zram *zram, struct bio_vec *bvec,
{
struct bio *bio;

- bio = bio_alloc(GFP_ATOMIC, 1);
+ bio = bio_alloc(GFP_KERNEL, 1);
if (!bio)
return -ENOMEM;

@@ -538,7 +538,7 @@ static int write_to_bdev(struct zram *zram, struct bio_vec *bvec,
struct bio *bio;
unsigned long entry;

- bio = bio_alloc(GFP_ATOMIC, 1);
+ bio = bio_alloc(GFP_KERNEL, 1);
if (!bio)
return -ENOMEM;

--
2.17.0



2018-07-24 02:50:39

by Sergey Senozhatsky

[permalink] [raw]
Subject: Re: [PATCH] block: zram: Replace GFP_ATOMIC with GFP_KERNEL

On (07/23/18 22:13), Jia-Ju Bai wrote:
> read_from_bdev_async() and write_to_bdev() are never called in atomic
> context. They call bio_alloc() with GFP_ATOMIC, which is not necessary.
> GFP_ATOMIC can be replaced with GFP_KERNEL.

[..]

> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> index 0f3fadd71230..b958ed0b8c35 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -450,7 +450,7 @@ static int read_from_bdev_async(struct zram *zram, struct bio_vec *bvec,
> {
> struct bio *bio;
>
> - bio = bio_alloc(GFP_ATOMIC, 1);
> + bio = bio_alloc(GFP_KERNEL, 1);
> if (!bio)
> return -ENOMEM;
>
> @@ -538,7 +538,7 @@ static int write_to_bdev(struct zram *zram, struct bio_vec *bvec,
> struct bio *bio;
> unsigned long entry;
>
> - bio = bio_alloc(GFP_ATOMIC, 1);
> + bio = bio_alloc(GFP_KERNEL, 1);
> if (!bio)
> return -ENOMEM;

I think the intent here is different and is not related to atomic
contexts.

Consider the following
OMM -> swapout -> __zram_bvec_write() -> write_to_bdev() -> bio_alloc(GFP_KERNEL) -> [OOM?]

So maybe we can do a bit better than GFP_ATOMIC (NOIO, etc.), but in general,
I believe, we can't use GFP_KERNEL [at least in write_to_bdev()].

-ss