From patchwork Wed Mar 20 02:08:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13597211 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 E7591C54E71 for ; Wed, 20 Mar 2024 02:08:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6768B6B009A; Tue, 19 Mar 2024 22:08:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 627656B009B; Tue, 19 Mar 2024 22:08:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4EF8B6B009C; Tue, 19 Mar 2024 22:08:28 -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 3F4186B009A for ; Tue, 19 Mar 2024 22:08:28 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1AD261C0520 for ; Wed, 20 Mar 2024 02:08:28 +0000 (UTC) X-FDA: 81915783096.03.CD164B5 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf11.hostedemail.com (Postfix) with ESMTP id 752B840002 for ; Wed, 20 Mar 2024 02:08:26 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="F/yF2zb3"; spf=pass (imf11.hostedemail.com: domain of 3GUX6ZQoKCMI6w0z6ipumlowwotm.kwutqv25-uus3iks.wzo@flex--yosryahmed.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3GUX6ZQoKCMI6w0z6ipumlowwotm.kwutqv25-uus3iks.wzo@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710900506; a=rsa-sha256; cv=none; b=K3Uj0ZlQ2IzzVuejPtE9rEjWpn8kBeTvHKdCb/4pQTlCE0/4iQwfyj58eubyT49sPbBJ/N N24vwX2CeZozpxROlANb9bS06HzmLExDwQsD/Dqf+lWfyv4goHrUCZH4JMZQ2bOerOYGY0 kp4Ycg+Y/3/uCt7VteLAarHf4PC/K/g= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="F/yF2zb3"; spf=pass (imf11.hostedemail.com: domain of 3GUX6ZQoKCMI6w0z6ipumlowwotm.kwutqv25-uus3iks.wzo@flex--yosryahmed.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3GUX6ZQoKCMI6w0z6ipumlowwotm.kwutqv25-uus3iks.wzo@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=1710900506; 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: references:dkim-signature; bh=yYVHze7eFk58oRqMFdcZXvqqb2SqrJB7jmdU82oAHB0=; b=7RfyF7Vex9sDotqr6fpvfcbBw4yJ8uvuMIPjDHJasZivLDH1YOt1V2LaVqChdlKxYerE3V ckzKC85Pjg3kZm/7tHLEcpnq29+CMuOG0gaz3Rf7aGjyPmeISrNiK9P8AAZLIquJJmiFmn g0RwsAwwE8PPWkUdCMiCKMVMKz6mlhw= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-610f160f43fso10511437b3.2 for ; Tue, 19 Mar 2024 19:08:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710900505; x=1711505305; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=yYVHze7eFk58oRqMFdcZXvqqb2SqrJB7jmdU82oAHB0=; b=F/yF2zb3h4NB/o6giWnZAhaSL0WL2EfE72mRb0syUOvR7FYBt4ebJNIwBDNSFck98o l9IVSKNvzhLxNijv5Li3vE2duxVMn/2mv+OxpCufuciy113zO22Drkb+WDv1I9flW8Nh 15mYxc00zexu0nWOU5GcaeEctv9tcLuKTkNsqRn6OKRuK4gM3I+PiOWvbVE6IuesCNVf 6Pk0PIewlD9kv4DqR/HH3DMuFZ0lI2aLmNU9kyxnFYkrN8MgfAb/BratRNbf8KnkuMVy WnOPpA/07EeohrZCsiCI9OjE2lKKUnhWyrNzwA061V9Fp6Ze/pY5BG0Jm94Lela12ICE gZRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710900505; x=1711505305; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=yYVHze7eFk58oRqMFdcZXvqqb2SqrJB7jmdU82oAHB0=; b=bIHTRMI7BIXVC7peTSEa9q8qYXJn0UHU8HP51VNvG4pvFaLXMOhY8dYidGTBDGZbsy 9/06yfYOvfGjOQWfZNuQSiyeVupUm9BwqeKOTv44thEDiwOq7NknTd+GHJLYyBc/xP44 Vw/PPADYIWMF1TaBdyWEf1NnUgolSkOWYlKT8XY9aLjX79fk0CwneG6vHPYmM6+getLt pPouNLsFE3h14q30qT+PwZnWYraTRzGO8c09xuzy5JOjI0ngkEOC8qHN/j4V6amw2b3g uiLqbVV/dlKwnTzki+9L2Z+vF0W7op0n+CumMObOYS92FvlD7RWHwhJzaFY6J925lRxZ fOQA== X-Forwarded-Encrypted: i=1; AJvYcCVGEu8MPTZz1pn1IK1HHMZgoz89aBnzjuoxEXphP1ecOqyMx7EnC+DEC7/hPmeR7z/rRk+UQfZ3vOwYLapjWFNYYuA= X-Gm-Message-State: AOJu0YwM4wAGOzdv3QL2Epc36Vkecryr9zk7BDI+lNHPQL1UPtzPWHR2 35CWPFoTftV2IvB73pJavdn+h10NwDf1jTJ1vkKkt34uNSI+WxVm9xqVm2OB1XozoVzpNmqvOml X/usaq1RjxLX68CjNow== X-Google-Smtp-Source: AGHT+IHmnbH7OIFT3vXCgDBMNN/LSpOqXUQlqADVGRo/DP6oT7pIALKkMG8DtSLjyTbflgHEateyR8upPPsuWMd6 X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:70e:b0:dcc:6bf0:2eb6 with SMTP id k14-20020a056902070e00b00dcc6bf02eb6mr966645ybt.6.1710900505416; Tue, 19 Mar 2024 19:08:25 -0700 (PDT) Date: Wed, 20 Mar 2024 02:08:22 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.44.0.291.gc1ea87d7ee-goog Message-ID: <20240320020823.337644-1-yosryahmed@google.com> Subject: [PATCH 1/2] mm: zswap: increase shrinking protection for zswap swapins only From: Yosry Ahmed To: Andrew Morton Cc: Johannes Weiner , Nhat Pham , Chengming Zhou , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 752B840002 X-Stat-Signature: iscrdyd5qy8bww4ektgrhibbs6aua3w5 X-Rspam-User: X-HE-Tag: 1710900506-381817 X-HE-Meta: U2FsdGVkX1/DTcWUmiOUVWNi59wZn0uRM/uUhi+L8RGOlqmEX9wEki82PpFvuBCBwD9eMvdq/p3OKQ0l2pliSYbMLDn0iyjQI+3y5W3dj6GjA1GFBZsDJSPsJDeAhC+VcEfApcF3CnT0ot+7WByKE+FbYalVqHmUWz3e00Oj1UfP9YecD+ZAqxJSW/ktiE70ff+UvHLHo3+J5ddPl/jtXkgCeFNqu5GS+eoryWWd8WzBM6uXg+QbyHRKcn3QiGvD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DGaKuyu0S25pdz7GptQAoGqhxYR9MQEmMX/wksCSBRBhVAFAS+zE5diC6ealgmFMXxXAn4grr5Wmh607h40HqfLyNXLuXotz0trpV59z4fTU+LlfhqeKtgpgW1E4OEKArNzT873qwnxpq1VbwNK0HDEWPvB8UoVCIFq//zKT18C9MFTOb/s3e29or7dKfmUZaNFDzgvfAunisrCuV5sT5HoVycJ3F1rGr5PZJibTEpmsENNIFcLJpcN7r5dfSPaeYppS47r2Dbqp+UdrU7F25aw2UO658L++D5rzav6vHreK0H1y07Bm+u11TvaBaGw= 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, the number of protected zswap entries corresponding to an lruvec are incremented every time we swapin a page. This happens regardless of whether or not the page originated in zswap. Hence, swapins from disk will lead to increasing protection on potentially stale zswap entries. Furthermore, the increased shrinking protection can lead to more pages skipping zswap and going to disk, eventually leading to even more swapins from disk and starting a vicious circle. Instead, only increase the protection when pages are loaded from zswap. This also has a nice side effect of removing zswap_folio_swapin() and replacing it with a static helper that is only called from zswap_load(). No problems were observed in practice, this was found through code inspection. Signed-off-by: Yosry Ahmed --- include/linux/zswap.h | 2 -- mm/swap_state.c | 8 ++------ mm/zswap.c | 10 +++------- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/include/linux/zswap.h b/include/linux/zswap.h index 2a85b941db975..1f020b5427e3d 100644 --- a/include/linux/zswap.h +++ b/include/linux/zswap.h @@ -34,7 +34,6 @@ int zswap_swapon(int type, unsigned long nr_pages); void zswap_swapoff(int type); void zswap_memcg_offline_cleanup(struct mem_cgroup *memcg); void zswap_lruvec_state_init(struct lruvec *lruvec); -void zswap_folio_swapin(struct folio *folio); bool is_zswap_enabled(void); #else @@ -58,7 +57,6 @@ static inline int zswap_swapon(int type, unsigned long nr_pages) static inline void zswap_swapoff(int type) {} static inline void zswap_memcg_offline_cleanup(struct mem_cgroup *memcg) {} static inline void zswap_lruvec_state_init(struct lruvec *lruvec) {} -static inline void zswap_folio_swapin(struct folio *folio) {} static inline bool is_zswap_enabled(void) { diff --git a/mm/swap_state.c b/mm/swap_state.c index bfc7e8c58a6d3..32e151054ec47 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -696,10 +696,8 @@ struct folio *swap_cluster_readahead(swp_entry_t entry, gfp_t gfp_mask, /* The page was likely read above, so no need for plugging here */ folio = __read_swap_cache_async(entry, gfp_mask, mpol, ilx, &page_allocated, false); - if (unlikely(page_allocated)) { - zswap_folio_swapin(folio); + if (unlikely(page_allocated)) swap_read_folio(folio, false, NULL); - } return folio; } @@ -872,10 +870,8 @@ static struct folio *swap_vma_readahead(swp_entry_t targ_entry, gfp_t gfp_mask, /* The folio was likely read above, so no need for plugging here */ folio = __read_swap_cache_async(targ_entry, gfp_mask, mpol, targ_ilx, &page_allocated, false); - if (unlikely(page_allocated)) { - zswap_folio_swapin(folio); + if (unlikely(page_allocated)) swap_read_folio(folio, false, NULL); - } return folio; } diff --git a/mm/zswap.c b/mm/zswap.c index b31c977f53e9c..323f1dea43d22 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -773,14 +773,9 @@ void zswap_lruvec_state_init(struct lruvec *lruvec) atomic_long_set(&lruvec->zswap_lruvec_state.nr_zswap_protected, 0); } -void zswap_folio_swapin(struct folio *folio) +static void zswap_lruvec_inc_protected(struct lruvec *lruvec) { - struct lruvec *lruvec; - - if (folio) { - lruvec = folio_lruvec(folio); - atomic_long_inc(&lruvec->zswap_lruvec_state.nr_zswap_protected); - } + atomic_long_inc(&lruvec->zswap_lruvec_state.nr_zswap_protected); } void zswap_memcg_offline_cleanup(struct mem_cgroup *memcg) @@ -1644,6 +1639,7 @@ bool zswap_load(struct folio *folio) zswap_entry_free(entry); folio_mark_dirty(folio); + zswap_lruvec_inc_protected(folio_lruvec(folio)); return true; }