From: Julian Sun <sunjunchao@bytedance.com>
To: linux-block@vger.kernel.org, cgroups@vger.kernel.org,
linux-mm@kvack.org, linux-fsdevel@vger.kernel.org
Cc: 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: [PATCH v7 1/3] block: introduce bdev_flush_by_dev()
Date: Mon, 21 Sep 2026 20:06:56 +0800 [thread overview]
Message-ID: <20260921120658.1627992-2-sunjunchao@bytedance.com> (raw)
In-Reply-To: <20260921120658.1627992-1-sunjunchao@bytedance.com>
Add bdev_flush_by_dev() to submit page-cache writeback for a device
identified by dev_t without requiring callers to hold a persistent
device reference.
A subsequent patch will use this helper to flush foreign bdev mappings.
Signed-off-by: Julian Sun <sunjunchao@bytedance.com>
---
block/bdev.c | 18 ++++++++++++++++++
include/linux/blkdev.h | 4 ++++
2 files changed, 22 insertions(+)
diff --git a/block/bdev.c b/block/bdev.c
index cd8323083740..5cbf01a13a33 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -264,6 +264,24 @@ int sync_blockdev_nowait(struct block_device *bdev)
}
EXPORT_SYMBOL_GPL(sync_blockdev_nowait);
+/**
+ * bdev_flush_by_dev - attempt writeback of a block device's page cache
+ * @dev: target block device number
+ *
+ * May sleep while submitting writeback; does not wait for all I/O to complete.
+ */
+void bdev_flush_by_dev(dev_t dev)
+{
+ struct block_device *bdev;
+
+ bdev = blkdev_get_no_open(dev, false);
+ if (!bdev)
+ return;
+
+ sync_blockdev_nowait(bdev);
+ blkdev_put_no_open(bdev);
+}
+
/*
* Write out and wait upon all the dirty data associated with a block
* device via its mapping. Does not take the superblock lock.
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 4f7905c3412b..27afe3ff6fb5 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1710,6 +1710,7 @@ void invalidate_bdev(struct block_device *bdev);
int sync_blockdev(struct block_device *bdev);
int sync_blockdev_range(struct block_device *bdev, loff_t lstart, loff_t lend);
int sync_blockdev_nowait(struct block_device *bdev);
+void bdev_flush_by_dev(dev_t dev);
void sync_bdevs(bool wait);
void bdev_statx(const struct path *path, struct kstat *stat, u32 request_mask);
void printk_all_partitions(void);
@@ -1726,6 +1727,9 @@ static inline int sync_blockdev_nowait(struct block_device *bdev)
{
return 0;
}
+static inline void bdev_flush_by_dev(dev_t dev)
+{
+}
static inline void sync_bdevs(bool wait)
{
}
--
2.39.5
next prev parent reply other threads:[~2026-09-21 12:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-21 12:06 [PATCH v7 0/3] memcg,writeback: flush foreign bdev mappings separately Julian Sun
2026-09-21 12:06 ` Julian Sun [this message]
2026-09-21 12:06 ` [PATCH v7 2/3] memcg,writeback: flush foreign bdev mappings separately from owner wbs Julian Sun
2026-09-21 17:55 ` Tejun Heo
2026-09-22 9:52 ` Julian Sun
2026-09-21 12:06 ` [PATCH v7 3/3] writeback: record bdev targets in foreign writeback tracepoints 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=20260921120658.1627992-2-sunjunchao@bytedance.com \
--to=sunjunchao@bytedance.com \
--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=tj@kernel.org \
--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