Skip to content

Commit 06caf1b

Browse files
mRrvzakpm00
authored andcommitted
zram: add size class equals check into recompression
Patch series "zsmalloc/zram: configurable zspage size", v4. Some use-cases and/or data patterns may benefit from larger zspages. Currently the limit on the number of physical pages that are linked into a zspage is hardcoded to 4. Higher limit changes key characteristics of a number of the size classes, improving compactness of the pool and redusing the amount of memory zsmalloc pool uses. More on this in 0002 commit message. This patch (of 9): It makes no sense for us to recompress the object if it will be in the same size class. We anyway don't get any memory gain. But, at the same time, we get a CPU time overhead when inserting this object into zspage and decompressing it afterwards. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Alexey Romanov <[email protected]> Reviewed-by: Sergey Senozhatsky <[email protected]> Signed-off-by: Sergey Senozhatsky <[email protected]> Cc: Minchan Kim <[email protected]> Cc: Nitin Gupta <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 80a8383 commit 06caf1b

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

drivers/block/zram/zram_drv.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,6 +1632,8 @@ static int zram_recompress(struct zram *zram, u32 index, struct page *page,
16321632
unsigned long handle_next;
16331633
unsigned int comp_len_next;
16341634
unsigned int comp_len_prev;
1635+
unsigned int class_index_prev;
1636+
unsigned int class_index_next;
16351637
struct zcomp_strm *zstrm;
16361638
void *src, *dst;
16371639
int ret;
@@ -1656,13 +1658,16 @@ static int zram_recompress(struct zram *zram, u32 index, struct page *page,
16561658
ret = zcomp_compress(zstrm, src, &comp_len_next);
16571659
kunmap_atomic(src);
16581660

1661+
class_index_prev = zs_lookup_class_index(zram->mem_pool, comp_len_prev);
1662+
class_index_next = zs_lookup_class_index(zram->mem_pool, comp_len_next);
16591663
/*
16601664
* Either a compression error or we failed to compressed the object
16611665
* in a way that will save us memory. Mark the object so that we
16621666
* don't attempt to re-compress it again (RECOMP_SKIP).
16631667
*/
16641668
if (comp_len_next >= huge_class_size ||
16651669
comp_len_next >= comp_len_prev ||
1670+
class_index_next >= class_index_prev ||
16661671
ret) {
16671672
zram_set_flag(zram, index, ZRAM_RECOMP_SKIP);
16681673
zram_clear_flag(zram, index, ZRAM_IDLE);

include/linux/zsmalloc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,7 @@ void zs_unmap_object(struct zs_pool *pool, unsigned long handle);
5555
unsigned long zs_get_total_pages(struct zs_pool *pool);
5656
unsigned long zs_compact(struct zs_pool *pool);
5757

58+
unsigned int zs_lookup_class_index(struct zs_pool *pool, unsigned int size);
59+
5860
void zs_pool_stats(struct zs_pool *pool, struct zs_pool_stats *stats);
5961
#endif

mm/zsmalloc.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,27 @@ static bool zspage_full(struct size_class *class, struct zspage *zspage)
13001300
return get_zspage_inuse(zspage) == class->objs_per_zspage;
13011301
}
13021302

1303+
/**
1304+
* zs_lookup_class_index() - Returns index of the zsmalloc &size_class
1305+
* that hold objects of the provided size.
1306+
* @pool: zsmalloc pool to use
1307+
* @size: object size
1308+
*
1309+
* Context: Any context.
1310+
*
1311+
* Return: the index of the zsmalloc &size_class that hold objects of the
1312+
* provided size.
1313+
*/
1314+
unsigned int zs_lookup_class_index(struct zs_pool *pool, unsigned int size)
1315+
{
1316+
struct size_class *class;
1317+
1318+
class = pool->size_class[get_size_class_index(size)];
1319+
1320+
return class->index;
1321+
}
1322+
EXPORT_SYMBOL_GPL(zs_lookup_class_index);
1323+
13031324
unsigned long zs_get_total_pages(struct zs_pool *pool)
13041325
{
13051326
return atomic_long_read(&pool->pages_allocated);

0 commit comments

Comments
 (0)