Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2358294pxp; Mon, 21 Mar 2022 17:57:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJymG6+M5THzi5cqoTSPkw7GVmqN9aNj1+7+5bRMYPDpCG1p8YJNwufHTqqZ43KTyzk4nZMd X-Received: by 2002:a63:4665:0:b0:374:7305:dab4 with SMTP id v37-20020a634665000000b003747305dab4mr20192392pgk.256.1647910650646; Mon, 21 Mar 2022 17:57:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647910650; cv=none; d=google.com; s=arc-20160816; b=X8RDspVUpVdlDKn9KO/F27ezedRN4pvOKefUY8h7zi1SF3O82fkzw0GzyMILmLW9GN TVHXdnzGn9dxYOOgP2gMuGHBVwh9q5n+j31lpjIfjDbRqktVnP2wgnJDBsXnc2cMoSLQ fkbWkbnRe9+aQTGepCc5dP9HVqQoQ8KGun1nGbm4EZ58h1H8/QDo6Qxw/Bsi3AvWs+Gj RGOp5tggWwZKLcPWXyZe8dfXbwQko2r7WipLg/khEm4MOHIlUbNH9h2SsH4XpAiKrhDT WZIqA8plsPCjPBbOnMwpbYu6EPzGQbXsiPcY+SjhgzuDwvWRXXZEyJCbTMPxPMpSpMkb 9sQQ== 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=zZqXUZvSGoiAU4OWPpv+kWmYsbJWpiQeFt4daxe81ds=; b=buzNFG9wwohiZaN5hpc4d/hSmrfDTdYVgsqQ8fl9v96pQjkIdMtr+bM6IiJ9nV71G0 YqBhOROfqzmzuzw6zgbw/5ipLVRpnfOIq9xJ5JdFM33bMpMaCz2HargdVJ5mlKisoZyL xmqdEAVNNGAOdjFPBSvAYdOlyzay4+txS9s+hKRd5vBYoepL5p1CMJq4uB/u+P1bWdYo o2k8eXoJXy+UqDXjlAhicXgrMWhdkEDKDNywiQPk9URg8yJlusIFckejBCHy3imJY60n tKfEc170x5szTOyADo8JBmk2Hcbjf4IIcJP7iJpKnMhEuYMxSNARo6k/jopm1B0lt3yH b3OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=hfrCmbEH; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id 26-20020a630d5a000000b003816043f141si14290529pgn.822.2022.03.21.17.57.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 17:57:30 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=hfrCmbEH; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 929FA37C858; Mon, 21 Mar 2022 17:30:28 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234274AbiCVAbt (ORCPT + 99 others); Mon, 21 Mar 2022 20:31:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234276AbiCVAbp (ORCPT ); Mon, 21 Mar 2022 20:31:45 -0400 Received: from mail-vs1-xe2b.google.com (mail-vs1-xe2b.google.com [IPv6:2607:f8b0:4864:20::e2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21351375D05 for ; Mon, 21 Mar 2022 17:30:19 -0700 (PDT) Received: by mail-vs1-xe2b.google.com with SMTP id a127so9272528vsa.3 for ; Mon, 21 Mar 2022 17:30:19 -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=zZqXUZvSGoiAU4OWPpv+kWmYsbJWpiQeFt4daxe81ds=; b=hfrCmbEHl2h5Rii7re10yHpXsfBWYOfGCKo+XQHmbiS2ORaNCnijKzF+qeBzW3BQpF fyyM1ZUD/bMfWg5gp9nIKppanhrDqXzd0BiDWLV4odII5vc2bLY4QqqpziOuJ2O1TrJw flhQd3vAAwtgT1Xv8Ojt/JsqvVFijWUgiWh0miJ97JPj/PZDacbcaVTJnJ+7etv/AVCb /mgprhIyrwN2hOE5UMF6b/8I774/2nwphiQzlUB+Lwssicdx9Q+0boWzoygBzkomBf1m M0MRwgVymI1GJRyV7aTF9G1e9F0CjK38bjWTNQmYAksU3FtMFXOstcscKc0OheQ8B1wS VTwQ== 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=zZqXUZvSGoiAU4OWPpv+kWmYsbJWpiQeFt4daxe81ds=; b=5ODSj++clfIkR2yX8tqlLSpesAi9Le4Clnz+RbNNGG1vDjlQGSCZNDJQLnTOhvTQ2n zinNFQ3UFYMjMYa3GI5xmiRVF/XC4BdJppKJiK9bYhFJeK+k+TGqBidZIU1y1T4PrtiR h5+ZPjp7OzrmlJ/nVQC/b14c8XpbWe9ZUo3ux9NpULbV4Z4ODnNIGHVZTiK7/Hwxqcsx oV2sPy8A985ZFp+kLnLs6teYpCpghBpNbGW+ZynmMXyJIIDwtrQ7zyyM27KHk9A7znD8 Uv2mOjrHlsRcvyhEdMvjgxOks63m/8Iswt8VJjhEm6biwP9HM4Iaf8d+WtlYWgkZ9HBu clqg== X-Gm-Message-State: AOAM530+FfxveHAI3Zhzc3h6+wM/6iW0QbVB7GjhdGkraPMSoA5kCt/I sqfPaLbaHGwCN8nRfAAxol25BkDPdB46CX4UORxX5Q== X-Received: by 2002:a05:6102:291f:b0:325:11be:5bf0 with SMTP id cz31-20020a056102291f00b0032511be5bf0mr2955888vsb.41.1647909018098; Mon, 21 Mar 2022 17:30:18 -0700 (PDT) MIME-Version: 1.0 References: <20220309021230.721028-1-yuzhao@google.com> <20220309021230.721028-7-yuzhao@google.com> In-Reply-To: From: Yu Zhao Date: Mon, 21 Mar 2022 18:30:06 -0600 Message-ID: Subject: Re: [PATCH v9 06/14] mm: multi-gen LRU: minimal implementation 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 Sat, Mar 19, 2022 at 5:15 AM Barry Song <21cnbao@gmail.com> wrote: > > > + unsigned long *min_seq, bool can_swap, bool *need_aging) > > +{ > > + int gen, type, zone; > > + long old = 0; > > + long young = 0; > > + long total = 0; > > + struct lru_gen_struct *lrugen = &lruvec->lrugen; > > + > > + for (type = !can_swap; type < ANON_AND_FILE; type++) { > > + unsigned long seq; > > + > > + for (seq = min_seq[type]; seq <= max_seq; seq++) { > > + long size = 0; > > + > > + gen = lru_gen_from_seq(seq); > > + > > + for (zone = 0; zone < MAX_NR_ZONES; zone++) > > + size += READ_ONCE(lrugen->nr_pages[gen][type][zone]); > > + > > + total += size; > > + if (seq == max_seq) > > + young += size; > > + if (seq + MIN_NR_GENS == max_seq) > > + old += size; > > + } > > + } > > + > > + /* try to spread pages out across MIN_NR_GENS+1 generations */ > > + if (min_seq[LRU_GEN_FILE] + MIN_NR_GENS > max_seq) > > + *need_aging = true; > > + else if (min_seq[LRU_GEN_FILE] + MIN_NR_GENS < max_seq) > > + *need_aging = false; > > + else if (young * MIN_NR_GENS > total) > > + *need_aging = true; > > Could we have some doc here? Will do. > Given MIN_NR_GENS=2 and MAX_NR_GENS=4, > it seems you mean if we have three generations and the youngest pages are more > than 1/2 of the total pages, we need aging? Yes. > > + else if (old * (MIN_NR_GENS + 2) < total) > > + *need_aging = true; > > it seems you mean if the oldest pages are less than 1/4 of the total pages, > we need aging? Yes. > Can we have comments to explain why here? > > your commit message only says " The aging produces young generations. > Given an lruvec, it increments max_seq when max_seq-min_seq+1 > approaches MIN_NR_GENS." it can't explain what the code is doing > here. Fair enough. Approaching MIN_NR_GENS=2 means getting close to it. From the consumer's POV, if it *reaches* 2, the eviction will have to stall, because the two youngest generations are not yet fully aged, i.e., the second chance policy similar to the active/inactive lru. From the producer's POV, the aging tries to be lazy to reduce the overhead. So ideally, we want 3 generations, which gives a reasonable range [2, 4], hence the first two if's. In addition, we want pages to spread out evenly over these 3 generations, meaning an average 1/3 of total pages for each generation, which gives another reasonable range [1/2, 1/4]. Since the eviction reduces the number of old pages, we only need to check against the lower bound, i.e., 1/4. On the other hand, page (re)faults increase the number of young pages, so in this case, we need to check against the upper bound. I'll include these details in the next spin.