Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp489104lqp; Thu, 4 Apr 2024 22:36:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVavNqJzhw/Jj3USUTj+qB9f2gP+uWF8iIrNM6QAJ98rrimuG6/9oVPFuSO220W0remwqwmobPqmiabHP+2v++17QpEVbkEDuWRQRMMyg== X-Google-Smtp-Source: AGHT+IGOuZyL5AQq0VxbM/lyqOckqTGY1hpq0glX/CJLGCo/9itqekgE1Zb1gpJdoBijIKgRYIh4 X-Received: by 2002:a05:622a:1451:b0:42e:e02b:c65e with SMTP id v17-20020a05622a145100b0042ee02bc65emr424532qtx.34.1712295364556; Thu, 04 Apr 2024 22:36:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712295364; cv=pass; d=google.com; s=arc-20160816; b=BG27csEz/vWWXNh3r9oBytK8fRtDKYzhPtUJOIz6LWAg+thUFuNQaNcTZCFeu4v4me tFzzSZf86z7y14/Ry841rot9liiWtrTq9zapQ3YBd6jiuLy/1gh9/0NnYO7PYwAhQek9 Fysa0ZI87iRD0yBILUATE9Z0KjGIOuGZAyZEaFSHIbamkGeUvTcNqQG8KMS8KFpkl400 Uz0uv6glls5cioCE74f8oXXzNEyfRRHZTqzo9cGebQvXBd+V/qHCbykJyOdlTg7PhKPe DGZeN44OlIEKSdKv63t5LbjthIOnuovWV0tv8lRdeT+XCwQkWiw5PxemwW0H8B7LUET9 upnA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=WDqFLsTFGLxbu9w6SZiJvC7ASuSVfXA4IdBaekrBdf8=; fh=T5lSGkEGvQg/0ko00E0GsWAPzeceC6fv8+Cl/ebp2IU=; b=zldJZBKH+Z3rrsuPMoN+/T6IXyS2gyU9+/3cdD0NMJ92xbXMlv2ut//cwU33S6cy93 fTYOhX38vJ/Jx5l5BFRzWb7cTFEqt1UaV8WKEnHSWcR9GlWvijulYX4vuZYWlFJs5E8Q IAwNNMzeaXkxGPtTYm+2+P67NyN22B1svy8wXUJ63QiRnFSztM91kOnaW7B+w9fGeFqE Q2Nr2K7vqe9lfTsA9odRti4VWTWa8VdeOILGMBpEMEC/x/Ta8MhaauvNC/Q2VQtetZ5n DEmphPK8XBvKVSNC9ngjwOHuDXm3RQR/niosUJzeZUxXfAxiIMhZjXbV2zBxEJAzAR1G xQYw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=3LJID+pE; arc=pass (i=1 spf=pass spfdomain=flex--yosryahmed.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-132427-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132427-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g5-20020ac87f45000000b00432c273f671si996883qtk.656.2024.04.04.22.36.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 22:36:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-132427-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=3LJID+pE; arc=pass (i=1 spf=pass spfdomain=flex--yosryahmed.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-132427-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132427-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 4D5211C22636 for ; Fri, 5 Apr 2024 05:36:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 957A626AF5; Fri, 5 Apr 2024 05:35:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="3LJID+pE" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3EFE323754 for ; Fri, 5 Apr 2024 05:35:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712295320; cv=none; b=TI67GtkImj3SrHaUBFTQgX1IHoMK6f/bXg1aD9Q2p5A3MgLGSBx+/BTi+uiEho7Fsqa+9WKJ0epcL4pRjJqK7szaB+lukNKvzsYoI7QUpdiLbBkBJVPdpLKHcRgeOKI1Vrh+c160teeB+j0nk0CMgNZzsYJDfxIYtUmyW/TTG4w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712295320; c=relaxed/simple; bh=5F9Bd2r28dJJtSqVJvAZgDM+tkC4MEPTNqJzfo5xl94=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=co+w8QEZpxaETuZD74gJXEhtLIfs0s1XwRawdKjfhWryEbdDK/KDDbVxyX7olYqkb9E04GtyDDOybaMdw9F3tjyZCDcLOoqP9DixyfWyWo5FeY/9nfNV0NV78VuWpaSP3jx5t90eTyJrtFW6NcUsrlmrb9CWMOe+52GuR5q3qyc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--yosryahmed.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=3LJID+pE; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--yosryahmed.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6b26845cdso2671109276.3 for ; Thu, 04 Apr 2024 22:35:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712295318; x=1712900118; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=WDqFLsTFGLxbu9w6SZiJvC7ASuSVfXA4IdBaekrBdf8=; b=3LJID+pEMcwH0yskP0DUVBV2i+K6M4YSiMLshgOUMvFPpVFyUnPs04ou2cP14RQ3fQ wc2zNRvL5OwymJ6/qLuZ3Sz39rM8NTEPIpuMzB+ZRrvcDdL/wcQ+ZoWh3ENe3QlPfWFM Izj0oxVMv8mf2suI4zInck5ABr5I7LC5BM/OI6zo5lP867H93VXMG10rPa0PaxrnNTFB EDAFXN/GFDZ4O4qkITUnQppisW6UUxykUEtc4RwF/d6xUgLylNyuR6uoerNRLwIpZHCG GkTwEMTfIj9E5N6khHxyNfPkT1sXacSfcQW36XlRi6HDqUNZtEOZLK9b0/fPvlULH6/f Bz/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712295318; x=1712900118; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WDqFLsTFGLxbu9w6SZiJvC7ASuSVfXA4IdBaekrBdf8=; b=QOdjZlZeJCJ+Z9xc8YNa83aNrj7uLKEtq75BMGewVyp0Q4RAmZ0F35DVrK5U1v9gOF MbW1pys+nu2hxoR4Xbj6lvLV4HeAzGMXW6cT29BCD/DV+RYkCluNfxawL5PTp1syBMTN yqU7j6XfkRw+Byn3AtHkdyF72JDy+sMim90tHmObYMLLeFBz9ro81f+hY6Kp7o2667xL Pu6ZQ97IrlCqQm+thxd15vK9swrbqgRpFDH2kXYXiIW3z7dDHVl3ZmluAC5UWddbDcqE HysiYZ+dgfx2crQUYPilUpeWY9ictZUDIeasKt97E579WNdGT16iE2UQT7bl4AJ5WWSt v+/A== X-Forwarded-Encrypted: i=1; AJvYcCWSSL1ykBC81KknABgiY7mSCmHoywIIDKZuSB7Cb/+uCCVjIWgxqzFIsZWR2t5rpxLZiJHLLoiouGhYwEwgYyBrEpeSKUy+xRM4PGfk X-Gm-Message-State: AOJu0YysFeC4Yittima2ESMUSW6pz+F6Lq+YG9wKvXVNXgXqpo/lIN5Z nI+2DUcrsZ9F3yCaBKpbh0U+l4F7yp9yVHOBRxn6hqaI1CP0yLWdUbJh2/W7vYgnsQBJcnvBn1J TnS6aZihqYYHBgDwziA== X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:1893:b0:dcc:5a91:aee9 with SMTP id cj19-20020a056902189300b00dcc5a91aee9mr112599ybb.7.1712295318409; Thu, 04 Apr 2024 22:35:18 -0700 (PDT) Date: Fri, 5 Apr 2024 05:35:08 +0000 In-Reply-To: <20240405053510.1948982-1-yosryahmed@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240405053510.1948982-1-yosryahmed@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240405053510.1948982-4-yosryahmed@google.com> Subject: [PATCH v2 3/5] mm: zswap: refactor limit checking from zswap_store() From: Yosry Ahmed To: Andrew Morton Cc: Johannes Weiner , Nhat Pham , Chengming Zhou , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed Content-Type: text/plain; charset="UTF-8" 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 | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 832e3f56232f0..ab3cd43cdfc9d 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1444,6 +1444,20 @@ static void zswap_fill_page(void *ptr, unsigned long value) memset_l(page, value, PAGE_SIZE / sizeof(unsigned long)); } +static bool zswap_check_full(void) +{ + unsigned long cur_pages = zswap_total_pages(); + + if (cur_pages >= READ_ONCE(zswap_max_pages)) { + zswap_pool_limit_hit++; + zswap_pool_reached_full = true; + } else if (zswap_pool_reached_full && + cur_pages <= READ_ONCE(zswap_accept_thr_pages)) { + zswap_pool_reached_full = false; + } + return zswap_pool_reached_full; +} + bool zswap_store(struct folio *folio) { swp_entry_t swp = folio->swap; @@ -1452,7 +1466,6 @@ bool zswap_store(struct folio *folio) struct zswap_entry *entry, *old; struct obj_cgroup *objcg = NULL; struct mem_cgroup *memcg = NULL; - unsigned long max_pages, cur_pages; VM_WARN_ON_ONCE(!folio_test_locked(folio)); VM_WARN_ON_ONCE(!folio_test_swapcache(folio)); @@ -1475,20 +1488,8 @@ bool zswap_store(struct folio *folio) mem_cgroup_put(memcg); } - /* Check global limits */ - cur_pages = zswap_total_pages(); - if (cur_pages >= READ_ONCE(zswap_max_pages)) { - zswap_pool_limit_hit++; - zswap_pool_reached_full = true; + if (zswap_check_full()) goto reject; - } - - if (zswap_pool_reached_full) { - if (cur_pages > READ_ONCE(zswap_accept_thr_pages)) - goto reject; - else - zswap_pool_reached_full = false; - } /* allocate entry */ entry = zswap_entry_cache_alloc(GFP_KERNEL, folio_nid(folio)); -- 2.44.0.478.gd926399ef9-goog