[RFC PATCH v2 0/3] btrfs: Convert zlib.c to use kmap_local_page()

From: Fabio M. De Francesco
Date: Fri Jun 17 2022 - 08:05:52 EST


The use of kmap() is being deprecated in favor of kmap_local_page(). With
kmap_local_page(), the mapping is per thread, CPU local and not globally
visible.

Therefore, use kmap_local_page() / kunmap_local() in zlib.c because in
this file the mappings are per thread and are not visible in other
contexts.

This is an RFC because patch 3/3 uses an horrid hack. I'm using an array
based stack which tracks local mappings / un-mappings. I understand that
it is not the better solution, but it works and it is easy to implement :)

I've decided to decompose RFC v1 into a series of three patches in order to
make clear that I encountered problems with conversions in patch 3/3. I'm
pretty sure that people who are familiar with these functions could refactor
this code and provide much more elegant and efficient solutions.

Since this code currently uses kmap() / kunmap(), I think that the functions
I'm converting had been designed without taking into account the rules of
ordering of nesting local mappings / un-mappings.

I've been trying to refactor this code but it is something beyond my current
level of knowledge and skills...

Can anyone please provide any better suited solutions for patch 3/3?

Tested with xfstests on QEMU + KVM 32 bits VM with 4GB of RAM and
HIGHMEM64G enabled. Each patch of this series passes 26/26 tests of group
"compress".

tweed32:/usr/lib/xfstests # ./check -g compress
FSTYP -- btrfs
PLATFORM -- Linux/i686 tweed32 5.19.0-rc2-vanilla-debug+ #45 SMP PREEMPT_DYNAMIC Fri Jun 17 11:14:11 CEST 2022
MKFS_OPTIONS -- /dev/loop1
MOUNT_OPTIONS -- /dev/loop1 /mnt/scratch

btrfs/024 2s ... 3s
btrfs/026 5s ... 5s
btrfs/037 3s ... 3s
btrfs/038 3s ... 2s
btrfs/041 3s ... 3s
btrfs/062 41s ... 41s
btrfs/063 22s ... 23s
btrfs/067 39s ... 40s
btrfs/068 14s ... 14s
btrfs/070 [not run] btrfs and this test needs 5 or more disks in SCRATCH_DEV_POOL
btrfs/071 [not run] btrfs and this test needs 5 or more disks in SCRATCH_DEV_POOL
btrfs/072 39s ... 41s
btrfs/073 20s ... 20s
btrfs/074 41s ... 41s
btrfs/076 3s ... 3s
btrfs/103 3s ... 3s
btrfs/106 3s ... 3s
btrfs/109 3s ... 3s
btrfs/113 3s ... 3s
btrfs/138 53s ... 54s
btrfs/149 3s ... 3s
btrfs/183 3s ... 2s
btrfs/205 4s ... 3s
btrfs/234 4s ... 4s
btrfs/246 2s ... 3s
btrfs/251 3s ... 2s
Ran: btrfs/024 btrfs/026 btrfs/037 btrfs/038 btrfs/041 btrfs/062 btrfs/063 btrfs/067 btrfs/068 btrfs/070 btrfs/071 btrfs/072 btrfs/073 btrfs/074 btrfs/076 btrfs/103 btrfs/106 btrfs/109 btrfs/113 btrfs/138 btrfs/149 btrfs/183 btrfs/205 btrfs/234 btrfs/246 btrfs/251
Not run: btrfs/070 btrfs/071
Passed all 26 tests

Fabio M. De Francesco (3):
btrfs: Convert zlib_decompress_bio() to use kmap_local_page()
btrfs: Use kmap_local_page() on "out_page" in zlib_compress_pages()
btrfs: Use kmap_local_page() on "in_page" in zlib_compress_pages()

fs/btrfs/zlib.c | 91 ++++++++++++++++++++++++++++++++++++-------------
1 file changed, 67 insertions(+), 24 deletions(-)

--
2.36.1