linux-nilfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
	linux-nilfs@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: [PATCH 26/35] nilfs2: Switch to kmap_local for directory handling
Date: Mon,  6 Nov 2023 17:38:54 +0000	[thread overview]
Message-ID: <20231106173903.1734114-27-willy@infradead.org> (raw)
In-Reply-To: <20231106173903.1734114-1-willy@infradead.org>

Match ext2 by using kmap_local() instead of kmap().  This is more
efficient.  Also use unmap_and_put_page() instead of duplicating
it as a nilfs function.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 fs/nilfs2/dir.c   | 37 +++++++++++++++----------------------
 fs/nilfs2/namei.c |  9 +++------
 2 files changed, 18 insertions(+), 28 deletions(-)

diff --git a/fs/nilfs2/dir.c b/fs/nilfs2/dir.c
index 1ae370521249..01c57573211e 100644
--- a/fs/nilfs2/dir.c
+++ b/fs/nilfs2/dir.c
@@ -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.
@@ -195,7 +189,7 @@ static void *nilfs_get_page(struct inode *dir, unsigned long n,
 	if (IS_ERR(page))
 		return page;
 
-	kaddr = kmap(page);
+	kaddr = kmap_local_page(page);
 	if (unlikely(!PageChecked(page))) {
 		if (!nilfs_check_page(page, kaddr))
 			goto fail;
@@ -205,7 +199,7 @@ static void *nilfs_get_page(struct inode *dir, unsigned long n,
 	return kaddr;
 
 fail:
-	nilfs_put_page(page);
+	unmap_and_put_page(page, kaddr);
 	return ERR_PTR(-EIO);
 }
 
@@ -293,7 +287,7 @@ static int nilfs_readdir(struct file *file, struct dir_context *ctx)
 		for ( ; (char *)de <= limit; de = nilfs_next_entry(de)) {
 			if (de->rec_len == 0) {
 				nilfs_error(sb, "zero-length directory entry");
-				nilfs_put_page(page);
+				unmap_and_put_page(page, kaddr);
 				return -EIO;
 			}
 			if (de->inode) {
@@ -306,13 +300,13 @@ static int nilfs_readdir(struct file *file, struct dir_context *ctx)
 
 				if (!dir_emit(ctx, de->name, de->name_len,
 						le64_to_cpu(de->inode), t)) {
-					nilfs_put_page(page);
+					unmap_and_put_page(page, kaddr);
 					return 0;
 				}
 			}
 			ctx->pos += nilfs_rec_len_from_disk(de->rec_len);
 		}
-		nilfs_put_page(page);
+		unmap_and_put_page(page, kaddr);
 	}
 	return 0;
 }
@@ -357,14 +351,14 @@ nilfs_find_entry(struct inode *dir, const struct qstr *qstr,
 				if (de->rec_len == 0) {
 					nilfs_error(dir->i_sb,
 						"zero-length directory entry");
-					nilfs_put_page(page);
+					unmap_and_put_page(page, kaddr);
 					goto out;
 				}
 				if (nilfs_match(namelen, name, de))
 					goto found;
 				de = nilfs_next_entry(de);
 			}
-			nilfs_put_page(page);
+			unmap_and_put_page(page, kaddr);
 		}
 		if (++n >= npages)
 			n = 0;
@@ -404,8 +398,7 @@ ino_t nilfs_inode_by_name(struct inode *dir, const struct qstr *qstr)
 	de = nilfs_find_entry(dir, qstr, &page);
 	if (de) {
 		res = le64_to_cpu(de->inode);
-		kunmap(page);
-		put_page(page);
+		unmap_and_put_page(page, de);
 	}
 	return res;
 }
@@ -425,7 +418,7 @@ 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);
+	unmap_and_put_page(page, de);
 	inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir));
 }
 
@@ -491,7 +484,7 @@ int nilfs_add_link(struct dentry *dentry, struct inode *inode)
 			de = (struct nilfs_dir_entry *)((char *)de + rec_len);
 		}
 		unlock_page(page);
-		nilfs_put_page(page);
+		unmap_and_put_page(page, kaddr);
 	}
 	BUG();
 	return -EINVAL;
@@ -519,7 +512,7 @@ int nilfs_add_link(struct dentry *dentry, struct inode *inode)
 	nilfs_mark_inode_dirty(dir);
 	/* OFFSET_CACHE */
 out_put:
-	nilfs_put_page(page);
+	unmap_and_put_page(page, de);
 out:
 	return err;
 out_unlock:
@@ -565,7 +558,7 @@ int nilfs_delete_entry(struct nilfs_dir_entry *dir, struct page *page)
 	nilfs_commit_chunk(page, mapping, from, to);
 	inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
 out:
-	nilfs_put_page(page);
+	unmap_and_put_page(page, kaddr);
 	return err;
 }
 
@@ -617,10 +610,10 @@ int nilfs_make_empty(struct inode *inode, struct inode *parent)
 int nilfs_empty_dir(struct inode *inode)
 {
 	struct page *page = NULL;
+	char *kaddr;
 	unsigned long i, npages = dir_pages(inode);
 
 	for (i = 0; i < npages; i++) {
-		char *kaddr;
 		struct nilfs_dir_entry *de;
 
 		kaddr = nilfs_get_page(inode, i, &page);
@@ -652,12 +645,12 @@ int nilfs_empty_dir(struct inode *inode)
 			}
 			de = nilfs_next_entry(de);
 		}
-		nilfs_put_page(page);
+		unmap_and_put_page(page, kaddr);
 	}
 	return 1;
 
 not_empty:
-	nilfs_put_page(page);
+	unmap_and_put_page(page, kaddr);
 	return 0;
 }
 
diff --git a/fs/nilfs2/namei.c b/fs/nilfs2/namei.c
index 2a4e7f4a8102..8eebd8a464d8 100644
--- a/fs/nilfs2/namei.c
+++ b/fs/nilfs2/namei.c
@@ -421,13 +421,10 @@ static int nilfs_rename(struct mnt_idmap *idmap,
 	return err;
 
 out_dir:
-	if (dir_de) {
-		kunmap(dir_page);
-		put_page(dir_page);
-	}
+	if (dir_de)
+		unmap_and_put_page(dir_page, dir_de);
 out_old:
-	kunmap(old_page);
-	put_page(old_page);
+	unmap_and_put_page(old_page, old_de);
 out:
 	nilfs_transaction_abort(old_dir->i_sb);
 	return err;
-- 
2.42.0


  parent reply	other threads:[~2023-11-06 17:39 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-06 17:38 [PATCH 00/35] nilfs2: Folio conversions Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 01/35] nilfs2: Add nilfs_end_folio_io() Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 02/35] nilfs2: Convert nilfs_abort_logs to use folios Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 03/35] nilfs2: Convert nilfs_segctor_complete_write " Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 04/35] nilfs2: Convert nilfs_forget_buffer to use a folio Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 05/35] nilfs2: Convert to nilfs_folio_buffers_clean() Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 06/35] nilfs2: Convert nilfs_writepage() to use a folio Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 07/35] nilfs2: Convert nilfs_mdt_write_page() " Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 08/35] nilfs2: Convert to nilfs_clear_folio_dirty() Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 09/35] nilfs2: Convert to __nilfs_clear_folio_dirty() Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 10/35] nilfs2: Convert nilfs_segctor_prepare_write to use folios Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 11/35] nilfs2: Convert nilfs_page_mkwrite() to use a folio Matthew Wilcox (Oracle)
2023-11-09 13:11   ` Ryusuke Konishi
2023-11-09 13:37     ` Matthew Wilcox
2023-11-09 14:22       ` Ryusuke Konishi
2023-11-06 17:38 ` [PATCH 12/35] nilfs2: Convert nilfs_mdt_create_block " Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 13/35] nilfs2: Convert nilfs_mdt_submit_block " Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 14/35] nilfs2: Convert nilfs_gccache_submit_read_data " Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 15/35] nilfs2: Convert nilfs_btnode_create_block " Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 16/35] nilfs2: Convert nilfs_btnode_submit_block " Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 17/35] nilfs2: Convert nilfs_btnode_delete " Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 18/35] nilfs2: Convert nilfs_btnode_prepare_change_key " Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 19/35] nilfs2: Convert nilfs_btnode_commit_change_key " Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 20/35] nilfs2: Convert nilfs_btnode_abort_change_key " Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 21/35] nilfs2: Remove page_address() from nilfs_set_link Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 22/35] nilfs2: Remove page_address() from nilfs_add_link Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 23/35] nilfs2: Remove page_address() from nilfs_delete_entry Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 24/35] nilfs2: Return the mapped address from nilfs_get_page() Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 25/35] nilfs2: Pass the mapped address to nilfs_check_page() Matthew Wilcox (Oracle)
2023-11-06 17:38 ` Matthew Wilcox (Oracle) [this message]
2023-11-06 17:38 ` [PATCH 27/35] nilfs2: Add nilfs_get_folio() Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 28/35] nilfs2: Convert nilfs_readdir to use a folio Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 29/35] nilfs2: Convert nilfs_find_entry " Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 30/35] nilfs2: Convert nilfs_rename() to use folios Matthew Wilcox (Oracle)
2023-11-06 17:38 ` [PATCH 31/35] nilfs2: Convert nilfs_add_link() to use a folio Matthew Wilcox (Oracle)
2023-11-06 17:39 ` [PATCH 32/35] nilfs2: Convert nilfs_empty_dir() " Matthew Wilcox (Oracle)
2023-11-06 17:39 ` [PATCH 33/35] nilfs2: Convert nilfs_make_empty() " Matthew Wilcox (Oracle)
2023-11-06 17:39 ` [PATCH 34/35] nilfs2: Convert nilfs_prepare_chunk() and nilfs_commit_chunk() to folios Matthew Wilcox (Oracle)
2023-11-06 17:39 ` [PATCH 35/35] nilfs2: Convert nilfs_page_bug() to nilfs_folio_bug() Matthew Wilcox (Oracle)
2023-11-07  1:49 ` [PATCH 00/35] nilfs2: Folio conversions Ryusuke Konishi
2023-11-12  0:10   ` Ryusuke Konishi
2023-11-21 17:43     ` Ryusuke Konishi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231106173903.1734114-27-willy@infradead.org \
    --to=willy@infradead.org \
    --cc=konishi.ryusuke@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-nilfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).