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 70D16C433EF for ; Mon, 21 Mar 2022 09:04:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D2E9F6B0072; Mon, 21 Mar 2022 05:04:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CB7066B0073; Mon, 21 Mar 2022 05:04:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B58506B0074; Mon, 21 Mar 2022 05:04:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id 9FC276B0072 for ; Mon, 21 Mar 2022 05:04:34 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 4EB191213AD for ; Mon, 21 Mar 2022 09:04:34 +0000 (UTC) X-FDA: 79267807668.01.D523A5F Received: from mail-vk1-f175.google.com (mail-vk1-f175.google.com [209.85.221.175]) by imf03.hostedemail.com (Postfix) with ESMTP id F3FAD20021 for ; Mon, 21 Mar 2022 09:04:33 +0000 (UTC) Received: by mail-vk1-f175.google.com with SMTP id 134so5616240vkz.12 for ; Mon, 21 Mar 2022 02:04:33 -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=yjtt9ycsHbUJ5QBYMRIeFRiwman4osJf2LfGt85fojMIcXAavoz/p/c4BR5GTnA75O 3qT0m3vs0dx188nykPpxWa72KdmkVSweZSIOn/lWdmFyMLQKpYOUGnHEkgOtDN9NVPvr inHo1wr/6N1wRcd1yw1KNyI2HL4/5aiNmiO2tSnrWMHiyNxFxQeyhf9mJ7NOroRSdn+X AlAnozJvam5sAvknVORqeFrm6bMIAtPXqAOysbOx6LsdHZOFvpLcSSBvtgey08SA+k8U LXGb1D2exlpxmKxQbVwYhixGoSt5EFm0Ry/S3MWTlzXxUzlvujuno3FbWMxK99jR8yVY c6tw== X-Gm-Message-State: AOAM530zDkDrDypZGCVPabqhFnuG5GUPh1xZeJmy081ZEiEh/2KycI3u 8cln0MAOkXUKW94L2hwt4UZXVGETV2ALbXcFRaOU5w== X-Google-Smtp-Source: ABdhPJxuRciUn+oY3wnewEQkilpGm38vR9ImNxAg3e9AzR+RkgvyjkxY1qoy9t19D3xPUVD8aiVNfRU8zWykxCwstYE= 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-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: F3FAD20021 X-Stat-Signature: 7puprfgir1997sb3z1inreswcykh1tmb Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=mhKgHTFz; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf03.hostedemail.com: domain of yuzhao@google.com designates 209.85.221.175 as permitted sender) smtp.mailfrom=yuzhao@google.com X-HE-Tag: 1647853473-715692 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 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 :)