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 E5BB2C83038 for ; Wed, 2 Jul 2025 00:31:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 68AAA6B00D8; Tue, 1 Jul 2025 20:31:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 638B06B00D9; Tue, 1 Jul 2025 20:31:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 54EEB6B00DA; Tue, 1 Jul 2025 20:31:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4479F6B00D8 for ; Tue, 1 Jul 2025 20:31:34 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D641F10734E for ; Wed, 2 Jul 2025 00:31:33 +0000 (UTC) X-FDA: 83617446066.02.3086976 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf17.hostedemail.com (Postfix) with ESMTP id 0C2CC4000B for ; Wed, 2 Jul 2025 00:31:31 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=IBmSV8Ah; spf=pass (imf17.hostedemail.com: domain of yuanchu@google.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=yuanchu@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=1751416292; 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=UNyRC6n8pZY3KnOpU1YR78OZYzfubaOPbY/4YQWNz6Y=; b=7mJv7xRkDGJcEUdKqVkA/x0ds47esHugA4dmY8l2q3viYJXJJcWn+twY9G+EjL7h8jscYj alLdfkA35iNXDAzggeWx/aXWkMVEG+xjx3X8by6t8/Cz2h+Mwnp/BDpShRWf3c4hSzI0dR uTUY+8wPhZJUHDxWLoVmVy4MmMqZau4= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=IBmSV8Ah; spf=pass (imf17.hostedemail.com: domain of yuanchu@google.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=yuanchu@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751416292; a=rsa-sha256; cv=none; b=Egcb0VLlS34ySZ1jfbfRcGbQJcpC8U9QewKpHVRuIlDRkImUhkzvUzxA5qdoTSESjh9Kml BpOijUU2htUIJ1GrzmZ3ZHw0O9wowzAho9neu+ZuNJa/Vdra5MFFppMVy+F8QlkkBPjhVk VCtmi/1Z7p7fKl2akiibuKB51mqdbYc= Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-237f18108d2so312455ad.0 for ; Tue, 01 Jul 2025 17:31:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751416291; x=1752021091; 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=UNyRC6n8pZY3KnOpU1YR78OZYzfubaOPbY/4YQWNz6Y=; b=IBmSV8AhTol/Eib9+WKHeGaRUW24015rUfBI3YYhNOqfvo52QGYyXksp6a9FDuPhXx n8JAItAUR8oVNWWveP2w5TvKGEwe8hq+7LEllCuy3wlo/WhuQnqMFshQsLIEp+FUp971 +m9xP9NYO1FtCmSa2+C2sK97AoU2ZLoaKJEBteIwSOci7CHxEb4SIe9gXswtJoZX8BGX k0cWsQICnctp3/qdof/glqib68HiO30j4r6JrYoqc6gXvwjCmiRhJJR3WfGUhNbTlpgQ M+iIruYudTtWZ1r0zAKte3PXbOw1MIc+l8aOFFDaianeZPdh4BPprto0LTq0jEsUQE3U Slcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751416291; x=1752021091; 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=UNyRC6n8pZY3KnOpU1YR78OZYzfubaOPbY/4YQWNz6Y=; b=jJ4dKU+4AEUaWORz96MHG9ryTefvatE1GAHYkwtAg7XMMXI0unWLSFhUuJgjwqtaJQ NtCZpxyLWjMy73VgCfRjyTLsqqwlOBC5cZUeQbDDLjgZGrvlONWacWXUmQYoi5E1vG8+ fXgVEtYV9/gto443jBL/Q/kq1ib3EBnxJQLbso9mHXsVSERUO+6UA4o7N9DSiyIOKxDu kBYFW7FaxFNrh72clgPUJzah2alliA0neYFop76gmVxaiGFNc85n6nZndjLKwa9e37x/ KmFLyp9xEQcpna8Sk8rE8kPwUE2qS9kYUJiaFfmfMLadnsFjT6CWqSGOwN2zQkbDrHZy F+Aw== X-Forwarded-Encrypted: i=1; AJvYcCW2n1rjsUxxpplZGEWZlhEVTlwPpXkpHOSmQEmsVjUESs9s4nVCNPOtIiC58kI7qHiOi9/bfzzcKw==@kvack.org X-Gm-Message-State: AOJu0YzU5wfPvpv3mtjzhnZjuF4m2KleugmE1wVCjzmdbPjahwhlRKUS E3/LyXMnptCmzHHWAc54+eTweje3jp3w58S6CiLfE4wJPTIQ5/P7L46EOeM02bxz/ZZ4MDmgvI7 Xsoftd90sC7effittmUqpe6Dzw5Zql7ER3uIv6mod X-Gm-Gg: ASbGncugPx6Uv6LhR+q5L1ar620YqiFMTTVQ+PVxONB/ysMsRUIA4LVeb1Bhjb13lP3 ZqObHf/o/JI+R2q2qBkx869tRTlKTu5KAY38UpKGdKlkbaTznxTdKGlLJMk7ndAVsf91nhy6XCZ sMl0RSIW6oG+8M7coNrtg4a7eG/8mPet2Vhe7ippchNcI= X-Google-Smtp-Source: AGHT+IGUumd5nbkwerjTRuTS5MsiUEJyQlxvPQ6oEN4zMddkaaHoI+CgrAbDk5gtjz0/RYY1Dc9FM675+CDe6jApn60= X-Received: by 2002:a17:903:1112:b0:22c:3cda:df11 with SMTP id d9443c01a7336-23c5ff0723dmr4432595ad.10.1751416290521; Tue, 01 Jul 2025 17:31:30 -0700 (PDT) MIME-Version: 1.0 References: <20250630080603.36171-1-jiahao.kernel@gmail.com> In-Reply-To: <20250630080603.36171-1-jiahao.kernel@gmail.com> From: Yuanchu Xie Date: Tue, 1 Jul 2025 17:31:13 -0700 X-Gm-Features: Ac12FXyKl7BufdimK-urCRewhoe1OH3xwr5f_fDhhkztRRmlCdR63ldZBaBfX2E Message-ID: Subject: Re: [PATCH] mm/mglru: Stop try_to_inc_min_seq() if the oldest generation LRU lists are not empty To: Hao Jia Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, yuzhao@google.com, kinseyho@google.com, david@redhat.com, mhocko@kernel.org, zhengqi.arch@bytedance.com, shakeel.butt@linux.dev, lorenzo.stoakes@oracle.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Hao Jia Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 0C2CC4000B X-Stat-Signature: uaepq7n9o5ummd8dkbkwmf45ch1guy3g X-HE-Tag: 1751416291-114352 X-HE-Meta: U2FsdGVkX1+MgzRl9iBMbhNGN/XS/HA1MaG0JrrVZiEJPPsK0MYyB1IZrwIJtvVI+rAUjTcCyrvdBIrD9lC4hOrEXPp6YuLyw0B3VwU2fK7lXU6KsJqJh/83bUVm4VNkq1g42yDEeylb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bFK51dEw6m3eNJOrGXNwmnM4sCgwYgOU19U5jiuPJM/w0C2WGf5wSRBKOvcMgla36H/bKvhEmJMXhnQyRwU23pb9TQz6ZK1HUyNJmdbMFulxwh3l1CdTo03/kCn9N3o9dAyh1NNyTbE 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: On Mon, Jun 30, 2025 at 1:06=E2=80=AFAM Hao Jia w= rote: > > From: Hao Jia > > In try_to_inc_min_seq(), if the oldest generation of LRU lists > (anonymous and file) are not empty. Then we should return directly > to avoid unnecessary subsequent overhead. > > Corollary: If the lrugen->folios[gen][type][zone] lists of both > anonymous and file are not empty, try_to_inc_min_seq() will fail. > > Proof: Taking LRU_GEN_ANON as an example, consider the following two case= s: > > Case 1: min_seq[LRU_GEN_ANON] <=3D seq (seq is lrugen->max_seq - MIN_NR_G= ENS) > > Since min_seq[LRU_GEN_ANON] has not increased, > so min_seq[LRU_GEN_ANON] is still equal to lrugen->min_seq[LRU_GEN_ANON]. > Therefore, in the following judgment: > min_seq[LRU_GEN_ANON] <=3D lrugen->min_seq[LRU_GEN_ANON] is always true. > So, we will not increase the seq of the oldest generation of anonymous, > and try_to_inc_min_seq() will return false. > > case 2: min_seq[LRU_GEN_ANON] > seq (seq is lrugen->max_seq - MIN_NR_GENS= ) > > If min_seq[LRU_GEN_ANON] > seq, that is, lrugen->min_seq[LRU_GEN_ANON] > = seq This part doesn't make sense to me. The code is as follows: /* find the oldest populated generation */ for_each_evictable_type(type, swappiness) { while (min_seq[type] + MIN_NR_GENS <=3D lrugen->max_seq) { gen =3D lru_gen_from_seq(min_seq[type]); for (zone =3D 0; zone < MAX_NR_ZONES; zone++) { if (!list_empty(&lrugen->folios[gen][type][zone])) goto next; } min_seq[type]++; } Here, it could be that , min_seq[type] > lrugen->max_seq - MIN_NR_GENS (what you refer to as seq) However, this is a result of incrementing a copy of lrugen->min_seq[type] as this piece of code finds the oldest populated generation. next: ; } > Then min_seq[LRU_GEN_ANON] is assigned seq. This is not necessarily true, because swappiness can be 0, and the assignments happen to prevent one LRU type from going more than 1 gen past the other. so if `min_seq[LRU_GEN_ANON] > seq && min_seq[LRU_GEN_FILE] =3D=3D seq` is true, then min_seq[LRU_GEN_ANON] is not assigned seq. > Therefore, in the following judgment: > min_seq[LRU_GEN_ANON] (seq) <=3D lrugen->min_seq[LRU_GEN_ANON] is always = true. > So, we will not update the oldest generation seq of anonymous, > and try_to_inc_min_seq() will return false. > > It is similar for LRU_GEN_FILE. Therefore, in try_to_inc_min_seq(), > if the oldest generation LRU lists (anonymous and file) are not empty, > in other words, min_seq[type] has not increased. > we can directly return false to avoid unnecessary checking overhead later= . Yeah I don't think this proof holds. If you think it does please elaborate more and make your assumptions more clear. > > Signed-off-by: Hao Jia > --- > mm/vmscan.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/mm/vmscan.c b/mm/vmscan.c > index f8dfd2864bbf..3ba63d87563f 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -3928,6 +3928,7 @@ static bool try_to_inc_min_seq(struct lruvec *lruve= c, int swappiness) > int gen, type, zone; > bool success =3D false; > struct lru_gen_folio *lrugen =3D &lruvec->lrugen; > + int seq_inc_flags[ANON_AND_FILE] =3D {0}; > DEFINE_MIN_SEQ(lruvec); > > VM_WARN_ON_ONCE(!seq_is_valid(lruvec)); > @@ -3943,11 +3944,20 @@ static bool try_to_inc_min_seq(struct lruvec *lru= vec, int swappiness) > } > > min_seq[type]++; > + seq_inc_flags[type] =3D 1; > } > next: > ; > } > > + /* > + * If the oldest generation of LRU lists (anonymous and file) > + * are not empty, we can directly return false to avoid unnecessa= ry > + * checking overhead later. > + */ > + if (!seq_inc_flags[LRU_GEN_ANON] && !seq_inc_flags[LRU_GEN_FILE]) > + return success; > + > /* see the comment on lru_gen_folio */ > if (swappiness && swappiness <=3D MAX_SWAPPINESS) { > unsigned long seq =3D lrugen->max_seq - MIN_NR_GENS; > -- > 2.34.1 > > I don't understand what problem this patch tries to solve. Yuanchu