From patchwork Thu Jan 30 11:10:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13954490 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4395DC0218D for ; Thu, 30 Jan 2025 11:12:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 79678280286; Thu, 30 Jan 2025 06:12:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 751DB2800D6; Thu, 30 Jan 2025 06:12:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5713B280286; Thu, 30 Jan 2025 06:12:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 304B22800D6 for ; Thu, 30 Jan 2025 06:12:29 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4F52447429 for ; Thu, 30 Jan 2025 11:12:00 +0000 (UTC) X-FDA: 83063853642.09.8248084 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by imf29.hostedemail.com (Postfix) with ESMTP id 5CEEB12000A for ; Thu, 30 Jan 2025 11:11:58 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=AS0i2nzD; spf=pass (imf29.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.54 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738235518; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lQgITLXPodNhhg8f+6QVX/YiryNImYUIb8lIo2kz1cc=; b=OfW86AC7zktJOtc8wFplZDzZB5cenNZFPdUSEOvYOcVCpTcs1sLtsS7TqpYfqJnZYdwBrm KEqKpLPKPdkWshEsy5ziwanY24MhyjRsWoZuyoUH0Ym/enZwclNb9X/VOjsZ034/MvzcO5 OsQMJXu/KKfTIX9lyTUCgDJp4UlDuag= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=AS0i2nzD; spf=pass (imf29.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.54 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738235518; a=rsa-sha256; cv=none; b=zvJF/2BgwTM48llhUnfzuoxa8ew+i0T4KQxril66iG7n/SjWcN3s12w4BuyY65NzP+QraR tYj7OQbVavbfMWjUjpohH+q0vpKg0fyHSId4uZ7ZhJYiif4ya0YhhjG/tKjDP7I0gA2Onn bb2IK8Ev9PO4uCEDuARv84igDh6DiDw= Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-2f13acbe29bso2724950a91.1 for ; Thu, 30 Jan 2025 03:11:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1738235517; x=1738840317; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lQgITLXPodNhhg8f+6QVX/YiryNImYUIb8lIo2kz1cc=; b=AS0i2nzDCD05U16ft9F1Ey8Vl5TgyC0hm068mn1mDCbFpo7sVihUjPDGcakhezw1pZ at6Tv7Qsy1RQAyXwijIWCAhYC6EM3qBGJjpviDgakjPPu4qB28ivsH5tho4zDM5dZ2WI EGUqwZWCIXgT2NrJNJqrvAtFg/V8yzI5jlZKc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738235517; x=1738840317; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lQgITLXPodNhhg8f+6QVX/YiryNImYUIb8lIo2kz1cc=; b=dAnukYthDohdVmAh9IFwaN6Ngl8yfzPqPoszRppdZXh+P3PEI8qibGop9o28Pv7TJV X48tuzJn5tQ0LvKCHJSnM/eeAjr6/LHr74EVyixkNp7BsYRh8zlqgc7gq237XoWYuH0k jz3QXMZvbfZhrbJS6SUnVz4yUWq8++Hn6o5O3E9bPBLceeoGeDsWkjcr6yKFnZkkcbVB A2EDP7zSlZHaCJEhxkCTdvBbRJD+N8qJ2QfUC0rpzW9bh9GWBaMiJo4/9BmKE5gK3Af/ RlJ+Lla91HrjrowlHbZcqA2t8CNo9YQDQlWAWltFWUauNiM+SRAo0cPIzMpNgq8KgXtV K8UQ== X-Forwarded-Encrypted: i=1; AJvYcCVGs3eHPZCBrTVkGhjXIFD0PPpBU+WyQE9MhAKUktULuKZ4OoouozMKLE3dzOL/U106M/qoJJSggQ==@kvack.org X-Gm-Message-State: AOJu0YyXNmS6rkMeRg2PoLKEzhT6sdNlyOIQ6mS3beSvFXbS2rWsyC28 8DeISskwxqEMRTSBG9ot83aNzuR6f8Fx9+zLKPYaokEgfDnoOCxfuov5je+nuw== X-Gm-Gg: ASbGncuXPKjKIhm0ofh7t+hZhYlziLcpdv4MxOMJG2kTTnn3HYBzS1gCUdG1/p6mB94 s3Ngbzq7hzx7SfpDHqLM+8bGMp+iKhkVUfAGx5ooCIyJvqIGsCaVEPZ++PAXcjDR1SEEvAD8PzR RtFEjkXSqO1kPEgKgN6rhd/0y957LLDdkYdv9RvdW/O01JQbehX8gb3qZiGMcnUr2OST5qMBkYW CG8eBAsYHHqIT9JuqNpQ+giFnBPBiWIHnOpo5AREhX5qzJSoAP/y3hLm/gCit+aIGtNm2wq+1rq 1JRjxfegeLIgZGwg X-Google-Smtp-Source: AGHT+IHdIqAq1Ip7rjsfMeTr4P2qYVZikb+j/nc93lXmG1/0trH7vosRiIP+YWEpphAlbCSobUlWtw== X-Received: by 2002:aa7:86d6:0:b0:729:425:fde4 with SMTP id d2e1a72fcca58-72fe2dbbf37mr4157189b3a.11.1738235517164; Thu, 30 Jan 2025 03:11:57 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:d4ce:e744:f46b:4fb]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-72fe69bba21sm1144810b3a.114.2025.01.30.03.11.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 30 Jan 2025 03:11:56 -0800 (PST) From: Sergey Senozhatsky To: Andrew Morton Cc: Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv3 09/11] zram: limit max recompress prio to num_active_comps Date: Thu, 30 Jan 2025 20:10:54 +0900 Message-ID: <20250130111105.2861324-10-senozhatsky@chromium.org> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog In-Reply-To: <20250130111105.2861324-1-senozhatsky@chromium.org> References: <20250130111105.2861324-1-senozhatsky@chromium.org> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 5CEEB12000A X-Stat-Signature: t1niqwmwfaicfuskub4o95nqohk8d83i X-Rspam-User: X-HE-Tag: 1738235518-403572 X-HE-Meta: U2FsdGVkX1+Gsnqg+yv6aC+hmQXfoGsL2T7jwX7+r303gxzvly4y3KrvRk/sMVhO/hnQhUBaLpGjMlYfFOY3ndh+/Vyax6j8fQOifJUqefXZsFEIu7bpMep/RuGRMT1VyeTkn9m/gBeyvuS0+u1L6+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tUBqkP0B6CQ3XV7Ot0TKxftzI8ngyRCCZifPHgrUv8OMTLE3sM5S2MLBOhIBB0hlM2ybD3XisRwhZPFb+2E0NXakxJqVuu//ZdqW1FmSdcc/NM7aVXAoys1SS0z9+maFMX2uihU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 --- 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, ¶m, &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; }