From: Sergey Senozhatsky <senozhatsky@chromium.org>
To: Andrew Morton <akpm@linux-foundation.org>,
Minchan Kim <minchan@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org,
linux-mm@kvack.org, Brian Geffon <bgeffon@google.com>,
Sergey Senozhatsky <senozhatsky@chromium.org>
Subject: [PATCH 2/5] zram: drop ->num_active_comps
Date: Fri, 27 Feb 2026 17:21:08 +0900 [thread overview]
Message-ID: <eb7cd3ca578320be9aff13e71298fc36e110af41.1772180459.git.senozhatsky@chromium.org> (raw)
In-Reply-To: <8a5d53d19a8dbd51d7d81d153676895163e0735e.1772180459.git.senozhatsky@chromium.org>
It's not entirely correct to use ->num_active_comps for
max-prio limit, as ->num_active_comps just tells the
number of configured algorithms, not the max configured
priority. For instance, in the following theoretical
example:
[lz4] [nil] [nil] [deflate]
->num_active_comps is 2, while the actual max-prio is 3.
Drop ->num_active_comps and use ZRAM_MAX_COMPS instead.
Suggested-by: Minchan Kim <minchan@kernel.org>
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
drivers/block/zram/zram_drv.c | 29 ++++++++++++++++-------------
drivers/block/zram/zram_drv.h | 1 -
2 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 53e0bbf9d6ec..6ca5a76c3865 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -2371,6 +2371,18 @@ static int scan_slots_for_recompress(struct zram *zram, u32 mode, u32 prio_max,
return 0;
}
+static bool highest_priority_algorithm(struct zram *zram, u32 prio)
+{
+ u32 p;
+
+ for (p = prio + 1; p < ZRAM_MAX_COMPS; p++) {
+ if (zram->comp_algs[p])
+ return false;
+ }
+
+ return true;
+}
+
/*
* This function will decompress (unless it's ZRAM_HUGE) the page and then
* attempt to compress it using provided compression algorithm priority
@@ -2478,12 +2490,11 @@ static int recompress_slot(struct zram *zram, u32 index, struct page *page,
* Secondary algorithms failed to re-compress the page
* in a way that would save memory.
*
- * Mark the object incompressible if the max-priority
- * algorithm couldn't re-compress it.
+ * Mark the object incompressible if the max-priority (the
+ * last configured one) algorithm couldn't re-compress it.
*/
- if (prio < zram->num_active_comps)
- return 0;
- set_slot_flag(zram, index, ZRAM_INCOMPRESSIBLE);
+ if (highest_priority_algorithm(zram, prio))
+ set_slot_flag(zram, index, ZRAM_INCOMPRESSIBLE);
return 0;
}
@@ -2615,12 +2626,6 @@ static ssize_t recompress_store(struct device *dev,
}
}
- prio_max = min(prio_max, (u32)zram->num_active_comps);
- if (prio >= prio_max) {
- ret = -EINVAL;
- goto out;
- }
-
if (prio < ZRAM_SECONDARY_COMP || prio >= ZRAM_MAX_COMPS) {
ret = -EINVAL;
goto out;
@@ -2833,7 +2838,6 @@ static void zram_destroy_comps(struct zram *zram)
if (!comp)
continue;
zcomp_destroy(comp);
- zram->num_active_comps--;
}
for (prio = ZRAM_PRIMARY_COMP; prio < ZRAM_MAX_COMPS; prio++)
@@ -2898,7 +2902,6 @@ static ssize_t disksize_store(struct device *dev, struct device_attribute *attr,
}
zram->comps[prio] = comp;
- zram->num_active_comps++;
}
zram->disksize = disksize;
set_capacity_and_notify(zram->disk, zram->disksize >> SECTOR_SHIFT);
diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h
index f0de8f8218f5..08d1774c15db 100644
--- a/drivers/block/zram/zram_drv.h
+++ b/drivers/block/zram/zram_drv.h
@@ -125,7 +125,6 @@ struct zram {
*/
u64 disksize; /* bytes */
const char *comp_algs[ZRAM_MAX_COMPS];
- s8 num_active_comps;
/*
* zram is claimed so open request will be failed
*/
--
2.53.0.473.g4a7958ca14-goog
next prev parent reply other threads:[~2026-02-27 8:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-27 8:21 [PATCH 1/5] zram: do not autocorrect bad recompression parameters Sergey Senozhatsky
2026-02-27 8:21 ` Sergey Senozhatsky [this message]
2026-02-27 8:21 ` [PATCH 3/5] zram: recompression priority param should override algo Sergey Senozhatsky
2026-02-27 8:21 ` [PATCH 4/5] zram: update recompression documentation Sergey Senozhatsky
2026-02-27 8:21 ` [PATCH 5/5] zram: remove chained recompression Sergey Senozhatsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=eb7cd3ca578320be9aff13e71298fc36e110af41.1772180459.git.senozhatsky@chromium.org \
--to=senozhatsky@chromium.org \
--cc=akpm@linux-foundation.org \
--cc=bgeffon@google.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=minchan@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox