Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1909140pxp; Mon, 21 Mar 2022 07:28:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBAnqyAzem1dtjbmMsW4M2p+KUTEa+ywBjQNPjGSOMqdt7NX+5vxD2jUynqZpkDsrtB6qu X-Received: by 2002:a17:907:2ce3:b0:6df:d819:8b98 with SMTP id hz3-20020a1709072ce300b006dfd8198b98mr10346254ejc.130.1647872924977; Mon, 21 Mar 2022 07:28:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647872924; cv=none; d=google.com; s=arc-20160816; b=DP+O1gXtXbYVc+Gg5OamzKxhw6Ek4rzfltJZXndHJls81Pdih0/iQ4wVRqfSpQ3UmO eRg8DqitpqBDxuACf8L2NL4HXgF0Eet9sL/ayNiBkKU8gxWh+mz/udWpXJleEA48Y0Sn jzl58nNuxNtwM5y5E0E0J4am/153GdFOTo9Pjc7EJyUR8GkhV2elSVrkVCbchCY4l8r+ 1g3tG2cKdwoQmM8pWhkMc3N4cT4jygGs8D26J6Wu2Y4c/9wgL5XZgkfc6ff+mu0erk2W v8BpXPjY/44lWe06ptjKCqMw3q2Sr6pNCbKVHPjz9e98ocdSPtyVAra9bTk97NQ38go2 4C4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=88d829WnB79xpVGm1h0821EVQqb5oWwm0bb9EwNJMDo=; b=JPWVb2YgeHIGU8Gg9e+Bq6dMSEOFwFW4T0qjuRESZRS7/MtOfdRqpHf39t5SfR081v tB5OlxcEhHiUkXTUJO+6tNJTvPQU4pq30L6+9JmPFXuQs+eoM48NLgt4dB3umEekzUIB QLrMAoE4XKdRd84Xv5ZGVif3LpTTphyGmDUMqJl714vqP+qKiSdRGnZYUHOFI8DidkaE ObC/Fi7MFakZ53iJz9H+97vU96OWY/mbQz7IzRwqSgTySDAK+JJIf9OxDLJsmgOqA2rk t7UKxKQcW1NU+ByTPDf7sQv7EGd41w96Td0Y4cW8OMNFODBs0w/KGmLWBkAy8Ss0QAX1 3ZFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=qhGeg5cK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m18-20020a509992000000b00418c2b5bed1si10387957edb.435.2022.03.21.07.28.08; Mon, 21 Mar 2022 07:28:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=qhGeg5cK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346840AbiCULtC (ORCPT + 99 others); Mon, 21 Mar 2022 07:49:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241385AbiCULtC (ORCPT ); Mon, 21 Mar 2022 07:49:02 -0400 Received: from mail-yb1-xb2d.google.com (mail-yb1-xb2d.google.com [IPv6:2607:f8b0:4864:20::b2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E7C511A9B5; Mon, 21 Mar 2022 04:47:37 -0700 (PDT) Received: by mail-yb1-xb2d.google.com with SMTP id f38so27534011ybi.3; Mon, 21 Mar 2022 04:47:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=88d829WnB79xpVGm1h0821EVQqb5oWwm0bb9EwNJMDo=; b=qhGeg5cKrVFOw2yjKtU+GQcTq/4SPpNyUWoLrArrXPKczeCKtnrtpPcY+bo/QzhXx8 cz2PbSvznBni6+X1UQZSEakm1Ol9znZz1TpkwHZqJtBYMxBezuuIf6+Gzjz0XROP1vso xXADlcbnv+8RWGxu1mG+cYH3kVfR72gVxF8nuiMGHKs722ZBmObGn9pAtyGmMRQu6pVB I42OdbIkrTIH+V8YoTztNOfm8ItTILuxMqkNNxPalgLdJ/f+DAQWj1t/xTE7tUtlPt+S WftMZe7Ebmeht1nx8P0v1nm7Qy1u9A7Mew3JGe6ClwSoBOrB+a72EEKz9XkAXy5xTGQv vzMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=88d829WnB79xpVGm1h0821EVQqb5oWwm0bb9EwNJMDo=; b=ibnIbHk3w25UIFjegs+47x4iTxzl/q90CJc4AVAET6HY6RAOOQVQRe80Zf6fU9UgXA sSNSgApf7KVsfHRHEPEvGq70LyYN2AcDq2hmsF9iM3Q8YQzm2ajdrRMeMH/280cfethK t+hpT3D8fe8yTBBsuOAQTSK7yE547ngcd/sRMxfu+upeBkEUPpKkYYxLicmsR4qC6k25 5z/19hrf1k8n/uUe/XtGWktIW2kzIVoQpPQXYdt/6sCcZ0FqM+sR/kKxrI8/TcMOPf68 qH8HOa1O+hPeTHjWjnNASlAPrDNV89xj7yG48Wvwpn4FVvjEc6YbyBgKl9E0CO4gVaCf VfIA== X-Gm-Message-State: AOAM532hazmb6ofnfJkB4pQz4bN4+4f2r/hb34Yv9vsUjA+2AbF8Y0ZI Mjqdn9jCjNjHT8UMAwB+OCmQC4+NA8WEPFY+/bZg6/Om X-Received: by 2002:a5b:807:0:b0:633:747:c7d1 with SMTP id x7-20020a5b0807000000b006330747c7d1mr22101647ybp.294.1647863256380; Mon, 21 Mar 2022 04:47:36 -0700 (PDT) MIME-Version: 1.0 References: <20220309021230.721028-1-yuzhao@google.com> <20220309021230.721028-6-yuzhao@google.com> In-Reply-To: From: Barry Song <21cnbao@gmail.com> Date: Tue, 22 Mar 2022 00:47:25 +1300 Message-ID: Subject: Re: [PATCH v9 05/14] mm: multi-gen LRU: groundwork To: Yu Zhao Cc: Andrew Morton , Linus Torvalds , Andi Kleen , Aneesh Kumar , Catalin Marinas , Dave Hansen , Hillf Danton , Jens Axboe , Jesse Barnes , Johannes Weiner , Jonathan Corbet , Matthew Wilcox , Mel Gorman , Michael Larabel , Michal Hocko , Mike Rapoport , Rik van Riel , Vlastimil Babka , Will Deacon , Ying Huang , LAK , Linux Doc Mailing List , LKML , Linux-MM , Kernel Page Reclaim v2 , x86 , Brian Geffon , Jan Alexander Steffens , Oleksandr Natalenko , Steven Barrett , Suleiman Souhlal , Daniel Byrne , Donald Carr , =?UTF-8?Q?Holger_Hoffst=C3=A4tte?= , Konstantin Kharlamov , Shuang Zhai , Sofia Trinh , Vaibhav Jain Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 21, 2022 at 10:04 PM Yu Zhao wrote: > > On Wed, Mar 16, 2022 at 5:25 PM Barry Song <21cnbao@gmail.com> wrote: > > > ... > > > +static inline bool lru_gen_add_folio(struct lruvec *lruvec, struct folio *folio, bool reclaiming) > > > +{ > > > + int gen; > > > + unsigned long old_flags, new_flags; > > > + int type = folio_is_file_lru(folio); > > > + int zone = folio_zonenum(folio); > > > + struct lru_gen_struct *lrugen = &lruvec->lrugen; > > > + > > > + if (folio_test_unevictable(folio)) > > > + return false; > > > + /* > > > + * There are three common cases for this page: > > > + * 1. If it's hot, e.g., freshly faulted in or previously hot and > > > + * migrated, add it to the youngest generation. > > > > usually, one page is not active when it is faulted in. till its second > > access is detected, it can be active. > > The active/inactive LRU *assumes* this; MGLRU *assumes* the opposite, > and there is no "active" in MGLRU -- we call it hot to avoid confusion > :) yep. > > > > + * 2. If it's cold but can't be evicted immediately, i.e., an anon page > > > + * not in swapcache or a dirty page pending writeback, add it to the > > > + * second oldest generation. > > > + * 3. Everything else (clean, cold) is added to the oldest generation. > > > + */ > ... > > > +#define LRU_GEN_MASK ((BIT(LRU_GEN_WIDTH) - 1) << LRU_GEN_PGOFF) > > > +#define LRU_REFS_MASK ((BIT(LRU_REFS_WIDTH) - 1) << LRU_REFS_PGOFF) > > > > The commit log said nothing about REFS flags and tiers. > > but the code is here. either the commit log lacks something > > or the code should belong to the next patch? > > It did: > A few macros, i.e., LRU_REFS_*, used later are added in this patch > to make the patchset less diffy. sorry for missing that. > > > > @@ -462,6 +462,11 @@ void folio_add_lru(struct folio *folio) > > > VM_BUG_ON_FOLIO(folio_test_active(folio) && folio_test_unevictable(folio), folio); > > > VM_BUG_ON_FOLIO(folio_test_lru(folio), folio); > > > > > > + /* see the comment in lru_gen_add_folio() */ > > > + if (lru_gen_enabled() && !folio_test_unevictable(folio) && > > > + lru_gen_in_fault() && !(current->flags & PF_MEMALLOC)) > > > + folio_set_active(folio); > > > > So here is our magic to make folio active as long as it is > > faulted in? i really don't think the below comment is good, > > could we say our purpose directly and explicitly? > > > > /* see the comment in lru_gen_add_folio() */ > > I generally keep comments in a few major locations and reference them > from many other minior locations so that it's easier to manage in the > long run. It is a hassle for reviews but once in the tree you can jump > to lru_gen_add_folio() with ctags/cscope or find all places that > reference it by grepping. Assuming we state the purpose, which is to > make lru_gen_add_folio() add the page to the youngest generation, you > still want to go to lru_gen_add_folio() to check if this is really the > case. So why bother :) well understood though my pain was that I needed to email you to get confirmed this is really the case. Thanks Barry