From mboxrd@z Thu Jan 1 00:00:00 1970 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 B0E50C3DA4A for ; Tue, 6 Aug 2024 00:15:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 29A7A6B007B; Mon, 5 Aug 2024 20:15:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 24A4C6B0082; Mon, 5 Aug 2024 20:15:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0EB2E6B0085; Mon, 5 Aug 2024 20:15:36 -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 E18EC6B007B for ; Mon, 5 Aug 2024 20:15:35 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 94BB01C22B2 for ; Tue, 6 Aug 2024 00:15:35 +0000 (UTC) X-FDA: 82419901830.20.C1570B2 Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) by imf03.hostedemail.com (Postfix) with ESMTP id BBCDA2000E for ; Tue, 6 Aug 2024 00:15:33 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=ke7Ld9uO; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf03.hostedemail.com: domain of yosryahmed@google.com designates 209.85.218.46 as permitted sender) smtp.mailfrom=yosryahmed@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722903283; a=rsa-sha256; cv=none; b=JMmKDhpNbfWGrJSqbnVfSiBQnrCvy4m55bdVxyibkTRYTIUvOdWAo4+Ry2wWdBCkXal1hP jXPNUnR3hrvSAv0MSKOBdReqdan2aydlZXjw2jV1xEXMEe29zKpZenvzNnEIWiqkqXw0jx bmBYQOxXbIMKcKwLjdeys8IR+PvHwNY= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=ke7Ld9uO; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf03.hostedemail.com: domain of yosryahmed@google.com designates 209.85.218.46 as permitted sender) smtp.mailfrom=yosryahmed@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722903283; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=AFetdo8Zo6q+vO4LJcQlpMZdBEcbEQLecTzEJMei5c0=; b=uJWFUQ31gEXs2Ln87ifxh/M3TsNfoiji+QspyyAiQfEv7g5RV9KVseo9HdYcZOLRjwCMOO H6an/kTRHLmTMlqvYbKamZt5YMqH/wuby4Uh8X4dWPSV30gDhgXr7ecs2Hlrbg1Ghnz3Yj gmx8hnRMRVqCDv6zoz2TdvZWK0fj8RU= Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a7aa4ca9d72so1279029266b.0 for ; Mon, 05 Aug 2024 17:15:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722903332; x=1723508132; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=AFetdo8Zo6q+vO4LJcQlpMZdBEcbEQLecTzEJMei5c0=; b=ke7Ld9uOtBC0FeNZJxmlUqWG5w8weExssUGk2Tv5TEdKvb8HMntQPfjKjnBeuSITi+ mWC5XlESQ2Jp/Hb7w3yGh6O6N8VKccI+wW3Oa9NLjPsqg+Ace+zgBcdIuJsYosTqUskP RbvLgm1QxWapSEdqadHpsgQ3ibxK1NuqYYFLU+h1ZmvYxq5ajSC6BV7jGe5tRmmZnRx5 D8H9RZnQq3YYlzhJd8v9JH/ioH2TBliD/hDI1ySPK2SBozUfCdB1TiQzj0VzxcPsv+bE 08B63w3vF2f61W40sOefLehiwLAaFEn0ZX9UOMXLrhEkGnPSN7x6U84C9gWGNZ7OPin/ EttA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722903332; x=1723508132; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AFetdo8Zo6q+vO4LJcQlpMZdBEcbEQLecTzEJMei5c0=; b=Y/7pi8tK2LsxtKl/qTKRP4rU7xf5OCSDEyfCE5xC17ahxiFMMuP7cvcTijz3NODCMf 4WGpOtDQDZqEkoUsaoV+27U8pghfV8hyWOc3sgFcbV1CazcpU7J3PO8kRQDecnFgO+nF 6pJvIBbe5pVMwyr2hZm71pyPQTv340E8bL37orvU6s2daUyri8/luqcllJfeL5tnZmpH HT0pFGR5p9uoi4FLRQEF7CtY2LgEJfH+AUEC1fWSXb6uhObWQ6c/xwMq8UXwXCZyJqxv IBisnOBMN4ok4C6CYxx8WJrYkFQBTp08MJjXrrnODtJBtN9jCAFxP2VWFKik44pTnFjn oP2Q== X-Forwarded-Encrypted: i=1; AJvYcCXqi44pAdf/8/ON0vXREwgKrYzfzZOOiUlQBeVCQQYzjgwkvLF58OaGECxrmGrLTjHSrMkFdQ56Fe4YfZdi/mDBPdA= X-Gm-Message-State: AOJu0YwPrBfYHbBT7BeHV48jVMPOohJ08qbew/njuSfrtjPxPjWS/KPl iSOscDZ3llcC2GD6QqhtI9n+G8wtFVHdv/NRopwQ7Yz7NRyujouqOxV1b7c9Xz5uks3k3oziPkz t8505CDhzNtIo1C5qQAjDcjgtdSU/PKlRTp8u X-Google-Smtp-Source: AGHT+IH3TDIpNCaYMTQZlOi85LYjn+dvBlxPFGo5G1vYUeXdPfkUltL8KE3MmqhV51gK1ANwsFmTXaFiSRhSZg4EXVY= X-Received: by 2002:a17:906:4789:b0:a7a:9447:3e91 with SMTP id a640c23a62f3a-a7dc4e9b1c4mr944137566b.39.1722903331492; Mon, 05 Aug 2024 17:15:31 -0700 (PDT) MIME-Version: 1.0 References: <20240805232243.2896283-1-nphamcs@gmail.com> <20240805232243.2896283-3-nphamcs@gmail.com> In-Reply-To: <20240805232243.2896283-3-nphamcs@gmail.com> From: Yosry Ahmed Date: Mon, 5 Aug 2024 17:14:55 -0700 Message-ID: Subject: Re: [PATCH v3 2/2] zswap: track swapins from disk more accurately To: Nhat Pham Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, shakeel.butt@linux.dev, linux-mm@kvack.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, flintglass@gmail.com, chengming.zhou@linux.dev Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: BBCDA2000E X-Stat-Signature: wy9tmswg5bhddquswwf47jjfe6ifbapa X-Rspam-User: X-HE-Tag: 1722903333-947602 X-HE-Meta: U2FsdGVkX1+fFRJ9z6YIdJuzzI8ceNY64Eyu4Rnu8nbMBqjICOqfn+DLmJPhGNwYwTDA7DMzoBJNo01Vrtw4lcX9WpVx+0pYd8hVbKWlw9M+/uVBMfuY+uoqY+nKxZaCbtco5LsvfTvZoe5vYeIZ6s3/Bu6PPhv6BkSPyo56FQw4CzTdzCdxpwAlVo/iFQr2HjAbW9cPAW5L3ZxO6xrigfiuK1GpcjWI6lc+b6VC9LiLmVzEoS4+UNsO9PPwOEGTxLYHbEQ19Q70NzxbPAAwiYWoPn4lhrrY3bZFSE7dr/PDTuAMjxpPGY2PiQ4iHEICI+T94hCkEn6GnyiNS/18HnJXssIGPukwSnuVqbgf2jyIaku6FRuvRm2OSvFt0fqMYqjXoW9mdr+d2YmDCO8vyUUkpZNdESmaJP/P/E3gosquHMNe3arOJ/DY4ziI3NOTvCAXQjn6iNE4GvPNKpkhFQLP7j3Vfc2gbvfDQBxCj+mlTYOeBPkI7fuH6EbFctK5KDpCPvr2hYHtrjQssaeZz/1ERX8s4Ve/GPKN6Q21IeDLGMK9qoouwLkAINFeBOnQXmVD1ADBcfsVzC3v03ENs8V37sSGgoDMmeQ9v8J+PzJI0Xcl+NhEaCR/ONt4nh9zuLVH9a46FbvgMVHJUOHbGvnDjNyNDuteyO+X3copoTK3cMNMjflan67cboWAf46Kh78f/6O/3GF4yhcG/EArwEDSfKigP4XX9NZxOxasVNLHTpkfqYI5hfSB4ZBeXKKo6eYSTB/r/2DEBqpnV/bGcgBLQ3Arc0RCopluio/Jm2XPVoYylpjiojMsnmzdh5zgrjlWpfnXZLh/Z2nXUcHB8tX3B3tMIWINJnat/FDaT00cdtlcVYmNMw5te3fxbESUTZvslVKYRskbwyQQ/EKhBkkYkS3bWDliasiqBjBueG6vsxV861v46AhknT+qjJs9FrTWQpMhF/9JKPTde9Y yKGi9YLM l/0erewfhG0q4JnDNJ3lNzwxnRLoHSnyZCyuhDnaA5EYomLWMifXAcHJh19avPnny/AneZ7zD8VQPmyyIA9t+kWUf2en6EXJlNmvvs9uhl0Fvb6wznQ//mD8yAWbCtF5uP6g70pSp3HGlTdWi8Ka/27bLIKE0xCNcBHli25EpfoVVJfJrRTChw6T7ElBlFNtEs721zMdiLFB5RaeVVeI5xHvoGEIWwwFQ+WKLcr8VTWXXtJv4V26qVh72WrbfLFJ+eHkFBd8Xhg0j1FEl9bOVPweRWA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000022, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Mon, Aug 5, 2024 at 4:22=E2=80=AFPM Nhat Pham wrote: > > Currently, there are a couple of issues with our disk swapin tracking > for dynamic zswap shrinker heuristics: > > 1. 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. > > 2. We are also incrementing when the pages are read from the zswap pool, > which is inaccurate. > > This patch rectifies these issues by incrementing the counter whenever > we need to perform a non-zswap read. Note that we are slightly > overcounting, as a page might be read into memory by the readahead > algorithm even though it will not be neeeded by users - however, this is needed* > an acceptable inaccuracy, as the readahead logic itself will adapt to > these kind of scenarios. > > 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 Combining* > 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. > > Fixes: b5ba474f3f51 ("zswap: shrink zswap pool based on memory pressure") > 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 swa= p_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 p= rotection. > + */ Can we fit this on a single line? Anyway, LGTM: Acked-by: Yosry Ahmed