Commit 2a418157 authored by Matthew Wilcox (Oracle)'s avatar Matthew Wilcox (Oracle) Committed by Andrew Morton

buffer: pass GFP flags to folio_alloc_buffers()

Patch series "Add and use bdev_getblk()", v2.

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.


This patch (of 8):

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.

Link: https://lkml.kernel.org/r/20230914150011.843330-1-willy@infradead.org
Link: https://lkml.kernel.org/r/20230914150011.843330-2-willy@infradead.orgSigned-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Cc: Hui Zhu <teawater@antgroup.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 1b2b7a17
...@@ -915,16 +915,12 @@ int remove_inode_buffers(struct inode *inode) ...@@ -915,16 +915,12 @@ int remove_inode_buffers(struct inode *inode)
* which may not fail from ordinary buffer allocations. * which may not fail from ordinary buffer allocations.
*/ */
struct buffer_head *folio_alloc_buffers(struct folio *folio, unsigned long size, struct buffer_head *folio_alloc_buffers(struct folio *folio, unsigned long size,
bool retry) gfp_t gfp)
{ {
struct buffer_head *bh, *head; struct buffer_head *bh, *head;
gfp_t gfp = GFP_NOFS | __GFP_ACCOUNT;
long offset; long offset;
struct mem_cgroup *memcg, *old_memcg; struct mem_cgroup *memcg, *old_memcg;
if (retry)
gfp |= __GFP_NOFAIL;
/* The folio lock pins the memcg */ /* The folio lock pins the memcg */
memcg = folio_memcg(folio); memcg = folio_memcg(folio);
old_memcg = set_active_memcg(memcg); old_memcg = set_active_memcg(memcg);
...@@ -967,7 +963,11 @@ EXPORT_SYMBOL_GPL(folio_alloc_buffers); ...@@ -967,7 +963,11 @@ EXPORT_SYMBOL_GPL(folio_alloc_buffers);
struct buffer_head *alloc_page_buffers(struct page *page, unsigned long size, struct buffer_head *alloc_page_buffers(struct page *page, unsigned long size,
bool retry) 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); EXPORT_SYMBOL_GPL(alloc_page_buffers);
...@@ -1069,7 +1069,7 @@ grow_dev_page(struct block_device *bdev, sector_t block, ...@@ -1069,7 +1069,7 @@ grow_dev_page(struct block_device *bdev, sector_t block,
goto failed; 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 * 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, ...@@ -1644,8 +1644,9 @@ void folio_create_empty_buffers(struct folio *folio, unsigned long blocksize,
unsigned long b_state) unsigned long b_state)
{ {
struct buffer_head *bh, *head, *tail; 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; bh = head;
do { do {
bh->b_state |= b_state; bh->b_state |= b_state;
......
...@@ -198,7 +198,7 @@ void touch_buffer(struct buffer_head *bh); ...@@ -198,7 +198,7 @@ void touch_buffer(struct buffer_head *bh);
void folio_set_bh(struct buffer_head *bh, struct folio *folio, void folio_set_bh(struct buffer_head *bh, struct folio *folio,
unsigned long offset); unsigned long offset);
struct buffer_head *folio_alloc_buffers(struct folio *folio, unsigned long size, 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, struct buffer_head *alloc_page_buffers(struct page *page, unsigned long size,
bool retry); bool retry);
void create_empty_buffers(struct page *, unsigned long, void create_empty_buffers(struct page *, unsigned long,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment