linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH v1 0/4] Introduce merge identical pages mechanism
@ 2022-11-21 19:00 Alexey Romanov
  2022-11-21 19:00 ` [RFC PATCH v1 1/4] zram: introduce " Alexey Romanov
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Alexey Romanov @ 2022-11-21 19:00 UTC (permalink / raw)
  To: minchan, senozhatsky, ngupta, akpm
  Cc: linux-mm, linux-kernel, kernel, ddrokosov, Alexey Romanov

Hello!

This RFC series adds feature which allows merge identical
compressed pages into a single one. The main idea is that
zram only stores object references, which store the compressed
content of the pages. Thus, the contents of the zsmalloc objects
don't change in any way.

For simplicity, let's imagine that 3 pages with the same content
got into zram:

+----------------+   +----------------+   +----------------+
|zram_table_entry|   |zram_table_entry|   |zram_table_entry|
+-------+--------+   +-------+--------+   +--------+-------+
        |                    |                     |
        | handle (1)         | handle (2)          | handle (3)
+-------v--------+   +-------v---------+  +--------v-------+
|zsmalloc  object|   |zsmalloc  object |  |zsmalloc  object|
++--------------++   +-+-------------+-+  ++--------------++
 +--------------+      +-------------+     +--------------+
 | buffer: "abc"|      |buffer: "abc"|     | buffer: "abc"|
 +--------------+      +-------------+     +--------------+

As you can see, the data is duplicated. Merge mechanism saves
(after scanning objects) only one zsmalloc object. Here's
what happens ater the scan and merge:

+----------------+   +----------------+   +----------------+
|zram_table_entry|   |zram_table_entry|   |zram_tabl _entry|
+-------+--------+   +-------+--------+   +--------+-------+
        |                    |                     |
        | handle (1)         | handle (1)          | handle (1)
        |           +--------v---------+           |
        +-----------> zsmalloc  object <-----------+
                    +--+-------------+-+
                       +-------------+
                       |buffer: "abc"|
                       +-------------+

Thus, we reduced the amount of memory occupied by 3 times.

This mechanism doesn't affect the perf of the zram itself in
any way (maybe just a little bit on the zram_free_page function).
In order to describe each such identical object, we (constantly)
need sizeof(zram_rbtree_node) bytes. So, for example, if the system
has 20 identical buffers with a size of 1024, the memory gain will be
(20 * 1024) - (1 * 1024 + sizeof(zram_rbtree_node)) = 19456 -
sizeof(zram_rbtree_node) bytes. But, it should be understood, these are
counts without zsmalloc data structures overhead.

Testing on my system (8GB ram + 1 gb zram swap) showed that at high 
loads, on average, when calling the merge mechanism, we can save 
up to 15-20% of the memory usage.

This patch serices adds a new sysfs node (trigger merging) and new 
field in mm_stat (how many pages are merged in zram at the moment):

  $ cat /sys/block/zram/mm_stat
    431452160 332984392 339894272 0 339894272 282 0 51374 51374 0

  $ echo 1 > /sys/block/zram/merge

  $ cat /sys/block/zram/mm_stat
    431452160 270376848 287301504 0 339894272 282 0 51374 51374 6593

Alexey Romanov (4):
  zram: introduce merge identical pages mechanism
  zram: add merge sysfs knob
  zram: add pages_merged counter to mm_stat
  zram: recompression: add ZRAM_MERGED check

 Documentation/admin-guide/blockdev/zram.rst |   2 +
 drivers/block/zram/zram_drv.c               | 315 +++++++++++++++++++-
 drivers/block/zram/zram_drv.h               |   7 +
 3 files changed, 320 insertions(+), 4 deletions(-)

-- 
2.25.1



^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2023-02-06 10:38 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-21 19:00 [RFC PATCH v1 0/4] Introduce merge identical pages mechanism Alexey Romanov
2022-11-21 19:00 ` [RFC PATCH v1 1/4] zram: introduce " Alexey Romanov
2022-11-23  8:25   ` Chen Wandun
2022-11-23  9:04     ` Aleksey Romanov
2022-11-21 19:00 ` [RFC PATCH v1 2/4] zram: add merge sysfs knob Alexey Romanov
2022-11-21 20:44 ` [RFC PATCH v1 0/4] Introduce merge identical pages mechanism Johannes Weiner
2022-11-22  3:00   ` Sergey Senozhatsky
2022-11-22  3:07     ` Sergey Senozhatsky
2022-11-22 12:14       ` Aleksey Romanov
2022-11-23  4:13         ` Sergey Senozhatsky
2022-11-23  8:53           ` Dmitry Rokosov
2022-12-01 10:14             ` Dmitry Rokosov
2022-12-01 10:47               ` Sergey Senozhatsky
2022-12-01 11:14                 ` Dmitry Rokosov
2022-12-01 13:29                   ` Sergey Senozhatsky
2023-01-11 14:00                 ` Alexey Romanov
2023-02-06 10:37                   ` Sergey Senozhatsky
2022-11-23  9:07           ` Aleksey Romanov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox