From patchwork Fri Apr 5 01:35:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13618348 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 8329ECD1292 for ; Fri, 5 Apr 2024 01:35:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DEABE6B00AF; Thu, 4 Apr 2024 21:35:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D81626B00B1; Thu, 4 Apr 2024 21:35:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BEC1A6B00B0; Thu, 4 Apr 2024 21:35:55 -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 9E4956B00AD for ; Thu, 4 Apr 2024 21:35:55 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2FF1340653 for ; Fri, 5 Apr 2024 01:35:55 +0000 (UTC) X-FDA: 81973761870.13.95B7FFB Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf07.hostedemail.com (Postfix) with ESMTP id 6BD0F40006 for ; Fri, 5 Apr 2024 01:35:52 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=R1tdHIiZ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of 3d1UPZgoKCJYOEIHO07C436EE6B4.2ECB8DKN-CCAL02A.EH6@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3d1UPZgoKCJYOEIHO07C436EE6B4.2ECB8DKN-CCAL02A.EH6@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712280952; 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=jd/4hHdb0b9stwIVLoMZEBN1L4dz0gMNo21N2D01dq8D5xbojDekGm49fGb386Yx918VC7 iL/S00FLvSErs7I5/lOWiTjYRhaCOqXFzavgZ62u4wSvZIK3FuDrmsT+sGTHX82HILh1tg 0w5RJ70IcKn9/n4JY4P6QJx7KP0B0jU= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=R1tdHIiZ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of 3d1UPZgoKCJYOEIHO07C436EE6B4.2ECB8DKN-CCAL02A.EH6@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3d1UPZgoKCJYOEIHO07C436EE6B4.2ECB8DKN-CCAL02A.EH6@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712280952; a=rsa-sha256; cv=none; b=5m9fUadTypbZgbB1/nDPmVP34qPOD16IuNovu8YBLAPs39PIKfvXPN/XVOa4IDjNw8PzWm yAQ6ZlBduFipRoxnDuxgrMqDJMkYcXhOQcYVmJuCVQ6LdjbxSCA9mMamr2wxrMOMy9mk99 AkmP2CKvXhugA+qXhmssTwDKWG8E4Jo= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-60cd041665bso28011287b3.0 for ; Thu, 04 Apr 2024 18:35:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712280951; x=1712885751; 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=R1tdHIiZDM5r5un85hSs9U8oMHN/Zh7H5tzEUmpEg2IMdh8N/SiucDfc2uonWR874c uax5ybYFxXxdMzvPySrIRentNWfxV9NslEVMiRZyFPhPi5vdfxQOJPtNyEA+hR5m0ZRQ XLbuhnag04WmKie3Bb1a/0Ml23FYgnC3z2eaYPN7VTWz6pB4XU1VDWVVXuukcs4Ygj8Z bnwH8ie0Lz57cvO+Kv8Xil6EzGshBicaMdFelUacEJEtFDYzy5yBUB0ndm184XVJkL4O uh5qVbiezv1Pp7/xVG+0v8QVBoyedMYxRR0PD+H8+8fzhYowM3/V1gDoUGwDg4vPfdwt rdhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712280951; x=1712885751; 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=p8BzSEdGr1q7tZfCqIDF/QU/sdTTHe76nwxVrX4jY30lV8jtcn2bw7MBrHydpWZ65B 1W8cv5DRsluIMVMwcHS5nikzQ0Ndgcvwyv9eIl8GaVemM5mOMOtSpVv1anEoenk+p2fZ i8N0FiS46ZzCO0mkl2uxsUvwqF4BwLwPElWCI/hcaVXuPLujwGhGq/5v/6S2bsVR6wos ZyapTYDeR2AOPntbPtZqeS8bb2nUmSSBpjJZOH7nGMsSCPlfMgvJ2rPX8qrZzo6g1PGv u4Vk2/fsRwUq9TdAo3yvQ8SXxPuZjd4iwSd8D8R7Qn9zYg8yXwfN7RCEQdePlvYqHA7T op2Q== X-Forwarded-Encrypted: i=1; AJvYcCWIrRCrJIpj6WQjXQAjnzldGWzldar2wS5bWJfSmvOSALQTKU9JK0LPcQtuDMPd+wPa2CEeE4SSQftC0ScKXomECzg= X-Gm-Message-State: AOJu0Yy8g0hUhu9ahzEZaTRlnf8vs2KjmMi6BdX6Js82j9Rv1mcAcNbA xQkIdUD+11oex3eb/HpM3EkcKhB5cQdovBizskGisU+9XD8cbwuHoMiUEICKmSqV6UEKJrACLQT Xzh6jNywABNTMpN3jEg== X-Google-Smtp-Source: AGHT+IGJTA/i85YTUBVw2cs8xuSEjY+bqpz8Alc8JIdeIpUrh1LGBbhlTI/u/mBkLRKZfoJj4MNZLvSP1tmwvTZh X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:690c:dc4:b0:615:102e:7d3b with SMTP id db4-20020a05690c0dc400b00615102e7d3bmr343711ywb.1.1712280951511; Thu, 04 Apr 2024 18:35:51 -0700 (PDT) Date: Fri, 5 Apr 2024 01:35:43 +0000 In-Reply-To: <20240405013547.1859126-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20240405013547.1859126-1-yosryahmed@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240405013547.1859126-2-yosryahmed@google.com> Subject: [PATCH v1 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: 6BD0F40006 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: jz96p71zkdc38e466x8wspjtn1m9fdnc X-HE-Tag: 1712280952-639919 X-HE-Meta: U2FsdGVkX1/xEquZmKvGsYSiCg+HdmiXFh2JKowF+s8VTcf2Bq4AZckqyPYW8EaqOSBEY+YkeQBi4OsbAE9NkbSdic3Drmher7+tmvzTQqU4NzSA71OSZAJdtHzliXbjnWYcEKNo/0jpCp/yQD8/OrlHrZlLyg/smOCNk6AgM0/C971Ye3oOk7XAc5WiqMFuMJk/1JSqC1n0F8M9Tl/eJ3qWL8PFVel6s78SBcTjuiruvNyMU1kfuHteG1kbsLpLm6f3uuXQT2Zk6hh50Xhobi09K3EwaE+f48vGY8eNbEgO0X7r2xD8vhu14BiJ5BOMDIIVKWnSItv5KRj37HKPQIvsQTVHgXMK04/BgTyeiC746H+1MJFHbXEpHN/LwfCImqNuXMVrGuquTFdYwOKWRYc66puWadpvwT6Aw4Ga3XR4VfFOeci/xVIXKPvTVEXoYAoPEqE9a9ty6ud03tCrp/rvzLgBKWMzatz2Q3Pz/aBvYBYPCcoBuC2/PecybsjI6F8/BpZS7m8XBGEqJjy+AEHJWKnemP+doX+g5P3+ZMFNzyiBTyhEoXWbkTVBYLPwfDoQrnmre8peEJN5Arn6BI1nAnkqmhl9rhYjoKPGLtCAvnFtp76B3Tka8Xr4UKyTV6bKXJCUjTCZCgqEC5Slh667UxqruVxMipof0RwR9m6nNPMEy/Dqe2Sn5fnWHdLQNJhqpabOpvSrMJGdU3fkK/xK0A9SkL51VbCS+wMEEQBCeptSxA+jn6NsjGIbXf6K87K/Yoos4SRzcVzCq5HrncCw/OqLDJo01YZS8nkM3JNJ/OKKsFnqA5S7SNepOBW/hqQTW4gG8nvhHGPjl3gGZCaV8AQQb64ICgMguIDmm1bfgDazG0W4lFo+zZTpEl0wk7038aMEZWhImh5Ivd6pFeIQnkK8Fu3yNWj3uD0K+/igH/0VXK6q/OAnkp27fg3467PRYpKbojwk4PS4B+Z TufiBBn7 B5/y+/KIuv//X4e3eJastJZOTEKjvnZ6bwFe2gFwsTSerMi0onqD+UDaRa5OUsdm0JGs8YyMDcI/yxrlVfhqkf05uMN+vUSsh78BTl8l+lHp2sKK8PLXy14knuZkdFrjTcTqNiJDyJu3bFFwiW/7B+1LlHfa6o+mC6dL7+O7YnGAWwdb5xLM51BehOTHaOI8KDEMj1wAgQAiM9wxXhXmLefr0ZtuVRRPMSk/DR/AvLA/HGUyhsHksgiDI61g/JGzBA3Q4KfECsstFfDXYk4HS7AZfSveq+FTQ+Wdjvb/dqjF11ujWoKNQWuXnrEFQuXFi0aK72xuVzovFkGz/dh5ark/yuexBKoQrECVmSQFKjxio5LuYMtNGvuuZN/C+yMJ5KO0/2Ut6HfNr8a9IYENLpR2ycaoRUvyYeZLnAF+kgkSRGjJTMIbrfcIZrN4JcSLclo1hsy1NDnoqRI2hEkVs3KLMMsfoj2jSQ3Pai+fu5QjTPaxG1PrhM2tSt1aXoZy/iQlvpuc1CwFb0aL4UbHltNiGoQz8TXEIGG+/7xVa0SVApWQta6j93SGHZ8MVuzYrddM03yLlRDpueMc3dcPfr1ehAzbs9qM+YaMoNCznlOJndiJKW/OgIXnD4+asF4rPG331cafasJYkebXWtIMQf7OodnaLEJgQ9EvVsj8ROgaZJQqmcxyNVozMmridDidBYVFKCSdVGYysRkAOK9vQq/nlcZ9PcjpADAOhltS0qmAXJDgMqOYpYtx/fzToRqFQc/z7g5tU0glvuzs= 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 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 01:35:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13618349 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 63BBDCD1284 for ; Fri, 5 Apr 2024 01:35:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 33D386B00AD; Thu, 4 Apr 2024 21:35:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2EF0C6B00B0; Thu, 4 Apr 2024 21:35:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0CEAE6B00B2; Thu, 4 Apr 2024 21:35:56 -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 D2B126B00AD for ; Thu, 4 Apr 2024 21:35:55 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8CD711202EF for ; Fri, 5 Apr 2024 01:35:55 +0000 (UTC) X-FDA: 81973761870.25.108998D Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf05.hostedemail.com (Postfix) with ESMTP id EA3EB10000D for ; Fri, 5 Apr 2024 01:35:53 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=4C14Ouxz; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf05.hostedemail.com: domain of 3eVUPZgoKCJgQGKJQ29E658GG8D6.4GEDAFMP-EECN24C.GJ8@flex--yosryahmed.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3eVUPZgoKCJgQGKJQ29E658GG8D6.4GEDAFMP-EECN24C.GJ8@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712280953; 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=l7c0YAXHYAARa4t+azzKsBRh7TpDkWZPSyUcI/Ckh5E=; b=7m6HUrWXe788ymXBiTmSNDDEFqQsflo8ZMBFYu/neQC9C7bxi6xlijselWMBkxkTwDokYg P+mXPV3HZx54uhqK/Dwr0aGLgKAj3VI8gKIWL+D6RNLR+NoHfDlc/MVdtRBrX/7gHUVA7G PZ1bAcg416hChPoqNUAFVdR/Y3JvhVE= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=4C14Ouxz; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf05.hostedemail.com: domain of 3eVUPZgoKCJgQGKJQ29E658GG8D6.4GEDAFMP-EECN24C.GJ8@flex--yosryahmed.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3eVUPZgoKCJgQGKJQ29E658GG8D6.4GEDAFMP-EECN24C.GJ8@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712280954; a=rsa-sha256; cv=none; b=pJowheln1+aFp1JOyHcTChnwcN827cPssL9pDbWCMgffG1j0mFLpBOat/0weh44W1/Q9Ml LFCGk9DOwPHiAjfFagCstTHCMJGDSKEmhGK2CnPlT+HiCcAexz2Uu+nu4J2vLnvfqatVpa qoZiupn2cwXUHQs7EaPxWHKJsLHaFyA= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-617bd0cf61fso19983517b3.3 for ; Thu, 04 Apr 2024 18:35:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712280953; x=1712885753; 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=l7c0YAXHYAARa4t+azzKsBRh7TpDkWZPSyUcI/Ckh5E=; b=4C14Ouxzsl3UC4Pc8d4FyLfA2jCrBFFq1G+Z/XjzTGwQGF08kQsq0DQLLpaLLANX5m TfIDHC5XYJQJ32vT0H1klnbUG8sfPf7Pd2QaiwCyC6PiecDPXjqFozxQpNmKHmlY0REc r0foFxCgRxuEG0YmYcojzX964UNvVJOccwNjdUZK9BOBzmRqywOoCzr5NPq/nEP8d/OZ DtrTX+DepFv96iu5snYGSzwgrOd2siw8R7qT4cdva/00PwYXBS8qK0FRFKR57rO+TcKv 6Iq6zicQMNQseiI6f4G/7OyA1VnEO/grG+TOb7pf5YH7qBzHnAKuodlZitpO9SThcNny Obkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712280953; x=1712885753; 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=l7c0YAXHYAARa4t+azzKsBRh7TpDkWZPSyUcI/Ckh5E=; b=Lb3iVAdi3Wq5DEHCeYTclf36mWsGxh9366yjHsJQ98NajrS5SkRfaEZbpGldIHxmLb zQvxdh+CkFXzE+qeqL61Nhkkug86bdhO0zRqBO+JJeBJaWGTkaNZQkW44EyrdN+unLMA 4HQlRaMH3FNbACMrsiyhDutargqjmUYNzBWnioUQqeWxJsH+l/VEx3aN3L0+VhTEE3GS R63o81DePP2gOHcEJfINB94ydvwOdQ+3BmloUTNWsTl7QPClChXrgsjPQ8aiaoM6xO3w +0WrmBiAUCiXvlnZfVM1bqdU9A9hrlDjRbUQvqPFJvpNZFqn6sq7yIgm2cC9WAlieXEj iPtg== X-Forwarded-Encrypted: i=1; AJvYcCWGDc6gtt0SBMLuTOpQ7SUbSMtUacWryE69AIzABjkzP+xgUPP5z747c8Md1qu7b7jADcXVZJXcoT4zcDY9POtAoZM= X-Gm-Message-State: AOJu0YzZPxykZOhKB7ZJ1jLyhb9dmzt1GV+OTZ2ZF51hNwy1r655zo25 OmWgs8bYYeiej6GhYQJBx20KATm5jT6GiS5E9HBMqDDKFZvypySwA94FQ33fDfQ9Rc89nAPg99U BGEOZrQH0J/nhA9kitQ== X-Google-Smtp-Source: AGHT+IGnr9sjDIzkHfWFA3r7NPAbrRE0n1gPgA8ilwWP/trrO+2CchhEjdvuhVNlYmxNUVKzC30LK0N41cvBJ/wG X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:690c:24f:b0:615:2f17:17ca with SMTP id ba15-20020a05690c024f00b006152f1717camr300974ywb.8.1712280953119; Thu, 04 Apr 2024 18:35:53 -0700 (PDT) Date: Fri, 5 Apr 2024 01:35:44 +0000 In-Reply-To: <20240405013547.1859126-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20240405013547.1859126-1-yosryahmed@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240405013547.1859126-3-yosryahmed@google.com> Subject: [PATCH v1 2/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-Queue-Id: EA3EB10000D X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: rbdwen6j8n1jtzozfdrbk3j7sxao17oe X-HE-Tag: 1712280953-83040 X-HE-Meta: U2FsdGVkX1/1MOsJqvSe+cvJlWl6qBc0jQgh+DVhAbSd1VwvGNl0JinCAQeOZDfe3x8lR59PQ8moKXgTfvx/ElecnJ9NLO4kHZNL0+EJbX27K0oRWWShBT23FJTLPRaFqyybwErDfo1Vu8fi3M2WuWd2cwIRz7vCAipcbwTjdvkqelQNPeZJIB8QYz2PCBjcsVsIjCRSMk7kF1sjpabU0SMJG9IGz7IF5CD6GmFIF5A2Pihr9ZouREO12IG8+NpDyeqJheajdXBJoGmCHUeL6qrK8Nk9AuP+vLjCd9sN2QSP9lNoOTYf5C7XLnyVIYZbOOwQvmNi0tBj4U8l3CwOGuTj9Vt3ZuHHo0ymQaogLGHdP882ZViunzH0mkDmA7qph2qWiUo7EaQJIcuAE1A2sTWLFPx7sv3Tlqer/QXF9Ymnxlt6bKQgTNVM8jYvhtOvIvivHlENb9CrZe52f0ddcICYckHbi3XpBjBMMpqHlj3CuftP2QWVbuKUUjm8UL268lbUvh9GQTlDfF8IWGAST0ewa2mz6bwwMXchaFgTcHoVAJU1XJC0H1/vvilMHWj1ViN7Nvo5EM5x/oy0MKkVOYmF5glI114f1PhjXS5DK09LabVxrg72aT6ZwL5NSKXUTHsxqzMf13mi8DMAmIvHLYfCmYJsgrfKuXgatuIVnZNcew+JisYx/oUNP1uDQfuYf88WUMIJPHkoEqz8CfQlk1rbR9i8HeFGDjKU4ol2aAeTBm7wwDZ+STcmDehn3HRoUnCGWbA9Svzn8SfSf4I7/vB5djYAHAvxmTbEJtBFrTjqmrOGcXRNA7HM1yrg8z1oTSLB+h8iHzJhWOm350+jC6PMIYQWzMrH/M5uYWVUfI7pEv0zCAqHmCaso2aISdcPhIAl2OeuGUdvRx3mQ0nV2EAm7ZZ+E3+eYVvvaKhsrQ2Z5ByUX+oxboep3TM3rJHeJCwy6b7fOxgPPZCiMy/ iq5WrcUT fek0dxKF0Ypm8gvOhLMBlp+fclmPys6gHaFvykma8ZeJa8uszn3Y1SwEOiThCHQEeKVTUa4TVdngAI6gCSEIfp11m2aYQcGFzuhu2fDpIca04UJNeHjbYJUaAtWq8KCHD9nAQFDpt9NxzE5dbU/WmDD1UCsq9QDikcu5WwB1kFjnMemIRAcwJH6lMKfS+xhgkNQJVoL8shgclLLf4KMTHcDNNgQ02LruOD40xxHkTtnqE/ZqGFKanZSOKg4dyZO7KTPSUD8issr5Vl9MFDjTE2xNJljgrNHL9ta3TMM4iV2jugF7PtPCIIFMJNWeigJ1eI6yGWUuo23cMlSBKEQ1XW5fNP3HSAwCY/1rG2mLoamXdqSkeo/2FbZYfXmr7CdC29ZGeNfyi6uqdu0CqS2euOkoi37pseNq0wan9rrZ7uvGYq24= 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: 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 --- mm/zswap.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 1cf3ab4b22e64..fba8f3c3596ab 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1391,6 +1391,21 @@ 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(); + unsigned long thr = zswap_accept_thr_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 <= thr) { + zswap_pool_reached_full = false; + } + return zswap_pool_reached_full; +} + bool zswap_store(struct folio *folio) { swp_entry_t swp = folio->swap; @@ -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_full()) 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 Fri Apr 5 01:35:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13618350 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 9B8F4CD1292 for ; Fri, 5 Apr 2024 01:36:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C8BA86B00B0; Thu, 4 Apr 2024 21:35:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B9F136B00B2; Thu, 4 Apr 2024 21:35:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9551F6B00B4; Thu, 4 Apr 2024 21:35:57 -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 77AFE6B00B0 for ; Thu, 4 Apr 2024 21:35:57 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3DB9AC01E1 for ; Fri, 5 Apr 2024 01:35:57 +0000 (UTC) X-FDA: 81973761954.19.7589C50 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf29.hostedemail.com (Postfix) with ESMTP id 94CD512000C for ; Fri, 5 Apr 2024 01:35:55 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=lEDqy7he; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of 3elUPZgoKCJkRHLKR3AF769HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3elUPZgoKCJkRHLKR3AF769HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712280955; 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=yEGVZyHSwt0QZZ3iWSnf36Lx2mkJ2T39ZbIwvSBmEnQ=; b=bEwTpxhvzttjpQTdp1i0jpHXt6cKxEDf4T5Cgo9Z4eL1QDMnyt25yLOyTo3Tab98ZFaT/T B2UvwlTxk1f1CAAV2T4ToPG2XKXIwb8kGuV76HywM3SYfxK1sLjsJ/4rTY+moXHRIyDeGy 7bmSVNxMu42mEakIHy7IUZJwGLybSyY= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=lEDqy7he; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of 3elUPZgoKCJkRHLKR3AF769HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3elUPZgoKCJkRHLKR3AF769HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712280955; a=rsa-sha256; cv=none; b=7WwFvd5oL3/j4Urc6SMwtJf/7o8uJ4x3dRVOCObFAwDPF5+Ph83k+Bd1KQStJpZ4QQmxd/ sXop8Xv4toaYin1y+MN0Iccv74zFOVEgwjH3Z6KC+b+Ki0m0dRfpbI9S6xYsQaV/8+djhS hUUykaZ34TsynVAiqC8a6EcZhiF+RHA= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6156b93c768so31847477b3.1 for ; Thu, 04 Apr 2024 18:35:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712280955; x=1712885755; 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=yEGVZyHSwt0QZZ3iWSnf36Lx2mkJ2T39ZbIwvSBmEnQ=; b=lEDqy7hegds8eeCNEfeG19o0F675DlZ9rTsXVJAtOgKvArAVrsjBIdjB3gZTDVii83 W7CHp5gYhUR1PqjbkJOysKm/fbZY4pM2Y0pLzESzh/o7lDKnR4XhimVvciC6POuakusg zGKjTJJjlrDfoXBEm860lNFYfI0BBHL/nYtW0W2pRdT/4ez5T3crkoGnwflzbH9XvKrW McFLBAj45rFbqDQOlmFcA1Of/dnyplkfJx0zn+eMkcZ+G7oNGPiy19/t36cxi7EVQHnl 4woEf6AFYGDzdXqNl1pQrkW2iV0Dms++ZlqEhnGBQ9CWooE4K3klP+tc5onnWLiOAXGp 8wVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712280955; x=1712885755; 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=yEGVZyHSwt0QZZ3iWSnf36Lx2mkJ2T39ZbIwvSBmEnQ=; b=IuFS/4GuBzT4Rt5szn16nkY+F50pz/odCXYZPJsTZh9GCjXVtiLJSYPjWQaT0ih/li mZkOkCwuB0hECj+z7PvOf5D9VklcbcDHS8FQNtMnLuUFkCCpRHlnBAqt7Tix7C7kf1XD GnC91ZGUALu+05nt6y/KVgfW0FIvXb7SoeX7EoEY8Kgytclg1zkDV0Fx3oFaCReSwtSX DVlOt6gaPNt4gUpnQqCOq3s1jObXQzbf1skVM8l1lKH7dfHynAhf56xysyFMIQubyLoI a+LnJfCuCibtDzf767puOiognLpWdYDixOIa7nHnbk82EzISpu3T7lL9rfPpOdmZaidO OafA== X-Forwarded-Encrypted: i=1; AJvYcCUMYtI5iz3uK7G2HHwHlzzI/K8ZQHRWl7tqXtFC971xpruwsn6W8e1MoMvD+39RMm8BccZUK8F9kNX6GWfa4AfZTns= X-Gm-Message-State: AOJu0Yx39cXvYkjp/gm3FdE+w/0nEcMWu38Ncz4iQYMpfxHGMtJDt+oM VjWTytNLqZMulW7RdhaVADvX7uHNtowsjxlRdhuoYMHBgEOHw9DxspRmrpt6Tj4VbM5/gRKuITg tY3GVe9XFpd4ndnUvNw== X-Google-Smtp-Source: AGHT+IH33+SVthekVVKeXhbUOG3wNDshSnpJ5/OwGTrydVxvAVq4kpl3zfciKOFqgaOZ9hcvtHjOLuShz0z5TQ52 X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:690c:e1e:b0:615:1b90:d987 with SMTP id cp30-20020a05690c0e1e00b006151b90d987mr342246ywb.6.1712280954789; Thu, 04 Apr 2024 18:35:54 -0700 (PDT) Date: Fri, 5 Apr 2024 01:35:45 +0000 In-Reply-To: <20240405013547.1859126-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20240405013547.1859126-1-yosryahmed@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240405013547.1859126-4-yosryahmed@google.com> Subject: [PATCH v1 3/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-Rspamd-Queue-Id: 94CD512000C X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: xjqbnww76wnegreyi4q63ychdxn4a69r X-HE-Tag: 1712280955-97019 X-HE-Meta: U2FsdGVkX1/RUj8vvuSftG+TNPQ1mYWEWZwP4yWNY/t0PErRaNNVnEO4Pio8wQkqzfVJexjPYZn/sA46OsoACSKL3PDy+nNi1q2cQcliMGdDa6PnaMe7q86F8czURSkHX2NBXmwpmIo6G9WxJcIR/whtLs/WnQQiYMiB7gdSFyGuws31nBvd7FAcweO6QSSsnGhQoU+HF05SUarDvC1L3gW6tBTckcoPCO2bf2KYxd4rTCVxUGS8AIftYcVKRyZIvQAF6apRLcNjH7tJCFR6FWWInHZuPv8ZfSbeq0cGMmbOn8NylCGZvie69dAreYBNOF/pZeaJcozcuHOfWjmXooTfsKkQMfhG5Tg20aRHu8J1VgAvZsI6ZbHbLuu0qeRl8JIZtwFCBxnPpLimEFcORI/4ywYLJxk83i9FGqhfDpFzVmF/IswCUSEEOi9FliTZOcQD73uhSlhpH+5oXfO9dCq4tHHK2utcxH2ti3crueiItyCYmXvuLbi2ZPE7gSk8vmaCPA5Jujw5Sru6OuIgGr6+J5JNrTSgsPrxKDH/o8eugIDElaKGxkrAeQv90pUN/KbV/qVzWTXkLi+alOW3BzwoNo436sZRCMWN4RaJPDliFUyR54p3sWQm8LXb0CaamwGJ1VxQnjCliiFHQbqHW3vlgAY9cn6ud2+2WCCL+PNelVQpYLpAkhpR4C83JdkMSf5sUZL/hz0NN44QChkgZlf92khyKAeEKABVPwfZH5j0R5nD0JLNUl7gUpaThOQbEmEqJZiBxfmRTNBfB7AkM8IEqMWFAek0449SGwRuz5gjGqfirQjeeNPs3izkJT5E0/vKEa6dQEAiTDcjzIGYXPmd8l8VotNd05bMyVSHAYSYZc75hSnQ9ybYlVkG4IbKHAe7RHQVY2Fu0f1s5EvoPbr2ueSocNH1eVUsDGyvNKHeZe3tjpKR9nbifeT4I8WIlj9byolJD32zuJc++lY 2Z7Sc9yM Judr0TH7Hq9Z7XIQChDASQGLCQNU0hT26NOCyaRrccDNtg0E3bA1P1LXUp9mQn04WJ5CFNv9QuXhWZP/wsguG5AkWwynnTXf8uVc6a6aFLitI2oMyaJJEt6BnHzXaSKNg8BOxj/e5TfQXgeUaRCQZ/VJ50JH51wvtATtsZYHwF2p0JLQGfhdetWTzpGrX2mhhMQVJsABH9T4JlNm0zH6xbALQk3imRXIlRqhtTbUSbXe76OfiW1V5K7RAfm+jddefITOpbIgsL+bHu22gTDVm251rDcMCNC468B9aUN9P/ne48wMPCbTZOAfE1bGviMFff1qOsNEA6Pbq2L/zc0O1zzyY1ER79sgRakRUUYQsL3Nf78KH49bSAG3Nq5bd2RrBFWWHI1k0d1qONBjorheLOEYm/13wsxSp7TcWZCa/Jog6DGc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000052, 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 fba8f3c3596ab..b92fa37bee277 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1361,26 +1361,32 @@ 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) +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) @@ -1414,6 +1420,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 +1453,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 +1480,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 01:35:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13618351 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 25591CD1299 for ; Fri, 5 Apr 2024 01:36:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A95446B00B2; Thu, 4 Apr 2024 21:35:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A3FF66B00B5; Thu, 4 Apr 2024 21:35:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 891E56B00B6; Thu, 4 Apr 2024 21:35:59 -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 65F026B00B2 for ; Thu, 4 Apr 2024 21:35:59 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2EDFE1A0FF7 for ; Fri, 5 Apr 2024 01:35:59 +0000 (UTC) X-FDA: 81973762038.10.A06C03A Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf17.hostedemail.com (Postfix) with ESMTP id 6A03E40009 for ; Fri, 5 Apr 2024 01:35:57 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=PLEUWqaO; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf17.hostedemail.com: domain of 3fFUPZgoKCJsTJNMT5CH98BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--yosryahmed.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3fFUPZgoKCJsTJNMT5CH98BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712280957; 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=/m5gy6JRDNvLrFZhE09AdQy3FefAqzIV084ImGWBY7k=; b=qcx40GvnoGkax7Kjwdz/UCJ+2MN95B33/f5RLyplmsPIcGUmoKluTa89+AaQX7j1J8Qydx OSeiH4r6uxOaHr3NGZSLLs68VXtu5qfjz6oXeml2p5e67Lc/SGlDWMyn5A7Oy76z5AaSR9 WMJLr6IX0cgjuCSn3ibJgYL+/jKfbLg= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=PLEUWqaO; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf17.hostedemail.com: domain of 3fFUPZgoKCJsTJNMT5CH98BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--yosryahmed.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3fFUPZgoKCJsTJNMT5CH98BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712280957; a=rsa-sha256; cv=none; b=bMCxd73s79H9kDRwMExkMc9yOV1yjJ6OOFZx1U8VD01MnfPGGrPfqHPKt6NOjYHed3F7Z9 Gw8LUlksEYRpr1Xe83xfQUrmhMrtvdDOyF9/bgTull1BoFcOFJuuiniHrsbXkfX4oSP/5M rPy7m5M7LdwUN2suwva1QfFsW6WyVBo= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6156b93c768so31847797b3.1 for ; Thu, 04 Apr 2024 18:35:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712280956; x=1712885756; 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=/m5gy6JRDNvLrFZhE09AdQy3FefAqzIV084ImGWBY7k=; b=PLEUWqaOHWcWoKZlMW2oC57mqYL44gVXSgAPyVQLFxTSJWoJ/2igwyZQzoUO/us7ec 1kllIao5OUsE99Oq5IwTgCYQMV+bX3iUADLiSh+Y/CLRq4kjiCW5ZQmR0kl22Ln+lqnc wQoQ8XHHB50UlJIR2czpJusPnF2ClwFuBhJLERiKRZdWL6uQ2mHln0lpACzWe3HgsIlo U6MBVL5g6Gb1E+N0IIyAqF5//U6j2VDFwNtxcS0+B3xanFCL02MPF22GEtA/2DzChZvv W1V/uvzt200pckSoglL/Zx32YhM5XwMoZhpu7d8GFEm0tIOvQ763Vh/q6b8KoKGplply 2ZKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712280956; x=1712885756; 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=/m5gy6JRDNvLrFZhE09AdQy3FefAqzIV084ImGWBY7k=; b=ZZoZH3FbjzqX0QV5qcA8+8bqksrdCQRL7l/0HxXOxJXVfsepTkVJHhVN5qNV2eQoWR KM9Xk2blOYcG3+M+NBG3ELbdgbH6BGNSVkpXsv007eqJaUAtbR3xLNmHaLIWbncl+M00 EfPYcsLEOKrlJgPxpkS/Jk0OaptnwNY/vuW8pwStIawxAqf9yo24sIzolzPsSrWLP3gm h8myNEKdIi9gtJ6DznLlC7VOF3JGAM4NkATpIZH+htrsn+ouADF6dCp1USsyU4x4tCmX U7Y0SaJQ4cpvM4YXH4uT8ffRMc9j5xgcRCTx+HpU1rwewQ5xW9vPTqpobolIT0FwsYc2 YPhw== X-Forwarded-Encrypted: i=1; AJvYcCU68pf97cSKdUml2yYzrOlWeKpdDkPVw8+FciNvV28qtA9F1uLuA8XxQ4eAjuSta23rAs6pEUVyGZXu6MVLEpbwfFQ= X-Gm-Message-State: AOJu0YylOf05j6XISQqIDkybxlG1Le8fA94o+5QWOPhqG7iL2K03HO/d frfZo5eKNqW3mG1KleZPF/20ObZWyoR9Sj2Crx9qRjsfQ414B3GYJ8h71RVoAjVBtNl60T3wsLE Brrh0LdWlqlKiIXeBoQ== X-Google-Smtp-Source: AGHT+IF7f54z2FdS42Ou0yg3jjIJwSZWrUbEzwVPRh5Hihv5pxBYL/oylI81O/dhSX/lYtxqrDRNaVzdafD0Up7i X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:20c5:b0:dc6:d233:ffdd with SMTP id dj5-20020a05690220c500b00dc6d233ffddmr362563ybb.0.1712280956608; Thu, 04 Apr 2024 18:35:56 -0700 (PDT) Date: Fri, 5 Apr 2024 01:35:46 +0000 In-Reply-To: <20240405013547.1859126-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20240405013547.1859126-1-yosryahmed@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240405013547.1859126-5-yosryahmed@google.com> Subject: [PATCH v1 4/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-Rspam-User: X-Stat-Signature: kz7n38hwua46wmyijixgfjy93eqn8q9w X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 6A03E40009 X-HE-Tag: 1712280957-384546 X-HE-Meta: U2FsdGVkX18nb2nYzupVNr4dSQFfaEVtPHhIVxZK4q20SCyJenZJiZI8TPuel2TcBnwp+O44i0dKymXrpvBJ0rCQ3JU9zt5Drlmddw9cn89evB5YBFn8e990TCUUVcpm+KsHgqm03pdQZ0uOSX3/IrTfg/OBAksXgTrMK5R57f+zixszPzzxE+wN0rn+XXtwQq5SF9wKrXUs97yxgXQCdR/rhzvd2YZ+1zW9HvB6s1bFw2xI4dn9TdDc6K1risA+5rPoWfeJd4isIvMENJCEsMyvI6WTh5MxPzqktTus5ECOFaydl9CbYC0KGn9H5J6CBUfBY48XzqjAtbj/2EeYnZ9lTbrutyPd94aVk6HyAosG4LEuFWoTH6UMUFbt2h0akEXfDL2oOvG98VJ4xLE52iV6JFqqpdSVOe6ext1gteAVnL1VF6+6P+W/4fUdYf4Qz/ImdCFzq8BSQsX9CYzCgm0NkT/JpRHai70S7V8bIB27HtquTdM8uvgxChe09uOzge8NbwaWmAIKBy7iVckvEXxS49KrJL0ASZmaYkGlRzlZ5ia7epXKU5SU11Mnw9BIieESZdTOYlcGiJ0So/QpbEFxS+K7m23B639bLv4AMVNO0NVy9xsfyiygTIe2yJjQv1gFZsTJl6oJi61GZS/fCJypNEQljf6xeEDOM9eIt4RB/TaGUoBRAEcHfxcvxe0vb4HIz4t0UdIjd8UJb1oy6AVERp67CQBrSPwgR/BHcXH3bi5W0iTIqptc02oHaoLHIHd2xDycWx/21DoLJY9jhZ2hzuSoF8fsoac1TdiK3JDvqUQC6zkQxU8NlE6CT6uqOfRw98xE3C8exTu1MBZZCtl4p6HtVN9R4+OvdFspRIsOM4jr5t8uhX2/uzejrbRDGjprmzvUFaBaMaXixd8iIwMgNSatTYa+qLHpkanBJc3P6zkjgWxXHy7c/dFSZGdng5MSjyHOd734xWECzBB gt9BxZgT Bhd6Q9BnXIn6GolBM/fm14K49ojlcptSKKTpw0qvBCUXcpc0cVSAxDmTk97TgusoaU6+1/xTIMQ6OZno8xhnHKbOpHOJ8Z/0CwCXrrVueX0H7Kkce9c+1LwIbyCCRwlzaArEY1LgA1unyYmZ3cFwLIWLa9b/1jHFqIE/5qoKcRPV7/yd+dDrYH+ya/GnuMmONApB/UR2YaFmvxPSid/I0edWbX08NneemVrQDmZWSLc/eHRRLnLe2unZBVi3LhBOaBVO5yKnILWhseSDY7j2Fj27Mu36mweHvedEogQ4h8f9gve+rG5mnS3Y9urnzMFVFwGt98xMzHT3LKMcSNwqr4om1fw1GBsGIiO9/8TatsArfHMlbOmlS5uPXsDW1pdZmUCt20sVBmUPkpv20JM/T9vWpfX86YSYsTURY0CdtmVNAlnfn//Af06N6WsS+x8Dp6uyTkNvpRBLGHIEpSjEeNnx+R9C1Gb4mqVJKR+XWxP+pb+m58KP+FLdiWqJlzni6WxeUXiPcDTy+VhvO9kOnsfe1N2FunOC6QndULhq12w7xYZkIzkzNFAvXGaSo/c4hpw0QxlXOsca6wcPhqL1SBcpTmUV6yohT3gXy00o2dO3I/gHWCFFIGVlin/XVLxmEDG84GvlF8UsgBvAt9j4TnnAmoLQDiboYeZch8wAuDmlDxBkFcKtyoHjJJl8dZ0SMNNWP4kfnkTfoQ0GPlUPFi+WNN65QZqasGEKvFd3gyCR3YPUMnDT77jYeH76FrvwQBuqfBH5j38ksWEI= 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 --- mm/zswap.c | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index b92fa37bee277..a85c9235d19d3 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 @@ -1368,9 +1355,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]; @@ -1460,9 +1444,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) From patchwork Fri Apr 5 01:35:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13618352 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 AA37ACD1292 for ; Fri, 5 Apr 2024 01:36:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B52026B00B5; Thu, 4 Apr 2024 21:36:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ADC586B00B7; Thu, 4 Apr 2024 21:36:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E1656B00B8; Thu, 4 Apr 2024 21:36:01 -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 5D30D6B00B5 for ; Thu, 4 Apr 2024 21:36:01 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 274991602D6 for ; Fri, 5 Apr 2024 01:36:01 +0000 (UTC) X-FDA: 81973762122.14.EBD8723 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf29.hostedemail.com (Postfix) with ESMTP id 59AC212001E for ; Fri, 5 Apr 2024 01:35:59 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=r+G1woGu; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of 3flUPZgoKCJ0VLPOV7EJBADLLDIB.9LJIFKRU-JJHS79H.LOD@flex--yosryahmed.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3flUPZgoKCJ0VLPOV7EJBADLLDIB.9LJIFKRU-JJHS79H.LOD@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712280959; 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=LZ1QXrjwhIal4gIkbl9SlMnvEbBP+lXyDn0RpoWpImY=; b=FEc4HCZyu2qj8ym8CSDiUX+wAKnMclCI/Juk2aY4MsSpWYhtamNWJjTvBpClFeW+eAkRBZ ThIZk1s0fQ+9rcDzW4vdwhUUAgdqqQjjTwAQSC+nyHCvnIhHyrJml4c/KQnilrVnxlXF6q Ja5wG5jb+Vfs0JSLFjambELKGuyyFNk= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=r+G1woGu; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of 3flUPZgoKCJ0VLPOV7EJBADLLDIB.9LJIFKRU-JJHS79H.LOD@flex--yosryahmed.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3flUPZgoKCJ0VLPOV7EJBADLLDIB.9LJIFKRU-JJHS79H.LOD@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712280959; a=rsa-sha256; cv=none; b=s8NkZc1eusm/AaDyjhCNp1Mw06/6qQN0XJmNQwQ34SKMgw1yJk0VhtR22XcbWwiYF4JHKD CUZk67kGfXAwBGPRtwTpCK2lx1BrfQeHLePbmOaD6/UyujdU90xG/TaZmrsJPloHxjbvnL qydbsWxoE18YHeeUMfTSSEoh5HfJ/PY= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-617bd0cf61fso19984197b3.3 for ; Thu, 04 Apr 2024 18:35:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712280958; x=1712885758; 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=LZ1QXrjwhIal4gIkbl9SlMnvEbBP+lXyDn0RpoWpImY=; b=r+G1woGubVqf4g0oyLp8ZstRQT3bVwHIOFoAbdmi6E60AqJASLcZ/mFHY1xL6KwKPG 4fPzzBaATDMmMxqNYoEEroQkGqNA1fw3DruJkObriude2spZo5ss4zNLBnYF4cYzhh2X toj0OnlsIJGVrctOwtVSNAuvnglZyTnqvWqYv8RiXDMDojPnexzSIL2IpEwiLVMH6ykS SbItFqTniPFTENY9diyEoPcvSyuwKIOlZPeDkk5geJ/aIZzJ8MQ5qnCY1FVFOgzpGpwd vmIlttWVouy0oecx5HwnQqZ6+AkhV681LHx2ferpKwoqV5Vt6eSmyoUjLu/3rga/amW5 Sjkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712280958; x=1712885758; 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=LZ1QXrjwhIal4gIkbl9SlMnvEbBP+lXyDn0RpoWpImY=; b=cykOgUWkaozrTPUNVS1X+pIRr/5miQYNr2EoQUkNPMPJ0yIJg6Fp4qrc3ZK+SqOnpq JRdVK44w1rKMrfDarzbZFI5P39uHZfV8bek3wJxlNEMkIfkYw13U2JshbJD15wQu+Kf0 UPblR9AcN6aiuAB9/x1KUGCrxJrXjuJ/NtEutR5T3ZHBtQQXmruL15j+c/RnYcO6bNwz DToQDQgyJDPA0BUQMJW+LiFPbWWpi+Iythgm/cpTNGSTqXuiW6kdpBHe0FAjtjJpwze+ 6oMmPLWNvLH1hs82aq8LNHaQJU2aO1HVRf+UaEhZBhR+fovTNtmuX3juVtWutw8ZrEox DRMQ== X-Forwarded-Encrypted: i=1; AJvYcCVlylfpnhDG52zZM77TKwJiezfkop5PR1vJ+J/IhqpSA4ECFQwsLJpfCP0UyR3QbskpcFqBRoPShwC7Fmj0RVpKG8w= X-Gm-Message-State: AOJu0YxtAXFtutkNxjmcMJQsQ+1JDQml/0q9pmfVp/3umkh80P43QR6n qwBCQ4efjx3J8amdG1XyOBD82E5J13q9Bo3I49MgLBU716krvmLDzJMUqCE0XCoyGmthCjTFdMr o0VtlnFdvwazhr+BdQA== X-Google-Smtp-Source: AGHT+IF08nd+KBQE70LXZSIBvDA4LHuHsKmvLNuPmdBMBqFS4+vTxuqxYNRCiDtgu7m3HgM9JubMSqb0OVDe26Bd X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:2b05:b0:dc6:e1ed:bd1a with SMTP id fi5-20020a0569022b0500b00dc6e1edbd1amr351076ybb.2.1712280958518; Thu, 04 Apr 2024 18:35:58 -0700 (PDT) Date: Fri, 5 Apr 2024 01:35:47 +0000 In-Reply-To: <20240405013547.1859126-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20240405013547.1859126-1-yosryahmed@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240405013547.1859126-6-yosryahmed@google.com> Subject: [PATCH v1 5/5] mm: zswap: do not check the global limit for same-filled pages 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: 59AC212001E X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: dapmmuu3qx9dz4tn4j57iu8q45hu4ra5 X-HE-Tag: 1712280959-669335 X-HE-Meta: U2FsdGVkX1/cmRrc68KKFLrV38GOmMQ6F7nNVmVOkI1CAqGuEmBFVzNWe5UXPpNvfCXap2LwVT5/0LS2UXLy7VQ9DPk97rJRBVnrOLA2et2iH09Gu5ilWYDw/bM9ZTKexrSVvhP7AOo8A/Rlq7jjs4hkD6EPBGDto8zY38JBs4vi4HNRgzes+qOYTMePWMxQx17qSbEhBAoQsqpmbjAW0Rs/E4DZk8IWZu+YJf3cp1hTslnpPeljks+39vTZXb4ON9wrSwi468UAbnfTrmIZl5WaSK2QNQ9QJyEyiA8H4OPgU7aOTlmvG9HvzO4397Op+9R4lD1tgosN3TVLxL7rH7bK1nwIrC9VH+Dcx+GYNkyM3yDJQ2mbdDmOZUakpXN4LDBWnIkH5lC/Z3IMkiBQTPvvER5OX5SB//3zhrJFSB0HhJYcxptMVKKwu1eRP02HXpWgqqYsM8g/63kFuXMQoksMrbDJzJXwJ8VTG8BfbuBI+RYlAon6hNW2vwpBJeklVZ+oyZQ5GBqHF2NEkY0Z0VYKMe8CKyJT72H/PVlj2F1PGnezHapjnn4LxhS5dr8oAPV3VkHMc9OuVYJ4NsgscUyeuDsyfsf6Zsc1+MG2RDehMJpbRHqQ4EKyzeyriU6DHTV/d4l2KUzsaAWvkPRNvV1g0ZDXcAjY0lvOmQT67+3vOrk/YiAwoaPEA39SwjSMchhmzzPI0RCk2RMaa7z4hAqg1oe174c9B5P8Pi8lDZflG2vccDaGCiuaziBc43xcrM7XCksB79/Ee6a6MuZneb/1P7GxfdLtLqkrEhBHhZZpkvYP6Va8en6qGTjX92tVVKFIXL6DXWP0LfDx/Qxu/2x5LYxMWeXM3J/USb9xUtLKCN7QwIH2Y3ZQ0GpUd2xzTJq7YPLnkFe1c5FYf5j1aqT7SnpD7FqTpMPMTRux8Oz8hfF6DNI+Zcfd4FBgqPKVc94mK0mP1jWz7s5ysAA MEDPCdVX fNyI/o5v5c0Nm16/odxhFWQyMiJhdusvPUGV6Xik4/VGlc/f5VQEqVe8XbvRFS7zzwJEBWy3lgpYCqngEAippODgVXhMGZeibM2zGpthth2wMXGjifnEBMCD9+AVkWdeD7u8uRKzzi5fqoYl8bWHZzOFgpkkUvcwoyov75u5QZ2irCyOZl/bMBY350q3lS7wYQ0suU10cspB+/gG2CP+9hAfdNC7ezLKFMnx1wJGXjfK7te/PlcypVaI9NBfVFF2vviAYJd6HUBizN7bfw3w5HUM/lb7kiPGEO4vsNC3jET1uBk2IQ77p0q3dczPCDQCrj4m2+nkWYwv058f4ktHgbT3fSsw/MShroHmQVG1PJsrJkhuxzsUTA8nx7lxnFCkZ7bAsMQN0PUdZN9f+Sp6kpy2kZ96TY/oak14FWFni0M9rYz2tFt5mVzOc2lRwJa1RvdTWXYRSbC7RjczpWzGqtrfiuKUP47DhlJ8KJl1WqREPjbjetqNkHtZQiKUea2YirmAgi7NWkbokfR+NUsM3Ppl3MvE/WOD3sBSTgnPMXTAn0+F5gynAyaXGv3QgfNW+laenvGlesA5AigR/uuqlWmnevlODjk+Kr5hxU+Fn2uyPUEl0bWpN8ctPV5M29r5v1U6w 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: When storing same-filled pages, there is no point of checking the global zswap limit as storing them does not contribute toward the limit Move the limit checking after same-filled pages are handled. This avoids having same-filled pages skip zswap and go to disk swap if the limit is hit. It also avoids queueing the shrink worker, which may end up being unnecessary if the zswap usage goes down on its own before another store is attempted. Ignoring the memcg limits as well for same-filled pages is more controversial. Those limits are more a matter of per-workload policy. Some workloads disable zswap completely by setting memory.zswap.max = 0, and those workloads could start observing some zswap activity even after disabling zswap. Although harmless, this could cause confusion to userspace. Remain conservative and keep respecting those limits. Signed-off-by: Yosry Ahmed --- mm/zswap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index a85c9235d19d3..8763a1e938441 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1404,6 +1404,7 @@ bool zswap_store(struct folio *folio) struct zswap_entry *entry, *old; struct obj_cgroup *objcg = NULL; struct mem_cgroup *memcg = NULL; + bool same_filled = false; unsigned long value; VM_WARN_ON_ONCE(!folio_test_locked(folio)); @@ -1427,7 +1428,8 @@ bool zswap_store(struct folio *folio) mem_cgroup_put(memcg); } - if (zswap_check_full()) + same_filled = zswap_is_folio_same_filled(folio, &value); + if (!same_filled && zswap_check_full()) goto reject; /* allocate entry */ @@ -1437,7 +1439,7 @@ bool zswap_store(struct folio *folio) goto reject; } - if (zswap_is_folio_same_filled(folio, &value)) { + if (same_filled) { entry->length = 0; entry->value = value; atomic_inc(&zswap_same_filled_pages);