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 C88C8C433EF for ; Tue, 19 Apr 2022 22:21:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346901AbiDSWYN (ORCPT ); Tue, 19 Apr 2022 18:24:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229599AbiDSWYJ (ORCPT ); Tue, 19 Apr 2022 18:24:09 -0400 Received: from mail-vk1-xa2b.google.com (mail-vk1-xa2b.google.com [IPv6:2607:f8b0:4864:20::a2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D10F23155 for ; Tue, 19 Apr 2022 15:21:25 -0700 (PDT) Received: by mail-vk1-xa2b.google.com with SMTP id 76so6303231vkc.7 for ; Tue, 19 Apr 2022 15:21:25 -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=oyX7jdm91Y3cY6FzRBU+xLcHpVF2MmsYGd3QZRua3aA=; b=V4gC/6OhWd7JLfFqf5LrqluKJ/0gAGO/zz9oi5MNIcbX9eHHRunor3t1xndoHYzvj2 i96EExDY21mINTs/0ap80iwV7fhDUeWtY64ZaRIo/Mdivnt9gytoup1M7oCqdpt4Be6Q zQE/PLc3d09D5OcLQ3Ed2ymnZtj223Z4YeRZ875duEbPbOol6rdVwCZbbjuTG455OMwg nD5X6EnqG11BaT3ehq9z34NHY6zGF5qwP6F7fvMUbjkj7caQoSzCjWDVd/8bDnFcwHxx J2NRT3hkrnia7S+L6/Qql7hzcDBZDrpDW565RwES1GZjcvaT45lFcK7QIob9mvlM5iqQ ZlJw== 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=oyX7jdm91Y3cY6FzRBU+xLcHpVF2MmsYGd3QZRua3aA=; b=hL8hAqFZbH36j4zKzSuWSGzvxNidCQccvaqbFgMHALuUMmo9z75Xchxz3UQT2CiPwX Ct8iuSRlzXddZC9Sg87CEjyaIkSIbybcYm7tQftt+qUMDMqUGc3kNxiZ9kLtIZMKa8TC r8+ufZ5UsSOvGGlcURRsnsJAR3Mm725veGMHWTf0XO3qLngzzwr2v3KBsTfeKQVu6on5 FiWHAcGA/Qmzr5H9As84sWwGnpBtRrqjy2FeylhO1Xcdt9biB0kZMxglnLDJhnorFAvX 7jaUBX3FwJHE/1wBDQjv/5M3ZJwqVqWxrb7BTpJbAypUVj5KozfoYmBDz1cvPWRysSu8 I3GA== X-Gm-Message-State: AOAM533YGlgazvS7RXU0aZItlae4L5EPszi8EpiPBdaZDf793MwRkKLl tRf6W5ZtoajsfgA15JYd9gS95JjN76zoR4mTxsoAAw== X-Google-Smtp-Source: ABdhPJwT9s2+ySt1xjN21ySwqnoiwcIwjz5wqrQKUUu70YIQJpY+Ce+T6BUiYU2bE7aDfJqRPgNvy/muGRwaf4fsVRk= X-Received: by 2002:a1f:314b:0:b0:331:fff6:a89e with SMTP id x72-20020a1f314b000000b00331fff6a89emr5110325vkx.26.1650406883569; Tue, 19 Apr 2022 15:21:23 -0700 (PDT) MIME-Version: 1.0 References: <20220407031525.2368067-1-yuzhao@google.com> <20220407031525.2368067-7-yuzhao@google.com> In-Reply-To: From: Yu Zhao Date: Tue, 19 Apr 2022 16:20:47 -0600 Message-ID: Subject: Re: [PATCH v10 06/14] mm: multi-gen LRU: minimal implementation To: Barry Song <21cnbao@gmail.com> Cc: Stephen Rothwell , Linux-MM , Andi Kleen , Andrew Morton , Aneesh Kumar , Catalin Marinas , Dave Hansen , Hillf Danton , Jens Axboe , Jesse Barnes , Johannes Weiner , Jonathan Corbet , Linus Torvalds , 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 , 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 Mon, Apr 18, 2022 at 10:26 PM Barry Song <21cnbao@gmail.com> wrote: > > On Tue, Apr 19, 2022 at 12:54 PM Yu Zhao wrote: > > > > On Mon, Apr 18, 2022 at 3:58 AM Barry Song <21cnbao@gmail.com> wrote: > > > > > > On Thu, Apr 7, 2022 at 3:16 PM Yu Zhao wrote: > > > > > > > > To avoid confusion, the terms "promotion" and "demotion" will be > > > > applied to the multi-gen LRU, as a new convention; the terms > > > > "activation" and "deactivation" will be applied to the active/inactive > > > > LRU, as usual. > > > > > > > > The aging produces young generations. Given an lruvec, it increments > > > > max_seq when max_seq-min_seq+1 approaches MIN_NR_GENS. The aging > > > > promotes hot pages to the youngest generation when it finds them > > > > accessed through page tables; the demotion of cold pages happens > > > > consequently when it increments max_seq. The aging has the complexity > > > > O(nr_hot_pages), since it is only interested in hot pages. Promotion > > > > in the aging path does not require any LRU list operations, only the > > > > updates of the gen counter and lrugen->nr_pages[]; demotion, unless as > > > > the result of the increment of max_seq, requires LRU list operations, > > > > e.g., lru_deactivate_fn(). > > > > > > > > The eviction consumes old generations. Given an lruvec, it increments > > > > min_seq when the lists indexed by min_seq%MAX_NR_GENS become empty. A > > > > feedback loop modeled after the PID controller monitors refaults over > > > > anon and file types and decides which type to evict when both types > > > > are available from the same generation. > > > > > > > > Each generation is divided into multiple tiers. Tiers represent > > > > different ranges of numbers of accesses through file descriptors. A > > > > page accessed N times through file descriptors is in tier > > > > order_base_2(N). Tiers do not have dedicated lrugen->lists[], only > > > > bits in folio->flags. In contrast to moving across generations, which > > > > requires the LRU lock, moving across tiers only involves operations on > > > > folio->flags. The feedback loop also monitors refaults over all tiers > > > > and decides when to protect pages in which tiers (N>1), using the > > > > first tier (N=0,1) as a baseline. The first tier contains single-use > > > > unmapped clean pages, which are most likely the best choices. The > > > > eviction moves a page to the next generation, i.e., min_seq+1, if the > > > > feedback loop decides so. This approach has the following advantages: > > > > 1. It removes the cost of activation in the buffered access path by > > > > inferring whether pages accessed multiple times through file > > > > descriptors are statistically hot and thus worth protecting in the > > > > eviction path. > > > > 2. It takes pages accessed through page tables into account and avoids > > > > overprotecting pages accessed multiple times through file > > > > descriptors. (Pages accessed through page tables are in the first > > > > tier, since N=0.) > > > > 3. More tiers provide better protection for pages accessed more than > > > > twice through file descriptors, when under heavy buffered I/O > > > > workloads. > > > > > > > > > > Hi Yu, > > > As I told you before, I tried to change the current LRU (not MGLRU) by only > > > promoting unmapped file pages to the head of the inactive head rather than > > > the active head on its second access: > > > https://lore.kernel.org/lkml/CAGsJ_4y=TkCGoWWtWSAptW4RDFUEBeYXwfwu=fUFvV4Sa4VA4A@mail.gmail.com/ > > > I have already seen some very good results by the decease of cpu consumption of > > > kswapd and direct reclamation in the testing. > > > > Glad to hear. I suspected you'd see some good results with that change :) > > > > > in mglru, it seems "twice" isn't a concern at all, one unmapped file > > > page accessed > > > twice has no much difference with those ones which are accessed once as you > > > only begin to increase refs from the third time: > > > > refs are *additional* accesses: > > PG_referenced: N=1 > > PG_referenced+PG_workingset: N=2 > > PG_referenced+PG_workingset+refs: N=3,4,5 > > > > When N=2, order_base_2(N)=1. So pages accessed twice are in the second > > tier. Therefore they are "different". > > > > More details [1]: > > > > +/* > > + * Each generation is divided into multiple tiers. Tiers represent different > > + * ranges of numbers of accesses through file descriptors. A page accessed N > > + * times through file descriptors is in tier order_base_2(N). A page in the > > + * first tier (N=0,1) is marked by PG_referenced unless it was faulted in > > + * though page tables or read ahead. A page in any other tier (N>1) is marked > > + * by PG_referenced and PG_workingset. > > + * > > + * In contrast to moving across generations which requires the LRU lock, moving > > + * across tiers only requires operations on folio->flags and therefore has a > > + * negligible cost in the buffered access path. In the eviction path, > > + * comparisons of refaulted/(evicted+protected) from the first tier and the > > + * rest infer whether pages accessed multiple times through file descriptors > > + * are statistically hot and thus worth protecting. > > + * > > + * MAX_NR_TIERS is set to 4 so that the multi-gen LRU can support twice of the > > + * categories of the active/inactive LRU when keeping track of accesses through > > + * file descriptors. It requires MAX_NR_TIERS-2 additional bits in > > folio->flags. > > + */ > > +#define MAX_NR_TIERS 4U > > > > [1] https://lore.kernel.org/linux-mm/20220407031525.2368067-7-yuzhao@google.com/ > > > > > +static void folio_inc_refs(struct folio *folio) > > > +{ > > > + unsigned long refs; > > > + unsigned long old_flags, new_flags; > > > + > > > + if (folio_test_unevictable(folio)) > > > + return; > > > + > > > + /* see the comment on MAX_NR_TIERS */ > > > + do { > > > + new_flags = old_flags = READ_ONCE(folio->flags); > > > + > > > + if (!(new_flags & BIT(PG_referenced))) { > > > + new_flags |= BIT(PG_referenced); > > > + continue; > > > + } > > > + > > > + if (!(new_flags & BIT(PG_workingset))) { > > > + new_flags |= BIT(PG_workingset); > > > + continue; > > > + } > > > + > > > + refs = new_flags & LRU_REFS_MASK; > > > + refs = min(refs + BIT(LRU_REFS_PGOFF), LRU_REFS_MASK); > > > + > > > + new_flags &= ~LRU_REFS_MASK; > > > + new_flags |= refs; > > > + } while (new_flags != old_flags && > > > + cmpxchg(&folio->flags, old_flags, new_flags) != old_flags); > > > +} > > > > > > So my question is what makes you so confident that twice doesn't need > > > any special treatment while the vanilla kernel is upgrading this kind of page > > > to the head of the active instead? I am asking this because I am considering > > > reclaiming unmapped file pages which are only accessed twice when they > > > get to the tail of the inactive list. > > > > Per above, pages accessed twice are in their own tier. Hope this clarifies it. > > Yep, I found the trick here , "+1" is magic behind the code, haha. > > +static int folio_lru_tier(struct folio *folio) > +{ > + int refs; > + unsigned long flags = READ_ONCE(folio->flags); > + > + refs = (flags & LRU_REFS_FLAGS) == LRU_REFS_FLAGS ? > + ((flags & LRU_REFS_MASK) >> LRU_REFS_PGOFF) + 1 : 0; > + > + return lru_tier_from_refs(refs); > +} > + > > TBH, this might need some comments, otherwise, it is easy to misunderstand > we are beginning to have protection from 3rd access :-) Agreed. Let me rework this function. I don't know how yet but I'll think of something. 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 D41ACC433F5 for ; Tue, 19 Apr 2022 22:23:02 +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=okXP27/308HiDbo4iunZYHC6D3qJpUM3nThwoevgkyA=; b=WdZnRkAWizF1H+ wCzTDHvj8ZNrQbagNqhQuHNaXDyUlubuPrzXY5mbl14TOmFr+9rU2FhRXiK52mAVhzdT7xShB/zU+ NJso+EmXtFNjqfHBplQHeXsjIScAdGbSatwKIk8HbOdfJ7FmRb7IYGwkDsG1n4VsToEuJy77cbRYa 6xECWvvgBwujlpSRhbm23CDvHguvBBJv5YaqtUHXnySZUhSGW7XSDhZSSma9SIJ7u9wd5+jKDMClE Bj/PMwmwc3fo/K5QJfeqvRyPdTRTU4ZqYjRstYcz0DTmNNg9Gj3+Kea7Iz0jc1EFITbwVpRTAzEnR LyVf8Qsz4P64sq3G166w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ngwDz-006VG6-8J; Tue, 19 Apr 2022 22:21:31 +0000 Received: from mail-vk1-xa2c.google.com ([2607:f8b0:4864:20::a2c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ngwDu-006VEs-In for linux-arm-kernel@lists.infradead.org; Tue, 19 Apr 2022 22:21:28 +0000 Received: by mail-vk1-xa2c.google.com with SMTP id c4so8169534vkq.9 for ; Tue, 19 Apr 2022 15:21:25 -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=oyX7jdm91Y3cY6FzRBU+xLcHpVF2MmsYGd3QZRua3aA=; b=V4gC/6OhWd7JLfFqf5LrqluKJ/0gAGO/zz9oi5MNIcbX9eHHRunor3t1xndoHYzvj2 i96EExDY21mINTs/0ap80iwV7fhDUeWtY64ZaRIo/Mdivnt9gytoup1M7oCqdpt4Be6Q zQE/PLc3d09D5OcLQ3Ed2ymnZtj223Z4YeRZ875duEbPbOol6rdVwCZbbjuTG455OMwg nD5X6EnqG11BaT3ehq9z34NHY6zGF5qwP6F7fvMUbjkj7caQoSzCjWDVd/8bDnFcwHxx J2NRT3hkrnia7S+L6/Qql7hzcDBZDrpDW565RwES1GZjcvaT45lFcK7QIob9mvlM5iqQ ZlJw== 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=oyX7jdm91Y3cY6FzRBU+xLcHpVF2MmsYGd3QZRua3aA=; b=4ASoUSmBERKqBbZVSSPISTlV4BztT8ADypX3UNdj0qZFIBzfbzFJ+rf1k1z2WQNX+D ASCJZvlee3c9ldQERZkoAcux0jomCZdI2huQitNFDssUlJPn4ARUE8L6k9oy4jTp6obp jFGt/m7YN3n+HDKqgp6t4dZEtOYN74xjWWoimUwcO+dUM53LveignvNa91W4cL6do72x HFJN5mul9lCrYPEOluIXnGMbJCZ1wYolw28u1LU/mLKYgnIwd3jh1Q58MvwvAMUN5uTm 01oLTYAi/kyYKSuTsn71xWNB222XetrXIKOWjpRIe8Hv/pmZ35JbdVHIWh8vX+79+utp zohA== X-Gm-Message-State: AOAM533HlIuJ9/DmvC6tdOFiD2NLd877+p9eXXU+2CRquOrJxoaNTKDO 7KEt3gryBXGEq0uaCwSuvn59/ahe7IeT/pWT4ADPag== X-Google-Smtp-Source: ABdhPJwT9s2+ySt1xjN21ySwqnoiwcIwjz5wqrQKUUu70YIQJpY+Ce+T6BUiYU2bE7aDfJqRPgNvy/muGRwaf4fsVRk= X-Received: by 2002:a1f:314b:0:b0:331:fff6:a89e with SMTP id x72-20020a1f314b000000b00331fff6a89emr5110325vkx.26.1650406883569; Tue, 19 Apr 2022 15:21:23 -0700 (PDT) MIME-Version: 1.0 References: <20220407031525.2368067-1-yuzhao@google.com> <20220407031525.2368067-7-yuzhao@google.com> In-Reply-To: From: Yu Zhao Date: Tue, 19 Apr 2022 16:20:47 -0600 Message-ID: Subject: Re: [PATCH v10 06/14] mm: multi-gen LRU: minimal implementation To: Barry Song <21cnbao@gmail.com> Cc: Stephen Rothwell , Linux-MM , Andi Kleen , Andrew Morton , Aneesh Kumar , Catalin Marinas , Dave Hansen , Hillf Danton , Jens Axboe , Jesse Barnes , Johannes Weiner , Jonathan Corbet , Linus Torvalds , 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 , 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-20220419_152126_650197_70ED5DA3 X-CRM114-Status: GOOD ( 49.58 ) 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 Mon, Apr 18, 2022 at 10:26 PM Barry Song <21cnbao@gmail.com> wrote: > > On Tue, Apr 19, 2022 at 12:54 PM Yu Zhao wrote: > > > > On Mon, Apr 18, 2022 at 3:58 AM Barry Song <21cnbao@gmail.com> wrote: > > > > > > On Thu, Apr 7, 2022 at 3:16 PM Yu Zhao wrote: > > > > > > > > To avoid confusion, the terms "promotion" and "demotion" will be > > > > applied to the multi-gen LRU, as a new convention; the terms > > > > "activation" and "deactivation" will be applied to the active/inactive > > > > LRU, as usual. > > > > > > > > The aging produces young generations. Given an lruvec, it increments > > > > max_seq when max_seq-min_seq+1 approaches MIN_NR_GENS. The aging > > > > promotes hot pages to the youngest generation when it finds them > > > > accessed through page tables; the demotion of cold pages happens > > > > consequently when it increments max_seq. The aging has the complexity > > > > O(nr_hot_pages), since it is only interested in hot pages. Promotion > > > > in the aging path does not require any LRU list operations, only the > > > > updates of the gen counter and lrugen->nr_pages[]; demotion, unless as > > > > the result of the increment of max_seq, requires LRU list operations, > > > > e.g., lru_deactivate_fn(). > > > > > > > > The eviction consumes old generations. Given an lruvec, it increments > > > > min_seq when the lists indexed by min_seq%MAX_NR_GENS become empty. A > > > > feedback loop modeled after the PID controller monitors refaults over > > > > anon and file types and decides which type to evict when both types > > > > are available from the same generation. > > > > > > > > Each generation is divided into multiple tiers. Tiers represent > > > > different ranges of numbers of accesses through file descriptors. A > > > > page accessed N times through file descriptors is in tier > > > > order_base_2(N). Tiers do not have dedicated lrugen->lists[], only > > > > bits in folio->flags. In contrast to moving across generations, which > > > > requires the LRU lock, moving across tiers only involves operations on > > > > folio->flags. The feedback loop also monitors refaults over all tiers > > > > and decides when to protect pages in which tiers (N>1), using the > > > > first tier (N=0,1) as a baseline. The first tier contains single-use > > > > unmapped clean pages, which are most likely the best choices. The > > > > eviction moves a page to the next generation, i.e., min_seq+1, if the > > > > feedback loop decides so. This approach has the following advantages: > > > > 1. It removes the cost of activation in the buffered access path by > > > > inferring whether pages accessed multiple times through file > > > > descriptors are statistically hot and thus worth protecting in the > > > > eviction path. > > > > 2. It takes pages accessed through page tables into account and avoids > > > > overprotecting pages accessed multiple times through file > > > > descriptors. (Pages accessed through page tables are in the first > > > > tier, since N=0.) > > > > 3. More tiers provide better protection for pages accessed more than > > > > twice through file descriptors, when under heavy buffered I/O > > > > workloads. > > > > > > > > > > Hi Yu, > > > As I told you before, I tried to change the current LRU (not MGLRU) by only > > > promoting unmapped file pages to the head of the inactive head rather than > > > the active head on its second access: > > > https://lore.kernel.org/lkml/CAGsJ_4y=TkCGoWWtWSAptW4RDFUEBeYXwfwu=fUFvV4Sa4VA4A@mail.gmail.com/ > > > I have already seen some very good results by the decease of cpu consumption of > > > kswapd and direct reclamation in the testing. > > > > Glad to hear. I suspected you'd see some good results with that change :) > > > > > in mglru, it seems "twice" isn't a concern at all, one unmapped file > > > page accessed > > > twice has no much difference with those ones which are accessed once as you > > > only begin to increase refs from the third time: > > > > refs are *additional* accesses: > > PG_referenced: N=1 > > PG_referenced+PG_workingset: N=2 > > PG_referenced+PG_workingset+refs: N=3,4,5 > > > > When N=2, order_base_2(N)=1. So pages accessed twice are in the second > > tier. Therefore they are "different". > > > > More details [1]: > > > > +/* > > + * Each generation is divided into multiple tiers. Tiers represent different > > + * ranges of numbers of accesses through file descriptors. A page accessed N > > + * times through file descriptors is in tier order_base_2(N). A page in the > > + * first tier (N=0,1) is marked by PG_referenced unless it was faulted in > > + * though page tables or read ahead. A page in any other tier (N>1) is marked > > + * by PG_referenced and PG_workingset. > > + * > > + * In contrast to moving across generations which requires the LRU lock, moving > > + * across tiers only requires operations on folio->flags and therefore has a > > + * negligible cost in the buffered access path. In the eviction path, > > + * comparisons of refaulted/(evicted+protected) from the first tier and the > > + * rest infer whether pages accessed multiple times through file descriptors > > + * are statistically hot and thus worth protecting. > > + * > > + * MAX_NR_TIERS is set to 4 so that the multi-gen LRU can support twice of the > > + * categories of the active/inactive LRU when keeping track of accesses through > > + * file descriptors. It requires MAX_NR_TIERS-2 additional bits in > > folio->flags. > > + */ > > +#define MAX_NR_TIERS 4U > > > > [1] https://lore.kernel.org/linux-mm/20220407031525.2368067-7-yuzhao@google.com/ > > > > > +static void folio_inc_refs(struct folio *folio) > > > +{ > > > + unsigned long refs; > > > + unsigned long old_flags, new_flags; > > > + > > > + if (folio_test_unevictable(folio)) > > > + return; > > > + > > > + /* see the comment on MAX_NR_TIERS */ > > > + do { > > > + new_flags = old_flags = READ_ONCE(folio->flags); > > > + > > > + if (!(new_flags & BIT(PG_referenced))) { > > > + new_flags |= BIT(PG_referenced); > > > + continue; > > > + } > > > + > > > + if (!(new_flags & BIT(PG_workingset))) { > > > + new_flags |= BIT(PG_workingset); > > > + continue; > > > + } > > > + > > > + refs = new_flags & LRU_REFS_MASK; > > > + refs = min(refs + BIT(LRU_REFS_PGOFF), LRU_REFS_MASK); > > > + > > > + new_flags &= ~LRU_REFS_MASK; > > > + new_flags |= refs; > > > + } while (new_flags != old_flags && > > > + cmpxchg(&folio->flags, old_flags, new_flags) != old_flags); > > > +} > > > > > > So my question is what makes you so confident that twice doesn't need > > > any special treatment while the vanilla kernel is upgrading this kind of page > > > to the head of the active instead? I am asking this because I am considering > > > reclaiming unmapped file pages which are only accessed twice when they > > > get to the tail of the inactive list. > > > > Per above, pages accessed twice are in their own tier. Hope this clarifies it. > > Yep, I found the trick here , "+1" is magic behind the code, haha. > > +static int folio_lru_tier(struct folio *folio) > +{ > + int refs; > + unsigned long flags = READ_ONCE(folio->flags); > + > + refs = (flags & LRU_REFS_FLAGS) == LRU_REFS_FLAGS ? > + ((flags & LRU_REFS_MASK) >> LRU_REFS_PGOFF) + 1 : 0; > + > + return lru_tier_from_refs(refs); > +} > + > > TBH, this might need some comments, otherwise, it is easy to misunderstand > we are beginning to have protection from 3rd access :-) Agreed. Let me rework this function. I don't know how yet but I'll think of something. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel