Skip to content

Commit e614a00

Browse files
Christoph Hellwigcmaiolino
authored andcommitted
xfs: cleanup mapping tmpfs folios into the buffer cache
Directly assign b_addr based on the tmpfs folios without a detour through pages, reuse the folio_put path used for non-tmpfs buffers and replace all references to pages in comments with folios. Partially based on a patch from Dave Chinner <[email protected]>. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Carlos Maiolino <[email protected]>
1 parent e287463 commit e614a00

File tree

3 files changed

+14
-32
lines changed

3 files changed

+14
-32
lines changed

fs/xfs/xfs_buf.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,7 @@ xfs_buf_free(
206206
if (!xfs_buftarg_is_mem(bp->b_target) && size >= PAGE_SIZE)
207207
mm_account_reclaimed_pages(howmany(size, PAGE_SHIFT));
208208

209-
if (xfs_buftarg_is_mem(bp->b_target))
210-
xmbuf_unmap_page(bp);
211-
else if (is_vmalloc_addr(bp->b_addr))
209+
if (is_vmalloc_addr(bp->b_addr))
212210
vfree(bp->b_addr);
213211
else if (bp->b_flags & _XBF_KMEM)
214212
kfree(bp->b_addr);
@@ -275,7 +273,7 @@ xfs_buf_alloc_backing_mem(
275273
struct folio *folio;
276274

277275
if (xfs_buftarg_is_mem(bp->b_target))
278-
return xmbuf_map_page(bp);
276+
return xmbuf_map_backing_mem(bp);
279277

280278
/* Assure zeroed buffer for non-read cases. */
281279
if (!(flags & XBF_READ))

fs/xfs/xfs_buf_mem.c

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ xmbuf_alloc(
7474

7575
/*
7676
* We don't want to bother with kmapping data during repair, so don't
77-
* allow highmem pages to back this mapping.
77+
* allow highmem folios to back this mapping.
7878
*/
7979
mapping_set_gfp_mask(inode->i_mapping, GFP_KERNEL);
8080

@@ -127,14 +127,13 @@ xmbuf_free(
127127
kfree(btp);
128128
}
129129

130-
/* Directly map a shmem page into the buffer cache. */
130+
/* Directly map a shmem folio into the buffer cache. */
131131
int
132-
xmbuf_map_page(
132+
xmbuf_map_backing_mem(
133133
struct xfs_buf *bp)
134134
{
135135
struct inode *inode = file_inode(bp->b_target->bt_file);
136136
struct folio *folio = NULL;
137-
struct page *page;
138137
loff_t pos = BBTOB(xfs_buf_daddr(bp));
139138
int error;
140139

@@ -159,30 +158,17 @@ xmbuf_map_page(
159158
return -EIO;
160159
}
161160

162-
page = folio_file_page(folio, pos >> PAGE_SHIFT);
163-
164161
/*
165-
* Mark the page dirty so that it won't be reclaimed once we drop the
166-
* (potentially last) reference in xmbuf_unmap_page.
162+
* Mark the folio dirty so that it won't be reclaimed once we drop the
163+
* (potentially last) reference in xfs_buf_free.
167164
*/
168-
set_page_dirty(page);
169-
unlock_page(page);
165+
folio_set_dirty(folio);
166+
folio_unlock(folio);
170167

171-
bp->b_addr = page_address(page);
168+
bp->b_addr = folio_address(folio);
172169
return 0;
173170
}
174171

175-
/* Unmap a shmem page that was mapped into the buffer cache. */
176-
void
177-
xmbuf_unmap_page(
178-
struct xfs_buf *bp)
179-
{
180-
ASSERT(xfs_buftarg_is_mem(bp->b_target));
181-
182-
put_page(virt_to_page(bp->b_addr));
183-
bp->b_addr = NULL;
184-
}
185-
186172
/* Is this a valid daddr within the buftarg? */
187173
bool
188174
xmbuf_verify_daddr(
@@ -196,7 +182,7 @@ xmbuf_verify_daddr(
196182
return daddr < (inode->i_sb->s_maxbytes >> BBSHIFT);
197183
}
198184

199-
/* Discard the page backing this buffer. */
185+
/* Discard the folio backing this buffer. */
200186
static void
201187
xmbuf_stale(
202188
struct xfs_buf *bp)
@@ -211,7 +197,7 @@ xmbuf_stale(
211197
}
212198

213199
/*
214-
* Finalize a buffer -- discard the backing page if it's stale, or run the
200+
* Finalize a buffer -- discard the backing folio if it's stale, or run the
215201
* write verifier to detect problems.
216202
*/
217203
int

fs/xfs/xfs_buf_mem.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,14 @@ int xmbuf_alloc(struct xfs_mount *mp, const char *descr,
1919
struct xfs_buftarg **btpp);
2020
void xmbuf_free(struct xfs_buftarg *btp);
2121

22-
int xmbuf_map_page(struct xfs_buf *bp);
23-
void xmbuf_unmap_page(struct xfs_buf *bp);
2422
bool xmbuf_verify_daddr(struct xfs_buftarg *btp, xfs_daddr_t daddr);
2523
void xmbuf_trans_bdetach(struct xfs_trans *tp, struct xfs_buf *bp);
2624
int xmbuf_finalize(struct xfs_buf *bp);
2725
#else
2826
# define xfs_buftarg_is_mem(...) (false)
29-
# define xmbuf_map_page(...) (-ENOMEM)
30-
# define xmbuf_unmap_page(...) ((void)0)
3127
# define xmbuf_verify_daddr(...) (false)
3228
#endif /* CONFIG_XFS_MEMORY_BUFS */
3329

30+
int xmbuf_map_backing_mem(struct xfs_buf *bp);
31+
3432
#endif /* __XFS_BUF_MEM_H__ */

0 commit comments

Comments
 (0)