Skip to content

Commit fb5a381

Browse files
committed
Merge patch series "Remove aops->writepage"
Matthew Wilcox (Oracle) <[email protected]> says: We have just one filesystm (vboxsf) left which implements ->writepage. This patchset converts it to writepages then removes all the callers of ->writepage. * patches from https://lore.kernel.org/r/[email protected]: fs: Remove aops->writepage mm: Remove swap_writepage() and shmem_writepage() ttm: Call shmem_writeout() from ttm_backup_backup_page() i915: Use writeback_iter() shmem: Add shmem_writeout() writeback: Remove writeback_use_writepage() migrate: Remove call to ->writepage vboxsf: Convert to writepages 9p: Add a migrate_folio method Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
2 parents 0af2f6b + 6b0dfab commit fb5a381

File tree

20 files changed

+101
-258
lines changed

20 files changed

+101
-258
lines changed

Documentation/admin-guide/cgroup-v2.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3019,7 +3019,7 @@ Filesystem Support for Writeback
30193019
--------------------------------
30203020

30213021
A filesystem can support cgroup writeback by updating
3022-
address_space_operations->writepage[s]() to annotate bio's using the
3022+
address_space_operations->writepages() to annotate bio's using the
30233023
following two functions.
30243024

30253025
wbc_init_bio(@wbc, @bio)

Documentation/filesystems/fscrypt.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ read the ciphertext into the page cache and decrypt it in-place. The
14091409
folio lock must be held until decryption has finished, to prevent the
14101410
folio from becoming visible to userspace prematurely.
14111411

1412-
For the write path (->writepage()) of regular files, filesystems
1412+
For the write path (->writepages()) of regular files, filesystems
14131413
cannot encrypt data in-place in the page cache, since the cached
14141414
plaintext must be preserved. Instead, filesystems must encrypt into a
14151415
temporary buffer or "bounce page", then write out the temporary

Documentation/filesystems/locking.rst

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ address_space_operations
249249
========================
250250
prototypes::
251251

252-
int (*writepage)(struct page *page, struct writeback_control *wbc);
253252
int (*read_folio)(struct file *, struct folio *);
254253
int (*writepages)(struct address_space *, struct writeback_control *);
255254
bool (*dirty_folio)(struct address_space *, struct folio *folio);
@@ -280,7 +279,6 @@ locking rules:
280279
====================== ======================== ========= ===============
281280
ops folio locked i_rwsem invalidate_lock
282281
====================== ======================== ========= ===============
283-
writepage: yes, unlocks (see below)
284282
read_folio: yes, unlocks shared
285283
writepages:
286284
dirty_folio: maybe
@@ -309,63 +307,15 @@ completion.
309307

310308
->readahead() unlocks the folios that I/O is attempted on like ->read_folio().
311309

312-
->writepage() is used for two purposes: for "memory cleansing" and for
313-
"sync". These are quite different operations and the behaviour may differ
314-
depending upon the mode.
315-
316-
If writepage is called for sync (wbc->sync_mode != WBC_SYNC_NONE) then
317-
it *must* start I/O against the page, even if that would involve
318-
blocking on in-progress I/O.
319-
320-
If writepage is called for memory cleansing (sync_mode ==
321-
WBC_SYNC_NONE) then its role is to get as much writeout underway as
322-
possible. So writepage should try to avoid blocking against
323-
currently-in-progress I/O.
324-
325-
If the filesystem is not called for "sync" and it determines that it
326-
would need to block against in-progress I/O to be able to start new I/O
327-
against the page the filesystem should redirty the page with
328-
redirty_page_for_writepage(), then unlock the page and return zero.
329-
This may also be done to avoid internal deadlocks, but rarely.
330-
331-
If the filesystem is called for sync then it must wait on any
332-
in-progress I/O and then start new I/O.
333-
334-
The filesystem should unlock the page synchronously, before returning to the
335-
caller, unless ->writepage() returns special WRITEPAGE_ACTIVATE
336-
value. WRITEPAGE_ACTIVATE means that page cannot really be written out
337-
currently, and VM should stop calling ->writepage() on this page for some
338-
time. VM does this by moving page to the head of the active list, hence the
339-
name.
340-
341-
Unless the filesystem is going to redirty_page_for_writepage(), unlock the page
342-
and return zero, writepage *must* run set_page_writeback() against the page,
343-
followed by unlocking it. Once set_page_writeback() has been run against the
344-
page, write I/O can be submitted and the write I/O completion handler must run
345-
end_page_writeback() once the I/O is complete. If no I/O is submitted, the
346-
filesystem must run end_page_writeback() against the page before returning from
347-
writepage.
348-
349-
That is: after 2.5.12, pages which are under writeout are *not* locked. Note,
350-
if the filesystem needs the page to be locked during writeout, that is ok, too,
351-
the page is allowed to be unlocked at any point in time between the calls to
352-
set_page_writeback() and end_page_writeback().
353-
354-
Note, failure to run either redirty_page_for_writepage() or the combination of
355-
set_page_writeback()/end_page_writeback() on a page submitted to writepage
356-
will leave the page itself marked clean but it will be tagged as dirty in the
357-
radix tree. This incoherency can lead to all sorts of hard-to-debug problems
358-
in the filesystem like having dirty inodes at umount and losing written data.
359-
360310
->writepages() is used for periodic writeback and for syscall-initiated
361311
sync operations. The address_space should start I/O against at least
362312
``*nr_to_write`` pages. ``*nr_to_write`` must be decremented for each page
363313
which is written. The address_space implementation may write more (or less)
364314
pages than ``*nr_to_write`` asks for, but it should try to be reasonably close.
365315
If nr_to_write is NULL, all dirty pages must be written.
366316

367-
writepages should _only_ write pages which are present on
368-
mapping->io_pages.
317+
writepages should _only_ write pages which are present in
318+
mapping->i_pages.
369319

370320
->dirty_folio() is called from various places in the kernel when
371321
the target folio is marked as needing writeback. The folio cannot be

Documentation/filesystems/vfs.rst

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -716,9 +716,8 @@ page lookup by address, and keeping track of pages tagged as Dirty or
716716
Writeback.
717717

718718
The first can be used independently to the others. The VM can try to
719-
either write dirty pages in order to clean them, or release clean pages
720-
in order to reuse them. To do this it can call the ->writepage method
721-
on dirty pages, and ->release_folio on clean folios with the private
719+
release clean pages in order to reuse them. To do this it can call
720+
->release_folio on clean folios with the private
722721
flag set. Clean pages without PagePrivate and with no external references
723722
will be released without notice being given to the address_space.
724723

@@ -731,8 +730,8 @@ maintains information about the PG_Dirty and PG_Writeback status of each
731730
page, so that pages with either of these flags can be found quickly.
732731

733732
The Dirty tag is primarily used by mpage_writepages - the default
734-
->writepages method. It uses the tag to find dirty pages to call
735-
->writepage on. If mpage_writepages is not used (i.e. the address
733+
->writepages method. It uses the tag to find dirty pages to
734+
write back. If mpage_writepages is not used (i.e. the address
736735
provides its own ->writepages) , the PAGECACHE_TAG_DIRTY tag is almost
737736
unused. write_inode_now and sync_inode do use it (through
738737
__sync_single_inode) to check if ->writepages has been successful in
@@ -756,23 +755,23 @@ pages, however the address_space has finer control of write sizes.
756755

757756
The read process essentially only requires 'read_folio'. The write
758757
process is more complicated and uses write_begin/write_end or
759-
dirty_folio to write data into the address_space, and writepage and
758+
dirty_folio to write data into the address_space, and
760759
writepages to writeback data to storage.
761760

762761
Adding and removing pages to/from an address_space is protected by the
763762
inode's i_mutex.
764763

765764
When data is written to a page, the PG_Dirty flag should be set. It
766-
typically remains set until writepage asks for it to be written. This
765+
typically remains set until writepages asks for it to be written. This
767766
should clear PG_Dirty and set PG_Writeback. It can be actually written
768767
at any point after PG_Dirty is clear. Once it is known to be safe,
769768
PG_Writeback is cleared.
770769

771770
Writeback makes use of a writeback_control structure to direct the
772-
operations. This gives the writepage and writepages operations some
771+
operations. This gives the writepages operation some
773772
information about the nature of and reason for the writeback request,
774773
and the constraints under which it is being done. It is also used to
775-
return information back to the caller about the result of a writepage or
774+
return information back to the caller about the result of a
776775
writepages request.
777776

778777

@@ -819,7 +818,6 @@ cache in your filesystem. The following members are defined:
819818
.. code-block:: c
820819
821820
struct address_space_operations {
822-
int (*writepage)(struct page *page, struct writeback_control *wbc);
823821
int (*read_folio)(struct file *, struct folio *);
824822
int (*writepages)(struct address_space *, struct writeback_control *);
825823
bool (*dirty_folio)(struct address_space *, struct folio *);
@@ -848,25 +846,6 @@ cache in your filesystem. The following members are defined:
848846
int (*swap_rw)(struct kiocb *iocb, struct iov_iter *iter);
849847
};
850848
851-
``writepage``
852-
called by the VM to write a dirty page to backing store. This
853-
may happen for data integrity reasons (i.e. 'sync'), or to free
854-
up memory (flush). The difference can be seen in
855-
wbc->sync_mode. The PG_Dirty flag has been cleared and
856-
PageLocked is true. writepage should start writeout, should set
857-
PG_Writeback, and should make sure the page is unlocked, either
858-
synchronously or asynchronously when the write operation
859-
completes.
860-
861-
If wbc->sync_mode is WB_SYNC_NONE, ->writepage doesn't have to
862-
try too hard if there are problems, and may choose to write out
863-
other pages from the mapping if that is easier (e.g. due to
864-
internal dependencies). If it chooses not to start writeout, it
865-
should return AOP_WRITEPAGE_ACTIVATE so that the VM will not
866-
keep calling ->writepage on that page.
867-
868-
See the file "Locking" for more details.
869-
870849
``read_folio``
871850
Called by the page cache to read a folio from the backing store.
872851
The 'file' argument supplies authentication information to network
@@ -909,7 +888,7 @@ cache in your filesystem. The following members are defined:
909888
given and that many pages should be written if possible. If no
910889
->writepages is given, then mpage_writepages is used instead.
911890
This will choose pages from the address space that are tagged as
912-
DIRTY and will pass them to ->writepage.
891+
DIRTY and will write them back.
913892

914893
``dirty_folio``
915894
called by the VM to mark a folio as dirty. This is particularly

block/blk-wbt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
enum wbt_flags {
3838
WBT_TRACKED = 1, /* write, tracked for throttling */
3939
WBT_READ = 2, /* read */
40-
WBT_SWAP = 4, /* write, from swap_writepage() */
40+
WBT_SWAP = 4, /* write, from swap_writeout() */
4141
WBT_DISCARD = 8, /* discard */
4242

4343
WBT_NR_BITS = 4, /* number of bits */

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

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -305,36 +305,20 @@ void __shmem_writeback(size_t size, struct address_space *mapping)
305305
.range_end = LLONG_MAX,
306306
.for_reclaim = 1,
307307
};
308-
unsigned long i;
308+
struct folio *folio = NULL;
309+
int error = 0;
309310

310311
/*
311312
* Leave mmapings intact (GTT will have been revoked on unbinding,
312-
* leaving only CPU mmapings around) and add those pages to the LRU
313+
* leaving only CPU mmapings around) and add those folios to the LRU
313314
* instead of invoking writeback so they are aged and paged out
314315
* as normal.
315316
*/
316-
317-
/* Begin writeback on each dirty page */
318-
for (i = 0; i < size >> PAGE_SHIFT; i++) {
319-
struct page *page;
320-
321-
page = find_lock_page(mapping, i);
322-
if (!page)
323-
continue;
324-
325-
if (!page_mapped(page) && clear_page_dirty_for_io(page)) {
326-
int ret;
327-
328-
SetPageReclaim(page);
329-
ret = mapping->a_ops->writepage(page, &wbc);
330-
if (!PageWriteback(page))
331-
ClearPageReclaim(page);
332-
if (!ret)
333-
goto put;
334-
}
335-
unlock_page(page);
336-
put:
337-
put_page(page);
317+
while ((folio = writeback_iter(mapping, &wbc, folio, &error))) {
318+
if (folio_mapped(folio))
319+
folio_redirty_for_writepage(&wbc, folio);
320+
else
321+
error = shmem_writeout(folio, &wbc);
338322
}
339323
}
340324

drivers/gpu/drm/ttm/ttm_backup.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,13 @@ ttm_backup_backup_page(struct ttm_backup *backup, struct page *page,
136136
.for_reclaim = 1,
137137
};
138138
folio_set_reclaim(to_folio);
139-
ret = mapping->a_ops->writepage(folio_file_page(to_folio, idx), &wbc);
139+
ret = shmem_writeout(to_folio, &wbc);
140140
if (!folio_test_writeback(to_folio))
141141
folio_clear_reclaim(to_folio);
142142
/*
143-
* If writepage succeeds, it unlocks the folio.
144-
* writepage() errors are otherwise dropped, since writepage()
145-
* is only best effort here.
143+
* If writeout succeeds, it unlocks the folio. errors
144+
* are otherwise dropped, since writeout is only best
145+
* effort here.
146146
*/
147147
if (ret)
148148
folio_unlock(to_folio);

fs/9p/vfs_addr.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,5 @@ const struct address_space_operations v9fs_addr_operations = {
164164
.invalidate_folio = netfs_invalidate_folio,
165165
.direct_IO = noop_direct_IO,
166166
.writepages = netfs_writepages,
167+
.migrate_folio = filemap_migrate_folio,
167168
};

fs/buffer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2695,7 +2695,7 @@ int block_truncate_page(struct address_space *mapping,
26952695
EXPORT_SYMBOL(block_truncate_page);
26962696

26972697
/*
2698-
* The generic ->writepage function for buffer-backed address_spaces
2698+
* The generic write folio function for buffer-backed address_spaces
26992699
*/
27002700
int block_write_full_folio(struct folio *folio, struct writeback_control *wbc,
27012701
void *get_block)
@@ -2715,7 +2715,7 @@ int block_write_full_folio(struct folio *folio, struct writeback_control *wbc,
27152715

27162716
/*
27172717
* The folio straddles i_size. It must be zeroed out on each and every
2718-
* writepage invocation because it may be mmapped. "A file is mapped
2718+
* writeback invocation because it may be mmapped. "A file is mapped
27192719
* in multiples of the page size. For a file that is not a multiple of
27202720
* the page size, the remaining memory is zeroed when mapped, and
27212721
* writes to that region are not written out to the file."

fs/vboxsf/file.c

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -262,40 +262,42 @@ static struct vboxsf_handle *vboxsf_get_write_handle(struct vboxsf_inode *sf_i)
262262
return sf_handle;
263263
}
264264

265-
static int vboxsf_writepage(struct page *page, struct writeback_control *wbc)
265+
static int vboxsf_writepages(struct address_space *mapping,
266+
struct writeback_control *wbc)
266267
{
267-
struct inode *inode = page->mapping->host;
268+
struct inode *inode = mapping->host;
269+
struct folio *folio = NULL;
268270
struct vboxsf_inode *sf_i = VBOXSF_I(inode);
269271
struct vboxsf_handle *sf_handle;
270-
loff_t off = page_offset(page);
271272
loff_t size = i_size_read(inode);
272-
u32 nwrite = PAGE_SIZE;
273-
u8 *buf;
274-
int err;
275-
276-
if (off + PAGE_SIZE > size)
277-
nwrite = size & ~PAGE_MASK;
273+
int error;
278274

279275
sf_handle = vboxsf_get_write_handle(sf_i);
280276
if (!sf_handle)
281277
return -EBADF;
282278

283-
buf = kmap(page);
284-
err = vboxsf_write(sf_handle->root, sf_handle->handle,
285-
off, &nwrite, buf);
286-
kunmap(page);
279+
while ((folio = writeback_iter(mapping, wbc, folio, &error))) {
280+
loff_t off = folio_pos(folio);
281+
u32 nwrite = folio_size(folio);
282+
u8 *buf;
287283

288-
kref_put(&sf_handle->refcount, vboxsf_handle_release);
284+
if (nwrite > size - off)
285+
nwrite = size - off;
289286

290-
if (err == 0) {
291-
/* mtime changed */
292-
sf_i->force_restat = 1;
293-
} else {
294-
ClearPageUptodate(page);
287+
buf = kmap_local_folio(folio, 0);
288+
error = vboxsf_write(sf_handle->root, sf_handle->handle,
289+
off, &nwrite, buf);
290+
kunmap_local(buf);
291+
292+
folio_unlock(folio);
295293
}
296294

297-
unlock_page(page);
298-
return err;
295+
kref_put(&sf_handle->refcount, vboxsf_handle_release);
296+
297+
/* mtime changed */
298+
if (error == 0)
299+
sf_i->force_restat = 1;
300+
return error;
299301
}
300302

301303
static int vboxsf_write_end(struct file *file, struct address_space *mapping,
@@ -347,10 +349,11 @@ static int vboxsf_write_end(struct file *file, struct address_space *mapping,
347349
*/
348350
const struct address_space_operations vboxsf_reg_aops = {
349351
.read_folio = vboxsf_read_folio,
350-
.writepage = vboxsf_writepage,
352+
.writepages = vboxsf_writepages,
351353
.dirty_folio = filemap_dirty_folio,
352354
.write_begin = simple_write_begin,
353355
.write_end = vboxsf_write_end,
356+
.migrate_folio = filemap_migrate_folio,
354357
};
355358

356359
static const char *vboxsf_get_link(struct dentry *dentry, struct inode *inode,

0 commit comments

Comments
 (0)