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 E68ABC001B2 for ; Thu, 8 Dec 2022 18:08:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6900F8E000C; Thu, 8 Dec 2022 13:08:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 63FE98E0001; Thu, 8 Dec 2022 13:08:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5097D8E000C; Thu, 8 Dec 2022 13:08:04 -0500 (EST) 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 41AB08E0001 for ; Thu, 8 Dec 2022 13:08:04 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 18236A0670 for ; Thu, 8 Dec 2022 18:08:04 +0000 (UTC) X-FDA: 80219922888.27.074B9B3 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) by imf26.hostedemail.com (Postfix) with ESMTP id 650A014000E for ; Thu, 8 Dec 2022 18:08:02 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=fKAHAf0T; spf=pass (imf26.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.221.53 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=1670522882; a=rsa-sha256; cv=none; b=lJ/DSEPoRvEY8UpaEDyExW6Q7V5fRmi3wp8fYFsT+ydLySQ1OKEl/QlhIW8HJR9ef27EHL m1KUhYDMsUpojguP+E6S/o3P2DKnj781P8QZNVu4p5dAYZoezndqy2PEEjj4ClJhe3aOC5 2UXLscrwfYayyhnjeQYu3YnS4sJ+i30= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=fKAHAf0T; spf=pass (imf26.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.221.53 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=1670522882; 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=TT+Voc8metN7pfdLgSuHhsI+ICrLJs1/K9Jt2tVGNSc=; b=IHp5+lKsfnqoW1grU89aGokA2/cGgfF+dMNmyrf+VHgUbmkCP79aSmky+gjsmxQVixepEj MHCKX9hctY3l7U4qidnRcEXDGi2xuQRbpFylM6qlVxOSMz2ri4I69RRB3ijqZJ4XyJiuRN 8LkHeHLru+l2ORAnlaYIcsN8oJk71Uo= Received: by mail-wr1-f53.google.com with SMTP id h7so2583989wrs.6 for ; Thu, 08 Dec 2022 10:08:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=TT+Voc8metN7pfdLgSuHhsI+ICrLJs1/K9Jt2tVGNSc=; b=fKAHAf0TzQnaeEWXQZb82rftHD1haj/5raCbmX4mH3M4z4i9I2mEXWBdoMOthflr2O Qu1/5LaUH1PdJbT0soPGXjZq0gvC+JCkv2e8U4JB3+9M5XHssvK+7gUMuOd672CsppRL 8atXZy8SJTvwUAEJPSz1KOQhzk//HP65ATDPxrHLqv/hGzQ9cXhYsfUISV1+rTpW40Gy pyRNuZwQp2qr/e17yW1/byAZfOn4DsOfxT2N2CALp4V1aEVZYEYy8uONsqbv5XrziKMe hRqLlpdkv/YZozg1xudnU+rlDhUGfbwqb8RAkJ9kg3C40bZ31kgFjGtvKFzGKBfrociU fg1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=TT+Voc8metN7pfdLgSuHhsI+ICrLJs1/K9Jt2tVGNSc=; b=6GUsoXSxUvnTE169g3Qoypq7r/oFSdLVWkkbgL4fmwHVjuV2dd0PdU+broWYkZ70yk qR95mlR5y0vDq1cRga/fE/ZmwDODaK7hf7AugfOJhEIrkvl3+Fjsiy+dmHVN1KGXt6JM +wznSo3K7P0lIe2NrPS0egQ8vEd1krYtf5O+m3Nknh8kYUZc+qzsRajeJaaDe/llFAuu EExnu317WLhQPvoH8nheFGh8oNLZWIhuEH4oeyEhhK5TDJxIigPUyJO/FjaDRkWo3hga 2Sc8lSNDRg/6DAiQoHUe/4IeB8P6q+pnjtuGmtfYfTdTmqwFSD5dySWt3v9ynhxanPsJ EPyg== X-Gm-Message-State: ANoB5pkpyTzdIMTy9qwWxDXJkzaWmY5/FJlXEqXVa2GHeY3vS3mBmp2H /1S1upsMzoWU1BqpxCTFbpV1XIc3J+0kAuCnNGE= X-Google-Smtp-Source: AA0mqf7MQtXUXyDy/9IOtmVh7ixnBHksG/E6FoGBme+KKN2Jmd9b62NpV4CZw+oBME1SnbH3f1UqxpnAJysSQDntSuk= X-Received: by 2002:a05:6000:1084:b0:241:f866:6bc8 with SMTP id y4-20020a056000108400b00241f8666bc8mr38140489wrw.501.1670522881019; Thu, 08 Dec 2022 10:08:01 -0800 (PST) MIME-Version: 1.0 References: <20221205175140.1543229-1-nphamcs@gmail.com> <20221205175140.1543229-3-nphamcs@gmail.com> In-Reply-To: From: Nhat Pham Date: Thu, 8 Dec 2022 10:07:49 -0800 Message-ID: Subject: Re: [PATCH v2 2/4] workingset: refactor LRU refault to expose refault recency check To: Yu Zhao Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, bfoster@redhat.com, willy@infradead.org, kernel-team@meta.com Content-Type: text/plain; charset="UTF-8" X-Rspam-User: X-Rspamd-Queue-Id: 650A014000E X-Rspamd-Server: rspam01 X-Stat-Signature: mowyeeuz845irn3sbqxw9i1zp79ujtui X-HE-Tag: 1670522882-364694 X-HE-Meta: U2FsdGVkX1+AUImLGamQ8NCLIdfaenAXORzpmGbQ1TYaPftuq73VAORZ2RvJTWBvv6N3RSDvdytTHzsbA0yGRNM0swInicChufnIctKjanqVnu4hSkeRS+qJhdytq/4rkvYEN2pJr/XjNxDZxkDY7Mp89T5aHLCinIG9nzo23flmbnPM2l+Srmnlfa7ZIygG3eFpWvxnqqOjKUDBDC1XBw8A8wPIHGslmelgiwoU8caGuLxBuvWl8CPdY0xbWjpBAD9ESIcRZcRard3crZefy5gzeK+HTd4MKM5vgYXXOyb5x8lM0Tn7j/QJab3AMZVHCnPEzwFXKYY0LNoPU7vCmlS4QScRhRJ/EsHNFMfKM13u62CdtRb5XaZ+IFwzqP631u3gbwwZMF6nB6G2gsJihYN2kJkudxK6fs4Bj7NHkuHTPN9YYUpXsG0vZsAz8XpbE09m0c/5LQXNlmoS5Pv4UWmNeRrGgzVqDqSwDi+3G3QF6J1dCcB6RGWmoSPlVl+zl624tikgKnf+tAJsrA6uag6oDwhFH/GZtvLG11p7n8z4CIQPDl5603Wq9NqFkolUSvWKtbKrxNcxoltKcxu3FO/bob0KlKzuBcMEAItWCdary5X62nanpEtqAhoOwIUBNjTW7fLtI1is5hOQwge6rqGxJ0jEzdf/NJp7yA5ik4vt7nPV182LNIVCdf+IoXmgJT4IvYL/YhcPs+q05sgeh40QrIgw2jBwoTbhR9G2/W9AGf0XsgsWaHYxIantUG1sd4kf2i6Y2mcBNuLi/QwQO4XwXb+5Ze26IgSB6V/QWpuZ7q6WhEwwnh/KnqEua5gJ4agVo8awPQOW47qugel0I/iC2S0SEO8fYEP+5UvvL3ATqh+/GF918AOeLednqkCrR8kwDWl6OCO1szwQP0/kO0vvLkvFf2uoINAkRLxKMv0sZyZrcYArYU6pU//j4muHYoB3oy8OrUS7qe2bWEO xBpYmtTG TPNq3itxXxqxzXgblTSEtZz9hLPGUJ1xNkeWENgnjiFLfiFtVRGvly/RCcw== 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: On Mon, Dec 5, 2022 at 6:26 PM Yu Zhao wrote: > > On Mon, Dec 5, 2022 at 7:22 PM Nhat Pham wrote: > > > > On Mon, Dec 5, 2022 at 5:29 PM Yu Zhao wrote: > > > > > > On Mon, Dec 5, 2022 at 6:19 PM Nhat Pham wrote: > > > > > > > > On Mon, Dec 5, 2022 at 3:49 PM Yu Zhao wrote: > > > > > > > > > > On Mon, Dec 5, 2022 at 10:51 AM Nhat Pham wrote: > > > > > > > > > > > > In preparation for computing recently evicted pages in cachestat, > > > > > > refactor workingset_refault and lru_gen_refault to expose a helper > > > > > > function that would test if an evicted page is recently evicted. > > > > > > > > > > > > Signed-off-by: Nhat Pham > > > > > > --- > > > > > > include/linux/swap.h | 1 + > > > > > > mm/workingset.c | 143 +++++++++++++++++++++++++++++-------------- > > > > > > 2 files changed, 99 insertions(+), 45 deletions(-) > > > > > > > > > > > > diff --git a/include/linux/swap.h b/include/linux/swap.h > > > > > > index a18cf4b7c724..dae6f6f955eb 100644 > > > > > > --- a/include/linux/swap.h > > > > > > +++ b/include/linux/swap.h > > > > > > @@ -361,6 +361,7 @@ static inline void folio_set_swap_entry(struct folio *folio, swp_entry_t entry) > > > > > > } > > > > > > > > > > > > /* linux/mm/workingset.c */ > > > > > > +bool workingset_test_recent(void *shadow, bool file, bool *workingset); > > > > > > void workingset_age_nonresident(struct lruvec *lruvec, unsigned long nr_pages); > > > > > > void *workingset_eviction(struct folio *folio, struct mem_cgroup *target_memcg); > > > > > > void workingset_refault(struct folio *folio, void *shadow); > > > > > > diff --git a/mm/workingset.c b/mm/workingset.c > > > > > > index 79585d55c45d..44b331ce3040 100644 > > > > > > --- a/mm/workingset.c > > > > > > +++ b/mm/workingset.c > > > > > > @@ -244,6 +244,30 @@ static void *lru_gen_eviction(struct folio *folio) > > > > > > return pack_shadow(mem_cgroup_id(memcg), pgdat, token, refs); > > > > > > } > > > > > > > > > > > > +/* > > > > > > + * Test if the folio is recently evicted. > > > > > > + * > > > > > > + * As a side effect, also populates the references with > > > > > > + * values unpacked from the shadow of the evicted folio. > > > > > > + */ > > > > > > +static bool lru_gen_test_recent(void *shadow, bool file, int *memcgid, > > > > > > + struct pglist_data **pgdat, unsigned long *token, bool *workingset) > > > > > > +{ > > > > > > + struct mem_cgroup *eviction_memcg; > > > > > > + struct lruvec *lruvec; > > > > > > + struct lru_gen_struct *lrugen; > > > > > > + unsigned long min_seq; > > > > > > + > > > > > > + unpack_shadow(shadow, memcgid, pgdat, token, workingset); > > > > > > + eviction_memcg = mem_cgroup_from_id(*memcgid); > > > > > > + > > > > > > + lruvec = mem_cgroup_lruvec(eviction_memcg, *pgdat); > > > > > > + lrugen = &lruvec->lrugen; > > > > > > + > > > > > > + min_seq = READ_ONCE(lrugen->min_seq[file]); > > > > > > + return !((*token >> LRU_REFS_WIDTH) != (min_seq & (EVICTION_MASK >> LRU_REFS_WIDTH))); > > > > > > +} > > > > > > > > > > Nit: not refactoring actually looks cleaner to me -- there are only a > > > > > few lines of duplicated code and you can get rid of 4 parameters > > > > > including the unused workingset in the next patch. > > > > > > > > (resending this because I forgot to forward to the rest of the > > > > group!) > > > > > > > > Thanks for the comment, Yu! > > > > > > > > Personally, I prefer refactoring this piece of logic - I do think that > > > > it is cleaner than copying the logic into the syscall implementation. > > > > > > Let me clarify. > > > > > > You can add > > > lru_gen_test_recent(void *shadow, bool file) > > > without refactoring the existing > > > lru_gen_refault(). > > > > > > Set the boilerplate aside, you only repeat one line of code, which is > > > the last line in the new function. > > > > > > (The boilerplate code is repeated in many places, and that's why it's > > > called boilerplate.) > > > > Oh maybe I've misunderstood your original comment. Your > > suggestion is to repeat the eviction recency check in workingset.c > > (i.e keep the *_gen_refault unchanged - just copy that logic to > > *_test_recent)? > > Correct. Thanks for the suggestion, Yu! I'll update if there are complications with this, but otherwise the change will be in v3 of this patch series.