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 E5E72C433F5 for ; Mon, 18 Apr 2022 09:58:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237567AbiDRKBU (ORCPT ); Mon, 18 Apr 2022 06:01:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231722AbiDRKBR (ORCPT ); Mon, 18 Apr 2022 06:01:17 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DF88167D1; Mon, 18 Apr 2022 02:58:39 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id v15so16874492edb.12; Mon, 18 Apr 2022 02:58:38 -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=H70ax/K9P4QL3LzdGVTK9ti/817Hb8ywEBUqt5hZdj0=; b=GeBFdqeInVINk9j3p1jL4YdrYvmbw+APLdasJXrZElFtNqqjtg0u5vMdO7cy1NM/oK cKMtopan96Nlh0y5BgOnmJ/UBkfjHuTlC/9hZVpL6/iXLm+7XIYVllPzDw0pYt8qgeSz 12/ZpkNLlaeSpsjbW7hTunAU82WkAeq4GsXGy0kvSwfhQr+5ughxENWSbQ9rK0t+3kgW Emdt3rEYET5rIYUeSjM5OdkYOp818aaNVao/t3nX8GCRTyftk7k0EZwTMONBelx1B7UN YX5ttmpAv4E2e3DHxLz0B3kjysiVYCFmtfBWpGmH+quPSkF8mHy3BsJAb6wirxHomkzx dQuQ== 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=H70ax/K9P4QL3LzdGVTK9ti/817Hb8ywEBUqt5hZdj0=; b=RUomIwKfBmAoIDrGs47JXJjp/l/4L2VgDUtfkEL2Pkjxdq+NUj/3S0aCTBk3lY8c2u vWB9ZrtmqRjpSIb4kmS2fThsq/T62zKOjTy7Uns14wQQKL7abYXw6yu2sF8WwMNtlxbw SfqyphXprzQ8xQ9sm/U1D0NKlYQRFeuEJUKiPCbAVTVCTgSveNyy0dYXPkVXE5yirndY 4xOwKW38HYcAMGFHfNDxWSszn+Eix/lGIKL9+ot3SuLvwAsInIDo7hKC6FlS7qJdsqGK Be1nSNWTXRDLQgvOgziOFYypkKY31BtbV1uv5ZZj0F0eSTbAP7w5aom43R2NSoY7xUJ+ tAZw== X-Gm-Message-State: AOAM531Cqex1snL9R7Wqapa1QRX4+DhTCKU+7yvrXus6EKGKf2A8Uh5l Lv8UJkNZdEJmp/VyT1MQkdq+jbo6kjVRm3E3lK8= X-Google-Smtp-Source: ABdhPJyFy6C4Lp1eZgRvFaLJ1+gIuUbSNc6rO3HvTwRx0okGsHBwah/dQbuEAd2aZ9IYbsuVfjuGtMbjPinfw4cuKUU= X-Received: by 2002:aa7:d2d6:0:b0:423:97a4:801c with SMTP id k22-20020aa7d2d6000000b0042397a4801cmr10507782edr.383.1650275917413; Mon, 18 Apr 2022 02:58:37 -0700 (PDT) MIME-Version: 1.0 References: <20220407031525.2368067-1-yuzhao@google.com> <20220407031525.2368067-7-yuzhao@google.com> In-Reply-To: <20220407031525.2368067-7-yuzhao@google.com> From: Barry Song <21cnbao@gmail.com> Date: Mon, 18 Apr 2022 21:58:26 +1200 Message-ID: Subject: Re: [PATCH v10 06/14] mm: multi-gen LRU: minimal implementation To: Yu Zhao 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 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. 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: +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. Thanks Barry