* [PATCH v2 0/8] Add and use bdev_getblk()
@ 2023-09-14 15:00 Matthew Wilcox (Oracle)
2023-09-14 15:00 ` [PATCH v2 1/8] buffer: Pass GFP flags to folio_alloc_buffers() Matthew Wilcox (Oracle)
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: Matthew Wilcox (Oracle) @ 2023-09-14 15:00 UTC (permalink / raw)
To: akpm; +Cc: Matthew Wilcox (Oracle), Hui Zhu, linux-fsdevel, linux-ext4
This patch series fixes a bug reported by Hui Zhu; see proposed
patches v1 and v2:
https://lore.kernel.org/linux-fsdevel/20230811035705.3296-1-teawaterz@linux.alibaba.com/
https://lore.kernel.org/linux-fsdevel/20230811071519.1094-1-teawaterz@linux.alibaba.com/
I decided to go in a rather different direction for this fix, and
fix a related problem at the same time. I don't think there's any
urgency to rush this into Linus' tree, nor have I marked it for stable.
Reasonable people may disagree.
For v2, I fixed a bug around the use of __GFP_ACCOUNT, and Jan Kara
pushed me into making __getblk_gfp() disappear entirely (patches 5-8).
It's currently churning through xfstests and has got up to generic/048.
Matthew Wilcox (Oracle) (8):
buffer: Pass GFP flags to folio_alloc_buffers()
buffer: Hoist GFP flags from grow_dev_page() to __getblk_gfp()
ext4: Use bdev_getblk() to avoid memory reclaim in readahead path
buffer: Use bdev_getblk() to avoid memory reclaim in readahead path
buffer: Convert getblk_unmovable() and __getblk() to use bdev_getblk()
buffer: Convert sb_getblk() to call __getblk()
ext4: Call bdev_getblk() from sb_getblk_gfp()
buffer: Remove __getblk_gfp()
fs/buffer.c | 79 ++++++++++++++++++++-----------------
fs/ext4/super.c | 13 ++++--
include/linux/buffer_head.h | 53 ++++++++++++++-----------
3 files changed, 83 insertions(+), 62 deletions(-)
--
2.40.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 1/8] buffer: Pass GFP flags to folio_alloc_buffers()
2023-09-14 15:00 [PATCH v2 0/8] Add and use bdev_getblk() Matthew Wilcox (Oracle)
@ 2023-09-14 15:00 ` Matthew Wilcox (Oracle)
2023-09-14 15:00 ` [PATCH v2 2/8] buffer: Hoist GFP flags from grow_dev_page() to __getblk_gfp() Matthew Wilcox (Oracle)
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Matthew Wilcox (Oracle) @ 2023-09-14 15:00 UTC (permalink / raw)
To: akpm; +Cc: Matthew Wilcox (Oracle), Hui Zhu, linux-fsdevel, linux-ext4
Instead of creating entirely new flags, inherit them from grow_dev_page().
The other callers create the same flags that this function used to create.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
fs/buffer.c | 17 +++++++++--------
include/linux/buffer_head.h | 2 +-
2 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/fs/buffer.c b/fs/buffer.c
index 2379564e5aea..a01b00d48de2 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -915,16 +915,12 @@ int remove_inode_buffers(struct inode *inode)
* which may not fail from ordinary buffer allocations.
*/
struct buffer_head *folio_alloc_buffers(struct folio *folio, unsigned long size,
- bool retry)
+ gfp_t gfp)
{
struct buffer_head *bh, *head;
- gfp_t gfp = GFP_NOFS | __GFP_ACCOUNT;
long offset;
struct mem_cgroup *memcg, *old_memcg;
- if (retry)
- gfp |= __GFP_NOFAIL;
-
/* The folio lock pins the memcg */
memcg = folio_memcg(folio);
old_memcg = set_active_memcg(memcg);
@@ -967,7 +963,11 @@ EXPORT_SYMBOL_GPL(folio_alloc_buffers);
struct buffer_head *alloc_page_buffers(struct page *page, unsigned long size,
bool retry)
{
- return folio_alloc_buffers(page_folio(page), size, retry);
+ gfp_t gfp = GFP_NOFS | __GFP_ACCOUNT;
+ if (retry)
+ gfp |= __GFP_NOFAIL;
+
+ return folio_alloc_buffers(page_folio(page), size, gfp);
}
EXPORT_SYMBOL_GPL(alloc_page_buffers);
@@ -1069,7 +1069,7 @@ grow_dev_page(struct block_device *bdev, sector_t block,
goto failed;
}
- bh = folio_alloc_buffers(folio, size, true);
+ bh = folio_alloc_buffers(folio, size, gfp_mask | __GFP_ACCOUNT);
/*
* Link the folio to the buffers and initialise them. Take the
@@ -1644,8 +1644,9 @@ void folio_create_empty_buffers(struct folio *folio, unsigned long blocksize,
unsigned long b_state)
{
struct buffer_head *bh, *head, *tail;
+ gfp_t gfp = GFP_NOFS | __GFP_ACCOUNT | __GFP_NOFAIL;
- head = folio_alloc_buffers(folio, blocksize, true);
+ head = folio_alloc_buffers(folio, blocksize, gfp);
bh = head;
do {
bh->b_state |= b_state;
diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h
index 4ede47649a81..79131e9941e7 100644
--- a/include/linux/buffer_head.h
+++ b/include/linux/buffer_head.h
@@ -195,7 +195,7 @@ void touch_buffer(struct buffer_head *bh);
void folio_set_bh(struct buffer_head *bh, struct folio *folio,
unsigned long offset);
struct buffer_head *folio_alloc_buffers(struct folio *folio, unsigned long size,
- bool retry);
+ gfp_t gfp);
struct buffer_head *alloc_page_buffers(struct page *page, unsigned long size,
bool retry);
void create_empty_buffers(struct page *, unsigned long,
--
2.40.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 2/8] buffer: Hoist GFP flags from grow_dev_page() to __getblk_gfp()
2023-09-14 15:00 [PATCH v2 0/8] Add and use bdev_getblk() Matthew Wilcox (Oracle)
2023-09-14 15:00 ` [PATCH v2 1/8] buffer: Pass GFP flags to folio_alloc_buffers() Matthew Wilcox (Oracle)
@ 2023-09-14 15:00 ` Matthew Wilcox (Oracle)
2023-09-14 15:00 ` [PATCH v2 3/8] ext4: Use bdev_getblk() to avoid memory reclaim in readahead path Matthew Wilcox (Oracle)
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Matthew Wilcox (Oracle) @ 2023-09-14 15:00 UTC (permalink / raw)
To: akpm; +Cc: Matthew Wilcox (Oracle), Hui Zhu, linux-fsdevel, linux-ext4
grow_dev_page() is only called by grow_buffers(). grow_buffers()
is only called by __getblk_slow() and __getblk_slow() is only called
from __getblk_gfp(), so it is safe to move the GFP flags setting
all the way up. With that done, add a new bdev_getblk() entry point
that leaves the GFP flags the way the caller specified them.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
fs/buffer.c | 60 ++++++++++++++++++++++++-------------
include/linux/buffer_head.h | 2 ++
2 files changed, 41 insertions(+), 21 deletions(-)
diff --git a/fs/buffer.c b/fs/buffer.c
index a01b00d48de2..3fe293c9f3ca 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -1043,20 +1043,11 @@ grow_dev_page(struct block_device *bdev, sector_t block,
struct buffer_head *bh;
sector_t end_block;
int ret = 0;
- gfp_t gfp_mask;
-
- gfp_mask = mapping_gfp_constraint(inode->i_mapping, ~__GFP_FS) | gfp;
-
- /*
- * XXX: __getblk_slow() can not really deal with failure and
- * will endlessly loop on improvised global reclaim. Prefer
- * looping in the allocator rather than here, at least that
- * code knows what it's doing.
- */
- gfp_mask |= __GFP_NOFAIL;
folio = __filemap_get_folio(inode->i_mapping, index,
- FGP_LOCK | FGP_ACCESSED | FGP_CREAT, gfp_mask);
+ FGP_LOCK | FGP_ACCESSED | FGP_CREAT, gfp);
+ if (IS_ERR(folio))
+ return PTR_ERR(folio);
bh = folio_buffers(folio);
if (bh) {
@@ -1069,7 +1060,9 @@ grow_dev_page(struct block_device *bdev, sector_t block,
goto failed;
}
- bh = folio_alloc_buffers(folio, size, gfp_mask | __GFP_ACCOUNT);
+ bh = folio_alloc_buffers(folio, size, gfp | __GFP_ACCOUNT);
+ if (!bh)
+ goto failed;
/*
* Link the folio to the buffers and initialise them. Take the
@@ -1420,24 +1413,49 @@ __find_get_block(struct block_device *bdev, sector_t block, unsigned size)
}
EXPORT_SYMBOL(__find_get_block);
+/**
+ * bdev_getblk - Get a buffer_head in a block device's buffer cache.
+ * @bdev: The block device.
+ * @block: The block number.
+ * @size: The size of buffer_heads for this @bdev.
+ * @gfp: The memory allocation flags to use.
+ *
+ * In contrast to __getblk_gfp(), the @gfp flags must be all of the flags;
+ * they are not augmented with the mapping's GFP flags.
+ *
+ * Return: The buffer head, or NULL if memory could not be allocated.
+ */
+struct buffer_head *bdev_getblk(struct block_device *bdev, sector_t block,
+ unsigned size, gfp_t gfp)
+{
+ struct buffer_head *bh = __find_get_block(bdev, block, size);
+
+ might_alloc(gfp);
+ if (bh)
+ return bh;
+
+ return __getblk_slow(bdev, block, size, gfp);
+}
+EXPORT_SYMBOL(bdev_getblk);
+
/*
* __getblk_gfp() will locate (and, if necessary, create) the buffer_head
* which corresponds to the passed block_device, block and size. The
* returned buffer has its reference count incremented.
- *
- * __getblk_gfp() will lock up the machine if grow_dev_page's
- * try_to_free_buffers() attempt is failing. FIXME, perhaps?
*/
struct buffer_head *
__getblk_gfp(struct block_device *bdev, sector_t block,
unsigned size, gfp_t gfp)
{
- struct buffer_head *bh = __find_get_block(bdev, block, size);
+ gfp |= mapping_gfp_constraint(bdev->bd_inode->i_mapping, ~__GFP_FS);
- might_sleep();
- if (bh == NULL)
- bh = __getblk_slow(bdev, block, size, gfp);
- return bh;
+ /*
+ * Prefer looping in the allocator rather than here, at least that
+ * code knows what it's doing.
+ */
+ gfp |= __GFP_NOFAIL;
+
+ return bdev_getblk(bdev, block, size, gfp);
}
EXPORT_SYMBOL(__getblk_gfp);
diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h
index 79131e9941e7..e389f0fbba5a 100644
--- a/include/linux/buffer_head.h
+++ b/include/linux/buffer_head.h
@@ -224,6 +224,8 @@ void __wait_on_buffer(struct buffer_head *);
wait_queue_head_t *bh_waitq_head(struct buffer_head *bh);
struct buffer_head *__find_get_block(struct block_device *bdev, sector_t block,
unsigned size);
+struct buffer_head *bdev_getblk(struct block_device *bdev, sector_t block,
+ unsigned size, gfp_t gfp);
struct buffer_head *__getblk_gfp(struct block_device *bdev, sector_t block,
unsigned size, gfp_t gfp);
void __brelse(struct buffer_head *);
--
2.40.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 3/8] ext4: Use bdev_getblk() to avoid memory reclaim in readahead path
2023-09-14 15:00 [PATCH v2 0/8] Add and use bdev_getblk() Matthew Wilcox (Oracle)
2023-09-14 15:00 ` [PATCH v2 1/8] buffer: Pass GFP flags to folio_alloc_buffers() Matthew Wilcox (Oracle)
2023-09-14 15:00 ` [PATCH v2 2/8] buffer: Hoist GFP flags from grow_dev_page() to __getblk_gfp() Matthew Wilcox (Oracle)
@ 2023-09-14 15:00 ` Matthew Wilcox (Oracle)
2023-09-14 15:00 ` [PATCH v2 4/8] buffer: " Matthew Wilcox (Oracle)
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Matthew Wilcox (Oracle) @ 2023-09-14 15:00 UTC (permalink / raw)
To: akpm; +Cc: Matthew Wilcox (Oracle), Hui Zhu, linux-fsdevel, linux-ext4
sb_getblk_gfp adds __GFP_NOFAIL, which is unnecessary for readahead;
we're quite comfortable with the possibility that we may not get a bh
back. Switch to bdev_getblk() which does not include __GFP_NOFAIL.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reported-by: Hui Zhu <teawater@antgroup.com>
Link: https://lore.kernel.org/linux-fsdevel/20230811035705.3296-1-teawaterz@linux.alibaba.com/
---
fs/ext4/super.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 38217422f938..8d6c82239368 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -255,7 +255,8 @@ struct buffer_head *ext4_sb_bread_unmovable(struct super_block *sb,
void ext4_sb_breadahead_unmovable(struct super_block *sb, sector_t block)
{
- struct buffer_head *bh = sb_getblk_gfp(sb, block, 0);
+ struct buffer_head *bh = bdev_getblk(sb->s_bdev, block,
+ sb->s_blocksize, GFP_NOWAIT);
if (likely(bh)) {
if (trylock_buffer(bh))
--
2.40.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 4/8] buffer: Use bdev_getblk() to avoid memory reclaim in readahead path
2023-09-14 15:00 [PATCH v2 0/8] Add and use bdev_getblk() Matthew Wilcox (Oracle)
` (2 preceding siblings ...)
2023-09-14 15:00 ` [PATCH v2 3/8] ext4: Use bdev_getblk() to avoid memory reclaim in readahead path Matthew Wilcox (Oracle)
@ 2023-09-14 15:00 ` Matthew Wilcox (Oracle)
2023-09-14 15:00 ` [PATCH v2 5/8] buffer: Convert getblk_unmovable() and __getblk() to use bdev_getblk() Matthew Wilcox (Oracle)
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Matthew Wilcox (Oracle) @ 2023-09-14 15:00 UTC (permalink / raw)
To: akpm; +Cc: Matthew Wilcox (Oracle), Hui Zhu, linux-fsdevel, linux-ext4
__getblk() adds __GFP_NOFAIL, which is unnecessary for readahead;
we're quite comfortable with the possibility that we may not get a bh
back. Switch to bdev_getblk() which does not include __GFP_NOFAIL.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
fs/buffer.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/fs/buffer.c b/fs/buffer.c
index 3fe293c9f3ca..58546bfd8903 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -1464,7 +1464,9 @@ EXPORT_SYMBOL(__getblk_gfp);
*/
void __breadahead(struct block_device *bdev, sector_t block, unsigned size)
{
- struct buffer_head *bh = __getblk(bdev, block, size);
+ struct buffer_head *bh = bdev_getblk(bdev, block, size,
+ GFP_NOWAIT | __GFP_MOVABLE);
+
if (likely(bh)) {
bh_readahead(bh, REQ_RAHEAD);
brelse(bh);
--
2.40.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 5/8] buffer: Convert getblk_unmovable() and __getblk() to use bdev_getblk()
2023-09-14 15:00 [PATCH v2 0/8] Add and use bdev_getblk() Matthew Wilcox (Oracle)
` (3 preceding siblings ...)
2023-09-14 15:00 ` [PATCH v2 4/8] buffer: " Matthew Wilcox (Oracle)
@ 2023-09-14 15:00 ` Matthew Wilcox (Oracle)
2023-09-14 15:00 ` [PATCH v2 6/8] buffer: Convert sb_getblk() to call __getblk() Matthew Wilcox (Oracle)
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Matthew Wilcox (Oracle) @ 2023-09-14 15:00 UTC (permalink / raw)
To: akpm; +Cc: Matthew Wilcox (Oracle), Hui Zhu, linux-fsdevel, linux-ext4
Move these two functions up in the file for the benefit of the next patch,
and pass in all of the GFP flags to use instead of the partial GFP flags
used by __getblk_gfp().
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
include/linux/buffer_head.h | 36 ++++++++++++++++++++++--------------
1 file changed, 22 insertions(+), 14 deletions(-)
diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h
index e389f0fbba5a..e92f604a423e 100644
--- a/include/linux/buffer_head.h
+++ b/include/linux/buffer_head.h
@@ -337,6 +337,28 @@ sb_breadahead(struct super_block *sb, sector_t block)
__breadahead(sb->s_bdev, block, sb->s_blocksize);
}
+static inline struct buffer_head *getblk_unmovable(struct block_device *bdev,
+ sector_t block, unsigned size)
+{
+ gfp_t gfp;
+
+ gfp = mapping_gfp_constraint(bdev->bd_inode->i_mapping, ~__GFP_FS);
+ gfp |= __GFP_NOFAIL;
+
+ return bdev_getblk(bdev, block, size, gfp);
+}
+
+static inline struct buffer_head *__getblk(struct block_device *bdev,
+ sector_t block, unsigned size)
+{
+ gfp_t gfp;
+
+ gfp = mapping_gfp_constraint(bdev->bd_inode->i_mapping, ~__GFP_FS);
+ gfp |= __GFP_MOVABLE | __GFP_NOFAIL;
+
+ return bdev_getblk(bdev, block, size, gfp);
+}
+
static inline struct buffer_head *
sb_getblk(struct super_block *sb, sector_t block)
{
@@ -384,20 +406,6 @@ static inline void lock_buffer(struct buffer_head *bh)
__lock_buffer(bh);
}
-static inline struct buffer_head *getblk_unmovable(struct block_device *bdev,
- sector_t block,
- unsigned size)
-{
- return __getblk_gfp(bdev, block, size, 0);
-}
-
-static inline struct buffer_head *__getblk(struct block_device *bdev,
- sector_t block,
- unsigned size)
-{
- return __getblk_gfp(bdev, block, size, __GFP_MOVABLE);
-}
-
static inline void bh_readahead(struct buffer_head *bh, blk_opf_t op_flags)
{
if (!buffer_uptodate(bh) && trylock_buffer(bh)) {
--
2.40.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 6/8] buffer: Convert sb_getblk() to call __getblk()
2023-09-14 15:00 [PATCH v2 0/8] Add and use bdev_getblk() Matthew Wilcox (Oracle)
` (4 preceding siblings ...)
2023-09-14 15:00 ` [PATCH v2 5/8] buffer: Convert getblk_unmovable() and __getblk() to use bdev_getblk() Matthew Wilcox (Oracle)
@ 2023-09-14 15:00 ` Matthew Wilcox (Oracle)
2023-09-14 15:00 ` [PATCH v2 7/8] ext4: Call bdev_getblk() from sb_getblk_gfp() Matthew Wilcox (Oracle)
2023-09-14 15:00 ` [PATCH v2 8/8] buffer: Remove __getblk_gfp() Matthew Wilcox (Oracle)
7 siblings, 0 replies; 9+ messages in thread
From: Matthew Wilcox (Oracle) @ 2023-09-14 15:00 UTC (permalink / raw)
To: akpm; +Cc: Matthew Wilcox (Oracle), Hui Zhu, linux-fsdevel, linux-ext4
Now that __getblk() is in the right place in the file, it is
trivial to call it from sb_getblk().
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
include/linux/buffer_head.h | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h
index e92f604a423e..9ea4b6337251 100644
--- a/include/linux/buffer_head.h
+++ b/include/linux/buffer_head.h
@@ -359,13 +359,12 @@ static inline struct buffer_head *__getblk(struct block_device *bdev,
return bdev_getblk(bdev, block, size, gfp);
}
-static inline struct buffer_head *
-sb_getblk(struct super_block *sb, sector_t block)
+static inline struct buffer_head *sb_getblk(struct super_block *sb,
+ sector_t block)
{
- return __getblk_gfp(sb->s_bdev, block, sb->s_blocksize, __GFP_MOVABLE);
+ return __getblk(sb->s_bdev, block, sb->s_blocksize);
}
-
static inline struct buffer_head *
sb_getblk_gfp(struct super_block *sb, sector_t block, gfp_t gfp)
{
--
2.40.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 7/8] ext4: Call bdev_getblk() from sb_getblk_gfp()
2023-09-14 15:00 [PATCH v2 0/8] Add and use bdev_getblk() Matthew Wilcox (Oracle)
` (5 preceding siblings ...)
2023-09-14 15:00 ` [PATCH v2 6/8] buffer: Convert sb_getblk() to call __getblk() Matthew Wilcox (Oracle)
@ 2023-09-14 15:00 ` Matthew Wilcox (Oracle)
2023-09-14 15:00 ` [PATCH v2 8/8] buffer: Remove __getblk_gfp() Matthew Wilcox (Oracle)
7 siblings, 0 replies; 9+ messages in thread
From: Matthew Wilcox (Oracle) @ 2023-09-14 15:00 UTC (permalink / raw)
To: akpm; +Cc: Matthew Wilcox (Oracle), Hui Zhu, linux-fsdevel, linux-ext4
Most of the callers of sb_getblk_gfp() already assumed that they were
passing the entire GFP flags to use. Fix up the two callers that didn't,
and remove the __GFP_NOFAIL from them since they both appear to correctly
handle failure.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
fs/ext4/super.c | 10 ++++++++--
include/linux/buffer_head.h | 6 +++---
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 8d6c82239368..2684ed69403e 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -244,13 +244,19 @@ static struct buffer_head *__ext4_sb_bread_gfp(struct super_block *sb,
struct buffer_head *ext4_sb_bread(struct super_block *sb, sector_t block,
blk_opf_t op_flags)
{
- return __ext4_sb_bread_gfp(sb, block, op_flags, __GFP_MOVABLE);
+ gfp_t gfp = mapping_gfp_constraint(sb->s_bdev->bd_inode->i_mapping,
+ ~__GFP_FS) | __GFP_MOVABLE;
+
+ return __ext4_sb_bread_gfp(sb, block, op_flags, gfp);
}
struct buffer_head *ext4_sb_bread_unmovable(struct super_block *sb,
sector_t block)
{
- return __ext4_sb_bread_gfp(sb, block, 0, 0);
+ gfp_t gfp = mapping_gfp_constraint(sb->s_bdev->bd_inode->i_mapping,
+ ~__GFP_FS);
+
+ return __ext4_sb_bread_gfp(sb, block, 0, gfp);
}
void ext4_sb_breadahead_unmovable(struct super_block *sb, sector_t block)
diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h
index 9ea4b6337251..5372deef732e 100644
--- a/include/linux/buffer_head.h
+++ b/include/linux/buffer_head.h
@@ -365,10 +365,10 @@ static inline struct buffer_head *sb_getblk(struct super_block *sb,
return __getblk(sb->s_bdev, block, sb->s_blocksize);
}
-static inline struct buffer_head *
-sb_getblk_gfp(struct super_block *sb, sector_t block, gfp_t gfp)
+static inline struct buffer_head *sb_getblk_gfp(struct super_block *sb,
+ sector_t block, gfp_t gfp)
{
- return __getblk_gfp(sb->s_bdev, block, sb->s_blocksize, gfp);
+ return bdev_getblk(sb->s_bdev, block, sb->s_blocksize, gfp);
}
static inline struct buffer_head *
--
2.40.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 8/8] buffer: Remove __getblk_gfp()
2023-09-14 15:00 [PATCH v2 0/8] Add and use bdev_getblk() Matthew Wilcox (Oracle)
` (6 preceding siblings ...)
2023-09-14 15:00 ` [PATCH v2 7/8] ext4: Call bdev_getblk() from sb_getblk_gfp() Matthew Wilcox (Oracle)
@ 2023-09-14 15:00 ` Matthew Wilcox (Oracle)
7 siblings, 0 replies; 9+ messages in thread
From: Matthew Wilcox (Oracle) @ 2023-09-14 15:00 UTC (permalink / raw)
To: akpm; +Cc: Matthew Wilcox (Oracle), Hui Zhu, linux-fsdevel, linux-ext4
Inline it into __bread_gfp().
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
fs/buffer.c | 36 +++++++++++-------------------------
include/linux/buffer_head.h | 2 --
2 files changed, 11 insertions(+), 27 deletions(-)
diff --git a/fs/buffer.c b/fs/buffer.c
index 58546bfd8903..ad2526dd7cb4 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -1420,9 +1420,6 @@ EXPORT_SYMBOL(__find_get_block);
* @size: The size of buffer_heads for this @bdev.
* @gfp: The memory allocation flags to use.
*
- * In contrast to __getblk_gfp(), the @gfp flags must be all of the flags;
- * they are not augmented with the mapping's GFP flags.
- *
* Return: The buffer head, or NULL if memory could not be allocated.
*/
struct buffer_head *bdev_getblk(struct block_device *bdev, sector_t block,
@@ -1438,27 +1435,6 @@ struct buffer_head *bdev_getblk(struct block_device *bdev, sector_t block,
}
EXPORT_SYMBOL(bdev_getblk);
-/*
- * __getblk_gfp() will locate (and, if necessary, create) the buffer_head
- * which corresponds to the passed block_device, block and size. The
- * returned buffer has its reference count incremented.
- */
-struct buffer_head *
-__getblk_gfp(struct block_device *bdev, sector_t block,
- unsigned size, gfp_t gfp)
-{
- gfp |= mapping_gfp_constraint(bdev->bd_inode->i_mapping, ~__GFP_FS);
-
- /*
- * Prefer looping in the allocator rather than here, at least that
- * code knows what it's doing.
- */
- gfp |= __GFP_NOFAIL;
-
- return bdev_getblk(bdev, block, size, gfp);
-}
-EXPORT_SYMBOL(__getblk_gfp);
-
/*
* Do async read-ahead on a buffer..
*/
@@ -1490,7 +1466,17 @@ struct buffer_head *
__bread_gfp(struct block_device *bdev, sector_t block,
unsigned size, gfp_t gfp)
{
- struct buffer_head *bh = __getblk_gfp(bdev, block, size, gfp);
+ struct buffer_head *bh;
+
+ gfp |= mapping_gfp_constraint(bdev->bd_inode->i_mapping, ~__GFP_FS);
+
+ /*
+ * Prefer looping in the allocator rather than here, at least that
+ * code knows what it's doing.
+ */
+ gfp |= __GFP_NOFAIL;
+
+ bh = bdev_getblk(bdev, block, size, gfp);
if (likely(bh) && !buffer_uptodate(bh))
bh = __bread_slow(bh);
diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h
index 5372deef732e..5f9208c3fa73 100644
--- a/include/linux/buffer_head.h
+++ b/include/linux/buffer_head.h
@@ -226,8 +226,6 @@ struct buffer_head *__find_get_block(struct block_device *bdev, sector_t block,
unsigned size);
struct buffer_head *bdev_getblk(struct block_device *bdev, sector_t block,
unsigned size, gfp_t gfp);
-struct buffer_head *__getblk_gfp(struct block_device *bdev, sector_t block,
- unsigned size, gfp_t gfp);
void __brelse(struct buffer_head *);
void __bforget(struct buffer_head *);
void __breadahead(struct block_device *, sector_t block, unsigned int size);
--
2.40.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2023-09-14 15:00 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-14 15:00 [PATCH v2 0/8] Add and use bdev_getblk() Matthew Wilcox (Oracle)
2023-09-14 15:00 ` [PATCH v2 1/8] buffer: Pass GFP flags to folio_alloc_buffers() Matthew Wilcox (Oracle)
2023-09-14 15:00 ` [PATCH v2 2/8] buffer: Hoist GFP flags from grow_dev_page() to __getblk_gfp() Matthew Wilcox (Oracle)
2023-09-14 15:00 ` [PATCH v2 3/8] ext4: Use bdev_getblk() to avoid memory reclaim in readahead path Matthew Wilcox (Oracle)
2023-09-14 15:00 ` [PATCH v2 4/8] buffer: " Matthew Wilcox (Oracle)
2023-09-14 15:00 ` [PATCH v2 5/8] buffer: Convert getblk_unmovable() and __getblk() to use bdev_getblk() Matthew Wilcox (Oracle)
2023-09-14 15:00 ` [PATCH v2 6/8] buffer: Convert sb_getblk() to call __getblk() Matthew Wilcox (Oracle)
2023-09-14 15:00 ` [PATCH v2 7/8] ext4: Call bdev_getblk() from sb_getblk_gfp() Matthew Wilcox (Oracle)
2023-09-14 15:00 ` [PATCH v2 8/8] buffer: Remove __getblk_gfp() Matthew Wilcox (Oracle)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).