mm: add ztree - new allocator for use via zpool API
Subsystems (3)
PATCH v3 1/1 mm: add ztree - new allocator for use via zpool API
From: Ananda Badmaev <[email protected]>
Ztree stores integer number of compressed objects per ztree block.
These blocks consist of several physical pages (from 1 to 8) and are arranged in trees.
The range from 0 to PAGE_SIZE is divided into the number of intervals
corresponding to the number of trees and each tree only operates objects of size from its interval. Thus the block trees are isolated from each other, which makes it possible to simultaneously perform actions with several objects from different trees.
Blocks make it possible to densely arrange objects of various sizes
resulting in low internal fragmentation. Also this allocator tries to fill incomplete blocks instead of adding new ones thus in many cases providing a compression ratio substantially higher than z3fold and zbud.
Apart from greater flexibility, ztree is significantly superior to other
zpool backends with regard to the worst execution times, thus allowing for better response time and real-time characteristics of the whole system.
---
v2: fixed compiler warnings
v3: added documentation and const modifier to struct tree_descr
Documentation/vm/ztree.rst | 104 +++++ MAINTAINERS | 7 + mm/Kconfig | 18 + mm/Makefile | 1 + mm/ztree.c | 754 +++++++++++++++++++++++++++++++++++++ 5 files changed, 884 insertions(+) create mode 100644 Documentation/vm/ztree.rst create mode 100644 mm/ztree.c
Documentation/vm/ztree.rst new file +104 -0
@@ -0,0 +1,104 @@ +.. _ztree: + +===== +ztree +===== + +Ztree stores integer number of compressed objects per ztree block. These +blocks consist of several consecutive physical pages (from 1 to 8) and +are arranged in trees. The range from 0 to PAGE_SIZE is divided into the +number of intervals corresponding to the number of trees and each tree +only operates objects of size from its interval. Thus the block trees are +isolated from each other, which makes it possible to simultaneously +perform actions with several objects from different trees. + +Blocks make it possible to densely arrange objects of various sizes +resulting in low internal fragmentation. Also this allocator tries to fill +incomplete blocks instead of adding new ones thus in many cases providing +a compression ratio substantially higher than z3fold and zbud. Apart from +greater flexibility, ztree is significantly superior to other zpool +backends with regard to the worst execution times, thus allowing for better +response time and real-time characteristics of the whole system. + +Like z3fold and zsmalloc ztree_alloc() does not return a dereferenceable +pointer. Instead, it returns an unsigned long handle which encodes actual +location of the allocated object. + +Unlike others ztree works well with objects of various sizes - both highly +compressed and poorly compressed including cases where both types are present. + +Tests +===== + +Test platform +------------- + +Qemu arm64 virtual board with debian 11. + +Kernel +------ + +Linux 5.17-rc6 with ztree and zram over zpool patch. Additionally, counters and +time measurements using ktime_get_ns() have been added to ZPOOL API. + +Tools +----- + +ZRAM disks of size 1000M/1500M/2G, fio 3.25. + +Test description +---------------- + +Run 2 fio scripts in parallel - one with VALUE=50, other with VALUE=70. +This emulates page content heterogeneity. + +fio --bs=4k --randrepeat=1 --randseed=100 --refill_buffers \ + --scramble_buffers=1 --buffer_compress_percentage=VALUE \ + --direct=1 --loops=1 --numjobs=1 --filename=/dev/zram0 \ + --name=seq-write --rw=write --stonewall --name=seq-read \ + --rw=read --stonewall --name=seq-readwrite --rw=rw --stonewall \ + --name=rand-readwrite --rw=randrw --stonewall + +Results +------- + +ztree +~~~~~ + +* average malloc time (us): 3.8 +* average free time (us): 3.1 +* average map time (us): 4.5 +* average unmap time (us): 1.2 +* worst zpool op time (us): ~2200 +* total zpool ops exceeding 1000 us: 29 + + +zsmalloc +~~~~~~~~ + +* average malloc time (us): 10.3 +* average free time (us): 6.5 +* average map time (us): 3.2 +* average unmap time (us): 1.2 +* worst zpool op time (us): ~6200 +* total zpool ops exceeding 1000 us: 1031 + +z3fold +~~~~~~ + +* average malloc time (us): 20.8 +* average free time (us): 29.9 +* average map time (us): 3.4 +* average unmap time (us): 1.4 +* worst zpool op time (us): ~4900 +* total zpool ops exceeding 1000 us: 100 + +zbud +~~~~ + +* average malloc time (us): 8.1 +* average free time (us): 4.0 +* average map time (us): 0.3 +* average unmap time (us): 0.3 +* worst zpool op time (us): ~9400 +* total zpool ops exceeding 1000 us: 727
MAINTAINERS +7 -0
@@ -21027,6 +21027,13 @@ L: [email protected] S: Maintained F: mm/zbud.c +ZTREE COMPRESSED PAGE ALLOCATOR +M: Ananda Badmaev <[email protected]> +M: Vitaly Wool <[email protected]> +L: [email protected] +S: Maintained +F: mm/ztree.c + ZD1211RW WIRELESS DRIVER M: Ulrich Kunitz <[email protected]> L: [email protected]
mm/Kconfig +18 -0
@@ -646,6 +646,12 @@ config ZSWAP_ZPOOL_DEFAULT_ZSMALLOC select ZSMALLOC help Use the zsmalloc allocator as the default allocator. + +config ZSWAP_ZPOOL_DEFAULT_ZTREE + bool "ztree" + select ZTREE + help + Use the ztree allocator as the default allocator. endchoice config ZSWAP_ZPOOL_DEFAULT
@@ -654,6 +660,7 @@ config ZSWAP_ZPOOL_DEFAULT default "zbud" if ZSWAP_ZPOOL_DEFAULT_ZBUD default "z3fold" if ZSWAP_ZPOOL_DEFAULT_Z3FOLD default "zsmalloc" if ZSWAP_ZPOOL_DEFAULT_ZSMALLOC + default "ztree" if ZSWAP_ZPOOL_DEFAULT_ZTREE default "" config ZSWAP_DEFAULT_ON
@@ -712,6 +719,17 @@ config ZSMALLOC_STAT information to userspace via debugfs. If unsure, say N. +config ZTREE + tristate "Simple allocator for compressed pages" + depends on ZPOOL + help + A special purpose allocator for storing compressed pages. + It stores integer number of compressed pages per block and + each block consists of integer number of physical pages. + Red-black trees are used for efficient block organization. + ztree provides fast write, limited worst case time for + operations and good compression ratio in most scenarios. + config GENERIC_EARLY_IOREMAP bool
mm/Makefile +1 -0
@@ -108,6 +108,7 @@ obj-$(CONFIG_ZPOOL) += zpool.o obj-$(CONFIG_ZBUD) += zbud.o obj-$(CONFIG_ZSMALLOC) += zsmalloc.o obj-$(CONFIG_Z3FOLD) += z3fold.o +obj-$(CONFIG_ZTREE) += ztree.o obj-$(CONFIG_GENERIC_EARLY_IOREMAP) += early_ioremap.o obj-$(CONFIG_CMA) += cma.o obj-$(CONFIG_MEMORY_BALLOON) += balloon_compaction.o
mm/ztree.c new file +754 -0
754 lines not on this page · raw message
Signature · 1 line
2.30.2
Quoted 3 lines · Ananda
+/*****************
+ * Structures
+ *****************/
You don't need this. I can see they're structures.
Quoted 4 lines
+/**
+ * structztree_block- block metadata
+ * Block consists of several (1/2/4/8) pages and contains fixed
+ * integer number of slots for allocating compressed pages.
Quoted 8 lines
+ * @block_node: links block into the relevant tree in the pool
+ * @slot_info: contains data about free/occupied slots
+ * @compressed_data: pointer to the memory block
+ * @block_index: unique for eachztree_blockin the tree
+ * @free_slots: number of free slots in the block
+ * @coeff: to switch between blocks
+ * @under_reclaim: if true shows that block is being evicted
+ */
Earlier in the file you say this exposes no API and is to be used only through zpool. So what's the point of marking this as kernel-doc?
mm/ztree.c line 93
Quoted 2 lines
mm/ztree.c new file +2
-0+ /* 1 page blocks with 11 slots */ + [1] = { PAGE_SIZE / (11 * sizeof(long)) * sizeof(long), 0xB, 0 },
Hm. So 368 bytes on 64-bit, but 372 bytes on 32-bit? Is that intentional? Why 11?
mm/ztree.c line 197
Quoted 5 lines
mm/ztree.c new file +5
-0+/* +* allocate new block and add it to corresponding block tree +*/ +static struct ztree_block *alloc_block (struct ztree_pool *pool, +int block_type,gfp_t gfp)
You have some very strange indentation (throughout).
mm/ztree.c line 207
Quoted 6 lines
mm/ztree.c new file +6
-0+ block =kmem_cache_alloc (pool->block_cache, + (gfp & ~(__GFP_HIGHMEM | __GFP_MOVABLE))); +if (!block) +return NULL ; + + block->compressed_data = (void *)__get_free_pages (gfp, tree_desc[block_type].order);
It makes no sense to mask out __GFP_HIGHMEM and __GFP_MOVABLE for the call to slab and then not mask them out here. Either they shouldn't ever be passed in, in which case that could either be asserted or made true in your own code. Or they can be passed in, and should always be masked. Or you genuinely want to be able to use highmem & movable memory for these data blocks, in which case you're missing calls to kmap() and memory notifiers to let you move the memory around.
This smacks of "I tried something, and slab warned, so I fixed the warning" instead of thinking about what the warning meant.
Quoted 9 lines
mm/ztree.c new file +9
-0+spin_lock (&tree->lock); +/* check if there are free slots in the current and the last added blocks */ +if (tree->current_block && tree->current_block->free_slots >0 ) { + block = tree->current_block; + goto found; + } +if (tree->last_block && tree->last_block->free_slots >0 ) { + block = tree->last_block; + goto found;
mm/ztree.c line 387
Quoted 10 lines
mm/ztree.c new file +10
-0+ } +spin_unlock (&tree->lock); + +/* not found block with free slots try to allocate new empty block */ + block =alloc_block (pool, block_type, gfp); +spin_lock (&tree->lock); +if (block) { + tree->current_block = block; + goto found; + }
Another place that looks like "I fixed the warning instead of thinking about it". What if you have two threads that execute this path concurrently? Looks to me like you leak the memory allocated by the first thread.
A message that is not in the archive (sent off-list or not yet received): [email protected]
This is unreadable. Please fix your email client.
Quoted 1 line · Ананда Бадмаев
<div>07.03.2022, 18:08, "Matthew Wilcox" <[email protected]>:</div><blockquote><p>On Mon, Mar 07, 2022 at 05:27:24PM +0300, Ananda wrote:</p><blockquote> +/*****************<br /> + * Structures<br /> + *****************/</blockquote><p><br />You don't need this. I can see they're structures.<br /> </p><blockquote> +/**<br /> + * struct
ztree_block- block metadata<br /> + * Block consists of several (1/2/4/8) pages and contains fixed<br /> + * integer number of slots for allocating compressed pages.<br /> + * @block_node: links block into the relevant tree in the pool<br /> + * @slot_info: contains data about free/occupied slots<br /> + * @compressed_data: pointer to the memory block<br /> + * @block_index: unique for eachztree_blockin the tree<br /> + * @free_slots: number of free slots in the block<br /> + * @coeff: to switch between blocks<br /> + * @under_reclaim: if true shows that block is being evicted<br /> + */</blockquote><p><br />Earlier in the file you say this exposes no API and is to be used only<br />through zpool. So what's the point of marking this as kernel-doc?</p></blockquote><div><div>It will be removed in the next version.</div></div><blockquote><blockquote> + /* 1 page blocks with 11 slots */<br /> + [1] = {PAGE_SIZE/ (11 * sizeof(long)) * sizeof(long),0xB, 0 },</blockquote><p><br />Hm. So 368 bytes on 64-bit, but 372 bytes on 32-bit? Is that<br />intentional? Why 11?</p></blockquote><div><div>Yes, 'slot_size' and 'slots_per_block' values are chosen so that in general</div><div>the range from 0 toPAGE_SIZEis split more or less evenly and the size</div><div>of the block is as close as possible to the power of 2. Also 'slot_size' values</div><div>are aligned to the size of long.</div></div><blockquote><blockquote> +/*<br /> + * allocate new block and add it to corresponding block tree<br /> + */<br /> +static structztree_block*alloc_block(structztree_pool*pool,<br /> + intblock_type,gfp_tgfp)</blockquote><p><br />You have some very strange indentation (throughout).</p></blockquote><div><div>I was trying to limit the length of lines.</div></div><blockquote><p> </p><blockquote> + block =kmem_cache_alloc(pool->block_cache,<br /> + (gfp & ~(__GFP_HIGHMEM | __GFP_MOVABLE)));<br /> + if (!block)<br /> + return NULL;<br /> +<br /> + block->compressed_data = (void *)__get_free_pages(gfp, tree_desc[block_type].order);</blockquote><p><br />It makes no sense to mask out__GFP_HIGHMEMand__GFP_MOVABLEfor the call<br />to slab and then not mask them out here. Either they shouldn't ever be<br />passed in, in which case that could either be asserted or made true in<br />your own code. Or they can be passed in, and should always be masked.<br />Or you genuinely want to be able to use highmem & movable memory for<br />these data blocks, in which case you're missing calls tokmap()and<br />memory notifiers to let you move the memory around.<br /><br />This smacks of "I tried something, and slab warned, so I fixed the<br />warning" instead of thinking about what the warning meant.</p></blockquote><div><div>It seems that these flags should be masked out in alloc_block().</div></div><blockquote><blockquote> + spin_lock(&tree->lock);<br /> + /* check if there are free slots in the current and the last added blocks */<br /> + if (tree->current_block && tree->current_block->free_slots > 0) {<!-- --><br /> + block = tree->current_block;<br /> + goto found;<br /> + }<br /> + if (tree->last_block && tree->last_block->free_slots > 0) {<!-- --><br /> + block = tree->last_block;<br /> + goto found;<br /> + }<br /> + spin_unlock(&tree->lock);<br /> +<br /> + /* not found block with free slots try to allocate new empty block */<br /> + block =alloc_block(pool, block_type, gfp);<br /> + spin_lock(&tree->lock);<br /> + if (block) {<!-- --><br /> + tree->current_block = block;<br /> + goto found;<br /> + }</blockquote><p><br />Another place that looks like "I fixed the warning instead of thinking<br />about it". What if you have two threads that execute this path<br />concurrently? Looks to me like you leak the memory allocated by the<br />first thread.</p></blockquote><div><div>Probably I should passGFP_ATOMICflag toalloc_block()and execute this entire</div><div>section of code under single spinlock.</div></div>
В Пн, 07/03/2022 в 15:08 +0000, Matthew Wilcox пишет:
Quoted 21 lines · Ananda
Quoted 3 lines
+/*****************
+ * Structures
+ *****************/You don't need this. I can see they're structures.
Quoted 5 lines
+/**
+ * structztree_block- block metadata
+ * Block consists of several (1/2/4/8) pages and contains fixed
+ * integer number of slots for allocating compressed pages.
+ * @block_node: links block into the relevant tree inQuoted 8 lines
the pool
+ * @slot_info: contains data about free/occupied slots
+ * @compressed_data: pointer to the memory block
+ * @block_index: unique for eachztree_blockin the tree
+ * @free_slots: number of free slots in the block
+ * @coeff: to switch between blocks
+ * @under_reclaim: if true shows that block is being evicted
+ */
Quoted 4 lines
Earlier in the file you say this exposes no API and is to be used only
through zpool. So what's the point of marking this as kernel-doc?
It will be removed in the next version.
Quoted 7 lines
Quoted 3 lines
+ /* 1 page blocks with 11 slots */
+ [1] = {PAGE_SIZE/ (11 * sizeof(long)) * sizeof(long),0xB, 0 },Hm. So 368 bytes on 64-bit, but 372 bytes on 32-bit? Is that intentional? Why 11?
Yes, 'slot_size' and 'slots_per_block' values are chosen so that in general the range from 0 to PAGE_SIZE is split more or less evenly and the size of the block is as close as possible to the power of 2. Also 'slot_size' values are aligned to the size of long.
Quoted 9 lines
Quoted 6 lines
mm/ztree.c new file +5
-0+/* +* allocate new block and add it to corresponding block tree +*/ +static struct ztree_block *alloc_block(struct ztree_pool *pool, +int
block_type,gfp_tgfp)You have some very strange indentation (throughout).
I was trying to limit the length of lines.
Quoted 21 lines
Quoted 8 lines
+ block = kmem_cache_alloc(pool->block_cache,
+ (gfp & ~(__GFP_HIGHMEM |__GFP_MOVABLE)));
+ if (!block)
+ return NULL;
+
+ block->compressed_data = (void *)__get_free_pages(gfp, tree_desc[block_type].order);It makes no sense to mask out
__GFP_HIGHMEMand__GFP_MOVABLEfor the call
to slab and then not mask them out here. Either they shouldn't ever be
passed in, in which case that could either be asserted or made true in
your own code. Or they can be passed in, and should always be masked.
Or you genuinely want to be able to use highmem & movable memory for these data blocks, in which case you're missing calls tokmap()and memory notifiers to let you move the memory around.
Quoted 3 lines
This smacks of "I tried something, and slab warned, so I fixed the warning" instead of thinking about what the warning meant.
It seems that these flags should be masked out in alloc_block().
Quoted 23 lines
Quoted 14 lines
+ spin_lock(&tree->lock);
+ /* check if there are free slots in the current and the last added blocks */
+ if (tree->current_block&&tree->current_block->free_slotsQuoted 1 line
0) {
+ block =
tree->current_block;
+ goto found;
+ }
+ if (tree->last_block&&tree->last_block->free_slots> 0) { + block =tree->last_block;
+ goto found;
+ }
+ spin_unlock(&tree->lock);
+Quoted 8 lines
+ /* not found block with free slots try to allocate new empty block */
+ block =alloc_block(pool, block_type, gfp); + spin_lock(&tree->lock);
+ if (block) {
+ tree->current_block = block;
+ goto found;
+ }
Quoted 6 lines
Another place that looks like "I fixed the warning instead of thinking
about it". What if you have two threads that execute this path concurrently? Looks to me like you leak the memory allocated by the first thread.
Probably I should pass GFP_ATOMIC flag to alloc_block() and execute this entire section of code under single spinlock.
Copy of previous mail message, but in text/plain.
Quoted 11 lines · Ananda Badmaev
Quoted 7 lines
Quoted 3 lines
+ /* 1 page blocks with 11 slots */
+ [1] = {PAGE_SIZE/ (11 * sizeof(long)) * sizeof(long),0xB, 0 },Hm. So 368 bytes on 64-bit, but 372 bytes on 32-bit? Is that intentional? Why 11?
Yes, '
slot_size' and 'slots_per_block' values are chosen so that in general the range from 0 toPAGE_SIZEis split more or less evenly and the size of the block is as close as possible to the power of 2. Also 'slot_size' values are aligned to the size of long.
Is it intrinsic to the design that the blocks are aligned to sizeof(long)?
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines
mm/ztree.c new file +5
-0+/* +* allocate new block and add it to corresponding block tree +*/ +static struct ztree_block *alloc_block(struct ztree_pool *pool, +int
block_type,gfp_tgfp)You have some very strange indentation (throughout).
I was trying to limit the length of lines.
But you didn't achieve that. The _start_ of the line containing block_type and gfp was _more indented_ than the end of the previous line. Do you have unusual tab settings?
Quoted 21 lines
Quoted 21 lines
Quoted 8 lines
+ block = kmem_cache_alloc(pool->block_cache,
+ (gfp & ~(__GFP_HIGHMEM |__GFP_MOVABLE)));
+ if (!block)
+ return NULL;
+
+ block->compressed_data = (void *)__get_free_pages(gfp, tree_desc[block_type].order);It makes no sense to mask out
__GFP_HIGHMEMand__GFP_MOVABLEfor the call
to slab and then not mask them out here. Either they shouldn't ever be
passed in, in which case that could either be asserted or made true in
your own code. Or they can be passed in, and should always be masked.
Or you genuinely want to be able to use highmem & movable memory for these data blocks, in which case you're missing calls tokmap()and memory notifiers to let you move the memory around.
Quoted 4 lines
Quoted 3 lines
This smacks of "I tried something, and slab warned, so I fixed the warning" instead of thinking about what the warning meant.
It seems that these flags should be masked out in
alloc_block().
Maybe? I don't know the
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
+ spin_lock(&tree->lock);
+ /* check if there are free slots in the current and the last added blocks */
+ if (tree->current_block&&tree->current_block->free_slotsQuoted 1 line
0) {
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
+ block =
tree->current_block;thinking
about it". What if you have two threads that execute this path concurrently? Looks to me like you leak the memory allocated by the first thread.Probably I should pass
GFP_ATOMICflag toalloc_block()and execute this entire section of code under single spinlock.
I think that's a bad approach. Better would be:
spin_lock();
if (free_slot_block)
goto found;
spin_unlock();
block = alloc_block();
spin_lock();
if (free_slot_block) {
free_block(block);
block = free_slot_block;
} else {
free_slot_block = block;
}
found:
...
spin_unlock();В Вт, 08/03/2022 в 15:40 +0000, Matthew Wilcox пишет:
Quoted 11 lines · Ananda Badmaev
Quoted 9 lines
Quoted 3 lines
Hm. So 368 bytes on 64-bit, but 372 bytes on 32-bit? Is that intentional? Why 11?
Yes, '
slot_size' and 'slots_per_block' values are chosen so that in general the range from 0 toPAGE_SIZEis split more or less evenly and
the size of the block is as close as possible to the power of 2. Also
'slot_size' values are aligned to the size of long.
Quoted 2 lines
Is it intrinsic to the design that the blocks are aligned to sizeof(long)?
slot_size values must be aligned so that the slot addresses in blocks are also algined to avoid potential problems with unalinged access. I guess 4/8 byte alignment is enough for 32/64 bit systems respectively.
Quoted 9 lines
Quoted 4 lines
Quoted 3 lines
You have some very strange indentation (throughout).
I was trying to limit the length of lines.
But you didn't achieve that. The _start_ of the line containing
block_typeand gfp was_moreindented_than the end of the previous line. Do you have unusual tab settings?
Maybe it's because I have tab size 4 in my editor.
Quoted 11 lines
Quoted 8 lines
Quoted 6 lines
thinking
about it". What if you have two threads that execute this path concurrently? Looks to me like you leak the memory allocated by the
first thread.Probably I should pass
GFP_ATOMICflag toalloc_block()and execute this entire section of code under single spinlock.I think that's a bad approach. Better would be:
Quoted 15 lines
spin_lock();
if (free_slot_block)
goto found;
spin_unlock();
block =alloc_block();
spin_lock();
if (free_slot_block) {
free_block(block);
block =free_slot_block;
} else {
free_slot_block = block;
}
found:
...
spin_unlock();
Yes, seems really better to do like this. Solution with GFP_ATOMIC probably will improve the worst time of ztree_alloc(), which was not big issue in the tests, but most likely general efficiency will be degraded.
Mike Rapoport
reviewerQuoted 25 lines · Ananda
From: Ananda Badmaev <[email protected]>
Ztree stores integer number of compressed objects per ztree block.
These blocks consist of several physical pages (from 1 to 8) and are arranged in trees.
The range from 0 toPAGE_SIZEis divided into the number of intervals
corresponding to the number of trees and each tree only operates objects of size from its interval. Thus the block trees are isolated from each other, which makes it possible to simultaneously perform actions with several objects from different trees.
Blocks make it possible to densely arrange objects of various sizes
resulting in low internal fragmentation. Also this allocator tries to fill incomplete blocks instead of adding new ones thus in many cases providing a compression ratio substantially higher than z3fold and zbud.
Apart from greater flexibility, ztree is significantly superior to other
zpool backends with regard to the worst execution times, thus allowing for better response time and real-time characteristics of the whole system.Signed-off-by Ananda Badmaev <[email protected]>---
v2: fixed compiler warnings
v3: added documentation and const modifier to struct
tree_descr
Quoted 8 lines
Documentation/vm/ztree.rst | 104 +++++ MAINTAINERS | 7 + mm/Kconfig | 18 + mm/Makefile | 1 + mm/ztree.c | 754 +++++++++++++++++++++++++++++++++++++ 5 files changed, 884 insertions(+) create mode 100644 Documentation/vm/ztree.rst create mode 100644 mm/ztree.c
There are a lot of style issues, please run scripts/checkpatch.pl.
Quoted 27 lines
Documentation/vm/ztree.rst new file +21
-0@@ -0,0 +1,104 @@ +.. _ztree: + +===== +ztree +===== + +Ztree stores integer number of compressed objects per ztree block. These +blocks consist of several consecutive physical pages (from 1 to 8) and +are arranged in trees. The range from 0 to PAGE_SIZE is divided into the +number of intervals corresponding to the number of trees and each tree +only operates objects of size from its interval. Thus the block trees are +isolated from each other, which makes it possible to simultaneously +perform actions with several objects from different trees. + +Blocks make it possible to densely arrange objects of various sizes +resulting in low internal fragmentation. Also this allocator tries to fill +incomplete blocks instead of adding new ones thus in many cases providing +a compression ratio substantially higher than z3fold and zbud. Apart from +greater flexibility, ztree is significantly superior to other zpool +backends with regard to the worst execution times, thus allowing for better +response time and real-time characteristics of the whole system.
Documentation/vm/ztree.rst line 31
Quoted 10 lines
Documentation/vm/ztree.rst new file +10
-0+ +Like z3fold and zsmalloc ztree_alloc() does not return a dereferenceable +pointer. Instead, it returns an unsigned long handle which encodes actual +location of the allocated object. + +Unlike others ztree works well with objects of various sizes - both highly +compressed and poorly compressed including cases where both types are present. + +Tests +=====
I don't think the sections below belong to the Documentation. IMO they are more suitable to the changelog
Quoted 73 lines
Documentation/vm/ztree.rst new file +73
-0+ +Test platform +------------- + +Qemu arm64 virtual board with debian 11. + +Kernel +------ + +Linux 5.17-rc6 with ztree and zram over zpool patch. Additionally, counters and +time measurements using ktime_get_ns() have been added to ZPOOL API. + +Tools +----- + +ZRAM disks of size 1000M/1500M/2G, fio 3.25. + +Test description +---------------- + +Run 2 fio scripts in parallel - one with VALUE=50, other with VALUE=70. +This emulates page content heterogeneity. + +fio --bs=4k --randrepeat=1 --randseed=100 --refill_buffers \ + --scramble_buffers=1 --buffer_compress_percentage=VALUE \ + --direct=1 --loops=1 --numjobs=1 --filename=/dev/zram0 \ + --name=seq-write --rw=write --stonewall --name=seq-read \ + --rw=read --stonewall --name=seq-readwrite --rw=rw --stonewall \ + --name=rand-readwrite --rw=randrw --stonewall + +Results +------- + +ztree +~~~~~ + +* average malloc time (us): 3.8 +* average free time (us): 3.1 +* average map time (us): 4.5 +* average unmap time (us): 1.2 +* worst zpool op time (us): ~2200 +* total zpool ops exceeding 1000 us: 29 + + +zsmalloc +~~~~~~~~ + +* average malloc time (us): 10.3 +* average free time (us): 6.5 +* average map time (us): 3.2 +* average unmap time (us): 1.2 +* worst zpool op time (us): ~6200 +* total zpool ops exceeding 1000 us: 1031 + +z3fold +~~~~~~ + +* average malloc time (us): 20.8 +* average free time (us): 29.9 +* average map time (us): 3.4 +* average unmap time (us): 1.4 +* worst zpool op time (us): ~4900 +* total zpool ops exceeding 1000 us: 100 + +zbud +~~~~ + +* average malloc time (us): 8.1 +* average free time (us): 4.0 +* average map time (us): 0.3 +* average unmap time (us): 0.3 +* worst zpool op time (us): ~9400 +* total zpool ops exceeding 1000 us: 727
Signature · 2 lines
Sincerely yours, Mike.