public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCHv2 0/3] zram: optimal post-processing target selection
@ 2024-09-08 11:45 Sergey Senozhatsky
  2024-09-08 11:45 ` [PATCHv2 1/3] zram: introduce ZRAM_PP_SLOT flag Sergey Senozhatsky
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Sergey Senozhatsky @ 2024-09-08 11:45 UTC (permalink / raw)
  To: Minchan Kim, Andrew Morton
  Cc: Richard Chang, linux-kernel, Sergey Senozhatsky

Problem:
--------
Both recompression and writeback perform a very simple linear scan
of all zram slots in search for post-processing (writeback or
recompress) candidate slots.  This often means that we pick the
worst candidate for pp (post-processing), e.g. a 48 bytes object for
writeback, which is nearly useless, because it only releases 48
bytes from zsmalloc pool, but consumes an entire 4K slot in the
backing device.  Similarly, recompression of an 48 bytes objects
is unlikely to save more memory that recompression of a 3000 bytes
object.  Both recompression and writeback consume constrained
resources (CPU time, batter, backing device storage space) and
quite often have a (daily) limit on the number of items they
post-process, so we should utilize those constrained resources in
the most optimal way.

Solution:
---------
This patch reworks the way we select pp targets.  We, quite clearly,
want to sort all the candidates and always pick the largest, be it
recompression or writeback.  Especially for writeback, because the
larger object we writeback the more memory we release.  This series
introduces concept of pp buckets and pp scan/selection.

The scan step is a simple iteration over all zram->table entries,
just like what we currently do, but we don't post-process a candidate
slot immediately.  Instead we assign it to a PP (post-processing)
bucket.  PP bucket is, basically, a list which holds pp candidate
slots that belong to the same size class.  PP buckets are 64 bytes
apart, slots are not strictly sorted within a bucket there is a
64 bytes variance.

The select step simply iterates over pp buckets from highest to lowest
and picks all candidate slots a particular buckets contains.  So this
gives us sorted candidates (in linear time) and allows us to select
most optimal (largest) candidates for post-processing first.

v2..v1:
-- clear PP_SLOT when slot is accessed
-- kmalloc pp_ctl instead of keeoing it on the stack
-- increase the number of pp-buckets and rework the way it's defined
-- code reshuffle and refactoring

Sergey Senozhatsky (3):
  zram: introduce ZRAM_PP_SLOT flag
  zram: rework recompress target selection strategy
  zram: rework writeback target selection strategy

 drivers/block/zram/zram_drv.c | 279 ++++++++++++++++++++++++++++------
 drivers/block/zram/zram_drv.h |   1 +
 2 files changed, 235 insertions(+), 45 deletions(-)

--
2.46.0.469.g59c65b2a67-goog


^ permalink raw reply	[flat|nested] 8+ messages in thread
* [PATCHv2 0/3] zram: optimal post-processing target selection
@ 2024-09-08 11:42 Sergey Senozhatsky
  2024-09-08 11:45 ` Sergey Senozhatsky
  0 siblings, 1 reply; 8+ messages in thread
From: Sergey Senozhatsky @ 2024-09-08 11:42 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Richard Chang, linux-kernel, Sergey Senozhatsky

Problem:
--------
Both recompression and writeback perform a very simple linear scan
of all zram slots in search for post-processing (writeback or
recompress) candidate slots.  This often means that we pick the
worst candidate for pp (post-processing), e.g. a 48 bytes object for
writeback, which is nearly useless, because it only releases 48
bytes from zsmalloc pool, but consumes an entire 4K slot in the
backing device.  Similarly, recompression of an 48 bytes objects
is unlikely to save more memory that recompression of a 3000 bytes
object.  Both recompression and writeback consume constrained
resources (CPU time, batter, backing device storage space) and
quite often have a (daily) limit on the number of items they
post-process, so we should utilize those constrained resources in
the most optimal way.

Solution:
---------
This patch reworks the way we select pp targets.  We, quite clearly,
want to sort all the candidates and always pick the largest, be it
recompression or writeback.  Especially for writeback, because the
larger object we writeback the more memory we release.  This series
introduces concept of pp buckets and pp scan/selection.

The scan step is a simple iteration over all zram->table entries,
just like what we currently do, but we don't post-process a candidate
slot immediately.  Instead we assign it to a PP (post-processing)
bucket.  PP bucket is, basically, a list which holds pp candidate
slots that belong to the same size class.  PP buckets are 64 bytes
apart, slots are not strictly sorted within a bucket there is a
64 bytes variance.

The select step simply iterates over pp buckets from highest to lowest
and picks all candidate slots a particular buckets contains.  So this
gives us sorted candidates (in linear time) and allows us to select
most optimal (largest) candidates for post-processing first.

v2..v1:
-- clear PP_SLOT when slot is accessed
-- kmalloc pp_ctl instead of keeoing it on the stack
-- increase the number of pp-buckets and rework the way it's defined
-- code reshuffle and refactoring

Sergey Senozhatsky (3):
  zram: introduce ZRAM_PP_SLOT flag
  zram: rework recompress target selection strategy
  zram: rework writeback target selection strategy

 drivers/block/zram/zram_drv.c | 279 ++++++++++++++++++++++++++++------
 drivers/block/zram/zram_drv.h |   1 +
 2 files changed, 235 insertions(+), 45 deletions(-)

--
2.46.0.469.g59c65b2a67-goog


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

end of thread, other threads:[~2024-09-10  9:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-08 11:45 [PATCHv2 0/3] zram: optimal post-processing target selection Sergey Senozhatsky
2024-09-08 11:45 ` [PATCHv2 1/3] zram: introduce ZRAM_PP_SLOT flag Sergey Senozhatsky
2024-09-08 11:45 ` [PATCHv2 2/3] zram: rework recompress target selection strategy Sergey Senozhatsky
2024-09-08 11:45 ` [PATCHv2 3/3] zram: rework writeback " Sergey Senozhatsky
2024-09-10  9:37 ` [PATCHv2 0/3] zram: optimal post-processing target selection Sergey Senozhatsky
  -- strict thread matches above, loose matches on Subject: below --
2024-09-08 11:42 Sergey Senozhatsky
2024-09-08 11:45 ` Sergey Senozhatsky
2024-09-08 11:47   ` Sergey Senozhatsky

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