Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2285077pxp; Mon, 21 Mar 2022 15:53:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzaLUoQkZNjIrdjDCSIVRYWYo7I5GgMhHa1p5kMR2JC/5JX74l4SH1p6nmMh5eyabCcYS6I X-Received: by 2002:a17:902:9308:b0:14e:def5:e6b5 with SMTP id bc8-20020a170902930800b0014edef5e6b5mr15020696plb.73.1647903217490; Mon, 21 Mar 2022 15:53:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647903217; cv=none; d=google.com; s=arc-20160816; b=JY/W3b6XJ5JiFxpb/0ZryKa1tgRJNd/VSibTYPPKRiL1JMYOxdzkr/9reQzUJdRY5H xvBnq4M+Z6pyMjjcN2Y+F89hZWnTD5dyv946mPKA/3Ktxee05AzDa8kNmloMS8n71ek7 pE2+AcNKJbjGK5aGVzjEDf5JrTLHsDHZN/DrBii3InF/vVpj/P8ooLXx3oSmajEPtarI XDpNuylxeDLL6O8/1daIa4haWtwYz33CazguG4upm+rMCXUhRnakM1eRsZ4CzwS/7ulY 3/p5L4trrRy2yVmoptTuWn+U7NecvMsOTv+bhAhoN2Gs7sqOxgKf1K0nD67lV2JvKUZK lt7A== 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=BSajJ2xfMXe0EesuiYqSnQHfA+SOs3A5X1wQXKbJeiY=; b=CNCt5l97wuYrs5PzAkV1IOVLcMIQgvdadF/DjiZqvezDLRCv/9pt0o6afATw2cZZYA pDkPs6WjcmydnAis86Vz/bGjOumSDTyv354YmWxY/c49TqXf/pl8m7E55xVYx4hR76DJ eVLfJQyRy05FmJQBjmZMEJUo3T/89HDgDTigNeRMSb7pK1TVEpn/81Wyo/pBZrVt2IKl dZEj3fbCJ+BAXy10cxfpS3fIEKQCU0PPkmnTg1UIIFMhovrYBMsMXAc05oh+KSTv4plo o/kJBT1HPtFc6LMXMn8Il4sIjRnw3ESjgYnfWd8h76232YoJmu0nw/zZSB7u+j73NoVj /dmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=mhKgHTFz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id g1-20020a639f01000000b003816043ef94si15178508pge.393.2022.03.21.15.53.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 15:53:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=mhKgHTFz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E0EB16E541; Mon, 21 Mar 2022 15:02:55 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344573AbiCUJGA (ORCPT + 99 others); Mon, 21 Mar 2022 05:06:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235161AbiCUJF6 (ORCPT ); Mon, 21 Mar 2022 05:05:58 -0400 Received: from mail-vk1-xa35.google.com (mail-vk1-xa35.google.com [IPv6:2607:f8b0:4864:20::a35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2004013D7A for ; Mon, 21 Mar 2022 02:04:34 -0700 (PDT) Received: by mail-vk1-xa35.google.com with SMTP id q85so315912vkq.4 for ; Mon, 21 Mar 2022 02:04:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=BSajJ2xfMXe0EesuiYqSnQHfA+SOs3A5X1wQXKbJeiY=; b=mhKgHTFztD4oE1EO0aenWDmlULX65b1m4LYL+6Va/xTwD8g+WylKqkfidYvvemJqQE sWKW4q+jh7O+QPqR5QigKYyd3Ed+LdIBHLCNLL83S6Aom8OkqzFm9eyF0iShDfNjahjk qSWGbA5KIK+XiK2K7lI+QTSvEbFkotgelp3oVrQ7wng+ePpozZYjgCAini9Dbk4oad88 zNn4JUZ2F3CNGX70mqq43GUbix/DYaiELvDjkJb3a0Nwz26CP2Uf019q5/IOHIQJWDq8 wPwl9GGmEspIMrKwLSmP11v9e7Vgy3/0p68Nv+V1o+IrDFUwu5BpAkabzo4k+hn7I3FE z1Bg== 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=BSajJ2xfMXe0EesuiYqSnQHfA+SOs3A5X1wQXKbJeiY=; b=b/U7Ac0rjuTpswosemLfqopgCj1528n04Rv7sqYi4zMS6mvSuhlpV3WSEfg7U1FEZg XgeUD5U8Kc+WC1UZORtaWd/h9PnIsYcfjzSOL0m00ETYAv43chJOGU70ESDXJo0bSmIE IIhI++68F9an7XVGxHn+X/2lXEN+kI+2DoizF51jC6JvVKxr83fzqm+IxvCGuc+ec2hl 2n2YHuTY8oFRAL7VX5P3U7Q9eFU6IH8OYO1AyqXaV+hVSsw/je0qu4Kc4feGZJd0NPwc t8WTKueuV5o+W+3qe8CXRkqcbTieKLC2bM3A5b1gbu715JPnjXnUlTrY2FocmL2gJJjL lRvw== X-Gm-Message-State: AOAM533SDMLMoanWlwtBnlDpqnpIJSyYpc82I0eZwWfpuLWhhSaliEAd NhjwijgA7Gfhiz2VXvSQwzjy5lAhMUSl8V76AMjlxg== X-Received: by 2002:a1f:314b:0:b0:331:fff6:a89e with SMTP id x72-20020a1f314b000000b00331fff6a89emr7275468vkx.26.1647853473054; Mon, 21 Mar 2022 02:04:33 -0700 (PDT) MIME-Version: 1.0 References: <20220309021230.721028-1-yuzhao@google.com> <20220309021230.721028-6-yuzhao@google.com> In-Reply-To: From: Yu Zhao Date: Mon, 21 Mar 2022 03:04:22 -0600 Message-ID: Subject: Re: [PATCH v9 05/14] mm: multi-gen LRU: groundwork To: Barry Song <21cnbao@gmail.com> 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=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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 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 :) > > + * 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. > > @@ -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 :)