From patchwork Tue Jul 30 22:27:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 13747949 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 ADB54C3DA49 for ; Tue, 30 Jul 2024 22:27:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 11B396B0083; Tue, 30 Jul 2024 18:27:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0CA446B0085; Tue, 30 Jul 2024 18:27:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E85E66B0089; Tue, 30 Jul 2024 18:27:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id CB6A66B0083 for ; Tue, 30 Jul 2024 18:27:12 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 72C131A0124 for ; Tue, 30 Jul 2024 22:27:12 +0000 (UTC) X-FDA: 82397855904.10.C37D9E3 Received: from mail-yb1-f178.google.com (mail-yb1-f178.google.com [209.85.219.178]) by imf22.hostedemail.com (Postfix) with ESMTP id 9CE50C0003 for ; Tue, 30 Jul 2024 22:27:10 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="haeXqU/C"; spf=pass (imf22.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.219.178 as permitted sender) smtp.mailfrom=nphamcs@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722378426; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=p4hnJFsfLt33aZBeoJY1bqyzrEBlyMzRqpVt6Wmxo/I=; b=Ofz9YLBNoXbGo8IDRAjgBC9nx4/57BFSbLl7D/5/fGUYBezxXtmBCzlTpmmb7rKt31FW7t 6YrSyQg3yKlP5rqG5BCCL+demGQSl8LAyIXJXi7xrT9MD+TBSslbqScoYv8wM2cmNXgLDn OCYZ5DTaFsJDjJ2GsR5+fXYb/CaTDXc= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="haeXqU/C"; spf=pass (imf22.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.219.178 as permitted sender) smtp.mailfrom=nphamcs@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722378426; a=rsa-sha256; cv=none; b=l0BUY1AUF/Le8YcFoKz8hS1uL6NNu62nvDxccDDECbbaj9MhUO89kqFMzUQ+BkRRxA6OJ0 +VYSMRLr8m3LLYTWqOb8jcyK1IUYDiQRwW+BWRrd/ovRJ/sq/tC7pwbcFrf3BoH01iiUcg Q+LYdwC2p3nG1cgd/2Rf6SmYCg/smZU= Received: by mail-yb1-f178.google.com with SMTP id 3f1490d57ef6-e087641d2a2so3994043276.0 for ; Tue, 30 Jul 2024 15:27:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722378430; x=1722983230; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=p4hnJFsfLt33aZBeoJY1bqyzrEBlyMzRqpVt6Wmxo/I=; b=haeXqU/CLjpYIEtdNt20WJ/oOf5V6Z7OVeirRorzxOxfxInonJkGbDDvgrovVNua7O F8r68+gdbFzW9uyfS7kvm5VPLlQmyRM0fGQNA/p1bIeteGVVIkVEYDx5tyRpjFGPXa/+ jEPM4ODwgzVBTW8EXYYlWKrAq/TILyZSIn8j+SPLPD8YN+GuCPYWnfKMCcYjZFEio2ox gU0gGTZsi6tEs+gKOsQRO3Yt+oU0QM0dcnbmC26Xzr7+eyWWUh7Lh19c9L1mrW4ShyyL 0KG/WPc4OdFx4WJGPRNtFKu6Qra4/UwEzdfaznREQVocObFamooZ83DqCnC1nVQK3ecr +6ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722378430; x=1722983230; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=p4hnJFsfLt33aZBeoJY1bqyzrEBlyMzRqpVt6Wmxo/I=; b=hfrxXeYTShxtHE2PVrVcF4BIRN0E1tBVUbXJ342dJHl8rFqH9xV6lGv4HSHfkgUi8A kFjl9bj3PCqeYHtipXaIhNTefMO2DIVrz4IEHIjdcfWQAUA0ygcZlsd6Q8K/eXCc7o1l NoqU62pOZrchifiKk3b6kHl7habtBue4WGAw/fl5lKwXRieKZSGkePZlUBx2cgzIOnje AIAj110zVIzFNS8OKnJGXKTQsmDMbgnf9U0rebfZQQdY9d82NopB47ZfZs9I88yIzpJU s4NgzUTz0SlBoxwd81M3NV0lNJbBLzcKzoA9dZNnG5FJBWxpYp97kiQP5XBjPw8kdD6d quwg== X-Forwarded-Encrypted: i=1; AJvYcCW4xDl0kH/bI9QpePxmmteBfYsm4XIzkgiR4Uo7PTNvLfRObSH9K4EcF8shiF+Mb8U2A05ispU9+a3YyZmZTFzLNQk= X-Gm-Message-State: AOJu0YzeTnESnmSvNYjAKqXXHdi3Tw8zL5cAhTar0pgtp3KymF8xVLju rEfO/cE9zsqs56xUmUQdLz6uEfIszMSmG7iRLkN1tqaBXoIf64o/ X-Google-Smtp-Source: AGHT+IEDpXcJKoeIOERp2NH7899jLowbHdtHLsB6NDYOMXttj9SNXSNeVKXOov11l1XP/MwO3SJ8Jg== X-Received: by 2002:a05:6902:1209:b0:e03:a983:3d83 with SMTP id 3f1490d57ef6-e0b544c9f51mr12729774276.27.1722378429577; Tue, 30 Jul 2024 15:27:09 -0700 (PDT) Received: from localhost (fwdproxy-nha-112.fbsv.net. [2a03:2880:25ff:70::face:b00c]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e0b29f7e037sm2597472276.26.2024.07.30.15.27.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jul 2024 15:27:09 -0700 (PDT) From: Nhat Pham To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, yosryahmed@google.com, shakeel.butt@linux.dev, linux-mm@kvack.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, flintglass@gmail.com, chengming.zhou@linux.dev Subject: [PATCH v2 2/2] zswap: increment swapin count for non-pivot swapped in pages Date: Tue, 30 Jul 2024 15:27:07 -0700 Message-ID: <20240730222707.2324536-3-nphamcs@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240730222707.2324536-1-nphamcs@gmail.com> References: <20240730222707.2324536-1-nphamcs@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: jhnkidzamszgpi5hefaoqinkhgbm3e96 X-Rspamd-Queue-Id: 9CE50C0003 X-Rspamd-Server: rspam11 X-HE-Tag: 1722378430-883887 X-HE-Meta: U2FsdGVkX1+a/DY7T59GFGdnkVheEnaUGYWCgy6O8Rl/aDuuejvF3FWa6kWTDz7C6R03Izu7/a0sreJKMKQXPAHC6Km4Vi7kX8k49ZfWnU/NYHnEVvbaxImZYdtTg2hNMOOkoh3CGfZsWjr5A8O3Nx1cpQOjcmESYdC4mN0RKwYjgiE7wz3JmPgq4H5mNYuFWTcAHeVo0w2X5PhEBrPVVtE02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VtHAiloL69tLaAPaNA/j+4kS9A2Ui2xNuo0hKZG720ufrmUwsMDIPm3J+XmDln9mu127HQpI+FirkL1or48DLvGsOZjSZ6R7TYUNlik4= 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, we only increment the swapin counter on pivot pages. This means we are not taking into account pages that also need to be swapped in, but are already taken care of as part of the readahead window. We are also incrementing when the pages are read from the zswap pool, which is inaccurate. This patch rectifies this issue by incrementing whenever we need to perform a non-zswap read. To test this change, I built the kernel under a cgroup with its memory.max set to 2 GB: real: 236.66s user: 4286.06s sys: 652.86s swapins: 81552 For comparison, with just the new second chance algorithm, the build time is as follows: real: 244.85s user: 4327.22s sys: 664.39s swapins: 94663 Without neither: real: 263.89s user: 4318.11s sys: 673.29s swapins: 227300.5 (average over 5 runs) With this change, the kernel CPU time reduces by a further 1.7%, and the real time is reduced by another 3.3%, compared to just the second chance algorithm by itself. The swapins count also reduces by another 13.85%. Combinng the two changes, we reduce the real time by 10.32%, kernel CPU time by 3%, and number of swapins by 64.12%. To gauge the new scheme's ability to offload cold data, I ran another benchmark, in which the kernel was built under a cgroup with memory.max set to 3 GB, but with 0.5 GB worth of cold data allocated before each build (in a shmem file). Under the old scheme: real: 197.18s user: 4365.08s sys: 289.02s zswpwb: 72115.2 Under the new scheme: real: 195.8s user: 4362.25s sys: 290.14s zswpwb: 87277.8 (average over 5 runs) Notice that we actually observe a 21% increase in the number of written back pages - so the new scheme is just as good, if not better at offloading pages from the zswap pool when they are cold. Build time reduces by around 0.7% as a result. Suggested-by: Johannes Weiner Signed-off-by: Nhat Pham --- mm/page_io.c | 11 ++++++++++- mm/swap_state.c | 8 ++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/mm/page_io.c b/mm/page_io.c index ff8c99ee3af7..0004c9fbf7e8 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -521,7 +521,15 @@ void swap_read_folio(struct folio *folio, struct swap_iocb **plug) if (zswap_load(folio)) { folio_unlock(folio); - } else if (data_race(sis->flags & SWP_FS_OPS)) { + goto finish; + } + + /* + * We have to read the page from slower devices. Increase zswap protection. + */ + zswap_folio_swapin(folio); + + if (data_race(sis->flags & SWP_FS_OPS)) { swap_read_folio_fs(folio, plug); } else if (synchronous) { swap_read_folio_bdev_sync(folio, sis); @@ -529,6 +537,7 @@ void swap_read_folio(struct folio *folio, struct swap_iocb **plug) swap_read_folio_bdev_async(folio, sis); } +finish: if (workingset) { delayacct_thrashing_end(&in_thrashing); psi_memstall_leave(&pflags); diff --git a/mm/swap_state.c b/mm/swap_state.c index a1726e49a5eb..3a0cf965f32b 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -698,10 +698,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, NULL); - } return folio; } @@ -850,10 +848,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, NULL); - } return folio; }