2021-03-29 06:55:40

by Ira Weiny

[permalink] [raw]
Subject: [PATCH 0/2] ext2: Convert kmap to kmap_local_page

From: Ira Weiny <[email protected]>

kmap is inefficient and can be abused so it is being phased out in favor of
kmap_local_page where possible.

ext2 uses kmap in ext2_[get|put]_page(). All of the calls to
ext2_[get|put]_page() occur in single threads so it is perfectly safe and
preferable to use kmap_local_page().

This series has a clean up which matches ext2_put_page() with ext2_dotdot() and
ext2_find_entry(). Those calls use ext2_get_page() to map the page prior to
returning it to their callers. And they document that ext2_put_page() should
be matched up with them. This was the case but the ext2_put_page() calls were
hidden in other functions. We lift the ext2_put_page() calls to match up to
the functions where ext2_dotdot() and ext2_find_entry() are called.

After that clean up convert ext2_[get|put]_page() to kmap and adjust for
kunmap_local() requiring the page address.

Nesting of kmap_local_page() calls is maintained with minor changes.

Ira Weiny (2):
ext2: Match up ext2_put_page() with ext2_dotdot() and
ext2_find_entry()
fs/ext2: Replace kmap() with kmap_local_page()

fs/ext2/dir.c | 94 +++++++++++++++++++++++++++++++------------------
fs/ext2/ext2.h | 12 ++++---
fs/ext2/namei.c | 34 +++++++++++-------
3 files changed, 89 insertions(+), 51 deletions(-)

--
2.28.0.rc0.12.gb6a658bd00c9


2021-03-29 06:55:40

by Ira Weiny

[permalink] [raw]
Subject: [PATCH 1/2] ext2: Match up ext2_put_page() with ext2_dotdot() and ext2_find_entry()

From: Ira Weiny <[email protected]>

ext2_dotdot() and ext2_find_entry() both require ext2_put_page() to be
called after successful return. For some of the calls this
corresponding put was hidden in ext2_set_link and ext2_delete_entry().

Match up ext2_put_page() with ext2_dotdot() and ext2_find_entry() in the
functions which call them. This makes the code easier to follow
regarding the get/put of the page.

Clean up comments to match new behavior.

To: Jan Kara <[email protected]>
Signed-off-by: Ira Weiny <[email protected]>
---
fs/ext2/dir.c | 5 +----
fs/ext2/namei.c | 7 +++++--
2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/fs/ext2/dir.c b/fs/ext2/dir.c
index 14aa45316ad2..f0b8311cdf5b 100644
--- a/fs/ext2/dir.c
+++ b/fs/ext2/dir.c
@@ -434,7 +434,6 @@ static int ext2_prepare_chunk(struct page *page, loff_t pos, unsigned len)
return __block_write_begin(page, pos, len, ext2_get_block);
}

-/* Releases the page */
void ext2_set_link(struct inode *dir, struct ext2_dir_entry_2 *de,
struct page *page, struct inode *inode, int update_times)
{
@@ -449,7 +448,6 @@ void ext2_set_link(struct inode *dir, struct ext2_dir_entry_2 *de,
de->inode = cpu_to_le32(inode->i_ino);
ext2_set_de_type(de, inode);
err = ext2_commit_chunk(page, pos, len);
- ext2_put_page(page);
if (update_times)
dir->i_mtime = dir->i_ctime = current_time(dir);
EXT2_I(dir)->i_flags &= ~EXT2_BTREE_FL;
@@ -556,7 +554,7 @@ int ext2_add_link (struct dentry *dentry, struct inode *inode)

/*
* ext2_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 ext2_delete_entry (struct ext2_dir_entry_2 * dir, struct page * page )
{
@@ -594,7 +592,6 @@ int ext2_delete_entry (struct ext2_dir_entry_2 * dir, struct page * page )
EXT2_I(inode)->i_flags &= ~EXT2_BTREE_FL;
mark_inode_dirty(inode);
out:
- ext2_put_page(page);
return err;
}

diff --git a/fs/ext2/namei.c b/fs/ext2/namei.c
index 3367384d344d..7af9ab3f975e 100644
--- a/fs/ext2/namei.c
+++ b/fs/ext2/namei.c
@@ -294,6 +294,7 @@ static int ext2_unlink(struct inode * dir, struct dentry *dentry)
}

err = ext2_delete_entry (de, page);
+ ext2_put_page(page);
if (err)
goto out;

@@ -371,6 +372,7 @@ static int ext2_rename (struct user_namespace * mnt_userns,
goto out_dir;
}
ext2_set_link(new_dir, new_de, new_page, old_inode, 1);
+ ext2_put_page(new_page);
new_inode->i_ctime = current_time(new_inode);
if (dir_de)
drop_nlink(new_inode);
@@ -391,12 +393,13 @@ static int ext2_rename (struct user_namespace * mnt_userns,
mark_inode_dirty(old_inode);

ext2_delete_entry (old_de, old_page);
+ ext2_put_page(old_page);

if (dir_de) {
if (old_dir != new_dir)
ext2_set_link(old_inode, dir_de, dir_page, new_dir, 0);
- else
- ext2_put_page(dir_page);
+
+ ext2_put_page(dir_page);
inode_dec_link_count(old_dir);
}
return 0;
--
2.28.0.rc0.12.gb6a658bd00c9

2021-03-31 12:06:23

by Jan Kara

[permalink] [raw]
Subject: Re: [PATCH 0/2] ext2: Convert kmap to kmap_local_page

Hi Ira!

On Sun 28-03-21 23:54:00, [email protected] wrote:
> From: Ira Weiny <[email protected]>
>
> kmap is inefficient and can be abused so it is being phased out in favor of
> kmap_local_page where possible.
>
> ext2 uses kmap in ext2_[get|put]_page(). All of the calls to
> ext2_[get|put]_page() occur in single threads so it is perfectly safe and
> preferable to use kmap_local_page().
>
> This series has a clean up which matches ext2_put_page() with ext2_dotdot() and
> ext2_find_entry(). Those calls use ext2_get_page() to map the page prior to
> returning it to their callers. And they document that ext2_put_page() should
> be matched up with them. This was the case but the ext2_put_page() calls were
> hidden in other functions. We lift the ext2_put_page() calls to match up to
> the functions where ext2_dotdot() and ext2_find_entry() are called.
>
> After that clean up convert ext2_[get|put]_page() to kmap and adjust for
> kunmap_local() requiring the page address.
>
> Nesting of kmap_local_page() calls is maintained with minor changes.

Pulled into my tree. Thanks!

Honza

>
> Ira Weiny (2):
> ext2: Match up ext2_put_page() with ext2_dotdot() and
> ext2_find_entry()
> fs/ext2: Replace kmap() with kmap_local_page()
>
> fs/ext2/dir.c | 94 +++++++++++++++++++++++++++++++------------------
> fs/ext2/ext2.h | 12 ++++---
> fs/ext2/namei.c | 34 +++++++++++-------
> 3 files changed, 89 insertions(+), 51 deletions(-)
>
> --
> 2.28.0.rc0.12.gb6a658bd00c9
>
--
Jan Kara <[email protected]>
SUSE Labs, CR