Skip to content

Commit 2775df6

Browse files
committed
Merge tag 'vfs-6.12.folio' of gitolite.kernel.org:pub/scm/linux/kernel/git/vfs/vfs
Pull vfs folio updates from Christian Brauner: "This contains work to port write_begin and write_end to rely on folios for various filesystems. This converts ocfs2, vboxfs, orangefs, jffs2, hostfs, fuse, f2fs, ecryptfs, ntfs3, nilfs2, reiserfs, minixfs, qnx6, sysv, ufs, and squashfs. After this series lands a bunch of the filesystems in this list do not mention struct page anymore" * tag 'vfs-6.12.folio' of gitolite.kernel.org:pub/scm/linux/kernel/git/vfs/vfs: (61 commits) Squashfs: Ensure all readahead pages have been used Squashfs: Rewrite and update squashfs_readahead_fragment() to not use page->index Squashfs: Update squashfs_readpage_block() to not use page->index Squashfs: Update squashfs_readahead() to not use page->index Squashfs: Update page_actor to not use page->index jffs2: Use a folio in jffs2_garbage_collect_dnode() jffs2: Convert jffs2_do_readpage_nolock to take a folio buffer: Convert __block_write_begin() to take a folio ocfs2: Convert ocfs2_write_zero_page to use a folio fs: Convert aops->write_begin to take a folio fs: Convert aops->write_end to take a folio vboxsf: Use a folio in vboxsf_write_end() orangefs: Convert orangefs_write_begin() to use a folio orangefs: Convert orangefs_write_end() to use a folio jffs2: Convert jffs2_write_begin() to use a folio jffs2: Convert jffs2_write_end() to use a folio hostfs: Convert hostfs_write_end() to use a folio fuse: Convert fuse_write_begin() to use a folio fuse: Convert fuse_write_end() to use a folio f2fs: Convert f2fs_write_begin() to use a folio ...
2 parents 8f72c31 + 84e0e03 commit 2775df6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+994
-1064
lines changed

Documentation/filesystems/locking.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,10 @@ prototypes::
251251
void (*readahead)(struct readahead_control *);
252252
int (*write_begin)(struct file *, struct address_space *mapping,
253253
loff_t pos, unsigned len,
254-
struct page **pagep, void **fsdata);
254+
struct folio **foliop, void **fsdata);
255255
int (*write_end)(struct file *, struct address_space *mapping,
256256
loff_t pos, unsigned len, unsigned copied,
257-
struct page *page, void *fsdata);
257+
struct folio *folio, void *fsdata);
258258
sector_t (*bmap)(struct address_space *, sector_t);
259259
void (*invalidate_folio) (struct folio *, size_t start, size_t len);
260260
bool (*release_folio)(struct folio *, gfp_t);
@@ -280,7 +280,7 @@ read_folio: yes, unlocks shared
280280
writepages:
281281
dirty_folio: maybe
282282
readahead: yes, unlocks shared
283-
write_begin: locks the page exclusive
283+
write_begin: locks the folio exclusive
284284
write_end: yes, unlocks exclusive
285285
bmap:
286286
invalidate_folio: yes exclusive

Documentation/filesystems/vfs.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ cache in your filesystem. The following members are defined:
810810
struct page **pagep, void **fsdata);
811811
int (*write_end)(struct file *, struct address_space *mapping,
812812
loff_t pos, unsigned len, unsigned copied,
813-
struct page *page, void *fsdata);
813+
struct folio *folio, void *fsdata);
814814
sector_t (*bmap)(struct address_space *, sector_t);
815815
void (*invalidate_folio) (struct folio *, size_t start, size_t len);
816816
bool (*release_folio)(struct folio *, gfp_t);
@@ -926,12 +926,12 @@ cache in your filesystem. The following members are defined:
926926
(if they haven't been read already) so that the updated blocks
927927
can be written out properly.
928928

929-
The filesystem must return the locked pagecache page for the
930-
specified offset, in ``*pagep``, for the caller to write into.
929+
The filesystem must return the locked pagecache folio for the
930+
specified offset, in ``*foliop``, for the caller to write into.
931931

932932
It must be able to cope with short writes (where the length
933933
passed to write_begin is greater than the number of bytes copied
934-
into the page).
934+
into the folio).
935935

936936
A void * may be returned in fsdata, which then gets passed into
937937
write_end.
@@ -944,8 +944,8 @@ cache in your filesystem. The following members are defined:
944944
called. len is the original len passed to write_begin, and
945945
copied is the amount that was able to be copied.
946946

947-
The filesystem must take care of unlocking the page and
948-
releasing it refcount, and updating i_size.
947+
The filesystem must take care of unlocking the folio,
948+
decrementing its refcount, and updating i_size.
949949

950950
Returns < 0 on failure, otherwise the number of bytes (<=
951951
'copied') that were able to be copied into pagecache.

block/fops.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -451,20 +451,20 @@ static void blkdev_readahead(struct readahead_control *rac)
451451
}
452452

453453
static int blkdev_write_begin(struct file *file, struct address_space *mapping,
454-
loff_t pos, unsigned len, struct page **pagep, void **fsdata)
454+
loff_t pos, unsigned len, struct folio **foliop, void **fsdata)
455455
{
456-
return block_write_begin(mapping, pos, len, pagep, blkdev_get_block);
456+
return block_write_begin(mapping, pos, len, foliop, blkdev_get_block);
457457
}
458458

459459
static int blkdev_write_end(struct file *file, struct address_space *mapping,
460-
loff_t pos, unsigned len, unsigned copied, struct page *page,
460+
loff_t pos, unsigned len, unsigned copied, struct folio *folio,
461461
void *fsdata)
462462
{
463463
int ret;
464-
ret = block_write_end(file, mapping, pos, len, copied, page, fsdata);
464+
ret = block_write_end(file, mapping, pos, len, copied, folio, fsdata);
465465

466-
unlock_page(page);
467-
put_page(page);
466+
folio_unlock(folio);
467+
folio_put(folio);
468468

469469
return ret;
470470
}

drivers/gpu/drm/i915/gem/i915_gem_shmem.c

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,8 @@ shmem_pwrite(struct drm_i915_gem_object *obj,
424424
struct address_space *mapping = obj->base.filp->f_mapping;
425425
const struct address_space_operations *aops = mapping->a_ops;
426426
char __user *user_data = u64_to_user_ptr(arg->data_ptr);
427-
u64 remain, offset;
427+
u64 remain;
428+
loff_t pos;
428429
unsigned int pg;
429430

430431
/* Caller already validated user args */
@@ -457,12 +458,12 @@ shmem_pwrite(struct drm_i915_gem_object *obj,
457458
*/
458459

459460
remain = arg->size;
460-
offset = arg->offset;
461-
pg = offset_in_page(offset);
461+
pos = arg->offset;
462+
pg = offset_in_page(pos);
462463

463464
do {
464465
unsigned int len, unwritten;
465-
struct page *page;
466+
struct folio *folio;
466467
void *data, *vaddr;
467468
int err;
468469
char __maybe_unused c;
@@ -480,21 +481,19 @@ shmem_pwrite(struct drm_i915_gem_object *obj,
480481
if (err)
481482
return err;
482483

483-
err = aops->write_begin(obj->base.filp, mapping, offset, len,
484-
&page, &data);
484+
err = aops->write_begin(obj->base.filp, mapping, pos, len,
485+
&folio, &data);
485486
if (err < 0)
486487
return err;
487488

488-
vaddr = kmap_local_page(page);
489+
vaddr = kmap_local_folio(folio, offset_in_folio(folio, pos));
489490
pagefault_disable();
490-
unwritten = __copy_from_user_inatomic(vaddr + pg,
491-
user_data,
492-
len);
491+
unwritten = __copy_from_user_inatomic(vaddr, user_data, len);
493492
pagefault_enable();
494493
kunmap_local(vaddr);
495494

496-
err = aops->write_end(obj->base.filp, mapping, offset, len,
497-
len - unwritten, page, data);
495+
err = aops->write_end(obj->base.filp, mapping, pos, len,
496+
len - unwritten, folio, data);
498497
if (err < 0)
499498
return err;
500499

@@ -504,7 +503,7 @@ shmem_pwrite(struct drm_i915_gem_object *obj,
504503

505504
remain -= len;
506505
user_data += len;
507-
offset += len;
506+
pos += len;
508507
pg = 0;
509508
} while (remain);
510509

@@ -660,7 +659,7 @@ i915_gem_object_create_shmem_from_data(struct drm_i915_private *i915,
660659
struct drm_i915_gem_object *obj;
661660
struct file *file;
662661
const struct address_space_operations *aops;
663-
resource_size_t offset;
662+
loff_t pos;
664663
int err;
665664

666665
GEM_WARN_ON(IS_DGFX(i915));
@@ -672,29 +671,27 @@ i915_gem_object_create_shmem_from_data(struct drm_i915_private *i915,
672671

673672
file = obj->base.filp;
674673
aops = file->f_mapping->a_ops;
675-
offset = 0;
674+
pos = 0;
676675
do {
677676
unsigned int len = min_t(typeof(size), size, PAGE_SIZE);
678-
struct page *page;
679-
void *pgdata, *vaddr;
677+
struct folio *folio;
678+
void *fsdata;
680679

681-
err = aops->write_begin(file, file->f_mapping, offset, len,
682-
&page, &pgdata);
680+
err = aops->write_begin(file, file->f_mapping, pos, len,
681+
&folio, &fsdata);
683682
if (err < 0)
684683
goto fail;
685684

686-
vaddr = kmap(page);
687-
memcpy(vaddr, data, len);
688-
kunmap(page);
685+
memcpy_to_folio(folio, offset_in_folio(folio, pos), data, len);
689686

690-
err = aops->write_end(file, file->f_mapping, offset, len, len,
691-
page, pgdata);
687+
err = aops->write_end(file, file->f_mapping, pos, len, len,
688+
folio, fsdata);
692689
if (err < 0)
693690
goto fail;
694691

695692
size -= len;
696693
data += len;
697-
offset += len;
694+
pos += len;
698695
} while (size);
699696

700697
return obj;

fs/adfs/inode.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,11 @@ static void adfs_write_failed(struct address_space *mapping, loff_t to)
5555

5656
static int adfs_write_begin(struct file *file, struct address_space *mapping,
5757
loff_t pos, unsigned len,
58-
struct page **pagep, void **fsdata)
58+
struct folio **foliop, void **fsdata)
5959
{
6060
int ret;
6161

62-
*pagep = NULL;
63-
ret = cont_write_begin(file, mapping, pos, len, pagep, fsdata,
62+
ret = cont_write_begin(file, mapping, pos, len, foliop, fsdata,
6463
adfs_get_block,
6564
&ADFS_I(mapping->host)->mmu_private);
6665
if (unlikely(ret))

fs/affs/file.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -417,12 +417,11 @@ affs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
417417

418418
static int affs_write_begin(struct file *file, struct address_space *mapping,
419419
loff_t pos, unsigned len,
420-
struct page **pagep, void **fsdata)
420+
struct folio **foliop, void **fsdata)
421421
{
422422
int ret;
423423

424-
*pagep = NULL;
425-
ret = cont_write_begin(file, mapping, pos, len, pagep, fsdata,
424+
ret = cont_write_begin(file, mapping, pos, len, foliop, fsdata,
426425
affs_get_block,
427426
&AFFS_I(mapping->host)->mmu_private);
428427
if (unlikely(ret))
@@ -433,12 +432,12 @@ static int affs_write_begin(struct file *file, struct address_space *mapping,
433432

434433
static int affs_write_end(struct file *file, struct address_space *mapping,
435434
loff_t pos, unsigned int len, unsigned int copied,
436-
struct page *page, void *fsdata)
435+
struct folio *folio, void *fsdata)
437436
{
438437
struct inode *inode = mapping->host;
439438
int ret;
440439

441-
ret = generic_write_end(file, mapping, pos, len, copied, page, fsdata);
440+
ret = generic_write_end(file, mapping, pos, len, copied, folio, fsdata);
442441

443442
/* Clear Archived bit on file writes, as AmigaOS would do */
444443
if (AFFS_I(inode)->i_protect & FIBF_ARCHIVED) {
@@ -648,7 +647,7 @@ static int affs_read_folio_ofs(struct file *file, struct folio *folio)
648647

649648
static int affs_write_begin_ofs(struct file *file, struct address_space *mapping,
650649
loff_t pos, unsigned len,
651-
struct page **pagep, void **fsdata)
650+
struct folio **foliop, void **fsdata)
652651
{
653652
struct inode *inode = mapping->host;
654653
struct folio *folio;
@@ -671,7 +670,7 @@ static int affs_write_begin_ofs(struct file *file, struct address_space *mapping
671670
mapping_gfp_mask(mapping));
672671
if (IS_ERR(folio))
673672
return PTR_ERR(folio);
674-
*pagep = &folio->page;
673+
*foliop = folio;
675674

676675
if (folio_test_uptodate(folio))
677676
return 0;
@@ -687,9 +686,8 @@ static int affs_write_begin_ofs(struct file *file, struct address_space *mapping
687686

688687
static int affs_write_end_ofs(struct file *file, struct address_space *mapping,
689688
loff_t pos, unsigned len, unsigned copied,
690-
struct page *page, void *fsdata)
689+
struct folio *folio, void *fsdata)
691690
{
692-
struct folio *folio = page_folio(page);
693691
struct inode *inode = mapping->host;
694692
struct super_block *sb = inode->i_sb;
695693
struct buffer_head *bh, *prev_bh;
@@ -882,14 +880,14 @@ affs_truncate(struct inode *inode)
882880

883881
if (inode->i_size > AFFS_I(inode)->mmu_private) {
884882
struct address_space *mapping = inode->i_mapping;
885-
struct page *page;
883+
struct folio *folio;
886884
void *fsdata = NULL;
887885
loff_t isize = inode->i_size;
888886
int res;
889887

890-
res = mapping->a_ops->write_begin(NULL, mapping, isize, 0, &page, &fsdata);
888+
res = mapping->a_ops->write_begin(NULL, mapping, isize, 0, &folio, &fsdata);
891889
if (!res)
892-
res = mapping->a_ops->write_end(NULL, mapping, isize, 0, 0, page, fsdata);
890+
res = mapping->a_ops->write_end(NULL, mapping, isize, 0, 0, folio, fsdata);
893891
else
894892
inode->i_size = AFFS_I(inode)->mmu_private;
895893
mark_inode_dirty(inode);

fs/bcachefs/fs-io-buffered.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ int bch2_writepages(struct address_space *mapping, struct writeback_control *wbc
659659

660660
int bch2_write_begin(struct file *file, struct address_space *mapping,
661661
loff_t pos, unsigned len,
662-
struct page **pagep, void **fsdata)
662+
struct folio **foliop, void **fsdata)
663663
{
664664
struct bch_inode_info *inode = to_bch_ei(mapping->host);
665665
struct bch_fs *c = inode->v.i_sb->s_fs_info;
@@ -728,12 +728,11 @@ int bch2_write_begin(struct file *file, struct address_space *mapping,
728728
goto err;
729729
}
730730

731-
*pagep = &folio->page;
731+
*foliop = folio;
732732
return 0;
733733
err:
734734
folio_unlock(folio);
735735
folio_put(folio);
736-
*pagep = NULL;
737736
err_unlock:
738737
bch2_pagecache_add_put(inode);
739738
kfree(res);
@@ -743,12 +742,11 @@ int bch2_write_begin(struct file *file, struct address_space *mapping,
743742

744743
int bch2_write_end(struct file *file, struct address_space *mapping,
745744
loff_t pos, unsigned len, unsigned copied,
746-
struct page *page, void *fsdata)
745+
struct folio *folio, void *fsdata)
747746
{
748747
struct bch_inode_info *inode = to_bch_ei(mapping->host);
749748
struct bch_fs *c = inode->v.i_sb->s_fs_info;
750749
struct bch2_folio_reservation *res = fsdata;
751-
struct folio *folio = page_folio(page);
752750
unsigned offset = pos - folio_pos(folio);
753751

754752
lockdep_assert_held(&inode->v.i_rwsem);

fs/bcachefs/fs-io-buffered.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ int bch2_read_folio(struct file *, struct folio *);
1010
int bch2_writepages(struct address_space *, struct writeback_control *);
1111
void bch2_readahead(struct readahead_control *);
1212

13-
int bch2_write_begin(struct file *, struct address_space *, loff_t,
14-
unsigned, struct page **, void **);
13+
int bch2_write_begin(struct file *, struct address_space *, loff_t pos,
14+
unsigned len, struct folio **, void **);
1515
int bch2_write_end(struct file *, struct address_space *, loff_t,
16-
unsigned, unsigned, struct page *, void *);
16+
unsigned len, unsigned copied, struct folio *, void *);
1717

1818
ssize_t bch2_write_iter(struct kiocb *, struct iov_iter *);
1919

fs/bfs/file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,11 @@ static void bfs_write_failed(struct address_space *mapping, loff_t to)
172172

173173
static int bfs_write_begin(struct file *file, struct address_space *mapping,
174174
loff_t pos, unsigned len,
175-
struct page **pagep, void **fsdata)
175+
struct folio **foliop, void **fsdata)
176176
{
177177
int ret;
178178

179-
ret = block_write_begin(mapping, pos, len, pagep, bfs_get_block);
179+
ret = block_write_begin(mapping, pos, len, foliop, bfs_get_block);
180180
if (unlikely(ret))
181181
bfs_write_failed(mapping, pos + len);
182182

0 commit comments

Comments
 (0)