Skip to contentSkip to conversation

affs: replace kmap_atomic() with kmap_local_page()

PATCH In review David Sterba 4 participants 5 messages Jul 12, 2022 – Jul 22, 2022

Subsystems (2)
lore
Share & tools
lore

David Sterba

author maintainer
#0 lore raw

PATCH 1/1 affs: replace kmap_atomic() with kmap_local_page()

The use of kmap() is being deprecated in favor of kmap_local_page() where it is feasible. With kmap_local_page(), the mapping is per thread, CPU local and not globally visible, like in this case around a simple memcpy().

CC Ira Weiny <[email protected]>
CC Fabio M. De Francesco <[email protected]>
---
 fs/affs/file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/affs/file.c +2 -2
index cd00a4c68a12..92754c40c5cd 100644
@@ -545,9 +545,9 @@ affs_do_readpage_ofs(struct page *page, unsigned to, int create)
 			return PTR_ERR(bh);
 		tmp = min(bsize - boff, to - pos);
 		BUG_ON(pos + tmp > to || tmp > bsize);
-		data = kmap_atomic(page);
+		data = kmap_local_page(page);
 		memcpy(data + pos, AFFS_DATA(bh) + boff, tmp);
-		kunmap_atomic(data);
+		kunmap_local(data);
 		affs_brelse(bh);
 		bidx++;
 		pos += tmp;
Signature · 1 line
2.36.1
#1 lore raw

fs/affs/file.c affs_do_readpage_ofs(struct page *page, unsigned to,

Quoted 17 lines · On mercoledì 13 luglio 2022 00:27:44 CEST David Sterba wrote:

The use of kmap() is being deprecated in favor of kmap_local_page() where it is feasible. With kmap_local_page(), the mapping is per thread, CPU local and not globally visible, like in this case around a simple memcpy().

CC Ira Weiny <[email protected]>
CC Fabio M. De Francesco <[email protected]>
---
 fs/affs/file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/affs/file.c +0 -0
index cd00a4c68a12..92754c40c5cd 100644
@@ -545,9 +545,9 @@ affs_do_readpage_ofs(struct page *page, unsigned to, 

int create)

Quoted 14 lines
fs/affs/file.c +2 -2
 			return PTR_ERR(bh);
 		tmp = min(bsize - boff, to - pos);
 		BUG_ON(pos + tmp > to || tmp > bsize);
-		data = kmap_atomic(page);
+		data = kmap_local_page(page);
 		memcpy(data + pos, AFFS_DATA(bh) + boff, tmp);
-		kunmap_atomic(data);
+		kunmap_local(data);
 		affs_brelse(bh);
 		bidx++;
 		pos += tmp;
Signature · 1 line
2.36.1

It looks good but... what about using memcpy_to_page() instead of open coding kmap_local_page() + memcpy() and delete variable "char *data" since it will become unused?

Thanks,

Fabio

author maintainer
#2 lore raw

PATCH v2 1/1 affs: use memcpy_to_zero and remove replace kmap_atomic()

In reply to David Sterba

The use of kmap() is being deprecated in favor of kmap_local_page() where it is feasible. For kmap around a memcpy there's a convenience helper memcpy_to_page, use it.

CC Ira Weiny <[email protected]>
CC Fabio M. De Francesco <[email protected]>
---
 fs/affs/file.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
fs/affs/file.c +1 -4
index cd00a4c68a12..45a21729f358 100644
@@ -526,7 +526,6 @@ affs_do_readpage_ofs(struct page *page, unsigned to, int create)
 	struct inode *inode = page->mapping->host;
 	struct super_block *sb = inode->i_sb;
 	struct buffer_head *bh;
-	char *data;
 	unsigned pos = 0;
 	u32 bidx, boff, bsize;
 	u32 tmp;
@@ -545,9 +544,7 @@ affs_do_readpage_ofs(struct page *page, unsigned to, int create)
 			return PTR_ERR(bh);
 		tmp = min(bsize - boff, to - pos);
 		BUG_ON(pos + tmp > to || tmp > bsize);
-		data = kmap_atomic(page);
-		memcpy(data + pos, AFFS_DATA(bh) + boff, tmp);
-		kunmap_atomic(data);
+		memcpy_to_page(page, pos, AFFS_DATA(bh) + boff, tmp);
 		affs_brelse(bh);
 		bidx++;
 		pos += tmp;
Signature · 1 line
2.36.1
Reviewed-by on v2 1/1
#3 lore raw

Re: [PATCH v2] affs: use memcpy_to_zero and remove replace kmap_atomic()

Quoted 5 lines · David Sterba

The use of kmap() is being deprecated in favor of kmap_local_page() where it is feasible. For kmap around a memcpy there's a convenience helper memcpy_to_page, use it.

CC Ira Weiny <[email protected]>

Typo in the subject: s/memcpy_to_page/memcpy_to_zero

Other than that.

Quoted 32 lines
CC Fabio M. De Francesco <[email protected]>
---
 fs/affs/file.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
fs/affs/file.c +1 -4
index cd00a4c68a12..45a21729f358 100644
@@ -526,7 +526,6 @@ affs_do_readpage_ofs(struct page *page, unsigned to, int create)
 	struct inode *inode = page->mapping->host;
 	struct super_block *sb = inode->i_sb;
 	struct buffer_head *bh;
-	char *data;
 	unsigned pos = 0;
 	u32 bidx, boff, bsize;
 	u32 tmp;
@@ -545,9 +544,7 @@ affs_do_readpage_ofs(struct page *page, unsigned to, int create)
 			return PTR_ERR(bh);
 		tmp = min(bsize - boff, to - pos);
 		BUG_ON(pos + tmp > to || tmp > bsize);
-		data = kmap_atomic(page);
-		memcpy(data + pos, AFFS_DATA(bh) + boff, tmp);
-		kunmap_atomic(data);
+		memcpy_to_page(page, pos, AFFS_DATA(bh) + boff, tmp);
 		affs_brelse(bh);
 		bidx++;
 		pos += tmp;
Signature · 1 line
2.36.1
#4 lore raw

Re: [PATCH v2] affs: use memcpy_to_zero and remove replace kmap_atomic()

Quoted 5 lines · Ira Weiny
Quoted 4 lines · David Sterba

The use of kmap() is being deprecated in favor of kmap_local_page() where it is feasible. For kmap around a memcpy there's a convenience helper memcpy_to_page, use it.

Quoted 7 lines
Quoted 1 line
CC Ira Weiny <[email protected]>

Typo in the subject: s/memcpy_to_page/memcpy_to_zero

Other than that.

Thanks, fixed.