Skip to content

Commit 584db20

Browse files
konisakpm00
authored andcommitted
nilfs2: move page release outside of nilfs_delete_entry and nilfs_set_link
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>
1 parent 9d02330 commit 584db20

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

fs/nilfs2/dir.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,6 @@ static inline unsigned int nilfs_chunk_size(struct inode *inode)
6464
return inode->i_sb->s_blocksize;
6565
}
6666

67-
static inline void nilfs_put_page(struct page *page)
68-
{
69-
kunmap(page);
70-
put_page(page);
71-
}
72-
7367
/*
7468
* Return the offset into page `page_nr' of the last valid
7569
* byte in that page, plus one.
@@ -413,7 +407,6 @@ ino_t nilfs_inode_by_name(struct inode *dir, const struct qstr *qstr)
413407
return res;
414408
}
415409

416-
/* Releases the page */
417410
void nilfs_set_link(struct inode *dir, struct nilfs_dir_entry *de,
418411
struct page *page, struct inode *inode)
419412
{
@@ -428,7 +421,6 @@ void nilfs_set_link(struct inode *dir, struct nilfs_dir_entry *de,
428421
de->inode = cpu_to_le64(inode->i_ino);
429422
nilfs_set_de_type(de, inode);
430423
nilfs_commit_chunk(page, mapping, from, to);
431-
nilfs_put_page(page);
432424
inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir));
433425
}
434426

@@ -533,7 +525,7 @@ int nilfs_add_link(struct dentry *dentry, struct inode *inode)
533525

534526
/*
535527
* nilfs_delete_entry deletes a directory entry by merging it with the
536-
* previous entry. Page is up-to-date. Releases the page.
528+
* previous entry. Page is up-to-date.
537529
*/
538530
int nilfs_delete_entry(struct nilfs_dir_entry *dir, struct page *page)
539531
{
@@ -569,7 +561,6 @@ int nilfs_delete_entry(struct nilfs_dir_entry *dir, struct page *page)
569561
nilfs_commit_chunk(page, mapping, from, to);
570562
inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
571563
out:
572-
nilfs_put_page(page);
573564
return err;
574565
}
575566

fs/nilfs2/namei.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ static int nilfs_do_unlink(struct inode *dir, struct dentry *dentry)
280280
set_nlink(inode, 1);
281281
}
282282
err = nilfs_delete_entry(de, page);
283+
nilfs_put_page(page);
283284
if (err)
284285
goto out;
285286

@@ -386,6 +387,7 @@ static int nilfs_rename(struct mnt_idmap *idmap,
386387
if (!new_de)
387388
goto out_dir;
388389
nilfs_set_link(new_dir, new_de, new_page, old_inode);
390+
nilfs_put_page(new_page);
389391
nilfs_mark_inode_dirty(new_dir);
390392
inode_set_ctime_current(new_inode);
391393
if (dir_de)
@@ -409,9 +411,11 @@ static int nilfs_rename(struct mnt_idmap *idmap,
409411
inode_set_ctime_current(old_inode);
410412

411413
nilfs_delete_entry(old_de, old_page);
414+
nilfs_put_page(old_page);
412415

413416
if (dir_de) {
414417
nilfs_set_link(old_inode, dir_de, dir_page, new_dir);
418+
nilfs_put_page(dir_page);
415419
drop_nlink(old_dir);
416420
}
417421
nilfs_mark_inode_dirty(old_dir);
@@ -421,13 +425,10 @@ static int nilfs_rename(struct mnt_idmap *idmap,
421425
return err;
422426

423427
out_dir:
424-
if (dir_de) {
425-
kunmap(dir_page);
426-
put_page(dir_page);
427-
}
428+
if (dir_de)
429+
nilfs_put_page(dir_page);
428430
out_old:
429-
kunmap(old_page);
430-
put_page(old_page);
431+
nilfs_put_page(old_page);
431432
out:
432433
nilfs_transaction_abort(old_dir->i_sb);
433434
return err;

fs/nilfs2/nilfs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ extern struct nilfs_dir_entry *nilfs_dotdot(struct inode *, struct page **);
237237
extern void nilfs_set_link(struct inode *, struct nilfs_dir_entry *,
238238
struct page *, struct inode *);
239239

240+
static inline void nilfs_put_page(struct page *page)
241+
{
242+
kunmap(page);
243+
put_page(page);
244+
}
245+
240246
/* file.c */
241247
extern int nilfs_sync_file(struct file *, loff_t, loff_t, int);
242248

0 commit comments

Comments
 (0)