Skip to content

Commit c71124a

Browse files
Panky-codesakpm00
authored andcommitted
buffer: add folio_alloc_buffers() helper
Folio version of alloc_page_buffers() helper. This is required to convert create_page_buffers() to folio_create_buffers() later in the series. alloc_page_buffers() has been modified to call folio_alloc_buffers() which adds one call to compound_head() but folio_alloc_buffers() removes one call to compound_head() compared to the existing alloc_page_buffers() implementation. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Pankaj Raghav <[email protected]> Reviewed-by: Matthew Wilcox (Oracle) <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Cc: Alexander Viro <[email protected]> Cc: Christian Brauner <[email protected]> Cc: Luis Chamberlain <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 465e5e6 commit c71124a

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

fs/buffer.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -843,16 +843,16 @@ int remove_inode_buffers(struct inode *inode)
843843
}
844844

845845
/*
846-
* Create the appropriate buffers when given a page for data area and
846+
* Create the appropriate buffers when given a folio for data area and
847847
* the size of each buffer.. Use the bh->b_this_page linked list to
848848
* follow the buffers created. Return NULL if unable to create more
849849
* buffers.
850850
*
851851
* The retry flag is used to differentiate async IO (paging, swapping)
852852
* which may not fail from ordinary buffer allocations.
853853
*/
854-
struct buffer_head *alloc_page_buffers(struct page *page, unsigned long size,
855-
bool retry)
854+
struct buffer_head *folio_alloc_buffers(struct folio *folio, unsigned long size,
855+
bool retry)
856856
{
857857
struct buffer_head *bh, *head;
858858
gfp_t gfp = GFP_NOFS | __GFP_ACCOUNT;
@@ -862,12 +862,12 @@ struct buffer_head *alloc_page_buffers(struct page *page, unsigned long size,
862862
if (retry)
863863
gfp |= __GFP_NOFAIL;
864864

865-
/* The page lock pins the memcg */
866-
memcg = page_memcg(page);
865+
/* The folio lock pins the memcg */
866+
memcg = folio_memcg(folio);
867867
old_memcg = set_active_memcg(memcg);
868868

869869
head = NULL;
870-
offset = PAGE_SIZE;
870+
offset = folio_size(folio);
871871
while ((offset -= size) >= 0) {
872872
bh = alloc_buffer_head(gfp);
873873
if (!bh)
@@ -879,8 +879,8 @@ struct buffer_head *alloc_page_buffers(struct page *page, unsigned long size,
879879

880880
bh->b_size = size;
881881

882-
/* Link the buffer to its page */
883-
set_bh_page(bh, page, offset);
882+
/* Link the buffer to its folio */
883+
folio_set_bh(bh, folio, offset);
884884
}
885885
out:
886886
set_active_memcg(old_memcg);
@@ -899,6 +899,13 @@ struct buffer_head *alloc_page_buffers(struct page *page, unsigned long size,
899899

900900
goto out;
901901
}
902+
EXPORT_SYMBOL_GPL(folio_alloc_buffers);
903+
904+
struct buffer_head *alloc_page_buffers(struct page *page, unsigned long size,
905+
bool retry)
906+
{
907+
return folio_alloc_buffers(page_folio(page), size, retry);
908+
}
902909
EXPORT_SYMBOL_GPL(alloc_page_buffers);
903910

904911
static inline void

include/linux/buffer_head.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ void set_bh_page(struct buffer_head *bh,
199199
void folio_set_bh(struct buffer_head *bh, struct folio *folio,
200200
unsigned long offset);
201201
bool try_to_free_buffers(struct folio *);
202+
struct buffer_head *folio_alloc_buffers(struct folio *folio, unsigned long size,
203+
bool retry);
202204
struct buffer_head *alloc_page_buffers(struct page *page, unsigned long size,
203205
bool retry);
204206
void create_empty_buffers(struct page *, unsigned long,

0 commit comments

Comments
 (0)