Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Julian Sun <sunjunchao@bytedance.com>
Cc: linux-block@vger.kernel.org, cgroups@vger.kernel.org,
	linux-mm@kvack.org, linux-fsdevel@vger.kernel.org,
	axboe@kernel.dk, hannes@cmpxchg.org, mhocko@kernel.org,
	roman.gushchin@linux.dev, shakeel.butt@linux.dev,
	muchun.song@linux.dev, willy@infradead.org, jack@suse.cz,
	tj@kernel.org, akpm@linux-foundation.org
Subject: Re: [PATCH v6 1/3] block: introduce bdev_flush_by_dev()
Date: Sun, 20 Sep 2026 02:37:54 -1000	[thread overview]
Message-ID: <b40622ed67f77f3ff88d5772e7ea8476@kernel.org> (raw)
In-Reply-To: <20260917065759.2643940-2-sunjunchao@bytedance.com>

Hello, Julian.

On Thu, Sep 17, 2026 at 02:57:57PM +0800, Julian Sun wrote:
> +void bdev_flush_by_dev(dev_t dev)
> +{
> +	struct block_device *bdev;
> +
> +	bdev = blkdev_get_no_open(dev, false);
> +	if (!bdev)
> +		return;
> +
> +	/* Prevent the device from closing between the check and writeback. */
> +	if (mutex_trylock(&bdev->bd_disk->open_mutex)) {
> +		if (atomic_read(&bdev->bd_openers))
> +			sync_blockdev_nowait(bdev);
> +		mutex_unlock(&bdev->bd_disk->open_mutex);
> +	}
> +	blkdev_put_no_open(bdev);
> +}

This holds the disk's open_mutex across the whole writepages pass, so every
throttle-triggered flush blocks opens, closes and partition rescans on the
disk for as long as submission takes, which can be a while on a congested
device. bdev_release() syncs before taking the mutex for the same reason.

I don't think the mutex or the openers check is needed. If the device is
closed underneath, the last close syncs and truncates the mapping and
truncate waits for writeback, so a racing no-wait flush either finishes
first or finds nothing left. Holding just the reference from
blkdev_get_no_open() should be enough.

> +void bdev_flush_by_dev(dev_t dev);

The neighbors have !CONFIG_BLOCK stubs. The only caller is under
CGROUP_WRITEBACK so it builds either way, just noting for consistency.

Thanks.

--
tejun


  reply	other threads:[~2026-09-20 12:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17  6:57 [PATCH v6 0/3] memcg,writeback: flush foreign bdev mappings separately Julian Sun
2026-09-17  6:57 ` [PATCH v6 1/3] block: introduce bdev_flush_by_dev() Julian Sun
2026-09-20 12:37   ` Tejun Heo [this message]
2026-09-17  7:01 ` [PATCH v6 2/3] memcg,writeback: flush foreign bdev mappings separately from owner wbs Julian Sun
2026-09-20 12:37   ` Tejun Heo
2026-09-17  7:01 ` [PATCH v6 3/3] writeback: record bdev targets in foreign writeback tracepoints Julian Sun
2026-09-17 22:53 ` [PATCH v6 0/3] memcg,writeback: flush foreign bdev mappings separately Andrew Morton
2026-09-18  4:57   ` Julian Sun
2026-09-18  5:12     ` Andrew Morton
2026-09-21 11:55 ` [PATCH v7 " Julian Sun

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=b40622ed67f77f3ff88d5772e7ea8476@kernel.org \
    --to=tj@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=cgroups@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=jack@suse.cz \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=muchun.song@linux.dev \
    --cc=roman.gushchin@linux.dev \
    --cc=shakeel.butt@linux.dev \
    --cc=sunjunchao@bytedance.com \
    --cc=willy@infradead.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