From patchwork Fri Apr 5 05:35:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13618544 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 7F154CD1284 for ; Fri, 5 Apr 2024 05:35:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A279D6B00E5; Fri, 5 Apr 2024 01:35:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D7B86B00E7; Fri, 5 Apr 2024 01:35:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C6846B00E8; Fri, 5 Apr 2024 01:35:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 6A8336B00E5 for ; Fri, 5 Apr 2024 01:35:17 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2DBED1A078B for ; Fri, 5 Apr 2024 05:35:17 +0000 (UTC) X-FDA: 81974365074.14.1857247 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf08.hostedemail.com (Postfix) with ESMTP id 73AF2160008 for ; Fri, 5 Apr 2024 05:35:15 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=0YDc2zrQ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf08.hostedemail.com: domain of 3ko0PZgoKCCMXNRQX9GLDCFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--yosryahmed.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3ko0PZgoKCCMXNRQX9GLDCFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712295315; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fbFnbwv9ZL9vnT6aD0Y4iZUVe+aMA3yOt75trlF6TiA=; b=2MiPiearcN3m39xTKO4Yfc7eJ5H8sZe+uiNx+wKWJyCpnEO9qobkJseL3CP9Pk+yF88xOj EaPxm0q2J3kPDA+tL/mZcHNdx+QDawV8JqNUreZL33y3JUudcqftu2i5CSciElC/iqMy1S j4MFY2HfxUaSigXSBgaMgKlUrqhbo4o= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=0YDc2zrQ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf08.hostedemail.com: domain of 3ko0PZgoKCCMXNRQX9GLDCFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--yosryahmed.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3ko0PZgoKCCMXNRQX9GLDCFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712295315; a=rsa-sha256; cv=none; b=Z6+Ztu+YJf+3Lv+v+9sICOtI4lDW/zDJ2nZWfi5QBZbgCnYRopS0zjTcgXGV8yx8BKytAO E1Ptzfc5bsLMcWt2SuK64fverKZGcaqjrDJQNnhtyozYrxsO2KQZw5dc6gxQDEXcsvXBIh AncSvvALP95huWrQCpO9+29J+h1HAso= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60ab69a9e6fso32714897b3.0 for ; Thu, 04 Apr 2024 22:35:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712295314; x=1712900114; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=fbFnbwv9ZL9vnT6aD0Y4iZUVe+aMA3yOt75trlF6TiA=; b=0YDc2zrQMsekfD+GfajOQ9ocqphEQTSd2u1tjaBnl0ALoaxF72q9Es8z51XWuBKrNZ dWHTR7yarHjJQQTJ3xoInGRXElGFay6M8mGPMTUlQl6+UWQea0Gmp97lTueNb0pN+BNU vPEc1uXSfvGuNf3xunNdN3fq0tMQ6dr15ok4g2OzXhSdWlRqGQ/FvsCqY6VptORZGtVy JopEgElqf5zC2sW+VjMPdj8FMGYyMroTSh1zHuDfTRhqkMrMgQGkeXf+oDHjJYl0SdJy 3YiOy8p5MgfL+9e57K+sl5+j+pR+FrbYulXkq26dDHPxQMr5srbxQudpciIAVjQiPU4B GcwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712295314; x=1712900114; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fbFnbwv9ZL9vnT6aD0Y4iZUVe+aMA3yOt75trlF6TiA=; b=pOLCP40pVafN6Xoh4Fcsq4IR4c0XisCALso+lhbqYUIAjnxhVxcr/bJsrEOs8SFGU+ FrULyuzDZrXm78GlmJ6/gXIEAtatYUnjVpBfZUl/EVtB2ZWySF0ISKBY8ng1bOP+JOMg Yh9np5O6xC9zsyuhJ6dM7YgkGJAJvUGSPDUXFrr0lanZC1PuJyuDUZ59hP7+NUIpYTy1 tjiEvRUAm99CaamnNvGmTg+HIC+y3LAqS1YPHmRu+Da6eEmeWQv/IFkUEd7JM7Fvxw/1 YLxmvF6sJHHSHQRK8ZXL9d6018ECQXLsXrq3DE/MzMcmmXR4lWXPXpKDWuXAu1I3gCmi 5vig== X-Forwarded-Encrypted: i=1; AJvYcCW/iFkrOHMdTdEcrjYTjkIA4/sWJ0uVGXSRf7yi/eX9tXV2eQwhukdBZJP2CxIXkjMZt/gtfJwHYUnZs3wS8D6ucZg= X-Gm-Message-State: AOJu0YyTdULaCgqfH9Xk/E/G7+zC16n6sZwtZVdwyfR+gMtpy2wfAR6f GyOaR3XEVpPHs2LTDqw/qI0F94bwLe5bnMDsmxHA69JtEx1TWHZ1GL+y0xf+5SMo+MCgY+Wuzke EIhZ1aGIadz/iS11fpg== X-Google-Smtp-Source: AGHT+IFlLjixyUEVN4p+xx4HWF7PyspM95D8o4YEWmVCPSbSGxL2ZvuIRWMLaNCJ7MC52j1a09GwvbWQG08Vtp36 X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:e84:b0:dc7:463a:46d2 with SMTP id dg4-20020a0569020e8400b00dc7463a46d2mr387870ybb.0.1712295314619; Thu, 04 Apr 2024 22:35:14 -0700 (PDT) Date: Fri, 5 Apr 2024 05:35:06 +0000 In-Reply-To: <20240405053510.1948982-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20240405053510.1948982-1-yosryahmed@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240405053510.1948982-2-yosryahmed@google.com> Subject: [PATCH v2 1/5] mm: zswap: always shrink in zswap_store() if zswap_pool_reached_full From: Yosry Ahmed To: Andrew Morton Cc: Johannes Weiner , Nhat Pham , Chengming Zhou , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed X-Rspamd-Queue-Id: 73AF2160008 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: om917pw6jh94n74s5s81irijqhe8mfxb X-HE-Tag: 1712295315-806410 X-HE-Meta: U2FsdGVkX1+lXRQavhvKeRa2GBIA3ti9mik0oHi3xByQZAdi0U/EIWRdCoI5pbCCeRDE1ggWFCN2x2BZBHDlGgTNP5401dh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/dqUjO4ORcbDVsy5jzy+dAxbzh+Oc4efU6GnhVxChx4ouBNQ7TgpJ5XVNOCmS/kQCldaObzd5Le6sh5nUlg70yIwsLsZWmWD4NchhLg2vqGoYKpVqcr7x0mi/85JL92qfRfOnrDZ6QLgZllRAsWzwug64VudLBS393cyzKZXgae7SbdVS5+0TFjufGogaUROCRg/TJNwq1nUQWoJAtbgq08dny7qhk/AD5aTvJSOXRhu42HvnpgP3hNaMxTFJvN3BQ+ANadSc6Z2PKLGS/QNb0wIR78KSHVLO3myzU5i8/kCABdlh4WVDF5iSLtLWKfOHprZAvA97roUY97dLZjFHm+IZUnkufYTLw9JZfcPPE7N23ACflThkTTEmxijI0KthBLkcoL2Ur+lplSwsb5V2aaShy53K6zendJ/fI9eDLQ7FMVs58cWeoPzBmnVvwSk5jv0m9EtXN6mjIF2CJ4S51Ps+aTqT9PdQozcjboV0JtDoZ4J9bprdo4S//EPH5sUE/tfxbMb8kEwPu13Pk/bWgFuSwj7LFPMvu1OVIUJRmiXFYBRR8VVzZOXzX2TBfo8zaKJ45mi+Jmux+W3IfJgdSNnA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000005, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The cleanup code in zswap_store() is not pretty, particularly the 'shrink' label at the bottom that ends up jumping between cleanup labels. Instead of having a dedicated label to shrink the pool, just use zswap_pool_reached_full directly to figure out if the pool needs shrinking. zswap_pool_reached_full should be true if and only if the pool needs shrinking. The only caveat is that the value of zswap_pool_reached_full may be changed by concurrent zswap_store() calls between checking the limit and testing zswap_pool_reached_full in the cleanup code. This is fine because: - If zswap_pool_reached_full was true during limit checking then became false during the cleanup code, then someone else already took care of shrinking the pool and there is no need to queue the worker. That would be a good change. - If zswap_pool_reached_full was false during limit checking then became true during the cleanup code, then someone else hit the limit meanwhile. In this case, both threads will try to queue the worker, but it never gets queued more than once anyway. Also, calling queue_work() multiple times when the limit is hit could already happen today, so this isn't a significant change in any way. Signed-off-by: Yosry Ahmed Reviewed-by: Nhat Pham Reviewed-by: Chengming Zhou Acked-by: Johannes Weiner --- mm/zswap.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index c4979c76d58e3..1cf3ab4b22e64 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1429,12 +1429,12 @@ bool zswap_store(struct folio *folio) if (cur_pages >= max_pages) { zswap_pool_limit_hit++; zswap_pool_reached_full = true; - goto shrink; + goto reject; } if (zswap_pool_reached_full) { if (cur_pages > zswap_accept_thr_pages()) - goto shrink; + goto reject; else zswap_pool_reached_full = false; } @@ -1540,6 +1540,8 @@ bool zswap_store(struct folio *folio) zswap_entry_cache_free(entry); reject: obj_cgroup_put(objcg); + if (zswap_pool_reached_full) + queue_work(shrink_wq, &zswap_shrink_work); check_old: /* * If the zswap store fails or zswap is disabled, we must invalidate the @@ -1550,10 +1552,6 @@ bool zswap_store(struct folio *folio) if (entry) zswap_entry_free(entry); return false; - -shrink: - queue_work(shrink_wq, &zswap_shrink_work); - goto reject; } bool zswap_load(struct folio *folio) From patchwork Fri Apr 5 05:35:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13618545 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 4C17BCD1284 for ; Fri, 5 Apr 2024 05:35:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BD5F36B00E7; Fri, 5 Apr 2024 01:35:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B86066B00E9; Fri, 5 Apr 2024 01:35:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A09296B00EA; Fri, 5 Apr 2024 01:35:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 7CD7E6B00E7 for ; Fri, 5 Apr 2024 01:35:19 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2AEC31A10D0 for ; Fri, 5 Apr 2024 05:35:19 +0000 (UTC) X-FDA: 81974365158.21.794552A Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf12.hostedemail.com (Postfix) with ESMTP id 6C0174000B for ; Fri, 5 Apr 2024 05:35:17 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=1ulCEXsh; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of 3lI0PZgoKCCUZPTSZBINFEHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--yosryahmed.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3lI0PZgoKCCUZPTSZBINFEHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712295317; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=kLsh2mavKyRbc6llROScpNs5yKk8UXbWOX30PW11RTM=; b=c+ZiiO3AkAed6S0QzZrXu8Lb2taUIH3OsX6P9n2CuzSANGgd9D9ddq7WKcVOtIFFMMDSBK n4Iyu0sy9QZmiAQF7ETVdcQ8iZiKgjAmHSK6cXnn3mpYAjR+osnnH4qVJAKsGGkPAeZvuW swvn3Hmip2KX4uDBrG1bHVptUvP04No= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=1ulCEXsh; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of 3lI0PZgoKCCUZPTSZBINFEHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--yosryahmed.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3lI0PZgoKCCUZPTSZBINFEHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712295317; a=rsa-sha256; cv=none; b=DLC0kzENLS+O5O6TV2cmawLfeNWEy5ecSTKSaoz6j8jkfNUEcH8EweHUsndnVilweisFLX LZQvf+HutKl9lFQWP8M38ukQY/N9DjRCYtNbb/WDHPJGPlOSLsVFwYxG3RQ00mCO29Jw0u k5/CBhz5zotrHnwINWvBrodukhZ4Xwc= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc693399655so3208981276.1 for ; Thu, 04 Apr 2024 22:35:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712295316; x=1712900116; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=kLsh2mavKyRbc6llROScpNs5yKk8UXbWOX30PW11RTM=; b=1ulCEXsh7EFXmnd/T15yPB1wXc/M4Y7NRYhMhdxJXgaYpWMNmwjup9WqrmY/oPkp37 HLPpgWxBgh+HBoMijVqu5560UXVtPuA+g1LV+NlHYjVk0PNv34FtqDgpk65oY0r/Y/FJ oAZnvZzEjXyd6Rcru1mn4X1WcBgDDymf/G1IF1xaUn3Qx5wZUy4NzKUYC+syP/+n5d1f lOLB9APdUzFLwlbRM7V1uWv1FD2VmAyemM/+vV01sTWQ2kRD+gNc62+vvbpWOdZ6uWsL 1zkAO/4s8q70i6oPMUpPoTvzxXy/FK+V44FbqQEW0P8M4M+AOH6X8tHA5Sux+IaJyzTK F2VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712295316; x=1712900116; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kLsh2mavKyRbc6llROScpNs5yKk8UXbWOX30PW11RTM=; b=CaJFf8L04xMDs5U5//Bx1ZZdENAlbIfD1brGbQkLNpEF9PPnk5u8YkJ9oTxbCeGdfP huHWro6eEUWpHPvmAkrGQ5PfDvCl02SRvKNJMsy2VMH4zfQjAa1yMtV4P0mmqQBIP9ao QBGF3YSXWvDhLmm3eY1+RGlPpTLY4fxyhIN0QTbLnogUkHoRuV46UnIMzfudL0qBX8xu hNjWy2NR0C0iloWqLowfiVirJ22vXBcMjl7LvKQhIAwD98qaI+ksR4bsD2h7eQBtg7da zapIoHZcCgkiTLOHm8pzFDpaLrIqj3ngoJKZCovWTjeADXCkP0vTJgbn0fcIrYDht1NB akIw== X-Forwarded-Encrypted: i=1; AJvYcCU5Ml/EJYQx/QG12jRdYgtB9q5MIM8ZwBDq8Tm7m86U2GdWV/+2kw9lu0K3hVkCIYvnP5wcNj56WU2CSpp9ykrZd+Y= X-Gm-Message-State: AOJu0Yxgx+73pDWRc6kmW91wTGjnTwrfJ9p8mU2ffX6bWw3tgzIb7Gkn apDEUjDyrjHMdvebH57ktdz7geHJC0MmQgKVq1pdXPozgCK+Pqjt5cfrWWnVU+43WHgWp5M1pAO mxJW1kfJOFAZOUKubmw== X-Google-Smtp-Source: AGHT+IH7oL3hUlxA/yZh4c4iQx4M23yR54gCIDKzNRckDvrgcltEIddaQ+ef2AO7ne3vgWVM1zEbXHHpxJ8/KEde X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:f87:b0:dc7:8e30:e2e3 with SMTP id ft7-20020a0569020f8700b00dc78e30e2e3mr97855ybb.2.1712295316513; Thu, 04 Apr 2024 22:35:16 -0700 (PDT) Date: Fri, 5 Apr 2024 05:35:07 +0000 In-Reply-To: <20240405053510.1948982-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20240405053510.1948982-1-yosryahmed@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240405053510.1948982-3-yosryahmed@google.com> Subject: [PATCH v2 2/5] mm: zswap: calculate limits only when updated From: Yosry Ahmed To: Andrew Morton Cc: Johannes Weiner , Nhat Pham , Chengming Zhou , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed X-Rspamd-Queue-Id: 6C0174000B X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: w73uze81h3sd8m8rj15bxogj3fj9th5i X-HE-Tag: 1712295317-524621 X-HE-Meta: U2FsdGVkX18sMNT+Gvr/tRPwz+Qq88iLI1EzuYURGBf/UtAPVYDJNexVGgrhcNT4U2RxtQetNutxLhalN5qqM2xPVCGivpamvJJ8fEqaef0ctQJXMClxmwIDI7JLFILp/JPGlNbSHmkwUOJj8kdQ7fy6BA2IjKleliZDkHLQgBb7RRl+oJoYPqUBaZYVgCFnrsdflv23TP+DCQBS8C3bsbjQ8GcVi8KssvdjiNmDI0bvgEA3/e9T/Kd5OqqGYvTrVGgSb1SNzcaiUSo7t9gThVN0N34M2R+gCyy17f31f17j1QwVEcfFyzotmv9Pn9ANupzhDhPCSitjziN3w0ecx/eBZuiulputEdou90JNLHsd60PeQF5rulrewtee/CJqvc01ZjpMXEoPMcjb3oMAcn193MdMroSedAaCLEhR0zVQRSmnwKcgBgJDGp57RyqBloZ3b3frtjGHTuI9Cl5OFOgykd/4xbGKaKZ1HARdAGJu9dB45SLzqmuLRIer5c7v8mFhz0BZenK83SEZaZrnRQ1S6rU+6CANgjfjhcNqP06KPyF/gG7sIJOrsvlRQgPaYR3TJQ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YmTXl/3837ZHj+EhzjzwgBUbEntm 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: Currently, we calculate the zswap global limit, and potentially the acceptance threshold in the zswap, in pages in the zswap store path. This is unnecessary because the values rarely change. Instead, precalculate the them when the module parameters are updated, which should be rare. Since we are adding custom handlers for setting the percentages now, add proper validation that they are <= 100. Suggested-by: Johannes Weiner Signed-off-by: Yosry Ahmed --- mm/zswap.c | 86 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 16 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 1cf3ab4b22e64..832e3f56232f0 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -116,12 +116,29 @@ module_param_cb(zpool, &zswap_zpool_param_ops, &zswap_zpool_type, 0644); /* The maximum percentage of memory that the compressed pool can occupy */ static unsigned int zswap_max_pool_percent = 20; -module_param_named(max_pool_percent, zswap_max_pool_percent, uint, 0644); +static unsigned long zswap_max_pages; + +static int zswap_max_pool_param_set(const char *, + const struct kernel_param *); +static const struct kernel_param_ops zswap_max_pool_param_ops = { + .set = zswap_max_pool_param_set, + .get = param_get_uint, +}; +module_param_cb(max_pool_percent, &zswap_max_pool_param_ops, + &zswap_max_pool_percent, 0644); /* The threshold for accepting new pages after the max_pool_percent was hit */ static unsigned int zswap_accept_thr_percent = 90; /* of max pool size */ -module_param_named(accept_threshold_percent, zswap_accept_thr_percent, - uint, 0644); +unsigned long zswap_accept_thr_pages; + +static int zswap_accept_thr_param_set(const char *, + const struct kernel_param *); +static const struct kernel_param_ops zswap_accept_thr_param_ops = { + .set = zswap_accept_thr_param_set, + .get = param_get_uint, +}; +module_param_cb(accept_threshold_percent, &zswap_accept_thr_param_ops, + &zswap_accept_thr_percent, 0644); /* * Enable/disable handling same-value filled pages (enabled by default). @@ -490,14 +507,16 @@ static struct zswap_pool *zswap_pool_find_get(char *type, char *compressor) return NULL; } -static unsigned long zswap_max_pages(void) +static void zswap_update_max_pages(void) { - return totalram_pages() * zswap_max_pool_percent / 100; + WRITE_ONCE(zswap_max_pages, + totalram_pages() * zswap_max_pool_percent / 100); } -static unsigned long zswap_accept_thr_pages(void) +static void zswap_update_accept_thr_pages(void) { - return zswap_max_pages() * zswap_accept_thr_percent / 100; + WRITE_ONCE(zswap_accept_thr_pages, + READ_ONCE(zswap_max_pages) * zswap_accept_thr_percent / 100); } unsigned long zswap_total_pages(void) @@ -684,6 +703,43 @@ static int zswap_enabled_param_set(const char *val, return ret; } +static int __zswap_percent_param_set(const char *val, + const struct kernel_param *kp) +{ + unsigned int n; + int ret; + + ret = kstrtouint(val, 10, &n); + if (ret || n > 100) + return -EINVAL; + + return param_set_uint(val, kp); +} + +static int zswap_max_pool_param_set(const char *val, + const struct kernel_param *kp) +{ + int err = __zswap_percent_param_set(val, kp); + + if (!err) { + zswap_update_max_pages(); + zswap_update_accept_thr_pages(); + } + + return err; +} + +static int zswap_accept_thr_param_set(const char *val, + const struct kernel_param *kp) +{ + int err = __zswap_percent_param_set(val, kp); + + if (!err) + zswap_update_accept_thr_pages(); + + return err; +} + /********************************* * lru functions **********************************/ @@ -1305,10 +1361,6 @@ static void shrink_worker(struct work_struct *w) { struct mem_cgroup *memcg; int ret, failures = 0; - unsigned long thr; - - /* Reclaim down to the accept threshold */ - thr = zswap_accept_thr_pages(); /* global reclaim will select cgroup in a round-robin fashion. */ do { @@ -1358,7 +1410,8 @@ static void shrink_worker(struct work_struct *w) break; resched: cond_resched(); - } while (zswap_total_pages() > thr); + /* Reclaim down to the accept threshold */ + } while (zswap_total_pages() > READ_ONCE(zswap_accept_thr_pages)); } static int zswap_is_page_same_filled(void *ptr, unsigned long *value) @@ -1424,16 +1477,14 @@ bool zswap_store(struct folio *folio) /* Check global limits */ cur_pages = zswap_total_pages(); - max_pages = zswap_max_pages(); - - if (cur_pages >= max_pages) { + if (cur_pages >= READ_ONCE(zswap_max_pages)) { zswap_pool_limit_hit++; zswap_pool_reached_full = true; goto reject; } if (zswap_pool_reached_full) { - if (cur_pages > zswap_accept_thr_pages()) + if (cur_pages > READ_ONCE(zswap_accept_thr_pages)) goto reject; else zswap_pool_reached_full = false; @@ -1734,6 +1785,9 @@ static int zswap_setup(void) zswap_enabled = false; } + zswap_update_max_pages(); + zswap_update_accept_thr_pages(); + if (zswap_debugfs_init()) pr_warn("debugfs initialization failed\n"); zswap_init_state = ZSWAP_INIT_SUCCEED; From patchwork Fri Apr 5 05:35:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13618546 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 05342CD11C2 for ; Fri, 5 Apr 2024 05:35:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A91676B00E9; Fri, 5 Apr 2024 01:35:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B0FD6B00EB; Fri, 5 Apr 2024 01:35:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 853006B00EC; Fri, 5 Apr 2024 01:35:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 65A976B00E9 for ; Fri, 5 Apr 2024 01:35:21 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 0755F40157 for ; Fri, 5 Apr 2024 05:35:21 +0000 (UTC) X-FDA: 81974365242.21.0D4AEF7 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf01.hostedemail.com (Postfix) with ESMTP id 42A204000D for ; Fri, 5 Apr 2024 05:35:19 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=XKgGy6cS; spf=pass (imf01.hostedemail.com: domain of 3lo0PZgoKCCcbRVUbDKPHGJRRJOH.FRPOLQXa-PPNYDFN.RUJ@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3lo0PZgoKCCcbRVUbDKPHGJRRJOH.FRPOLQXa-PPNYDFN.RUJ@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712295319; a=rsa-sha256; cv=none; b=U+wqE3s3M5FD1MtBYe0Mvwaimz/sGw5m8IX8zGQ+/ev2kJpKku9lFgmATEDiixOgVUh82o 4qQaKFJ8e6VLp637Jin3ynH7WlDaFYwVP6DtD7R0T40a5AI4jl+qBZpBavVc+ldtmI8n30 Im6J09S5A0Kv7NUt1p1Ieo1y6Btbmqg= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=XKgGy6cS; spf=pass (imf01.hostedemail.com: domain of 3lo0PZgoKCCcbRVUbDKPHGJRRJOH.FRPOLQXa-PPNYDFN.RUJ@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3lo0PZgoKCCcbRVUbDKPHGJRRJOH.FRPOLQXa-PPNYDFN.RUJ@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712295319; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=WDqFLsTFGLxbu9w6SZiJvC7ASuSVfXA4IdBaekrBdf8=; b=lgksMciua8G9UMMiRrazs8vlMc4RtHLXlShJW2mGX6VfY7Tzrjy7m5VZmc0Z0g7zD21Pz7 9ZPSiITrQ1/CLhrgxxesF6rxcpwhR5eWEI1z9e1jiWXB1cMODrryQ2pVeodk8PjKEBm3z6 twEXeZfaq7ENQuUSZgqbFthMhsrtJXk= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-61510f72bb3so31328957b3.0 for ; Thu, 04 Apr 2024 22:35:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712295318; x=1712900118; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=WDqFLsTFGLxbu9w6SZiJvC7ASuSVfXA4IdBaekrBdf8=; b=XKgGy6cS2RErH5HmK5dcGAFLTDD8no4tR+3+vWqUMhWTziBob92qID1uuKb49rQp8n GK/iFT0/fBeCfwQTeikqkq8Q+ODdsDQBzmygBZRWf4cyMvXLNm9F18SXi00kt2/MKfdg K/USW/nrLlE4JmeXTpq7inbpTvWpOb+iX1y2zORMdBFSThjM4uHoECdCWzEQSb3tt8tQ 47RSnXI3zD+W0pFAIsCSmAz9BwwO57L4X0uuDxAyQp/fRCMjZ6rBRcVvE6jvQ0agw9vV IBSrsFFR7E0uBsyFDDBCfiQlcVrXHQC3C8XsYA8h1TU1rk46fMi5n8MIDH2hoW94GOog sv1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712295318; x=1712900118; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WDqFLsTFGLxbu9w6SZiJvC7ASuSVfXA4IdBaekrBdf8=; b=F7xPjf7qj6IT4q63oubSfxXNCGS2b/6EyBCcR7NLPzLUuxQ+1DTYEyHee/t8l3LoBr uMYf5Cn3dyKVsrI6OvWyXkylgOx6OgGUzbNRjYXIFsKkFU1ZxkgO9vo4DJnt0ZAG1+qv n6pe9uWqkIQriuL7j50wbb7VdM7iNvEeGRdhpS/ZhiT55p5jQ0cTTDDHWfPM07fSrRid Xhz0JmRhjpoU7cbLtylmds8QPhXdg+m9Fj19gcLuBt5Pxz1SWFCYrlQjLjDfPX54DpUe 0PugjtV7gFqxDbcvW0UVycA0dYRM8V6dCDBKmUy7qGMy4WOmdE57eYitqVG2FvfPbrsW JZZg== X-Forwarded-Encrypted: i=1; AJvYcCUIyw37H8K51+JKxZKP0jdQQrlgEbqnZTj1BZiRgrcXbDDGJ4PyYKRrPsrgOlvFe357HWjm3XDxT1LBN+tCOrxfIAc= X-Gm-Message-State: AOJu0YwDYG7kAvklpd/ImUPkaCNwTCkuFoGLjCFE6h/lpJS5d+tJlHS3 9QoWL5lWh0+63DM28ufneFqh0Wk3Pa1LVd9xrQS7hT6Shb8d4HTRenitbr0DmX+ouq4WFM8t3YJ jmU4Y60n/fF9BfD+Vrw== X-Google-Smtp-Source: AGHT+IEIkNqISvh3/kP7GIAdlqcFQuxDthw7sLxMpCyp0IlORn7H21arD9nnFY26GvXJUA85AaAzJMEQR86jOyJW X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:1893:b0:dcc:5a91:aee9 with SMTP id cj19-20020a056902189300b00dcc5a91aee9mr112599ybb.7.1712295318409; Thu, 04 Apr 2024 22:35:18 -0700 (PDT) Date: Fri, 5 Apr 2024 05:35:08 +0000 In-Reply-To: <20240405053510.1948982-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20240405053510.1948982-1-yosryahmed@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240405053510.1948982-4-yosryahmed@google.com> Subject: [PATCH v2 3/5] mm: zswap: refactor limit checking from zswap_store() From: Yosry Ahmed To: Andrew Morton Cc: Johannes Weiner , Nhat Pham , Chengming Zhou , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 42A204000D X-Stat-Signature: qxqmw8jeam54d3db3oncq11qpgjrj4gz X-Rspam-User: X-HE-Tag: 1712295319-921742 X-HE-Meta: U2FsdGVkX1/mOOwf0cW/yi7/B3INkgr/ZwZK/EUThlOWpa8Waj4ER/jhuXLsVdwAbf07nMwCDOs90g+xRSp9z3gGYO4i+C38Tjo01mAIy/mxHdgrdSb5XnkB10faVAT5Yl/F1QvSsfNsTaIurGHiDDLvc4OaD7EVsoVcP3+l/O++xSY4MbeDQgQ/U1zrrmMB+ElAA0U0DE8OumYonPuv1AStgfHdAoSinKoV47+62xwS+q/lS8iecweAlFjMQ4FSF4dfbFrFz25x00OHDvuJza8Y8Rvtek66gvIfrWrmDDI5S41tmhMz7PsBE1M0hhWB5cicL1uiuTipDqJwN57W4dv9eBZ/q7uUibyj4u+4VMFwxEKytTRElJXInKFTBhzwl0wt/LxHQIq1j7HDDaH0EVlyk4WOnbHm6Squ/xl9XVp5IVx4iW1Ddn6gjA9oPWPrJg5nisBWCKoMAVcfQy7C1Ql21+PgsiAGjNjPlCdbGX9gvrggjyIa2rQEvu+PNONxLCfLz2pkouTcepZ++ZFZSJ3a0i/ZrYeit5b6U5X7rY5YEWOpbI5OetJuCCcCYg1gROxUDSsuXs2Rk5OUIj5QxcfupgbdEuor7txpGjh4AsGbUaSDUysPucsx3Os+mqjgCklkdFArIyX8ZaAxbyrv5b35xPzEKh9IxC/hFt49t6yXp+J9daGKM6y3B/boWM7njni9Yf8s/SXQkI5ntM3YA1WoGkF5g5DoTewPWLSuN0xxbTErplKS7EjwA9NYn+yRC1snDZ8gHd9bPwe4Jaf58rutwWeoXOI6gg+o/n9unwWjoevKU/jDOXTjBc3Iq9+72/XrpFmNpNg8rS9MT4rRb2t5sw1lXO57uS+l5cvIWfP/PpTnZJ0vSNOafOaDw2mbGgLHvyzCH0GojXFjxZ0evvKIqihu981oGQnW8q0+kzsUixrBGNACbqam846L8A/Z1YlQ0/WEH3hPD7VM3ml 4D7HBY/H 1n3o3NdGMjT47wLmekmkXTnmiBfzQaDOYr+TV6AXmRvB7h04Rtfi0WPcpZ+1f533c1YUR3JvCsxf3/Nbri5BaqdndhxAwNvBCV/vscuOWdQHfaEqfP9fr4SofC4g5VDkOsoKyOTUGT02zC5P02S2QuU87lyOcrQjUzzkySMc86vuV12ETgcA2fWNKrhp3ooDWGV4qVtHjlsCz8ALzoHDwxAcNRisRnxv9s5A4mBDXvSqkJeEvhX9aJpbiesRq/D7uUOwgTnJDoGK7WF82n65+504i5/6ltKCMDgUJ9/JsHGDelzyC+06q8/XNYYSn8aopjayMnqKNFJHmy4Mzn/9JVLgJjNEfaYFtisRGpR4Ctj3rNA1PDqWiVHudlr56cd2JZEikWDXFjc0qmzZX8SOwG7/a22qq8auCy2DxhByYSNFnxWUNLZ7sw1MJrCtWJGX8CAubc8LRX9WdLX90Qnc04omjXcHE+KYAgIcwowyFoWHq3zqkzqKofcra86ROxfjA0DbEQJ9VOQrGKFWaQCTm7koNw55/3KfCDsk3CjBluK3LSr4kdLsxyRPNFMS+JTLTVD3ldYtT+zVAS0lEDTiOEdqkpKhwZmfNvHmAkyTE0B7mlScexkY2VuHgDFTCkpe4CqZ3n8v7oJjCfJFtG66+h/MCOWkCZDo1pzJS55NVjwR2+zOpuhed4FeILirWiSE/8hdATnNgOQHXC462tGiqjdJfQw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000016, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Refactor limit and acceptance threshold checking outside of zswap_store(). This code will be moved around in a following patch, so it would be cleaner to move a function call around. Signed-off-by: Yosry Ahmed Reviewed-by: Nhat Pham Reviewed-by: Chengming Zhou --- mm/zswap.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 832e3f56232f0..ab3cd43cdfc9d 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1444,6 +1444,20 @@ static void zswap_fill_page(void *ptr, unsigned long value) memset_l(page, value, PAGE_SIZE / sizeof(unsigned long)); } +static bool zswap_check_full(void) +{ + unsigned long cur_pages = zswap_total_pages(); + + if (cur_pages >= READ_ONCE(zswap_max_pages)) { + zswap_pool_limit_hit++; + zswap_pool_reached_full = true; + } else if (zswap_pool_reached_full && + cur_pages <= READ_ONCE(zswap_accept_thr_pages)) { + zswap_pool_reached_full = false; + } + return zswap_pool_reached_full; +} + bool zswap_store(struct folio *folio) { swp_entry_t swp = folio->swap; @@ -1452,7 +1466,6 @@ bool zswap_store(struct folio *folio) struct zswap_entry *entry, *old; struct obj_cgroup *objcg = NULL; struct mem_cgroup *memcg = NULL; - unsigned long max_pages, cur_pages; VM_WARN_ON_ONCE(!folio_test_locked(folio)); VM_WARN_ON_ONCE(!folio_test_swapcache(folio)); @@ -1475,20 +1488,8 @@ bool zswap_store(struct folio *folio) mem_cgroup_put(memcg); } - /* Check global limits */ - cur_pages = zswap_total_pages(); - if (cur_pages >= READ_ONCE(zswap_max_pages)) { - zswap_pool_limit_hit++; - zswap_pool_reached_full = true; + if (zswap_check_full()) goto reject; - } - - if (zswap_pool_reached_full) { - if (cur_pages > READ_ONCE(zswap_accept_thr_pages)) - goto reject; - else - zswap_pool_reached_full = false; - } /* allocate entry */ entry = zswap_entry_cache_alloc(GFP_KERNEL, folio_nid(folio)); From patchwork Fri Apr 5 05:35:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13618547 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 E704ACD1284 for ; Fri, 5 Apr 2024 05:35:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6A7586B00EB; Fri, 5 Apr 2024 01:35:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 62E6D6B00EC; Fri, 5 Apr 2024 01:35:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 481E76B00ED; Fri, 5 Apr 2024 01:35:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 228806B00EB for ; Fri, 5 Apr 2024 01:35:23 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E632640803 for ; Fri, 5 Apr 2024 05:35:22 +0000 (UTC) X-FDA: 81974365284.25.D80C639 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf26.hostedemail.com (Postfix) with ESMTP id 2B8C914000F for ; Fri, 5 Apr 2024 05:35:20 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=tzIeoCuH; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of 3mI0PZgoKCCkdTXWdFMRJILTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3mI0PZgoKCCkdTXWdFMRJILTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712295321; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=JztYBciZAboPFg0UR8cifQAY1ELGwu5QR/HCIVJgmmg=; b=D1JVKXKbhx8HNMP8UQevA2LKGvlQGZCtFDbR5yZa6Q4u3OEHmdTLXGS7SGdWBsmlENztxV B0ay/LOGvpI+Gu4g6YG93+8KcaGWCJWSnyA+sxS95z/gVEp10Rpkiy3fNGfFUT810i6I9v 8e723iYA6cEYOLx0th12nuxFskGHJkA= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=tzIeoCuH; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of 3mI0PZgoKCCkdTXWdFMRJILTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3mI0PZgoKCCkdTXWdFMRJILTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712295321; a=rsa-sha256; cv=none; b=2D/KuJC019OlDPVkL5VYjtdED+fyE99emmA2LybnB62M2mE2e3ERjsdJBnqkxNB7EZUQkL t/Nuo/PZCwA6Aiso3zMuua/BcsXoo6/H1CMqSNKUmZ05IG9QoseMEwlloizIAyBm2I6DxI Y3QKV4/1lmNepmhkZpt2GSyq9MSeXGo= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dcbfe1a42a4so3078993276.2 for ; Thu, 04 Apr 2024 22:35:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712295320; x=1712900120; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=JztYBciZAboPFg0UR8cifQAY1ELGwu5QR/HCIVJgmmg=; b=tzIeoCuHwP29wUW8aLlKa4YtXhxi3NpGjSF+oWQCze08LRmqNXJugwP84zlwmYkhYD 9UWGuikHT1yDcY/dgllkT/uUmSIHwezYeeNd8s1l0DObu1oP82BStBbpJ/T0dKp11O38 SlSSMkebhe9fL1oFbsaLHxNvdzZAtdW3+ZIbz+2GHW9TT2RkCCQLhdq49tEKm72oT6V4 Gvpuufgv3aPX9h9IXhqIA8KIPOiMP9RLaqDfKxYaFT4hq3pJDLTq1F2w7JT09atqud+J I4ZTOvoTEUX+ygz2tYzJIE85bVwxxrfDd12QCmAUzVogPCuPicB+sZ0r2dnzl2jQUTCE ijzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712295320; x=1712900120; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JztYBciZAboPFg0UR8cifQAY1ELGwu5QR/HCIVJgmmg=; b=LHDzxxMHzhkLctIsSPRtSeURDCNdZj02tM7g33Zfrf/ZRezrJcaSRjVB9lZYz6MJ3F 39FM+rKFPjvfG8DxmkKpbDAFp1id4D/BmHeVFcYPFuMmN/K5fSez7DiuqWFhtuairNiB L9w8+B9bdgvpYzRqyleH4CyC1lT8dLuxxvlLF7Y5AQLFCoVgPBsHhNJH24qgpEE1S1Zr G6sQsz8vBRdTLFrfxsYycPLTjYeXb89QK5jJLsnrvtfmciccjQxwZaTUAS+PUU5gKPwk Tf5QjWLjjlHCEPitMH4Z0lv7oo1waIBNQM0FzN4g1XSSHLcg7dWvf6+UOJPW5w0BSz3V UKJw== X-Forwarded-Encrypted: i=1; AJvYcCWjeWTFvm0cMrS2yJL9Rk0LstJC/KSj0OowMpguOIlLBdlPn6u8AK3lieox60X+wk+MJ8gkiuxNQS3YiZI6+4qFNGU= X-Gm-Message-State: AOJu0YwEIDwkRqdRvaNyv4sX4NmmvZUM189eKZuV1BySmtxunK2CXa9I RWFEvccBx3McTAr/HcXuVFDdWs2cERVYpy9D1nPU1yX/ZrSO60690/csXfgnLPJMKsmqNveYuGm ikbTitLIZw0LdXWSu2A== X-Google-Smtp-Source: AGHT+IHCdA/5X8U1gt0bJVEbJvMDtws+40Zw9BGN0s2+vFjCACLLPLTtlCpMI+FJ2Yy+eJlQHuE46wlM5C0M0oGx X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a25:f30f:0:b0:dc6:cafd:dce5 with SMTP id c15-20020a25f30f000000b00dc6cafddce5mr105083ybs.12.1712295320201; Thu, 04 Apr 2024 22:35:20 -0700 (PDT) Date: Fri, 5 Apr 2024 05:35:09 +0000 In-Reply-To: <20240405053510.1948982-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20240405053510.1948982-1-yosryahmed@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240405053510.1948982-5-yosryahmed@google.com> Subject: [PATCH v2 4/5] mm: zswap: move more same-filled pages checks outside of zswap_store() From: Yosry Ahmed To: Andrew Morton Cc: Johannes Weiner , Nhat Pham , Chengming Zhou , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed X-Rspam-User: X-Stat-Signature: 7c4bw1pwr4pr66rns9nm739myrikmrqk X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 2B8C914000F X-HE-Tag: 1712295320-11087 X-HE-Meta: U2FsdGVkX1/xnISEqWqIAqvMle2tX013oNXAe70gksllFpoeRiQx7hBg4WpZWrwzvqX76t/MIbeNPsIC3tHa10uvefhBCtAFC6FoLb4xTaR3uF5d4PZ0Mv59yh/ebAt64YSlOJXXgNkudBXxqNusSsax5TNTvvNzC9XNvM68PuGtHm7L4qSJYlW1jiukpVtcytKx1dUAtbN5SJR2BxmIIwWlpFa/+DfREFjfy8Yh0+w1qQ/4g5Up8FrV7NyFLa4knzFK7OCaubNuhOe8aa9Kd1sncUDeLZf0N/R4PHmQvFAXWwAeZQev3Sf6a22KJxRa4K+z0NFgt1ETcAIYpmH6Ml54JKQcWoKFof/T7ioIZxk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Fn6we3aWuZGuDPTI4zj1NQgIcQrD9Wxms1hwI+tKp8bKrL53G5ioMX4UrlFmUYG0wXg5P/EImuP3PYKNDOmp/2QhnJ8ZZUFiRsq/YcZsblaR1iemXifzGiW+9Qz8AFU6/iZJlEidnt3Y3ybm+nkOucvRFRq38Rs1ZZcMXcuwcVn44LITC7fZrwxP64EeCozry9Z/EYNrYc6nRHkGpIV6DKAMno3U2Yp5mnsV1bG2uu7oDEj4MhrihEu/AwzRNwMD7S2CGz+jJv8yjo5O90jiy04LRt7AXo1h9X40QUNyks2mn2Gjei3+VoISuLIaH2fbxsW0= 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: Currently, zswap_store() checks zswap_same_filled_pages_enabled, kmaps the folio, then calls zswap_is_page_same_filled() to check the folio contents. Move this logic into zswap_is_page_same_filled() as well (and rename it to use 'folio' while we are at it). This makes zswap_store() cleaner, and makes following changes to that logic contained within the helper. While we are at it, rename the insert_entry label to store_entry to match xa_store(). No functional change intended. Signed-off-by: Yosry Ahmed Reviewed-by: Nhat Pham Reviewed-by: Chengming Zhou Acked-by: Johannes Weiner --- mm/zswap.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index ab3cd43cdfc9d..13869d18c13bd 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1414,26 +1414,32 @@ static void shrink_worker(struct work_struct *w) } while (zswap_total_pages() > READ_ONCE(zswap_accept_thr_pages)); } -static int zswap_is_page_same_filled(void *ptr, unsigned long *value) +static bool zswap_is_folio_same_filled(struct folio *folio, unsigned long *value) { unsigned long *page; unsigned long val; unsigned int pos, last_pos = PAGE_SIZE / sizeof(*page) - 1; + bool ret = false; - page = (unsigned long *)ptr; + if (!zswap_same_filled_pages_enabled) + return false; + + page = kmap_local_folio(folio, 0); val = page[0]; if (val != page[last_pos]) - return 0; + goto out; for (pos = 1; pos < last_pos; pos++) { if (val != page[pos]) - return 0; + goto out; } *value = val; - - return 1; + ret = true; +out: + kunmap_local(page); + return ret; } static void zswap_fill_page(void *ptr, unsigned long value) @@ -1466,6 +1472,7 @@ bool zswap_store(struct folio *folio) struct zswap_entry *entry, *old; struct obj_cgroup *objcg = NULL; struct mem_cgroup *memcg = NULL; + unsigned long value; VM_WARN_ON_ONCE(!folio_test_locked(folio)); VM_WARN_ON_ONCE(!folio_test_swapcache(folio)); @@ -1498,19 +1505,11 @@ bool zswap_store(struct folio *folio) goto reject; } - if (zswap_same_filled_pages_enabled) { - unsigned long value; - u8 *src; - - src = kmap_local_folio(folio, 0); - if (zswap_is_page_same_filled(src, &value)) { - kunmap_local(src); - entry->length = 0; - entry->value = value; - atomic_inc(&zswap_same_filled_pages); - goto insert_entry; - } - kunmap_local(src); + if (zswap_is_folio_same_filled(folio, &value)) { + entry->length = 0; + entry->value = value; + atomic_inc(&zswap_same_filled_pages); + goto store_entry; } if (!zswap_non_same_filled_pages_enabled) @@ -1533,7 +1532,7 @@ bool zswap_store(struct folio *folio) if (!zswap_compress(folio, entry)) goto put_pool; -insert_entry: +store_entry: entry->swpentry = swp; entry->objcg = objcg; From patchwork Fri Apr 5 05:35:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13618548 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 A8BC4CD1284 for ; Fri, 5 Apr 2024 05:35:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5E3136B00EC; Fri, 5 Apr 2024 01:35:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 591AC6B00ED; Fri, 5 Apr 2024 01:35:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 433F26B00EE; Fri, 5 Apr 2024 01:35:25 -0400 (EDT) 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 229F26B00EC for ; Fri, 5 Apr 2024 01:35:25 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id B02EB1A10D2 for ; Fri, 5 Apr 2024 05:35:24 +0000 (UTC) X-FDA: 81974365368.19.13FD53C Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf30.hostedemail.com (Postfix) with ESMTP id D55BF80007 for ; Fri, 5 Apr 2024 05:35:22 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=3ALc5Yqo; spf=pass (imf30.hostedemail.com: domain of 3mo0PZgoKCCsfVZYfHOTLKNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3mo0PZgoKCCsfVZYfHOTLKNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712295322; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lZdonMx397+2pSb+glDTuU5D6tQtRdHssQDj6gK5t2I=; b=bP38YCICa940hMii8wpHiQ0X+VJEIzVA7CmdjJeNUlHCF0ApyXxI0CC2RquawWJQfDDmAB Em7ctAV5U+DoJWY03d178bTU8krU1q9RM40iP7u5kigwH6mp9jKT/qhFvEIQZboH4Dcwh+ YZjIdX40oql74JGHmXc4oL/AM4tdG08= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712295322; a=rsa-sha256; cv=none; b=hUZVu2DcoWtasVpjBBY5jZ3thsnAZ2REmRP3x1Eiv4Regb+UTqTFlbjPeE3mfXupW3jnSh VyUJ4j2/jGfDu7ZvhkYK1pAmW4rSCPxHIR0bWE6KVNh9yAC8gycDYwwy5o3XnOM2HAwXzz RiUSiToZ8aoeiUg+Z7YyzZA6qWXZeWk= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=3ALc5Yqo; spf=pass (imf30.hostedemail.com: domain of 3mo0PZgoKCCsfVZYfHOTLKNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3mo0PZgoKCCsfVZYfHOTLKNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc693399655so3209076276.1 for ; Thu, 04 Apr 2024 22:35:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712295322; x=1712900122; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=lZdonMx397+2pSb+glDTuU5D6tQtRdHssQDj6gK5t2I=; b=3ALc5Yqo9ay8mraaThUG8L8/AfcmTwmUugmmfu2pQOB7FQvivfiqrsPBbfhtPGhIXP anWx/iit2ZN7B7hHJvKmR2R9fBGMlaQbHzMiorPrm6gdgKBmBTaGwZunOHrak7mIZcRH /e+/j8uy1DVF57lZIhxrSNpzkTTuPJ+qeIZ6e0sA8b5U4r1RT//5S+5YcuwptabKy0ti V0UjyBEEaXvAv+aP3BxEGIKLG+9vIbGMeG4JZ3w4Ybmh45bCBKWMopPRxeiZN/puc2Ny cuJK3BciILTTj6D1Mrs91U0l3GxwxXGcgoTfqogbzGE42bvle9TiEaq88aWa2EQUir4V FZIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712295322; x=1712900122; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lZdonMx397+2pSb+glDTuU5D6tQtRdHssQDj6gK5t2I=; b=Qu/MRbE+q1cpGw6WQNPAiAKe9e+hwaG43aA8ZydZwnoo4I8Fr1FL3XlAcNDsji8LNn OY6KpmWbLTyMokcjwxiExQVVx+yU211HUrTkuvIncXtHWnqm017aug6wXm70eV4Runwc Vjfq/fFO054utAXgxtzTWJFUuw16tvcDcWQrv+ORBn3IqYfWKxyp8trzLzFSfpcr5wi0 fzz3X6/zRYiNAdzE3A/bfPdBcNSQxe2PoDUk86QatUulHa1KBL/l/FaDUJaCP3OuyzIr ScmiV1Hm7pgEY21fu7ICvPoodsc6bDMja96f8mvrQNt9nSDcVGIRXmYwUj7m8E5t+0ro eo2g== X-Forwarded-Encrypted: i=1; AJvYcCVLbiiIXSIZXVVXx1pjGs/9XxLFJC+LbgjpDyb509/cB1vH5erF5h7npweTivUIUPsOAd6HhIeUFRJl1WVDIQ4akIQ= X-Gm-Message-State: AOJu0Ywni3MdoSG9mdsN1Nbew+i0v6Le1gAxUEdwFvKolrzj9ehVmYLI iNumEAr6z+YsJpSY9+s9D4qCLHZ/scoNB/vt9oIgBpzmX73aaD93383j9FNC9X+4kWSwU27xOwo Zco95xPap7agqxyD9dQ== X-Google-Smtp-Source: AGHT+IETG5LR7hNPprfABruUGpnm2Pwpk94U38LlqopJDrjx8AYajOaTbPkYn8vPcJdFb7ROfhozscrxJuJ96B7L X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:1882:b0:dc6:fec4:1c26 with SMTP id cj2-20020a056902188200b00dc6fec41c26mr100165ybb.1.1712295322064; Thu, 04 Apr 2024 22:35:22 -0700 (PDT) Date: Fri, 5 Apr 2024 05:35:10 +0000 In-Reply-To: <20240405053510.1948982-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20240405053510.1948982-1-yosryahmed@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240405053510.1948982-6-yosryahmed@google.com> Subject: [PATCH v2 5/5] mm: zswap: remove same_filled module params From: Yosry Ahmed To: Andrew Morton Cc: Johannes Weiner , Nhat Pham , Chengming Zhou , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed X-Rspamd-Queue-Id: D55BF80007 X-Rspam-User: X-Stat-Signature: ih795cj4wxxfumbyodjkdw6jnxmc19jq X-Rspamd-Server: rspam03 X-HE-Tag: 1712295322-935568 X-HE-Meta: U2FsdGVkX1/M1DEuO5LAqneXOq0zNvnHIdtBeKhT4Fq5u14l/rtLYvBl4jKEZ1DK8U/iQBteCiDJJsVR8kmwwYFIU4NUALoeGxhp5+F2XUbo3aSpAIoCh/EXXVYnpqQGHLBoR7661omZPWin09TcI09rbOzhCAryMbineXdgYVdR+DZrDN0AsRWf14GOjK1J12VWaPasBLji4GBheEx06JL/1TBqF+ZYpllspYVO6juAkvk0v/ldcXHkBhzXPNlM0fTBVWpIA73PZVETNyliSkMRKJyxkTAqIlNB60+XWewkWfhNP+KAn40qKvF66g/oSDRObY9vXTf4IHPUd3tX4fYJZgwQGTOtlLDFZU+jNmKq8jsiCOlv5R/G2mAwzHMm6NvkKDt1K/xt+dloV4FsaO98wDdAiA51DDD/KYoE1qC7yDs6di+czAVJjCcw7eHdo10hJNu9hcXC3lW3nKeNLO3F6zptSMu8ABWp0anqfJVipFeZtPCk6lhYsDPupJPM+HenF5DmoPANtrr6h26y1ZSufo0C+qtkFxQKSEZDhTGuX9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PNXAmCXq2w3ghJup85icYxgix7XSxqd0o4YaysO/4YF435n5j3dgp5UT9s4Yl7rsfu6Fi5TZDCIKGa/HTFjCvac53fsn+6cxd655dwQzEOSjwKKaJptvsE78nV7JTnzzrC5hTvROLY0Fm5Ko6STOeyyLCCK6wp7p89VONEfEANa2B 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: These knobs offer more fine-grained control to userspace than needed and directly expose/influence kernel implementation; remove them. For disabling same_filled handling, there is no logical reason to refuse storing same-filled pages more efficiently and opt for compression. Scanning pages for patterns may be an argument, but the page contents will be read into the CPU cache anyway during compression. Also, removing the same_filled handling code does not move the needle significantly in terms of performance anyway [1]. For disabling non_same_filled handling, it was added when the compressed pages in zswap were not being properly charged to memcgs, as workloads could escape the accounting with compression [2]. This is no longer the case after commit f4840ccfca25 ("zswap: memcg accounting"), and using zswap without compression does not make much sense. [1]https://lore.kernel.org/lkml/CAJD7tkaySFP2hBQw4pnZHJJwe3bMdjJ1t9VC2VJd=khn1_TXvA@mail.gmail.com/ [2]https://lore.kernel.org/lkml/19d5cdee-2868-41bd-83d5-6da75d72e940@maciej.szmigiero.name/ Signed-off-by: Yosry Ahmed Acked-by: Johannes Weiner Reviewed-by: Nhat Pham Reviewed-by: Chengming Zhou --- mm/zswap.c | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 13869d18c13bd..b738435215218 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -140,19 +140,6 @@ static const struct kernel_param_ops zswap_accept_thr_param_ops = { module_param_cb(accept_threshold_percent, &zswap_accept_thr_param_ops, &zswap_accept_thr_percent, 0644); -/* - * Enable/disable handling same-value filled pages (enabled by default). - * If disabled every page is considered non-same-value filled. - */ -static bool zswap_same_filled_pages_enabled = true; -module_param_named(same_filled_pages_enabled, zswap_same_filled_pages_enabled, - bool, 0644); - -/* Enable/disable handling non-same-value filled pages (enabled by default) */ -static bool zswap_non_same_filled_pages_enabled = true; -module_param_named(non_same_filled_pages_enabled, zswap_non_same_filled_pages_enabled, - bool, 0644); - /* Number of zpools in zswap_pool (empirically determined for scalability) */ #define ZSWAP_NR_ZPOOLS 32 @@ -1421,9 +1408,6 @@ static bool zswap_is_folio_same_filled(struct folio *folio, unsigned long *value unsigned int pos, last_pos = PAGE_SIZE / sizeof(*page) - 1; bool ret = false; - if (!zswap_same_filled_pages_enabled) - return false; - page = kmap_local_folio(folio, 0); val = page[0]; @@ -1512,9 +1496,6 @@ bool zswap_store(struct folio *folio) goto store_entry; } - if (!zswap_non_same_filled_pages_enabled) - goto freepage; - /* if entry is successfully added, it keeps the reference */ entry->pool = zswap_pool_current_get(); if (!entry->pool)