Skip to content

Commit 1da8661

Browse files
Matthew Wilcox (Oracle)brauner
authored andcommitted
fs: Convert aops->write_begin to take a folio
Convert all callers from working on a page to working on one page of a folio (support for working on an entire folio can come later). Removes a lot of folio->page->folio conversions. Reviewed-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent a225800 commit 1da8661

File tree

58 files changed

+190
-207
lines changed

Some content is hidden

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

58 files changed

+190
-207
lines changed

Documentation/filesystems/locking.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ 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,
257257
struct folio *folio, void *fsdata);
@@ -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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

block/fops.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,9 @@ 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,

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_folio(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_folio(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: 7 additions & 8 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))
@@ -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;
@@ -881,14 +880,14 @@ affs_truncate(struct inode *inode)
881880

882881
if (inode->i_size > AFFS_I(inode)->mmu_private) {
883882
struct address_space *mapping = inode->i_mapping;
884-
struct page *page;
883+
struct folio *folio;
885884
void *fsdata = NULL;
886885
loff_t isize = inode->i_size;
887886
int res;
888887

889-
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);
890889
if (!res)
891-
res = mapping->a_ops->write_end(NULL, mapping, isize, 0, 0, page_folio(page), fsdata);
890+
res = mapping->a_ops->write_end(NULL, mapping, isize, 0, 0, folio, fsdata);
892891
else
893892
inode->i_size = AFFS_I(inode)->mmu_private;
894893
mark_inode_dirty(inode);

fs/bcachefs/fs-io-buffered.c

Lines changed: 2 additions & 3 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);

fs/bcachefs/fs-io-buffered.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ 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,
1616
unsigned len, unsigned copied, struct folio *, void *);
1717

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

fs/buffer.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,7 +2222,7 @@ static void __block_commit_write(struct folio *folio, size_t from, size_t to)
22222222
* The filesystem needs to handle block truncation upon failure.
22232223
*/
22242224
int block_write_begin(struct address_space *mapping, loff_t pos, unsigned len,
2225-
struct page **pagep, get_block_t *get_block)
2225+
struct folio **foliop, get_block_t *get_block)
22262226
{
22272227
pgoff_t index = pos >> PAGE_SHIFT;
22282228
struct folio *folio;
@@ -2240,7 +2240,7 @@ int block_write_begin(struct address_space *mapping, loff_t pos, unsigned len,
22402240
folio = NULL;
22412241
}
22422242

2243-
*pagep = &folio->page;
2243+
*foliop = folio;
22442244
return status;
22452245
}
22462246
EXPORT_SYMBOL(block_write_begin);
@@ -2467,19 +2467,19 @@ int generic_cont_expand_simple(struct inode *inode, loff_t size)
24672467
{
24682468
struct address_space *mapping = inode->i_mapping;
24692469
const struct address_space_operations *aops = mapping->a_ops;
2470-
struct page *page;
2470+
struct folio *folio;
24712471
void *fsdata = NULL;
24722472
int err;
24732473

24742474
err = inode_newsize_ok(inode, size);
24752475
if (err)
24762476
goto out;
24772477

2478-
err = aops->write_begin(NULL, mapping, size, 0, &page, &fsdata);
2478+
err = aops->write_begin(NULL, mapping, size, 0, &folio, &fsdata);
24792479
if (err)
24802480
goto out;
24812481

2482-
err = aops->write_end(NULL, mapping, size, 0, 0, page_folio(page), fsdata);
2482+
err = aops->write_end(NULL, mapping, size, 0, 0, folio, fsdata);
24832483
BUG_ON(err > 0);
24842484

24852485
out:
@@ -2493,7 +2493,7 @@ static int cont_expand_zero(struct file *file, struct address_space *mapping,
24932493
struct inode *inode = mapping->host;
24942494
const struct address_space_operations *aops = mapping->a_ops;
24952495
unsigned int blocksize = i_blocksize(inode);
2496-
struct page *page;
2496+
struct folio *folio;
24972497
void *fsdata = NULL;
24982498
pgoff_t index, curidx;
24992499
loff_t curpos;
@@ -2512,12 +2512,12 @@ static int cont_expand_zero(struct file *file, struct address_space *mapping,
25122512
len = PAGE_SIZE - zerofrom;
25132513

25142514
err = aops->write_begin(file, mapping, curpos, len,
2515-
&page, &fsdata);
2515+
&folio, &fsdata);
25162516
if (err)
25172517
goto out;
2518-
zero_user(page, zerofrom, len);
2518+
folio_zero_range(folio, offset_in_folio(folio, curpos), len);
25192519
err = aops->write_end(file, mapping, curpos, len, len,
2520-
page_folio(page), fsdata);
2520+
folio, fsdata);
25212521
if (err < 0)
25222522
goto out;
25232523
BUG_ON(err != len);
@@ -2545,12 +2545,12 @@ static int cont_expand_zero(struct file *file, struct address_space *mapping,
25452545
len = offset - zerofrom;
25462546

25472547
err = aops->write_begin(file, mapping, curpos, len,
2548-
&page, &fsdata);
2548+
&folio, &fsdata);
25492549
if (err)
25502550
goto out;
2551-
zero_user(page, zerofrom, len);
2551+
folio_zero_range(folio, offset_in_folio(folio, curpos), len);
25522552
err = aops->write_end(file, mapping, curpos, len, len,
2553-
page_folio(page), fsdata);
2553+
folio, fsdata);
25542554
if (err < 0)
25552555
goto out;
25562556
BUG_ON(err != len);
@@ -2566,7 +2566,7 @@ static int cont_expand_zero(struct file *file, struct address_space *mapping,
25662566
*/
25672567
int cont_write_begin(struct file *file, struct address_space *mapping,
25682568
loff_t pos, unsigned len,
2569-
struct page **pagep, void **fsdata,
2569+
struct folio **foliop, void **fsdata,
25702570
get_block_t *get_block, loff_t *bytes)
25712571
{
25722572
struct inode *inode = mapping->host;
@@ -2584,7 +2584,7 @@ int cont_write_begin(struct file *file, struct address_space *mapping,
25842584
(*bytes)++;
25852585
}
25862586

2587-
return block_write_begin(mapping, pos, len, pagep, get_block);
2587+
return block_write_begin(mapping, pos, len, foliop, get_block);
25882588
}
25892589
EXPORT_SYMBOL(cont_write_begin);
25902590

0 commit comments

Comments
 (0)