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)