]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
nilfs2: move page release outside of nilfs_delete_entry and nilfs_set_link
authorRyusuke Konishi <konishi.ryusuke@gmail.com>
Mon, 27 Nov 2023 14:30:20 +0000 (23:30 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Mar 2025 11:47:43 +0000 (12:47 +0100)
commit 584db20c181f5e28c0386d7987406ace7fbd3e49 upstream.

Patch series "nilfs2: Folio conversions for directory paths".

This series applies page->folio conversions to nilfs2 directory
operations.  This reduces hidden compound_head() calls and also converts
deprecated kmap calls to kmap_local in the directory code.

Although nilfs2 does not yet support large folios, Matthew has done his
best here to include support for large folios, which will be needed for
devices with large block sizes.

This series corresponds to the second half of the original post [1], but
with two complementary patches inserted at the beginning and some
adjustments, to prevent a kmap_local constraint violation found during
testing with highmem mapping.

[1] https://lkml.kernel.org/r/20231106173903.1734114-1-willy@infradead.org

I have reviewed all changes and tested this for regular and small block
sizes, both on machines with and without highmem mapping.  No issues
found.

This patch (of 17):

In a few directory operations, the call to nilfs_put_page() for a page
obtained using nilfs_find_entry() or nilfs_dotdot() is hidden in
nilfs_set_link() and nilfs_delete_entry(), making it difficult to track
page release and preventing change of its call position.

By moving nilfs_put_page() out of these functions, this makes the page
get/put correspondence clearer and makes it easier to swap
nilfs_put_page() calls (and kunmap calls within them) when modifying
multiple directory entries simultaneously in nilfs_rename().

Also, update comments for nilfs_set_link() and nilfs_delete_entry() to
reflect changes in their behavior.

To make nilfs_put_page() visible from namei.c, this moves its definition
to nilfs.h and replaces existing equivalents to use it, but the exposure
of that definition is temporary and will be removed on a later kmap ->
kmap_local conversion.

Link: https://lkml.kernel.org/r/20231127143036.2425-1-konishi.ryusuke@gmail.com
Link: https://lkml.kernel.org/r/20231127143036.2425-2-konishi.ryusuke@gmail.com
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Stable-dep-of: ee70999a988b ("nilfs2: handle errors that nilfs_prepare_chunk() may return")
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/nilfs2/dir.c
fs/nilfs2/namei.c
fs/nilfs2/nilfs.h

index cd363e2fc071d5455a6705be866e6cce4d27e653..3a8ff6d4a1b0455aedbe6282c0a975040bb1ce8b 100644 (file)
@@ -64,12 +64,6 @@ static inline unsigned int nilfs_chunk_size(struct inode *inode)
        return inode->i_sb->s_blocksize;
 }
 
-static inline void nilfs_put_page(struct page *page)
-{
-       kunmap(page);
-       put_page(page);
-}
-
 /*
  * Return the offset into page `page_nr' of the last valid
  * byte in that page, plus one.
@@ -450,7 +444,6 @@ int nilfs_inode_by_name(struct inode *dir, const struct qstr *qstr, ino_t *ino)
        return 0;
 }
 
-/* Releases the page */
 void nilfs_set_link(struct inode *dir, struct nilfs_dir_entry *de,
                    struct page *page, struct inode *inode)
 {
@@ -465,7 +458,6 @@ void nilfs_set_link(struct inode *dir, struct nilfs_dir_entry *de,
        de->inode = cpu_to_le64(inode->i_ino);
        nilfs_set_de_type(de, inode);
        nilfs_commit_chunk(page, mapping, from, to);
-       nilfs_put_page(page);
        dir->i_mtime = dir->i_ctime = current_time(dir);
 }
 
@@ -569,7 +561,7 @@ out_unlock:
 
 /*
  * nilfs_delete_entry deletes a directory entry by merging it with the
- * previous entry. Page is up-to-date. Releases the page.
+ * previous entry. Page is up-to-date.
  */
 int nilfs_delete_entry(struct nilfs_dir_entry *dir, struct page *page)
 {
@@ -605,7 +597,6 @@ int nilfs_delete_entry(struct nilfs_dir_entry *dir, struct page *page)
        nilfs_commit_chunk(page, mapping, from, to);
        inode->i_ctime = inode->i_mtime = current_time(inode);
 out:
-       nilfs_put_page(page);
        return err;
 }
 
index 446af9c21a29302b8987925382ba3f0f2d4a0e84..9c5e169730e2ae19df179db1847bdef2a7eeb63e 100644 (file)
@@ -295,6 +295,7 @@ static int nilfs_do_unlink(struct inode *dir, struct dentry *dentry)
                set_nlink(inode, 1);
        }
        err = nilfs_delete_entry(de, page);
+       nilfs_put_page(page);
        if (err)
                goto out;
 
@@ -403,6 +404,7 @@ static int nilfs_rename(struct inode *old_dir, struct dentry *old_dentry,
                        goto out_dir;
                }
                nilfs_set_link(new_dir, new_de, new_page, old_inode);
+               nilfs_put_page(new_page);
                nilfs_mark_inode_dirty(new_dir);
                new_inode->i_ctime = current_time(new_inode);
                if (dir_de)
@@ -426,9 +428,11 @@ static int nilfs_rename(struct inode *old_dir, struct dentry *old_dentry,
        old_inode->i_ctime = current_time(old_inode);
 
        nilfs_delete_entry(old_de, old_page);
+       nilfs_put_page(old_page);
 
        if (dir_de) {
                nilfs_set_link(old_inode, dir_de, dir_page, new_dir);
+               nilfs_put_page(dir_page);
                drop_nlink(old_dir);
        }
        nilfs_mark_inode_dirty(old_dir);
@@ -438,13 +442,10 @@ static int nilfs_rename(struct inode *old_dir, struct dentry *old_dentry,
        return err;
 
 out_dir:
-       if (dir_de) {
-               kunmap(dir_page);
-               put_page(dir_page);
-       }
+       if (dir_de)
+               nilfs_put_page(dir_page);
 out_old:
-       kunmap(old_page);
-       put_page(old_page);
+       nilfs_put_page(old_page);
 out:
        nilfs_transaction_abort(old_dir->i_sb);
        return err;
index e1b230a5011a046e48305f671f14ee2a4a30097e..169c6c5e06720cbff5cfbb9902feda8cc1f082e2 100644 (file)
@@ -243,6 +243,12 @@ extern struct nilfs_dir_entry *nilfs_dotdot(struct inode *, struct page **);
 extern void nilfs_set_link(struct inode *, struct nilfs_dir_entry *,
                           struct page *, struct inode *);
 
+static inline void nilfs_put_page(struct page *page)
+{
+       kunmap(page);
+       put_page(page);
+}
+
 /* file.c */
 extern int nilfs_sync_file(struct file *, loff_t, loff_t, int);