* [PATCH] zram: add limit to recompression
@ 2024-03-29 9:06 Sergey Senozhatsky
2024-03-29 9:20 ` Sergey Senozhatsky
0 siblings, 1 reply; 2+ messages in thread
From: Sergey Senozhatsky @ 2024-03-29 9:06 UTC (permalink / raw)
To: Andrew Morton, Minchan Kim
Cc: Brian Geffon, linux-kernel, linux-block, Sergey Senozhatsky
Introduce "max_pages" param to recompression device attribute
which sets the upper limit on the number of entries (pages) zram
attempts to recompress.
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
Documentation/admin-guide/blockdev/zram.rst | 5 +++++
drivers/block/zram/zram_drv.c | 18 ++++++++++++++++++
2 files changed, 23 insertions(+)
diff --git a/Documentation/admin-guide/blockdev/zram.rst b/Documentation/admin-guide/blockdev/zram.rst
index ee2b0030d416..091e8bb38887 100644
--- a/Documentation/admin-guide/blockdev/zram.rst
+++ b/Documentation/admin-guide/blockdev/zram.rst
@@ -466,6 +466,11 @@ of equal or greater size:::
#recompress idle pages larger than 2000 bytes
echo "type=idle threshold=2000" > /sys/block/zramX/recompress
+It is also possible to limit the number of pages zram re-compression will
+attempt to recompress:::
+
+ echo "type=huge_idle max_pages=42" > /sys/block/zramX/recompress
+
Recompression of idle pages requires memory tracking.
During re-compression for every page, that matches re-compression criteria,
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index f0639df6cd18..a97986c52476 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1710,6 +1710,7 @@ static ssize_t recompress_store(struct device *dev,
struct zram *zram = dev_to_zram(dev);
unsigned long nr_pages = zram->disksize >> PAGE_SHIFT;
char *args, *param, *val, *algo = NULL;
+ u64 recomp_limit = ULLONG_MAX;
u32 mode = 0, threshold = 0;
unsigned long index;
struct page *page;
@@ -1732,6 +1733,17 @@ static ssize_t recompress_store(struct device *dev,
continue;
}
+ if (!strcmp(param, "max_pages")) {
+ /*
+ * Limit the number of entries (pages) we attempt to
+ * recompress.
+ */
+ ret = kstrtoull(val, 10, &recomp_limit);
+ if (ret)
+ return ret;
+ continue;
+ }
+
if (!strcmp(param, "threshold")) {
/*
* We will re-compress only idle objects equal or
@@ -1788,6 +1800,9 @@ static ssize_t recompress_store(struct device *dev,
for (index = 0; index < nr_pages; index++) {
int err = 0;
+ if (!recomp_limit)
+ break;
+
zram_slot_lock(zram, index);
if (!zram_allocated(zram, index))
@@ -1816,6 +1831,9 @@ static ssize_t recompress_store(struct device *dev,
break;
}
+ if (recomp_limit > 0)
+ recomp_limit--;
+
cond_resched();
}
--
2.44.0.478.gd926399ef9-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] zram: add limit to recompression
2024-03-29 9:06 [PATCH] zram: add limit to recompression Sergey Senozhatsky
@ 2024-03-29 9:20 ` Sergey Senozhatsky
0 siblings, 0 replies; 2+ messages in thread
From: Sergey Senozhatsky @ 2024-03-29 9:20 UTC (permalink / raw)
To: Sergey Senozhatsky
Cc: Andrew Morton, Minchan Kim, Brian Geffon, linux-kernel,
linux-block
On (24/03/29 18:06), Sergey Senozhatsky wrote:
> Introduce "max_pages" param to recompression device attribute
> which sets the upper limit on the number of entries (pages) zram
> attempts to recompress.
Scratch this one. I think I want recompression limit to
respect size thresholds, algo priority ranges, etc.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-03-29 9:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-29 9:06 [PATCH] zram: add limit to recompression Sergey Senozhatsky
2024-03-29 9:20 ` Sergey Senozhatsky
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.