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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D74A8C433FE for ; Mon, 21 Mar 2022 09:04:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345611AbiCUJGB (ORCPT ); Mon, 21 Mar 2022 05:06:01 -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-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" 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 :) 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EFB55C433F5 for ; Mon, 21 Mar 2022 09:06:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=q9XlngQhILbllPvhIabYoDCOvbC5ReKCT+JLqUTY3aI=; b=D6dsyEprfLwIlW yPAc6HW4NuukHeSn9XpnHOse4hHzxsPVNk2mo/I5zplbqyx+MSHOzQGoVxN8UamrWRTRSDZT2va9s n9xe82LFBNoQCDnmAT2YJbrTHLiUcZVNR8FPqAfcNPTcHXYFYbC6nw7LxlVCGrsrK3FUi6m/NMDNI wP32d0AclMwcm0Rx/YNbUHh1Kg+HeuPj6+sIdbNEdg/xHgCKHsDRzVlOrvTooHwTuIq1TFRYFnXYM GYgqgipTKWGruGoGgUMSTCBPF/p+i8j2UHNehEQ45HjWfl41zAjsuBitiX922XU1eYNBmtAlma6mX gem2dZ5UdTJ4IEB3GFkQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nWDxw-0076HX-Hp; Mon, 21 Mar 2022 09:04:40 +0000 Received: from mail-vk1-xa2f.google.com ([2607:f8b0:4864:20::a2f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nWDxs-0076Eu-8t for linux-arm-kernel@lists.infradead.org; Mon, 21 Mar 2022 09:04:37 +0000 Received: by mail-vk1-xa2f.google.com with SMTP id d7so7569152vkd.11 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=UWvrjPBPUMA0VOvigvA/xRax0XNPVC6S1yJtVNUiM6FsY0J+emUqSyRvQXIF0241iZ PaEBq8xKwe2hvzZ1MG0QHDVZYyQinIA1CycIw1WeZH0Rk8Iw/20n3S7i6UrSaY4/waqz d5jh7dixDAXT6JKXTnL29gnI/2W6/iARG0DBABM+F2068cO84akMQ/uhcgUI6YHlE9qy yukU0KZh4TIpseDV7eFoR/cU2PN6/OuVVj7QKVJpG1hZwtG69243fsV7n2O2iqRB6v5z vn46HhwtVbo79pB6OiTnRI2DrF64uRgg8QSnhqCeOIcwJkE/P5uqYvDBft2lc9pjJHng H9Hg== X-Gm-Message-State: AOAM531ispalc9j95Z1mG12ubDun+f+rY9P3cKKEDTSUt7AeIGlGzfCE 4mKe4WCIxyynYddcA5gJde4rNttyM1h9GSxPem7omA== 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220321_020436_341438_5014726E X-CRM114-Status: GOOD ( 29.84 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 :) _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel