linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <senozhatsky@chromium.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Minchan Kim <minchan@kernel.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Sergey Senozhatsky <senozhatsky@chromium.org>
Subject: [PATCHv3 09/11] zram: limit max recompress prio to num_active_comps
Date: Thu, 30 Jan 2025 20:10:54 +0900	[thread overview]
Message-ID: <20250130111105.2861324-10-senozhatsky@chromium.org> (raw)
In-Reply-To: <20250130111105.2861324-1-senozhatsky@chromium.org>

Use the actual number of algorithms zram was configure with
instead of theoretical limit of ZRAM_MAX_COMPS.

Also make sure that min prio is not above max prio.

Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
 drivers/block/zram/zram_drv.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index af4bce1e5fe1..3e91fd1dcfc7 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -2011,16 +2011,19 @@ static ssize_t recompress_store(struct device *dev,
 				struct device_attribute *attr,
 				const char *buf, size_t len)
 {
-	u32 prio = ZRAM_SECONDARY_COMP, prio_max = ZRAM_MAX_COMPS;
 	struct zram *zram = dev_to_zram(dev);
 	char *args, *param, *val, *algo = NULL;
 	u64 num_recomp_pages = ULLONG_MAX;
 	struct zram_pp_ctl *ctl = NULL;
 	struct zram_pp_slot *pps;
 	u32 mode = 0, threshold = 0;
+	u32 prio, prio_max;
 	struct page *page;
 	ssize_t ret;
 
+	prio = ZRAM_SECONDARY_COMP;
+	prio_max = zram->num_active_comps;
+
 	args = skip_spaces(buf);
 	while (*args) {
 		args = next_arg(args, &param, &val);
@@ -2073,7 +2076,7 @@ static ssize_t recompress_store(struct device *dev,
 			if (prio == ZRAM_PRIMARY_COMP)
 				prio = ZRAM_SECONDARY_COMP;
 
-			prio_max = min(prio + 1, ZRAM_MAX_COMPS);
+			prio_max = prio + 1;
 			continue;
 		}
 	}
@@ -2087,6 +2090,12 @@ static ssize_t recompress_store(struct device *dev,
 		goto release_init_lock;
 	}
 
+	prio_max = min(prio_max, (u32)zram->num_active_comps);
+	if (prio >= prio_max) {
+		ret = -EINVAL;
+		goto release_init_lock;
+	}
+
 	/* Do not permit concurrent post-processing actions. */
 	if (atomic_xchg(&zram->pp_in_progress, 1)) {
 		up_read(&zram->init_lock);
@@ -2101,7 +2110,7 @@ static ssize_t recompress_store(struct device *dev,
 				continue;
 
 			if (!strcmp(zram->comp_algs[prio], algo)) {
-				prio_max = min(prio + 1, ZRAM_MAX_COMPS);
+				prio_max = prio + 1;
 				found = true;
 				break;
 			}
-- 
2.48.1.262.g85cc9f2d1e-goog



  parent reply	other threads:[~2025-01-30 11:12 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-30 11:10 [PATCHv3 00/11] zram: preemptible writes and occasionally preemptible reads Sergey Senozhatsky
2025-01-30 11:10 ` [PATCHv3 01/11] zram: switch to non-atomic entry locking Sergey Senozhatsky
2025-01-30 11:10 ` [PATCHv3 02/11] zram: do not use per-CPU compression streams Sergey Senozhatsky
2025-01-30 11:10 ` [PATCHv3 03/11] zram: remove crypto include Sergey Senozhatsky
2025-01-30 11:10 ` [PATCHv3 04/11] zram: remove max_comp_streams device attr Sergey Senozhatsky
2025-01-30 11:10 ` [PATCHv3 05/11] zram: remove two-staged handle allocation Sergey Senozhatsky
2025-01-30 11:10 ` [PATCHv3 06/11] zram: permit reclaim in zstd custom allocator Sergey Senozhatsky
2025-01-30 11:10 ` [PATCHv3 07/11] zram: permit reclaim in recompression handle allocation Sergey Senozhatsky
2025-01-30 11:10 ` [PATCHv3 08/11] zram: remove writestall zram_stats member Sergey Senozhatsky
2025-01-30 11:10 ` Sergey Senozhatsky [this message]
2025-01-30 11:10 ` [PATCHv3 10/11] zram: filter out recomp targets based on priority Sergey Senozhatsky
2025-01-30 11:10 ` [PATCHv3 11/11] zram: unlock slot during recompression Sergey Senozhatsky
2025-01-30 14:18 ` [PATCHv3 00/11] zram: preemptible writes and occasionally preemptible reads 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=20250130111105.2861324-10-senozhatsky@chromium.org \
    --to=senozhatsky@chromium.org \
    --cc=akpm@linux-foundation.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