remove write_one_page / folio_write_one
Subsystems (7)
Hi all,
this series removes the write_one_page API, and it's folioized implementation as folio_write_one. These helpers internally call ->writepage which we are gradually removing from the kernel.
For most callers there are better APIs to use, and this cleans them up. The big questionmark is jfs, where the metapage abstraction uses the pagecache in a bit of an odd way, and which would probably benefit from not using the page cache at all like the XFS buffer cache, but given that jfs has been in minimum maintaince mode for a long time that might not be worth it. So for now it just moves the implementation of write_one_page into jfs instead.
Diffstat:
fs/btrfs/volumes.c | 50 ++++++++++++++++++++++++------------------------ fs/jfs/jfs_metapage.c | 39 ++++++++++++++++++++++++++++++++----- fs/minix/dir.c | 30 +++++++++++++++++++--------- fs/ocfs2/refcounttree.c | 9 ++++---- fs/sysv/dir.c | 29 ++++++++++++++++++--------- fs/ufs/dir.c | 29 ++++++++++++++++++--------- include/linux/pagemap.h | 6 ----- mm/page-writeback.c | 40 -------------------------------------- 8 files changed, 122 insertions(+), 110 deletions(-)
PATCH 1/7 btrfs: don't read the disk superblock for zoned devices in btrfs_scratch_superblocks
For zoned devices, btrfs_scratch_superblocks just resets the sb zones, which means there is no need to even read the previous superblock. Split the code to read, zero and write the superblock for conventional devices into a separate helper so that it isn't called for zoned devices.
--- fs/btrfs/volumes.c | 51 +++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 25 deletions(-)
fs/btrfs/volumes.c +26 -25
@@ -2005,42 +2005,43 @@ static u64 btrfs_num_devices(struct btrfs_fs_info *fs_info)return num_devices; } +static void btrfs_scratch_superblock (struct btrfs_fs_info *fs_info, +struct block_device *bdev,int copy_num) +{ +struct btrfs_super_block *disk_super; +struct page *page; +int ret; + + disk_super =btrfs_read_dev_one_super (bdev, copy_num, false); +if (IS_ERR (disk_super)) +return ; +memset (&disk_super->magic,0 ,sizeof (disk_super->magic)); + page =virt_to_page (disk_super); +set_page_dirty (page); +lock_page (page); +/* write_on_page() unlocks the page */ + ret =write_one_page (page); +if (ret) +btrfs_warn (fs_info, +"error clearing superblock number %d (%d)" , + copy_num, ret); +btrfs_release_disk_super (disk_super); +} +void btrfs_scratch_superblocks (struct btrfs_fs_info *fs_info,struct block_device *bdev,const char *device_path) { -struct btrfs_super_block *disk_super;int copy_num;if (!bdev)return ;for (copy_num =0 ; copy_num <BTRFS_SUPER_MIRROR_MAX ; copy_num++) { -struct page *page; -int ret; - - disk_super =btrfs_read_dev_one_super (bdev, copy_num, false); -if (IS_ERR (disk_super)) -continue ; - -if (bdev_is_zoned (bdev)) { +if (bdev_is_zoned (bdev))btrfs_reset_sb_log_zones (bdev, copy_num); -continue ; - } - -memset (&disk_super->magic,0 ,sizeof (disk_super->magic)); - - page =virt_to_page (disk_super); -set_page_dirty (page); -lock_page (page); -/* write_on_page() unlocks the page */ - ret =write_one_page (page); -if (ret) -btrfs_warn (fs_info, -"error clearing superblock number %d (%d)" , - copy_num, ret); -btrfs_release_disk_super (disk_super); - +else +btrfs_scratch_superblock (fs_info, bdev, copy_num); }/* Notify udev that device has changed */
Signature · 1 line
2.35.1
PATCH 2/7 btrfs: stop using write_one_page in btrfs_scratch_superblock
In reply to Christoph Hellwigwrite_one_page is an awkward interface that expects the page locked and ->writepage to be implemented. Just mark the sb dirty, put the page and then call the proper bdev helper to sync the range.
--- fs/btrfs/volumes.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
fs/btrfs/volumes.c +8 -9
@@ -2009,23 +2009,22 @@ static void btrfs_scratch_superblock(struct btrfs_fs_info *fs_info, struct block_device *bdev, int copy_num) {struct btrfs_super_block *disk_super; -struct page *page; +const size_t len =sizeof (disk_super->magic); +u64 bytenr =btrfs_sb_offset (copy_num);int ret; - disk_super =btrfs_read_dev_one_super (bdev, copy_num, false); + disk_super =btrfs_read_disk_super (bdev, bytenr, bytenr);if (IS_ERR (disk_super))return ; -memset (&disk_super->magic,0 ,sizeof (disk_super->magic)); - page =virt_to_page (disk_super); -set_page_dirty (page); -lock_page (page); -/* write_on_page() unlocks the page */ - ret =write_one_page (page); +memset (&disk_super->magic,0 , len); +set_page_dirty (virt_to_page (disk_super)); +btrfs_release_disk_super (disk_super); + + ret =sync_blockdev_range (bdev, bytenr, bytenr + len -1 );if (ret)btrfs_warn (fs_info,"error clearing superblock number %d (%d)" , copy_num, ret); -btrfs_release_disk_super (disk_super); } void btrfs_scratch_superblocks(struct btrfs_fs_info *fs_info,
Signature · 1 line
2.35.1
Matthew Wilcox
maintainerRe: [PATCH 2/7] btrfs: stop using write_one_page in btrfs_scratch_superblock
fs/btrfs/volumes.c static void btrfs_scratch_superblock(struct btrfs_fs_info *fs_info, · line 2020
Quoted 2 lines · Christoph Hellwig
fs/btrfs/volumes.c +2
-0+memset (&disk_super->magic,0 , len); +set_page_dirty (virt_to_page (disk_super));
Could we make this:
folio_mark_dirty(virt_to_folio(disk_super));
Other than that, looks good.
PATCH 3/7 minix: don't flush page immediately for DIRSYNC directories
In reply to Christoph HellwigWe do not need to writeout modified directory blocks immediately when modifying them while the page is locked. It is enough to do the flush somewhat later which has the added benefit that inode times can be flushed as well. It also allows us to stop depending on write_one_page() function.
Ported from an ext2 patch by Jan Kara.
--- fs/minix/dir.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-)
fs/minix/dir.c +20 -10
@@ -46,21 +46,27 @@ minix_last_byte(struct inode *inode, unsigned long page_nr)return last_byte; } -static int dir_commit_chunk (struct page *page,loff_t pos,unsigned len) +static void dir_commit_chunk (struct page *page,loff_t pos,unsigned len) {struct address_space *mapping = page->mapping;struct inode *dir = mapping->host; -int err =0 ; +block_write_end (NULL , mapping, pos, len, len, page,NULL );if (pos+len > dir->i_size) {i_size_write (dir, pos+len);mark_inode_dirty (dir); } -if (IS_DIRSYNC (dir)) - err =write_one_page (page); -else -unlock_page (page); +unlock_page (page); +} + +static int minix_handle_dirsync (struct inode *dir) +{ +int err; + + err =filemap_write_and_wait (dir->i_mapping); +if (!err) + err =sync_inode_metadata (dir,1 );return err; }
@@ -274,9 +280,10 @@ int minix_add_link(struct dentry *dentry, struct inode *inode)memset (namx + namelen,0 , sbi->s_dirsize - namelen -2 ); de->inode = inode->i_ino; } - err =dir_commit_chunk (page, pos, sbi->s_dirsize); +dir_commit_chunk (page, pos, sbi->s_dirsize); dir->i_mtime = dir->i_ctime =current_time (dir);mark_inode_dirty (dir); +minix_handle_dirsync (dir); out_put:dir_put_page (page); out:
@@ -302,13 +309,15 @@ int minix_delete_entry(struct minix_dir_entry *de, struct page *page) ((minix3_dirent *) de)->inode =0 ; else de->inode = 0; - err =dir_commit_chunk (page, pos, len); +dir_commit_chunk (page, pos, len); }else {unlock_page (page); }dir_put_page (page); inode->i_ctime = inode->i_mtime =current_time (inode);mark_inode_dirty (inode); +if (!err) + err =minix_handle_dirsync (inode);return err; }
@@ -349,7 +358,8 @@ int minix_make_empty(struct inode *inode, struct inode *dir) }kunmap_atomic (kaddr); - err =dir_commit_chunk (page,0 ,2 * sbi->s_dirsize); +dir_commit_chunk (page,0 ,2 * sbi->s_dirsize); + err =minix_handle_dirsync (inode); fail:put_page (page);return err;
@@ -426,7 +436,7 @@ void minix_set_link(struct minix_dir_entry *de, struct page *page, ((minix3_dirent *) de)->inode = inode->i_ino; else de->inode = inode->i_ino; - err =dir_commit_chunk (page, pos, sbi->s_dirsize); +dir_commit_chunk (page, pos, sbi->s_dirsize); }else {unlock_page (page); }
Signature · 1 line
2.35.1
Matthew Wilcox
maintainerRe: [PATCH 3/7] minix: don't flush page immediately for DIRSYNC directories
fs/minix/dir.c int minix_add_link(struct dentry *dentry, struct inode *inode) · line 286
Quoted 9 lines · Christoph Hellwig
fs/minix/dir.c +2
-1@@ -274,9 +280,10 @@ int minix_add_link(struct dentry *dentry, struct inode *inode)memset (namx + namelen,0 , sbi->s_dirsize - namelen -2 ); de->inode = inode->i_ino; } - err =dir_commit_chunk (page, pos, sbi->s_dirsize); +dir_commit_chunk (page, pos, sbi->s_dirsize); dir->i_mtime = dir->i_ctime =current_time (dir);mark_inode_dirty (dir); +minix_handle_dirsync (dir);
Doesn't this need to be:
err = minix_handle_dirsync(dir);
fs/minix/dir.c void minix_set_link(struct minix_dir_entry *de, struct page *page, · line 442
Quoted 10 lines
fs/minix/dir.c +1
-1@@ -426,7 +436,7 @@ void minix_set_link(struct minix_dir_entry *de, struct page *page, ((minix3_dirent *) de)->inode = inode->i_ino; else de->inode = inode->i_ino; - err =dir_commit_chunk (page, pos, sbi->s_dirsize); +dir_commit_chunk (page, pos, sbi->s_dirsize); }else {unlock_page (page); }
Aren't you missing a call to minix_handle_dirsync() in this function?
Re: [PATCH 3/7] minix: don't flush page immediately for DIRSYNC directories
Quoted 8 lines · Matthew Wilcox
fs/minix/dir.c int minix_add_link(struct dentry *dentry, struct inode *inode) · line 286
Quoted 4 lines
fs/minix/dir.c +2
-0+dir_commit_chunk (page, pos, sbi->s_dirsize); dir->i_mtime = dir->i_ctime =current_time (dir);mark_inode_dirty (dir); +minix_handle_dirsync (dir);Doesn't this need to be:
err = minix_handle_dirsync(dir);
Yes, fixed.
Quoted 13 lines
fs/minix/dir.c void minix_set_link(struct minix_dir_entry *de, struct page *page, · line 442
Quoted 11 lines
fs/minix/dir.c +1
-1@@ -426,7 +436,7 @@ void minix_set_link(struct minix_dir_entry *de, struct page *page, ((minix3_dirent *) de)->inode = inode->i_ino; else de->inode = inode->i_ino; - err =dir_commit_chunk (page, pos, sbi->s_dirsize); +dir_commit_chunk (page, pos, sbi->s_dirsize); }else {unlock_page (page); }Aren't you missing a call to
minix_handle_dirsync()in this function?
Yes, fixed.
Al Viro
maintainerRe: [PATCH 3/7] minix: don't flush page immediately for DIRSYNC directories
Quoted 26 lines · Christoph Hellwig
Quoted 8 lines · Matthew Wilcox
fs/minix/dir.c int minix_add_link(struct dentry *dentry, struct inode *inode) · line 286
Quoted 4 lines
fs/minix/dir.c +2
-0+dir_commit_chunk (page, pos, sbi->s_dirsize); dir->i_mtime = dir->i_ctime =current_time (dir);mark_inode_dirty (dir); +minix_handle_dirsync (dir);Doesn't this need to be:
err = minix_handle_dirsync(dir);Yes, fixed.
Quoted 13 lines
fs/minix/dir.c void minix_set_link(struct minix_dir_entry *de, struct page *page, · line 442
Quoted 11 lines
fs/minix/dir.c +1
-1@@ -426,7 +436,7 @@ void minix_set_link(struct minix_dir_entry *de, struct page *page, ((minix3_dirent *) de)->inode = inode->i_ino; else de->inode = inode->i_ino; - err =dir_commit_chunk (page, pos, sbi->s_dirsize); +dir_commit_chunk (page, pos, sbi->s_dirsize); }else {unlock_page (page); }Aren't you missing a call to
minix_handle_dirsync()in this function?
Quoted 1 line
Yes, fixed.
More seriously, all those ..._set_link() need to return an error and their callers (..._rename()) need to deal with failures. That goes for ext2 as well, and that part is worth splitting off into a prereq - it's a -stable fodder.
Re: [PATCH 3/7] minix: don't flush page immediately for DIRSYNC directories
Quoted 2 lines · Al Viro
More seriously, all those ..._set_link() need to return an error and their callers (..._rename()) need to deal with failures.
That's actually what I did yesterday:
http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/remove-write_one_page
Al Viro
maintainerRe: [PATCH 3/7] minix: don't flush page immediately for DIRSYNC directories
Quoted 7 lines · Christoph Hellwig
Quoted 2 lines · Al Viro
More seriously, all those ..._set_link() need to return an error and their callers (..._rename()) need to deal with failures.
That's actually what I did yesterday:
http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/remove-write_one_page
ext2 also has that bug. As well as "need to check for delete_entry errors" one (also in ext2_rename()).
Completely untested patch follows:
fs/ext2/dir.c +2 -2
@@ -461,7 +461,7 @@ static int ext2_handle_dirsync(struct inode *dir)return err; } -void ext2_set_link (struct inode *dir,struct ext2_dir_entry_2 *de, +int ext2_set_link (struct inode *dir,struct ext2_dir_entry_2 *de,struct page *page,void *page_addr,struct inode *inode,int update_times) {
@@ -480,7 +480,7 @@ void ext2_set_link(struct inode *dir, struct ext2_dir_entry_2 *de, dir->i_mtime = dir->i_ctime =current_time (dir);EXT2_I (dir)->i_flags &= ~EXT2_BTREE_FL ;mark_inode_dirty (dir); -ext2_handle_dirsync (dir); +return ext2_handle_dirsync (dir); }/*
fs/ext2/ext2.h +1 -1
@@ -734,7 +734,7 @@ extern int ext2_delete_entry(struct ext2_dir_entry_2 *dir, struct page *page, char *kaddr);extern int ext2_empty_dir (struct inode *);extern struct ext2_dir_entry_2 *ext2_dotdot (struct inode *dir,struct page **p,void **pa); -extern void ext2_set_link (struct inode *,struct ext2_dir_entry_2 *,struct page *,void *, +extern int ext2_set_link (struct inode *,struct ext2_dir_entry_2 *,struct page *,void *,struct inode *,int );static inline void ext2_put_page (struct page *page,void *page_addr) {
fs/ext2/namei.c +6 -2
@@ -370,8 +370,10 @@ static int ext2_rename (struct user_namespace * mnt_userns, err =PTR_ERR (new_de); goto out_dir; } -ext2_set_link (new_dir, new_de, new_page, page_addr, old_inode,1 ); + err =ext2_set_link (new_dir, new_de, new_page, page_addr, old_inode,1 );ext2_put_page (new_page, page_addr); +if (err) + goto out_dir; new_inode->i_ctime =current_time (new_inode);if (dir_de)drop_nlink (new_inode);
@@ -391,7 +393,9 @@ static int ext2_rename (struct user_namespace * mnt_userns, old_inode->i_ctime =current_time (old_inode);mark_inode_dirty (old_inode); -ext2_delete_entry (old_de, old_page, old_page_addr); + err =ext2_delete_entry (old_de, old_page, old_page_addr); +if (err) + goto out_dir;if (dir_de) {if (old_dir != new_dir)
PATCH 4/7 sysv: don't flush page immediately for DIRSYNC directories
In reply to Christoph HellwigWe do not need to writeout modified directory blocks immediately when modifying them while the page is locked. It is enough to do the flush somewhat later which has the added benefit that inode times can be flushed as well. It also allows us to stop depending on write_one_page() function.
Ported from an ext2 patch by Jan Kara.
--- fs/sysv/dir.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-)
fs/sysv/dir.c +19 -10
@@ -34,21 +34,26 @@ static inline void dir_put_page(struct page *page)put_page (page); } -static int dir_commit_chunk (struct page *page,loff_t pos,unsigned len) +static void dir_commit_chunk (struct page *page,loff_t pos,unsigned len) {struct address_space *mapping = page->mapping;struct inode *dir = mapping->host; -int err =0 ;block_write_end (NULL , mapping, pos, len, len, page,NULL );if (pos+len > dir->i_size) {i_size_write (dir, pos+len);mark_inode_dirty (dir); } -if (IS_DIRSYNC (dir)) - err =write_one_page (page); -else -unlock_page (page); +unlock_page (page); +} + +static int sysv_handle_dirsync (struct inode *dir) +{ +int err; + + err =filemap_write_and_wait (dir->i_mapping); +if (!err) + err =sync_inode_metadata (dir,1 );return err; }
@@ -215,9 +220,10 @@ int sysv_add_link(struct dentry *dentry, struct inode *inode)memcpy (de->name, name, namelen);memset (de->name + namelen,0 ,SYSV_DIRSIZE - namelen -2 ); de->inode =cpu_to_fs16 (SYSV_SB (inode->i_sb), inode->i_ino); - err =dir_commit_chunk (page, pos,SYSV_DIRSIZE ); +dir_commit_chunk (page, pos,SYSV_DIRSIZE ); dir->i_mtime = dir->i_ctime =current_time (dir);mark_inode_dirty (dir); +sysv_handle_dirsync (dir); out_page:dir_put_page (page); out:
@@ -238,10 +244,11 @@ int sysv_delete_entry(struct sysv_dir_entry *de, struct page *page) err =sysv_prepare_chunk (page, pos,SYSV_DIRSIZE );BUG_ON (err); de->inode =0 ; - err =dir_commit_chunk (page, pos,SYSV_DIRSIZE ); +dir_commit_chunk (page, pos,SYSV_DIRSIZE );dir_put_page (page); inode->i_ctime = inode->i_mtime =current_time (inode);mark_inode_dirty (inode); +sysv_handle_dirsync (inode);return err; }
@@ -272,7 +279,8 @@ int sysv_make_empty(struct inode *inode, struct inode *dir)strcpy (de->name,".." );kunmap (page); - err =dir_commit_chunk (page,0 ,2 *SYSV_DIRSIZE ); +dir_commit_chunk (page,0 ,2 *SYSV_DIRSIZE ); + err =sysv_handle_dirsync (inode); fail:put_page (page);return err;
@@ -336,10 +344,11 @@ void sysv_set_link(struct sysv_dir_entry *de, struct page *page, err =sysv_prepare_chunk (page, pos,SYSV_DIRSIZE );BUG_ON (err); de->inode =cpu_to_fs16 (SYSV_SB (inode->i_sb), inode->i_ino); - err =dir_commit_chunk (page, pos,SYSV_DIRSIZE ); +dir_commit_chunk (page, pos,SYSV_DIRSIZE );dir_put_page (page); dir->i_mtime = dir->i_ctime =current_time (dir);mark_inode_dirty (dir); +sysv_handle_dirsync (inode); }struct sysv_dir_entry *sysv_dotdot (struct inode *dir,struct page **p)
Signature · 1 line
2.35.1
Matthew Wilcox
maintainerRe: [PATCH 4/7] sysv: don't flush page immediately for DIRSYNC directories
Quoted 5 lines · Christoph Hellwig
We do not need to writeout modified directory blocks immediately when modifying them while the page is locked. It is enough to do the flush somewhat later which has the added benefit that inode times can be flushed as well. It also allows us to stop depending on
write_one_page()function.
Similar concerns to the minix patch here ... missing assignments to 'err'.
Re: [PATCH 4/7] sysv: don't flush page immediately for DIRSYNC directories
Quoted 9 lines · Matthew Wilcox
Quoted 5 lines · Christoph Hellwig
We do not need to writeout modified directory blocks immediately when modifying them while the page is locked. It is enough to do the flush somewhat later which has the added benefit that inode times can be flushed as well. It also allows us to stop depending on
write_one_page()function.Similar concerns to the minix patch here ... missing assignments to 'err'.
Fixed.
PATCH 5/7 ufs: don't flush page immediately for DIRSYNC directories
In reply to Christoph HellwigWe do not need to writeout modified directory blocks immediately when modifying them while the page is locked. It is enough to do the flush somewhat later which has the added benefit that inode times can be flushed as well. It also allows us to stop depending on write_one_page() function.
Ported from an ext2 patch by Jan Kara.
--- fs/ufs/dir.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-)
fs/ufs/dir.c +19 -10
@@ -42,11 +42,10 @@ static inline int ufs_match(struct super_block *sb, int len,return !memcmp (name, de->d_name, len); } -static int ufs_commit_chunk (struct page *page,loff_t pos,unsigned len) +static void ufs_commit_chunk (struct page *page,loff_t pos,unsigned len) {struct address_space *mapping = page->mapping;struct inode *dir = mapping->host; -int err =0 ;inode_inc_iversion (dir);block_write_end (NULL , mapping, pos, len, len, page,NULL );
@@ -54,10 +53,16 @@ static int ufs_commit_chunk(struct page *page, loff_t pos, unsigned len)i_size_write (dir, pos+len);mark_inode_dirty (dir); } -if (IS_DIRSYNC (dir)) - err =write_one_page (page); -else -unlock_page (page); +unlock_page (page); +} + +static int ufs_handle_dirsync (struct inode *dir) +{ +int err; + + err =filemap_write_and_wait (dir->i_mapping); +if (!err) + err =sync_inode_metadata (dir,1 );return err; }
@@ -99,11 +104,12 @@ void ufs_set_link(struct inode *dir, struct ufs_dir_entry *de, de->d_ino =cpu_to_fs32 (dir->i_sb, inode->i_ino);ufs_set_de_type (dir->i_sb, de, inode->i_mode); - err =ufs_commit_chunk (page, pos, len); +ufs_commit_chunk (page, pos, len);ufs_put_page (page);if (update_times) dir->i_mtime = dir->i_ctime =current_time (dir);mark_inode_dirty (dir); +ufs_handle_dirsync (dir); }
@@ -390,10 +396,11 @@ int ufs_add_link(struct dentry *dentry, struct inode *inode) de->d_ino =cpu_to_fs32 (sb, inode->i_ino);ufs_set_de_type (sb, de, inode->i_mode); - err =ufs_commit_chunk (page, pos, rec_len); +ufs_commit_chunk (page, pos, rec_len); dir->i_mtime = dir->i_ctime =current_time (dir);mark_inode_dirty (dir); + err =ufs_handle_dirsync (dir);/* OFFSET_CACHE */ out_put:ufs_put_page (page);
@@ -531,9 +538,10 @@ int ufs_delete_entry(struct inode *inode, struct ufs_dir_entry *dir,if (pde) pde->d_reclen =cpu_to_fs16 (sb, to - from); dir->d_ino =0 ; - err =ufs_commit_chunk (page, pos, to - from); +ufs_commit_chunk (page, pos, to - from); inode->i_ctime = inode->i_mtime =current_time (inode);mark_inode_dirty (inode); + err =ufs_handle_dirsync (inode); out:ufs_put_page (page);UFSD ("EXIT\n" );
@@ -579,7 +587,8 @@ int ufs_make_empty(struct inode * inode, struct inode *dir)strcpy (de->d_name,".." );kunmap (page); - err =ufs_commit_chunk (page,0 , chunk_size); +ufs_commit_chunk (page,0 , chunk_size); + err =ufs_handle_dirsync (inode); fail:put_page (page);return err;
Signature · 1 line
2.35.1
PATCH 6/7 ocfs2: don't use write_one_page in ocfs2_duplicate_clusters_by_page
In reply to Christoph HellwigUse filemap_write_and_wait_range to write back the range of the dirty page instead of write_one_page in preparation of removing write_one_page and eventually ->writepage.
--- fs/ocfs2/refcounttree.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
fs/ocfs2/refcounttree.c +5 -4
@@ -2952,10 +2952,11 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,*/ if (PAGE_SIZE <=OCFS2_SB (sb)->s_clustersize) {if (PageDirty (page)) { -/* -* write_on_page will unlock the page on return -*/ - ret =write_one_page (page); +unlock_page (page); +put_page (page); + + ret =filemap_write_and_wait_range (mapping, + offset, map_end -1 ); goto retry; } }
Signature · 1 line
2.35.1
Re: [PATCH 6/7] ocfs2: don't use write_one_page in ocfs2_duplicate_clusters_by_page
Quoted 5 lines · Christoph Hellwig
Use
filemap_write_and_wait_rangeto write back the range of the dirty page instead ofwrite_one_pagein preparation of removingwrite_one_pageand eventually ->writepage.Signed-off-by Christoph Hellwig <[email protected]>
Looks good to me. Feel free to add:
Honza
Quoted 27 lines
--- fs/ocfs2/refcounttree.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)fs/ocfs2/refcounttree.c +5
-4@@ -2952,10 +2952,11 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,*/ if (PAGE_SIZE <=OCFS2_SB (sb)->s_clustersize) {if (PageDirty (page)) { -/* -* write_on_page will unlock the page on return -*/ - ret =write_one_page (page); +unlock_page (page); +put_page (page); + + ret =filemap_write_and_wait_range (mapping, + offset, map_end -1 ); goto retry; } }Signature · 1 line
2.35.1
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [Ocfs2-devel] [PATCH 6/7] ocfs2: don't use write_one_page in ocfs2_duplicate_clusters_by_page
In reply to Christoph HellwigQuoted 5 lines · On 1/9/23 12:56 AM, Christoph Hellwig via Ocfs2-devel wrote:
Use
filemap_write_and_wait_rangeto write back the range of the dirty page instead ofwrite_one_pagein preparation of removingwrite_one_pageand eventually ->writepage.Signed-off-by Christoph Hellwig <[email protected]>
Looks good.
Quoted 24 lines
--- fs/ocfs2/refcounttree.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)fs/ocfs2/refcounttree.c +5
-4@@ -2952,10 +2952,11 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,*/ if (PAGE_SIZE <=OCFS2_SB (sb)->s_clustersize) {if (PageDirty (page)) { -/* -* write_on_page will unlock the page on return -*/ - ret =write_one_page (page); +unlock_page (page); +put_page (page); + + ret =filemap_write_and_wait_range (mapping, + offset, map_end -1 ); goto retry; } }
PATCH 7/7 mm,jfs: move write_one_page/folio_write_one to jfs
In reply to Christoph HellwigThe last remaining user of folio_write_one through the write_one_page wrapper is jfs, so move the functionality there and hard code the call to metapage_writepage.
Note that the use of the pagecache by the jfs 'metapage' buffer cache is a bit odd, and we could probably do without VM-level dirty tracking at all, but that's a change for another time.
--- fs/jfs/jfs_metapage.c | 39 ++++++++++++++++++++++++++++++++++----- include/linux/pagemap.h | 6 ------ mm/page-writeback.c | 40 ---------------------------------------- 3 files changed, 34 insertions(+), 51 deletions(-)
fs/jfs/jfs_metapage.c +34 -5
@@ -691,6 +691,35 @@ void grab_metapage(struct metapage * mp)unlock_page (mp->page); } +static int metapage_write_one (struct page *page) +{ +struct folio *folio =page_folio (page); +struct address_space *mapping = folio->mapping; +struct writeback_control wbc = { + .sync_mode =WB_SYNC_ALL , + .nr_to_write =folio_nr_pages (folio), + }; +int ret =0 ; + +BUG_ON (!folio_test_locked (folio)); + +folio_wait_writeback (folio); + +if (folio_clear_dirty_for_io (folio)) { +folio_get (folio); + ret =metapage_writepage (page, &wbc); +if (ret ==0 ) +folio_wait_writeback (folio); +folio_put (folio); + }else { +folio_unlock (folio); + } + +if (!ret) + ret =filemap_check_errors (mapping); +return ret; +} +void force_metapage (struct metapage *mp) {struct page *page = mp->page;
@@ -700,8 +729,8 @@ void force_metapage(struct metapage *mp)get_page (page);lock_page (page);set_page_dirty (page); -if (write_one_page (page)) -jfs_error (mp->sb,"write_one_page() failed\n" ); +if (metapage_write_one (page)) +jfs_error (mp->sb,"metapage_write_one() failed\n" );clear_bit (META_forcewrite, &mp->flag);put_page (page); }
@@ -746,9 +775,9 @@ void release_metapage(struct metapage * mp)set_page_dirty (page);if (test_bit (META_sync, &mp->flag)) {clear_bit (META_sync, &mp->flag); -if (write_one_page (page)) -jfs_error (mp->sb,"write_one_page() failed\n" ); -lock_page (page);/* write_one_page unlocks the page */ +if (metapage_write_one (page)) +jfs_error (mp->sb,"metapage_write_one() failed\n" ); +lock_page (page); } }else if (mp->lsn)/* discard_metapage doesn't remove it */ remove_from_logsync (mp);
include/linux/pagemap.h +0 -6
@@ -1062,12 +1062,6 @@ static inline void folio_cancel_dirty(struct folio *folio)bool folio_clear_dirty_for_io (struct folio *folio);bool clear_page_dirty_for_io (struct page *page);void folio_invalidate (struct folio *folio,size_t offset,size_t length); -int __must_check folio_write_one (struct folio *folio); -static inline int __must_check write_one_page (struct page *page) -{ -return folio_write_one (page_folio (page)); -} -int __set_page_dirty_nobuffers (struct page *page);bool noop_dirty_folio (struct address_space *mapping,struct folio *folio);
mm/page-writeback.c +0 -40
@@ -2581,46 +2581,6 @@ int do_writepages(struct address_space *mapping, struct writeback_control *wbc)return ret; } -/** -* folio_write_one - write out a single folio and wait on I/O. -* @folio: The folio to write. -* -* The folio must be locked by the caller and will be unlocked upon return. -* -* Note that the mapping's AS_EIO/AS_ENOSPC flags will be cleared when this -* function returns. -* -* Return: %0 on success, negative error code otherwise -*/ -int folio_write_one (struct folio *folio) -{ -struct address_space *mapping = folio->mapping; -int ret =0 ; -struct writeback_control wbc = { - .sync_mode =WB_SYNC_ALL , - .nr_to_write =folio_nr_pages (folio), - }; - -BUG_ON (!folio_test_locked (folio)); - -folio_wait_writeback (folio); - -if (folio_clear_dirty_for_io (folio)) { -folio_get (folio); - ret = mapping->a_ops->writepage (&folio->page, &wbc); -if (ret ==0 ) -folio_wait_writeback (folio); -folio_put (folio); - }else { -folio_unlock (folio); - } - -if (!ret) - ret =filemap_check_errors (mapping); -return ret; -} -EXPORT_SYMBOL (folio_write_one); -/* * For address_spaces which do not use buffers nor write back. */
Signature · 1 line
2.35.1
Matthew Wilcox
maintainerQuoted 11 lines · Christoph Hellwig
this series removes the
write_one_pageAPI, and it's folioized implementation asfolio_write_one. These helpers internally call ->writepage which we are gradually removing from the kernel.For most callers there are better APIs to use, and this cleans them up. The big questionmark is jfs, where the metapage abstraction uses the pagecache in a bit of an odd way, and which would probably benefit from not using the page cache at all like the XFS buffer cache, but given that jfs has been in minimum maintaince mode for a long time that might not be worth it. So for now it just moves the implementation of
write_one_pageinto jfs instead.
Thanks. This totally wrecks a patchset I was working on, but it's definitely the right thing to do, and I'll rebase on top of it once it's in. Looking forward to v2 with my niggles fixed ;-)
Quoted 14 lines · Christoph Hellwig
Hi all,
this series removes the
write_one_pageAPI, and it's folioized implementation asfolio_write_one. These helpers internally call ->writepage which we are gradually removing from the kernel.For most callers there are better APIs to use, and this cleans them up. The big questionmark is jfs, where the metapage abstraction uses the pagecache in a bit of an odd way, and which would probably benefit from not using the page cache at all like the XFS buffer cache, but given that jfs has been in minimum maintaince mode for a long time that might not be worth it. So for now it just moves the implementation of
write_one_pageinto jfs instead.
Quoted 2 lines
Diffstat:
fs/btrfs/volumes.c | 50 ++++++++++++++++++++++++------------------------
The btrfs patches were sent separately some time ago, now merged to misc-next with updated changelogs and with the suggested switch to folio API in the 2nd patch.
Quoted 3 lines · David Sterba
The btrfs patches were sent separately some time ago, now merged to misc-next with updated changelogs and with the suggested switch to folio API in the 2nd patch.
Yes, 7 weeks ago to be exact. I wish we could just feed everything together now that we've missed the previous merge window, as that makes patch juggling for Andrew and Matthew a lot simpler.
Quoted 8 lines · Christoph Hellwig
Quoted 3 lines · David Sterba
The btrfs patches were sent separately some time ago, now merged to misc-next with updated changelogs and with the suggested switch to folio API in the 2nd patch.
Yes, 7 weeks ago to be exact. I wish we could just feed everything together now that we've missed the previous merge window, as that makes patch juggling for Andrew and Matthew a lot simpler.
The patches are not fixes so they should wait for the next merge window.
Quoted 11 lines · David Sterba
Quoted 8 lines · Christoph Hellwig
Quoted 3 lines · David Sterba
The btrfs patches were sent separately some time ago, now merged to misc-next with updated changelogs and with the suggested switch to folio API in the 2nd patch.
Yes, 7 weeks ago to be exact. I wish we could just feed everything together now that we've missed the previous merge window, as that makes patch juggling for Andrew and Matthew a lot simpler.
The patches are not fixes so they should wait for the next merge window.
Agreed. But it would be a lot simpler if we could queue them up in -mm with the other patches now that we've missed the previous merge window.
Quoted 11 lines · Christoph Hellwig
Quoted 10 lines · David Sterba
Quoted 8 lines · Christoph Hellwig
Quoted 3 lines · David Sterba
The btrfs patches were sent separately some time ago, now merged to misc-next with updated changelogs and with the suggested switch to folio API in the 2nd patch.
Yes, 7 weeks ago to be exact. I wish we could just feed everything together now that we've missed the previous merge window, as that makes patch juggling for Andrew and Matthew a lot simpler.
Quoted 5 lines
Quoted 1 line
The patches are not fixes so they should wait for the next merge window.
Agreed. But it would be a lot simpler if we could queue them up in -mm with the other patches now that we've missed the previous merge window.
Ok then, to make it easier for the folio changes I'll send the two btrfs patches next week. As the rest of the series does not depend on it, I don't see the need to let them all go via the mm tree.
Quoted 3 lines · David Sterba
Ok then, to make it easier for the folio changes I'll send the two btrfs patches next week. As the rest of the series does not depend on it, I don't see the need to let them all go via the mm tree.
The last patch depends on the btrfs changes as it removes write_one_page entirely.