From patchwork Sat Apr 13 02:24:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13628595 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 4CF24C04FF6 for ; Sat, 13 Apr 2024 02:24:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AFD3F6B0089; Fri, 12 Apr 2024 22:24:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A86C96B008A; Fri, 12 Apr 2024 22:24:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 94EA56B008C; Fri, 12 Apr 2024 22:24:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 79ACC6B0089 for ; Fri, 12 Apr 2024 22:24:14 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 3056DA073D for ; Sat, 13 Apr 2024 02:24:14 +0000 (UTC) X-FDA: 82002914028.02.737AB43 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf29.hostedemail.com (Postfix) with ESMTP id 6A7D2120003 for ; Sat, 13 Apr 2024 02:24:12 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=THjePLAQ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of 3y-wZZgoKCEQ4uyx4gnskjmuumrk.iusrot03-ssq1giq.uxm@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3y-wZZgoKCEQ4uyx4gnskjmuumrk.iusrot03-ssq1giq.uxm@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712975052; 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=hOPR1bddD//aUuRH48FEXSlgeu+YRgqWmevGjhR2ITY=; b=OQejSWe8F0+KZQ37Ap64E/QkPvPa1RmLibboBG7YqvVinr6AISCcvX7m2Y4MPKZ55IHluO QItmHoO4MX5lZx6fj3mNpmvU0OInQkkN17jsIDiACEk2MznhAvBVI8QMqsVJm75lgJ+WOZ xT3GZ3lN8KJJ+Mnm5UIDzyuiLerhZ2k= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=THjePLAQ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of 3y-wZZgoKCEQ4uyx4gnskjmuumrk.iusrot03-ssq1giq.uxm@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3y-wZZgoKCEQ4uyx4gnskjmuumrk.iusrot03-ssq1giq.uxm@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712975052; a=rsa-sha256; cv=none; b=Ao3AwDnv7vQFT5oaWo/GCjCs0VrRlO8h0V3PIwbCuKoYEw5v9edVccN8iyDyOr0cEiGftS nqnEKzeRIYqjAPsMvUiuiQP+xWOeEsMVBHsir6tkrVK1Vh8K7JNOqfrfZrJ+VujO0z2j/X FkNYPwbGuumdFP3dzQtio56wdWQVLKQ= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-618596c23b4so25603607b3.0 for ; Fri, 12 Apr 2024 19:24:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712975051; x=1713579851; 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=hOPR1bddD//aUuRH48FEXSlgeu+YRgqWmevGjhR2ITY=; b=THjePLAQFsPQXveGHg8Vj5cvhtwki0DHELTLf6kjbhnZbDMqGb4VoUtWECVoePo5RF M4PeTe/bmyTsNNCOdyREMMpvFd8V2DK7/kdZIsxq5in5PPiWks608wtKNE8v/P2uVojR WHPFOSMe3VOZkyZXmpN2OELJQ1yM9LAs4bqKEdMVNmizWv0y3Q9OcyuyXOHtp1wsg8uY AYNY8bZzTxZZja+847HVf3baCoQ2hr0+K+nsOmBa7Q8lKd36o/4AWk0OP+kHPrJPx3ff 1CU7v1F+v9eQC0j/tfxyzoc206KFKh0aOwWHBcSjn14iiOy/3lwkSUxbn3l5/isLplCF fQsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712975051; x=1713579851; 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=hOPR1bddD//aUuRH48FEXSlgeu+YRgqWmevGjhR2ITY=; b=pe5/jtiVYshufZUOPoRTTEe1qwe8OxAToBbL+dozVNPcjImZzrl/DG9AB/C27Gt5xX 2wte7Xm9Hr+dqOkMLEfapWkRYpCjYdNUF+ydXixk3zz5bcDgZSXRF0mJtEQw3vPJcwBV 17XCEXG+E82yyve1XsThEAquGeOo4rEuh7ebPUeOPQzGJZdnJFYZTV4Q0n00U09PGCJE 984s0/EOqBWg9QIUCY5dtOFtSVfZVSr6HrpXiIxjLiQt0NAAps2Y459oOSe6Dul91e9G 7FXj2C3tt9m85Fg4bwGJVENHiHngUmxhzhaqR5cLokye2CZlQaWM/zuHWFp7FwHkRrLG ZcJw== X-Forwarded-Encrypted: i=1; AJvYcCXQHije6LPEZPD0F4sP9qhtUdADE2jbOg4ZNgJcSzQI0uZH6mlgooJ+JOiDCkmvZEp+Jo4V1xdw4/6CL/5ycowjlW0= X-Gm-Message-State: AOJu0YwQFxfxdM3fllhRze+TG0YXDIyNBv3Ek6cZeulhdUm2ZGcLpmi6 2QX7QM+HEiYErkuVDc/jIS10PSuAVLaUutj7sjmJepRqZafI6q2eQ45Ylj79TxWDQUu1+iP89Wc eHu1xT2VxkcyqmWlLbQ== X-Google-Smtp-Source: AGHT+IEIyih7J9L34SbhPW1Fs19b+bJp1g0bk94AkYr3vPB7zcxk8Z47Mpof1dxsaJMt8h1S+jqO5WIy+IoUE+4+ X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:690c:dc3:b0:610:f5e6:375a with SMTP id db3-20020a05690c0dc300b00610f5e6375amr996613ywb.9.1712975051525; Fri, 12 Apr 2024 19:24:11 -0700 (PDT) Date: Sat, 13 Apr 2024 02:24:04 +0000 In-Reply-To: <20240413022407.785696-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20240413022407.785696-1-yosryahmed@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240413022407.785696-2-yosryahmed@google.com> Subject: [PATCH v3 1/4] 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-Rspam-User: X-Stat-Signature: k6s47pxtukw1se387e5pjpxb1mzxcyhz X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 6A7D2120003 X-HE-Tag: 1712975052-995170 X-HE-Meta: U2FsdGVkX1+aBgduqZx+e+jLAVzbiCkkzhwT/SurvZ+CwdS8x/H7eyyt8xcwj1LpqVtgWHNOaipfZt130J52gjnfUUnaUV6BbcWs9hK4yVs+paPXjezen5V7tb8mG3JRVx4dsQoerpHZDRgn6yr8zS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SDb8aUmhjp/zQc5J0kUCK6HxCJRtxPazgjFfa3+oOYEDF4d/8Xu/Nekc1FrJhVsc68tMHuhrHbICGAsMK3kYmvEjhPSDVL2SB9tFHxVePN4gaAJvkwwqt1EedReewkdOdN29nbIuh1W2oMGe14U/2uUbf/m0jIH2u3hHQ/uYpc/dgzuEd2SpFA6mlYy7AOSDH8NvCr9qy0mJ8F0DEoWEs9vw4bwEE+fKqHVjXlAoh0vB8IXWHe7ELYgnTNhOkJ0bqpXTkPR/4yQF/ixAOQJ3bNwf1lFYXRcgBAVXFGCFJCyPUMRiwOHx4XXbOhk1DQ8mT3Ne3ibRTaXQ4tEU94EaZM/TBkg3lLkH2lI1cmuKWerSAarHFKwmmp734fqYy9evpjRhfFgV+8K+Tvu2VmWvuJZ2Mm3ink5dc+v8HG0itaEX476SPe6CXrwEXH2w1Lnf/UOeQV3PkZYhwKYDZGJh9L30qSzTLR9cnvp2C2lySiaeynYvuZRrvc9EBNftw4QlNMvaK6EFsUzO05S8jsHzQ1Wc9uTR4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.010529, 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 741957f36f38b..77b6bb2099763 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 Sat Apr 13 02:24:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13628596 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 3A256C4345F for ; Sat, 13 Apr 2024 02:24:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 50D486B008C; Fri, 12 Apr 2024 22:24:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 445A66B0092; Fri, 12 Apr 2024 22:24:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E92C6B0093; Fri, 12 Apr 2024 22:24:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 0A5306B008C for ; Fri, 12 Apr 2024 22:24:16 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C4BBD120760 for ; Sat, 13 Apr 2024 02:24:15 +0000 (UTC) X-FDA: 82002914070.30.CB8FA97 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf17.hostedemail.com (Postfix) with ESMTP id 08AC34000F for ; Sat, 13 Apr 2024 02:24:13 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=tttt37ak; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf17.hostedemail.com: domain of 3zewZZgoKCEY6w0z6ipumlowwotm.kwutqv25-uus3iks.wzo@flex--yosryahmed.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3zewZZgoKCEY6w0z6ipumlowwotm.kwutqv25-uus3iks.wzo@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712975054; 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=pFcpj0TvebZcgya6byXyrm5KOadn+Q+ON/Bz5Cqkl5I=; b=QKBHE5z8RmN4s7SRdZcxuIXx7VeLEHHuV+APM4Sv5idqxReQ0k8PKcHeEGDXphoviRMeED BWxzRZaXosMiuqHsroMvhofKvnQGqS5eXp3N/Iw/XDLpd8rURZb7PUgX3GhaGLxmX09fgJ 8ESUHKMNOkBI+YlflUeSXFlMJRKyA7Y= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=tttt37ak; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf17.hostedemail.com: domain of 3zewZZgoKCEY6w0z6ipumlowwotm.kwutqv25-uus3iks.wzo@flex--yosryahmed.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3zewZZgoKCEY6w0z6ipumlowwotm.kwutqv25-uus3iks.wzo@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712975054; a=rsa-sha256; cv=none; b=NCdu2nmuInoJt41Ua2em7XyF4REqiSQt15AAej2ktqdYAhOTba3HyqC8ypC9Z1CLExezQl QT49DXbtryzk0xdR3S/Q5AREmF9ejtj2SMXqgw9FW+nTSA5kbYqyM1dxcb6c4slzgVqGew wT+qUiBJT44hK0ujD8pYSBG17F8AGk8= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60a2386e932so30661987b3.1 for ; Fri, 12 Apr 2024 19:24:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712975053; x=1713579853; 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=pFcpj0TvebZcgya6byXyrm5KOadn+Q+ON/Bz5Cqkl5I=; b=tttt37ak0nCpBt78G06Pe5Ji0RkH/a+4HPBs94GhA88jCh9NlEwKtHAyuRxHWUCnYV KEuX16lN0kyYW7GdOnR11rWd9pWAAsJUwaFyhZUBr5VfLjuR1QrwysCJtf5dqXfImCH/ 8eimo3jLf6LIDYgNSnuV5sePy1R9swLbPraLCOJoc4ynTKJCBtupWdtQrHdj6p73fUlr gm/aG6OTKX77ro/4qLF4F12CGMBXSegMUY4wzrxif0ZOl7RWISJbOrTG9qvyKsCJBLUx og4iuv/Wwe2qNTm4Xd1NWZA6avCV1DiuJse9kl00py/yQwEjtj79slxpp28pbkBIN+F6 bC4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712975053; x=1713579853; 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=pFcpj0TvebZcgya6byXyrm5KOadn+Q+ON/Bz5Cqkl5I=; b=ph2j2o5ASVQBZociwfNy+ap+DX/krmuIqO1nVNk8rT2rO68s6c/7Jtwq0wZ73fj/Gw mi/mgWJ7/63b0Xl4et+5COy8wtpKm54rSGWtOw0zPZuMg0lWUMYTGSQBimfXkN0yumPS uC7aYnWqCko9IqN0fLYOIM+s0nhq+q4070tYYAZ8uL3Anlabk/OtFoKzWocQ0X/kCGiO Y1qUhbXxxm+kiYC1OjhNCPZUbk9Vvvv5vVWjvXNq7j27/QQJ2czHnT3san5Ott3+i7AI vKhycCYtk8Uhs9GPCF726SBYq3PiVkQS9YTQQ4y4nQ/VdBzfhxYF8xdH86fufTvCTBf8 QLeQ== X-Forwarded-Encrypted: i=1; AJvYcCVUKb/sbEKIHdVUaV04Z0Um+9CsWHthnovjvh7oxhm2J/X8cVXB3zw2zmhX4ZZXWE4vwlVJSOTyXtzAPZG+EtosAFw= X-Gm-Message-State: AOJu0Yw8kiUoWlrjk5hE88FdG2/jF9vFUIY+vT0yN80Y+d+Ef6jmdsc1 FLDuKl2dmf9xYsUR9WSCfvt1WuP2EXfvCbGDZXa2yPSHMiEkJM1g2fhthldi+jU7nvDI0eu6IRd y9qGFMBCcTnenGgMO7w== X-Google-Smtp-Source: AGHT+IHAlbeOydfvBUQ+AYR1qIuBuBzl/BOKahweaVpfLg8kz58GaVMgBySWi8xxEMGZJABW5nfoPZGjO8NmCCMB X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a0d:e209:0:b0:618:80c0:1a2e with SMTP id l9-20020a0de209000000b0061880c01a2emr834009ywe.6.1712975053165; Fri, 12 Apr 2024 19:24:13 -0700 (PDT) Date: Sat, 13 Apr 2024 02:24:05 +0000 In-Reply-To: <20240413022407.785696-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20240413022407.785696-1-yosryahmed@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240413022407.785696-3-yosryahmed@google.com> Subject: [PATCH v3 2/4] 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: rspam09 X-Rspamd-Queue-Id: 08AC34000F X-Stat-Signature: eqksuwfjg13wxeugpu1p7mtxs9w1cw5i X-Rspam-User: X-HE-Tag: 1712975053-414122 X-HE-Meta: U2FsdGVkX1+nc5QfX2z1Zaro4Z6iVQ5Mc6qxQheSDY+0ER2zNKi+ERLVyUjol05/w/S/8HJEoiIpbmBwm0wxNd5Ub4ldivhp54B7ZaTXMQYILlxuhrMh4DcypwHYLEzRkBiWyt3/RkRTytgYJmoY4rhfIaQQAxChLAJuEhyDeNKEV9n4qD+JPgrMSn/TTj8rX8PfAM2OqMloj5QJ6rsitKkroe97T7olQY5bSLrKddTatX5kMXbRUeSMIFBG+bobt3qRt6muKYvADwkcf0atjm39/jpav2B0oObKrSeiwANeC69KZV9LQvA+PP8HGRraJBaJYYpcifiYAwvCn4DTVLel3BpaBlPcdTPIGrnn77w7zWp/mfvV0+sFkDArVrO6QXr9dM/EK+JmddM9zPHhT5KyjYJBEj07C6V/7lfpElImbHZWrfYcBxjQEvuMMbvkG0gC5obD5XtVoD45KmKVcThXTruzbTWspW+eSa1GAxWbrFXZ/tN7oATStULdb0k50BIToyFJoCwSzI3JWVKdmA+1XwDF4ohhteqwACbudbU5UB6tMgk6M77drLmj1VxwDQurWiyIqoJMZY2HBAzgmSsaLKIJu983ruH9IUHgcH8bR/I3fP18kHuK0WzhXcWznAMmGVsMCl3KHgVDyf7T6LOorgq8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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 --- mm/zswap.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 77b6bb2099763..7cddbca3ac62c 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -517,6 +517,21 @@ unsigned long zswap_total_pages(void) return total; } +static bool zswap_check_limits(void) +{ + unsigned long cur_pages = zswap_total_pages(); + unsigned long max_pages = zswap_max_pages(); + + if (cur_pages >= max_pages) { + zswap_pool_limit_hit++; + zswap_pool_reached_full = true; + } else if (zswap_pool_reached_full && + cur_pages <= zswap_accept_thr_pages()) { + zswap_pool_reached_full = false; + } + return zswap_pool_reached_full; +} + /********************************* * param callbacks **********************************/ @@ -1399,7 +1414,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)); @@ -1422,22 +1436,8 @@ bool zswap_store(struct folio *folio) mem_cgroup_put(memcg); } - /* Check global limits */ - cur_pages = zswap_total_pages(); - max_pages = zswap_max_pages(); - - if (cur_pages >= max_pages) { - zswap_pool_limit_hit++; - zswap_pool_reached_full = true; + if (zswap_check_limits()) goto reject; - } - - if (zswap_pool_reached_full) { - if (cur_pages > 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 Sat Apr 13 02:24: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: 13628597 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 470EEC4345F for ; Sat, 13 Apr 2024 02:24:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 30EC26B0093; Fri, 12 Apr 2024 22:24:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2BEDC6B0096; Fri, 12 Apr 2024 22:24:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 112486B0095; Fri, 12 Apr 2024 22:24:18 -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 DFE1A6B0092 for ; Fri, 12 Apr 2024 22:24:17 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 79EF51603F8 for ; Sat, 13 Apr 2024 02:24:17 +0000 (UTC) X-FDA: 82002914154.20.265EF3D Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf30.hostedemail.com (Postfix) with ESMTP id BC94B8000D for ; Sat, 13 Apr 2024 02:24:15 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=2S3Ieg1K; spf=pass (imf30.hostedemail.com: domain of 3zuwZZgoKCEc7x107jqvnmpxxpun.lxvurw36-vvt4jlt.x0p@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3zuwZZgoKCEc7x107jqvnmpxxpun.lxvurw36-vvt4jlt.x0p@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=1712975055; 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=hZYUWNTiUhiZC6PVJ2X+TVQi5b4PqWXfNQ2Zo+Rl5yk=; b=u2sGCBs+JGGbUI9FuxulrYOMEFZvXTok12NLFc2BxtYZPz3q8i2NkmZb1K8bd1JYHqkgPd efZaCIExjSKAtqmcRRI/dNsNACYv38dQbbILePpTFjmaaS6QZZ7bCeHmfH6J2FHMjkeDeq URG4TB8GwLWgHlzQmXe7s/XjkmtRHV4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712975055; a=rsa-sha256; cv=none; b=x0IrBBh0zTH1jhCNI9SpaRRdYZYTJEU0TPYCJxv7iNmYhXh1yVa8iZdjsAdwoHorBIRZfN VEBaPDv4DSDGFTu+9Xjv4gRvA0ODrYxThkU8rH4e9iBZTStsfquEDSjkERj6O5nZrasDWo sclJyKPlo1C1JUJitkoFlcjVpfUfR4U= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=2S3Ieg1K; spf=pass (imf30.hostedemail.com: domain of 3zuwZZgoKCEc7x107jqvnmpxxpun.lxvurw36-vvt4jlt.x0p@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3zuwZZgoKCEc7x107jqvnmpxxpun.lxvurw36-vvt4jlt.x0p@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dd933a044baso3039873276.0 for ; Fri, 12 Apr 2024 19:24:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712975055; x=1713579855; 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=hZYUWNTiUhiZC6PVJ2X+TVQi5b4PqWXfNQ2Zo+Rl5yk=; b=2S3Ieg1Kv+GklRX3izDWoACdFfScC3iFPdRirVggxNoE+cG15iSnA2rLMNc0Di3EwA 9ANKk1pnyxyU6YlpZUgRibn53kZqiqefPas26Cj3c38IpLHNHbxZJHeQnkIsJwDGlISg rbV0ltXKNiX6LCWvVlLyxBDCY8uLQ/hvOgT9pjD7h2zdLXhZurJjq6FtiMnh4hWdQH1I pO+v0J1eNNm04xEO21UN0B9lYtiO51xYes580l48ih7nBPc0liarbLs9L4ayiDdwEaRE sJG9osl8Gc/VWf7/yMIa5NYN1Oywo3nY94K8B0hCHXtFi6vgdX2oy3ZuCU8TrA+vo8sQ RJow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712975055; x=1713579855; 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=hZYUWNTiUhiZC6PVJ2X+TVQi5b4PqWXfNQ2Zo+Rl5yk=; b=Vxyc2y/P8YF9VTqKGGy3V7E/HZ/KB6vBrWhSZBBsTcecPxmv8xI7hGUiG+Ma9Y4B5j D9FN/wxzGIFsLO7k3VSf7UYri8GMwY9NveDAkA9mTl3g1sK55rxS1WxLGPukJDWov5tF y4h/w9vPPRhf5aBEbmkXkwTLW2cYqN3UDt4d20Qw9/9++9uWkqFHD6eA0czjuncQMeB5 02OWgTq+5Y9NPZT5rZjDzYLICQ+aGb1HL9RoM8ovOlApT/FSmpHL9oZ/CepYLS1CTlcL 0Y1QNnTUH88+N6O4dcqupfEz80xFSYbfgKejfJAH8f9peKrkni5khcll7q1P3MWB9SWZ BjAw== X-Forwarded-Encrypted: i=1; AJvYcCVjF+CdEzvbUGVDCFQ8ktawtUUVAIKbbo59kxkgmTTPn2s/vFfSZ0nm6zbkpd2d9McwQi7ym1kjboDbqjjNcQUvi5s= X-Gm-Message-State: AOJu0YyA0HXGGUgOTUXeDK4KrrJwtatAe0myAq1VLsTcuylgBzhlwa11 u524xvTe/+FxLkX6zojIrT4bqtqkOvh2hszdqKGs5+X3o1OmKaD41Q65IMB0RBQYvwVg/JGNq6M jG/S1cCSfdamiB5Porw== X-Google-Smtp-Source: AGHT+IGTrx1GnvC7Seu3eWAOb4tBFHfkiqWBD9kd67Bwq3v4nuuqOaFgb15AT9eRdbOLIz4wHqs3/FUeUlx91LlG X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:1243:b0:dbd:ee44:8908 with SMTP id t3-20020a056902124300b00dbdee448908mr1442080ybu.0.1712975054816; Fri, 12 Apr 2024 19:24:14 -0700 (PDT) Date: Sat, 13 Apr 2024 02:24:06 +0000 In-Reply-To: <20240413022407.785696-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20240413022407.785696-1-yosryahmed@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240413022407.785696-4-yosryahmed@google.com> Subject: [PATCH v3 3/4] 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-Stat-Signature: 99669pq7hau8cenatm7y7rwdqhnrkoyo X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: BC94B8000D X-Rspam-User: X-HE-Tag: 1712975055-866064 X-HE-Meta: U2FsdGVkX1+wriET85wiZwWZ8WOUzmZkcrtIcp3qV7D8nNfdSmGbZXzC7MJUxPiMYfeTsATszTcIeLCS3uvVKFgIZBk/6fm35Gli5KT+t+/Ti1iuuzjNySHkEo3fD03G7UXCuM4VbMPWGXo6ci3F8lrJI/pjxb7D4g8x691wkfyTCVHfOySVIaM5d+8bVAQtL/pwVpKHCsk/SDKn9CNpfptrPozq09wrt5hElTgJYM/VvAh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gmjYwvKgudQziBUxrad5PMNhMgZb9XiVzj6fVl87Idy0jJCcjPyIOS9T6eDExHZstPjCux0xBwzTI75wuk3uZ5jiqATwABs8Y2Y9dGS8lJZ+vO9WlvzvwdbVRdT0shPe2rzTv/zjm9slgXvsYGgHLVwRRyXcFMJNOP+NbEpSSl1+nXBS3XNhyCVUUZV2E1QPatl3FIGQbbSeXZZI+SvRF4u7zVCvN5blZGfb3thF5riLw2Xg7+QbQpoSnghgC8EHzgXvhbnpf7sDLu7oxYiTA8QxdJxXGKGSJhhHoODONPcdlWN3KpRrQCJgSEreeaf/Heqpwt9oRu5ALMVNCbPi+cc76TVgQFfu5xkQHp2owAm2lVCsQUGHP2ke8bUfbeKHAUrdQnzVQfVI4sYx8mH/iNUZ8Fw6Y8DhUhAYoq8UL5RGfDv+jImQw0VCK6sAmUIU4fKir6B6fawvRS+5c= 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(). - Add comment headers for same-filled functions and the main API functions (load, store, invalidate, swapon, swapoff). No functional change intended. Signed-off-by: Yosry Ahmed Reviewed-by: Nhat Pham Reviewed-by: Chengming Zhou Acked-by: Johannes Weiner --- mm/zswap.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 7cddbca3ac62c..f1d3204c604bd 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1376,26 +1376,35 @@ static void shrink_worker(struct work_struct *w) } while (zswap_total_pages() > thr); } -static int zswap_is_page_same_filled(void *ptr, unsigned long *value) +/********************************* +* same-filled functions +**********************************/ +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) @@ -1406,6 +1415,9 @@ static void zswap_fill_page(void *ptr, unsigned long value) memset_l(page, value, PAGE_SIZE / sizeof(unsigned long)); } +/********************************* +* main API +**********************************/ bool zswap_store(struct folio *folio) { swp_entry_t swp = folio->swap; @@ -1414,6 +1426,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)); @@ -1446,19 +1459,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) @@ -1481,7 +1486,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 Sat Apr 13 02:24: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: 13628598 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 C0944C4345F for ; Sat, 13 Apr 2024 02:24:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 72E276B0095; Fri, 12 Apr 2024 22:24:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E2166B0096; Fri, 12 Apr 2024 22:24:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5586C6B0098; Fri, 12 Apr 2024 22:24:19 -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 2817D6B0095 for ; Fri, 12 Apr 2024 22:24:19 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id EA4F3A073D for ; Sat, 13 Apr 2024 02:24:18 +0000 (UTC) X-FDA: 82002914196.04.A95CED4 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf03.hostedemail.com (Postfix) with ESMTP id 341B720003 for ; Sat, 13 Apr 2024 02:24:17 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=KM3T+uT+; spf=pass (imf03.hostedemail.com: domain of 30OwZZgoKCEk9z329lsxporzzrwp.nzxwty58-xxv6lnv.z2r@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=30OwZZgoKCEk9z329lsxporzzrwp.nzxwty58-xxv6lnv.z2r@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=1712975057; 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=GGSekAACS+5O/41JM9vPAXBnj4QEps+gftm74rD23xg=; b=MyuPwYRjVCmdAlaevkY9qbTuXVuJbABQ4N73tMJuh6+fREaJ0pMl4I1HOZD1iasK6ksp2M LS/4Bm0G/vBzcIhyjW9SeknvU2V+dfqG7ucoPeI0D7UAiwUFVi6v1MWTrTcw+xj1AD1Fz5 03Az0CvlpbojUBkAB25x3tjRsHodyXM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712975057; a=rsa-sha256; cv=none; b=QhMyAcbI3nqNPfZExBwocBWcBawlXzMAYXCTFimmoClfj0f9I8zmzr1caIhINMkJfLqCYM nGf2iP7GqqalvaBaNDHK2OchufoVBu0wGheckaYJ1wjqBlHiYjtYo7w8M5y0fx35iIpjEj Cfp06CD6bUHm9otzMWm59vXXv3i3Odo= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=KM3T+uT+; spf=pass (imf03.hostedemail.com: domain of 30OwZZgoKCEk9z329lsxporzzrwp.nzxwty58-xxv6lnv.z2r@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=30OwZZgoKCEk9z329lsxporzzrwp.nzxwty58-xxv6lnv.z2r@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-61510f72bb3so26029337b3.0 for ; Fri, 12 Apr 2024 19:24:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712975056; x=1713579856; 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=GGSekAACS+5O/41JM9vPAXBnj4QEps+gftm74rD23xg=; b=KM3T+uT+t+EijGEj0biHJ2t4Bybb0J+sI0GOfPYGr06ZwIo+BjbUkJh7BV3jYPqXoT W8+a2f7WksDHDXtdvui9pDMUGY8/IZNMw7afH+FDErLv5NKd0yvBa4gN3riet4Rc+jdX XXVjGPykg7tu1FKVSjS3WUyaMWznx/YffcfQdOc+NSWdFtjghcHrvb08IKgut0sL0kZ3 8vYddtZElErLbpxsOhOsHJJcPRLM4NhA2Ke+w9a6zel2txSgKKaJzZuvKcd4fhtznU3e ircIcCbgGpPXjfXro2sI6r/dqxi9Kaq+AMPXrm2aXR11kcN7z6hLqgMl5F3pRQy7kp4I +UuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712975056; x=1713579856; 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=GGSekAACS+5O/41JM9vPAXBnj4QEps+gftm74rD23xg=; b=kTbcfi8k350M20vV1sqkRULNSeDkB5vzDI16b+SfFg9hIcEq7pXdylaKaKDXnTfe3f D2kRlXWSoBk/cpUSUalqkr1wr2itIgu5EY6+VjKEtf+TB/aUbqto8V8SZo5SdgDS9abt ly+12llwifcLzpGnwcZM0LjfJrfQic9KPj88poFwwkNDYfwgTZfyIoeGA8JFE+aZB3/f 9R+ZpXnBKCi1lFGrUqOh+8SCQahbAyUExGlF7WzIs55c4hfHS0OtrvegN/rcuON4iRLK Ha60hOaorAlalBY9MzdWEUiK857lDa63Y0c+S80yHGC2QPft4XEfQ9FJ2nr0NzCdJRMe S/pg== X-Forwarded-Encrypted: i=1; AJvYcCVW47mYJqyyxQSrVLrXuYgvw/yb41BS3RLoBYN1zly+sk8LNuyyYToVeFgEUya1wRcgQbijW2DT+cTrojvLH4rzhA8= X-Gm-Message-State: AOJu0Yyi7IwquqWCxZ6HOlrDhifhhJqeo+ZT24U+3To8Z3RTeeASPybL y+4A2lYDXVKQSqr5RR7QyjncjK7GfSqu3z6Uvj1b3BtjUQWD0/ulyADrNPdvRKcp2dEbahFABng 8ZrfT/SkVqQVhBLzvHQ== X-Google-Smtp-Source: AGHT+IFlkK/1syKwe6dvTycUcSxBT93UngoIpgQpJlcuebA8rvVZJNpQ+d8xJDsJnJOws2HVuhkwwg+6UgtMptz/ X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a81:4fcd:0:b0:618:a530:10aa with SMTP id d196-20020a814fcd000000b00618a53010aamr174476ywb.8.1712975056398; Fri, 12 Apr 2024 19:24:16 -0700 (PDT) Date: Sat, 13 Apr 2024 02:24:07 +0000 In-Reply-To: <20240413022407.785696-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20240413022407.785696-1-yosryahmed@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240413022407.785696-5-yosryahmed@google.com> Subject: [PATCH v3 4/4] 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 , "Maciej S. Szmigiero" X-Stat-Signature: sqyjknieu84e4qne44y3ep9w6y8unz93 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 341B720003 X-Rspam-User: X-HE-Tag: 1712975057-441402 X-HE-Meta: U2FsdGVkX1/IjwkoaNW9Zl7FURrFn3ekmo2r+xlGrU5f1b+rpyQ1lnhnKJz1zrBxTaKG389+Ne9tIn65bqdHP7Y/qVd4350DXf+XUURnuS2wsN/3uW9lseqJP3KH8SV7Y6GjR4HYZ+rGBLOoLpcJDgWFbqdUSTZqQWIY1Jp+Vcf+qM+t+RY2JcBTGeA/WY53jwvk6mdV2os/iS9VVke4ILiqAf0nSF5Zksf1uXyL9F/V0BDLg53PaymVu9D/GB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MELPEL++8Zn2qb8y122D+Vx2XWu/OSsbvpwiTMucajM+6Vx3Gs9xOlc4XdBqZBUeEYge+ecNqzzbVMyF1h1c4fD3Isz4tQksM0H0WldIccFSIpeXHXbHumW1zx4yyPksOGRBnc4WpnNPVofwtVyOaiD4q2npuWacqcCaoedWrN4ICd0Ed+fVPWfrIt3TYnxgEdhVZKh3S0o5PEBm9d6GYytRO57SR67sa7d6sVjRl33f5zmhycFO1p8Wa/0an82SIP4ROtQkcZEp74LskRYhOy1iw0Z35iQC93na7NckouCBR/lshS4qun7nAq8NXnX03Zlte0PVGkQI1ZEcetgn8tdE6t4NLw0+BKnh9stzd2Z6u4tRxVdbaOojuEv0ssn56ARV3aqMIU7gshkSRzL+dOL6EaupuiH0GrXO3D7pMNaWGdyWCfm/F6F0J5J1Tbmu4RxXcTpbSqG46gceN2zcLNzmyWNnIcg+Bz1z6d6QA3Me+HWD5TXJTui6ajdjkHyc= 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/ Cc: "Maciej S. Szmigiero" Signed-off-by: Yosry Ahmed Acked-by: Johannes Weiner Reviewed-by: Nhat Pham Reviewed-by: Chengming Zhou Signed-off-by: Yosry Ahmed --- mm/zswap.c | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index f1d3204c604bd..243a7c202c6c7 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -123,19 +123,6 @@ static unsigned int zswap_accept_thr_percent = 90; /* of max pool size */ module_param_named(accept_threshold_percent, zswap_accept_thr_percent, uint, 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 @@ -1386,9 +1373,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]; @@ -1466,9 +1450,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)