public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Chaitanya Kulkarni <chaitanyak@nvidia.com>
To: Keith Busch <kbusch@meta.com>
Cc: "axboe@kernel.dk" <axboe@kernel.dk>,
	Keith Busch <kbusch@kernel.org>,
	"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>
Subject: Re: [PATCH] brd: implement discard support
Date: Mon, 29 Apr 2024 19:54:05 +0000	[thread overview]
Message-ID: <c611759b-7d26-45c2-9655-33eb7bb69024@nvidia.com> (raw)
In-Reply-To: <20240429102308.147627-1-kbusch@meta.com>

On 4/29/24 03:23, Keith Busch wrote:
> From: Keith Busch <kbusch@kernel.org>
>
> The ramdisk memory utilization can only go up when data is written to
> new pages. Implement discard to provide the possibility to reduce memory
> usage for pages no longer in use. Aligned discards will free the
> associated pages, if any, and determinisitically return zeroed data
> until written again.
>
> Signed-off-by: Keith Busch <kbusch@kernel.org>
> ---
>   drivers/block/brd.c | 26 ++++++++++++++++++++++++++
>   1 file changed, 26 insertions(+)
>
> diff --git a/drivers/block/brd.c b/drivers/block/brd.c
> index e322cef6596bf..e741b0c3a4f79 100644
> --- a/drivers/block/brd.c
> +++ b/drivers/block/brd.c
> @@ -240,6 +240,23 @@ static int brd_do_bvec(struct brd_device *brd, struct page *page,
>   	return err;
>   }
>   
> +static void brd_do_discard(struct brd_device *brd, sector_t sector, u32 size)
> +{
> +	sector_t aligned_sector = (sector + PAGE_SECTORS) & ~PAGE_SECTORS;
> +	struct page *page;
> +
> +	size -= (aligned_sector - sector) * SECTOR_SIZE;
> +	xa_lock(&brd->brd_pages);
> +	while (size >= PAGE_SIZE && aligned_sector < rd_size * 2) {
> +		page = __xa_erase(&brd->brd_pages, aligned_sector >> PAGE_SECTORS_SHIFT);

overly long line ?

> +		if (page)
> +			__free_page(page);
> +		aligned_sector += PAGE_SECTORS;
> +		size -= PAGE_SIZE;
> +	}
> +	xa_unlock(&brd->brd_pages);
> +}
> +
>   static void brd_submit_bio(struct bio *bio)
>   {
>   	struct brd_device *brd = bio->bi_bdev->bd_disk->private_data;
> @@ -247,6 +264,12 @@ static void brd_submit_bio(struct bio *bio)
>   	struct bio_vec bvec;
>   	struct bvec_iter iter;
>   
> +	if (unlikely(op_is_discard(bio->bi_opf))) {

I've been told that unlikely should not be used with discard as it is
bad for discard workloads, if that is still true, then can you please
remove unlikely ?

Also, if you are doing this can you please also add support for
write-zeroes for the sake of completeness ? unless that support is
not desired for brd ...

-ck



  reply	other threads:[~2024-04-29 19:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-29 10:23 [PATCH] brd: implement discard support Keith Busch
2024-04-29 19:54 ` Chaitanya Kulkarni [this message]
2024-04-30  7:46   ` Keith Busch
2024-05-14  3:48 ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c611759b-7d26-45c2-9655-33eb7bb69024@nvidia.com \
    --to=chaitanyak@nvidia.com \
    --cc=axboe@kernel.dk \
    --cc=kbusch@kernel.org \
    --cc=kbusch@meta.com \
    --cc=linux-block@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox