2020-12-11 18:40:01

by Johannes Thumshirn

[permalink] [raw]
Subject: Re: [RFC PATCH v3 1/2] block: add simple copy support

On 11/12/2020 15:57, SelvaKumar S wrote:
[...]
> +int blk_copy_emulate(struct block_device *bdev, struct blk_copy_payload *payload,
> + gfp_t gfp_mask)
> +{
> + struct request_queue *q = bdev_get_queue(bdev);
> + struct bio *bio;
> + void *buf = NULL;
> + int i, nr_srcs, max_range_len, ret, cur_dest, cur_size;
> +
> + nr_srcs = payload->copy_range;
> + max_range_len = q->limits.max_copy_range_sectors << SECTOR_SHIFT;
> + cur_dest = payload->dest;
> + buf = kvmalloc(max_range_len, GFP_ATOMIC);

Why GFP_ATOMIC and not the passed in gfp_mask? Especially as this is a kvmalloc()
which has the potential to grow quite big.

> +int __blkdev_issue_copy(struct block_device *bdev, sector_t dest,
> + sector_t nr_srcs, struct range_entry *rlist, gfp_t gfp_mask,
> + int flags, struct bio **biop)
> +{

[...]

> + total_size = struct_size(payload, range, nr_srcs);
> + payload = kmalloc(total_size, GFP_ATOMIC | __GFP_NOWARN);

Same here.


> diff --git a/block/ioctl.c b/block/ioctl.c
> index 6b785181344f..a4a507d85e56 100644
> --- a/block/ioctl.c
> +++ b/block/ioctl.c
> @@ -142,6 +142,47 @@ static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode,
> GFP_KERNEL, flags);
> }
>
> +static int blk_ioctl_copy(struct block_device *bdev, fmode_t mode,
> + unsigned long arg, unsigned long flags)
> +{

[...]

> +
> + rlist = kmalloc_array(crange.nr_range, sizeof(*rlist),
> + GFP_ATOMIC | __GFP_NOWARN);

And here. I think this one can even be GFP_KERNEL.




2020-12-11 18:54:51

by Mikulas Patocka

[permalink] [raw]
Subject: Re: [RFC PATCH v3 1/2] block: add simple copy support



On Fri, 11 Dec 2020, Johannes Thumshirn wrote:

> On 11/12/2020 15:57, SelvaKumar S wrote:
> [...]
> > +int blk_copy_emulate(struct block_device *bdev, struct blk_copy_payload *payload,
> > + gfp_t gfp_mask)
> > +{
> > + struct request_queue *q = bdev_get_queue(bdev);
> > + struct bio *bio;
> > + void *buf = NULL;
> > + int i, nr_srcs, max_range_len, ret, cur_dest, cur_size;
> > +
> > + nr_srcs = payload->copy_range;
> > + max_range_len = q->limits.max_copy_range_sectors << SECTOR_SHIFT;
> > + cur_dest = payload->dest;
> > + buf = kvmalloc(max_range_len, GFP_ATOMIC);
>
> Why GFP_ATOMIC and not the passed in gfp_mask? Especially as this is a kvmalloc()
> which has the potential to grow quite big.

You are right, this is confusing.

There's this piece of code at the top of kvmalloc_node:
if ((flags & GFP_KERNEL) != GFP_KERNEL)
return kmalloc_node(size, flags, node);

So, when you use GFP_ATOMIC flag, it will always fall back to kmalloc.

Mikulas