mm: add ztree - new allocator for use via zpool API
Subsystems (3)
PATCH v4 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
v4: - fixed gfp flags for block allocation
- fixed potential memory leak when allocating blocks
- resolved some issues with code style and warnings from checkpatch (except warning about single line config symbol description)
- moved test results from documentation to changelog
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.
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 --stonewallResults:
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
Documentation/vm/ztree.rst | 30 ++ MAINTAINERS | 7 + mm/Kconfig | 18 + mm/Makefile | 1 + mm/ztree.c | 754 +++++++++++++++++++++++++++++++++++++ 5 files changed, 810 insertions(+) create mode 100644 Documentation/vm/ztree.rst create mode 100644 mm/ztree.c
Documentation/vm/ztree.rst new file +30 -0
@@ -0,0 +1,30 @@ +.. SPDX-License-Identifier: GPL-2.0 + +.. _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.
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