zram: support priority parameter in recompression

recompress device attribute supports alg=NAME parameter so that we can
specify only one particular algorithm we want to perform recompression
with.  However, with algo params we now can have several exactly same
secondary algorithms but each with its own params tuning (e.g.  priority 1
configured to use more aggressive level, and priority 2 configured to use
a pre-trained dictionary).  Support priority=NUM parameter so that we can
correctly determine which secondary algorithm we want to use.

Link: https://lkml.kernel.org/r/20240902105656.1383858-25-senozhatsky@chromium.org
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Nick Terrell <terrelln@fb.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
Sergey Senozhatsky 2024-09-02 19:56:12 +09:00 committed by Andrew Morton
parent 97ee4842f2
commit e899007a5e
2 changed files with 16 additions and 1 deletions

View File

@ -512,11 +512,14 @@ registered compression algorithms, increases our chances of finding the
algorithm that successfully compresses a particular page. Sometimes, however, algorithm that successfully compresses a particular page. Sometimes, however,
it is convenient (and sometimes even necessary) to limit recompression to it is convenient (and sometimes even necessary) to limit recompression to
only one particular algorithm so that it will not try any other algorithms. only one particular algorithm so that it will not try any other algorithms.
This can be achieved by providing a algo=NAME parameter::: This can be achieved by providing a `algo` or `priority` parameter:::
#use zstd algorithm only (if registered) #use zstd algorithm only (if registered)
echo "type=huge algo=zstd" > /sys/block/zramX/recompress echo "type=huge algo=zstd" > /sys/block/zramX/recompress
#use zstd algorithm only (if zstd was registered under priority 1)
echo "type=huge priority=1" > /sys/block/zramX/recompress
memory tracking memory tracking
=============== ===============

View File

@ -1855,6 +1855,18 @@ static ssize_t recompress_store(struct device *dev,
algo = val; algo = val;
continue; continue;
} }
if (!strcmp(param, "priority")) {
ret = kstrtouint(val, 10, &prio);
if (ret)
return ret;
if (prio == ZRAM_PRIMARY_COMP)
prio = ZRAM_SECONDARY_COMP;
prio_max = min(prio + 1, ZRAM_MAX_COMPS);
continue;
}
} }
if (threshold >= huge_class_size) if (threshold >= huge_class_size)