Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2626729pxp; Mon, 14 Mar 2022 00:57:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvUogSfRtTPm+CbDqDhFkD0Nri9YsdfJVlN47i8fkf/CSoH3sNUdNNW0af2D7Ix/itkWLE X-Received: by 2002:a17:902:cf03:b0:14d:7447:1003 with SMTP id i3-20020a170902cf0300b0014d74471003mr22178609plg.143.1647244660762; Mon, 14 Mar 2022 00:57:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647244660; cv=none; d=google.com; s=arc-20160816; b=SyaSOGErfFq+T+LWCAk38AlgeAXQyJEuRmLLVNXM5FtHbma7T/4VGvZEv7B3MwIGO7 11ZK1WKMtB7F0lyKVtoF3cSdO/9BhBhCauvCugJrDfNajnyy1fJLI3/UJLwg5u/2LtAi h+1FYAX9A2m0iJR/HS24152+cQQjaPQVKCVcc8K0L6O+a1shoNEd966ID7x4NXEmd50A AE+oV3uQP/QCKWe/rRa3meZmQTcput/HMiGP33wRgNzQvY5RYz/KuMtUshtiNOuYZMjI CZmWTnClZTIzIUUyfTqlo5ocCSVgp5NpCRcPRxgggiJB1yxea6Q/7yWEjggjALjQODYS x7dQ== 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=ostrLnUO2mj0wyzHZmJJ7h19bUlrS9Vf5+VLNn3DoVM=; b=BQqwRCrjS12Q/86UtYXLGcabLlptfHpKBBAr0sHb1qFJ7s4O8y3eApBX/q3bLmU0bd 1asniYOozueQwyzF9JdAEZbo2jpNNm3XVWFpefpcKZyg+i7MC4DwLRSqk0iqVQkAuxGG ZanTgfsyAIAdYkRGUEWqGLNTsFCfrIfFDDuBRh+PAP5AWRE93Iggdv1OpmTGhnEy9YBO Ta6cFvWkzsAmiG3L5ol5Vr48BAlRfHYZAJRADZwIH9GlJTiOMGPd+iZGRYzZRETMsh7Y Yi1p50UhJDw/HhBh17nxidUQNgzTmjhROy2uohdfCEDOtVr1aaXO+0nkb157VGV5jIOX zkkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dh66cpD7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e11-20020a170903240b00b0015338e22104si7935093plo.279.2022.03.14.00.57.29; Mon, 14 Mar 2022 00:57:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dh66cpD7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233585AbiCME6j (ORCPT + 99 others); Sat, 12 Mar 2022 23:58:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233169AbiCME6i (ORCPT ); Sat, 12 Mar 2022 23:58:38 -0500 Received: from mail-yw1-x112f.google.com (mail-yw1-x112f.google.com [IPv6:2607:f8b0:4864:20::112f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D8291CAF21; Sat, 12 Mar 2022 20:57:31 -0800 (PST) Received: by mail-yw1-x112f.google.com with SMTP id 00721157ae682-2dbd97f9bfcso131914897b3.9; Sat, 12 Mar 2022 20:57:31 -0800 (PST) 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=ostrLnUO2mj0wyzHZmJJ7h19bUlrS9Vf5+VLNn3DoVM=; b=dh66cpD7Wqk3kfXaEFRzK8xzrsPwvBoq7TZ9ooyv4XDKUeHYqyHlNZ0Puys6VeRCq8 ZeEpkcELlSmEMF3MWSQVxqGjMWhAh99RkXxOvPbH5tMn8FodBaVE/dZL9eot+WK/CbQx HqZrcT6pqKgB7yBCLCtMttlIgsBmt0IBQ3JReKBdETgcE3TvNmwx5qyZgU/RrOpBapxP K+98SC3kT6XN5AxVBYJ8VLI6yzHvkjthzDZBZRan0NBAbi7WMtxT6vqcbDN1OB4a8UGN WXG1deoOr8X+Iin1hE2aYBkPblipBdZaDwEy/f6g4jbyDEmnqTjq9qiFDjycfmwJ5WiH kFqg== 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=ostrLnUO2mj0wyzHZmJJ7h19bUlrS9Vf5+VLNn3DoVM=; b=D7a6QLxbR8al4IidV/lL6bkRIEmsIGCsWxHgTucXZpi4orh3c/vT462PIDncvju81V MZdjpKahHDRSK/bLzDqGihd7E5SiXOQUGo6IQlG0YaPc99+qFY/LM2onIsk9i0w6tuo+ mTG4MjxoqwFej0BDcMlE2Db4w67Mhy0i+heR0GC5NuvKweHSaGLc0lRibApKTrFSFWPu Oh0u7Yi9WRPDLZPdklMls31mKsB7EnitXlJQ/JAmkvrtZL94CALXT2wUjpQSlcUu5wg4 jbFDPViqJK275L+iMoqw561RWRoMIFUOMXtpdZW0ofV3WYAdEc5T4eISnQ2WarPzWy2s X3EQ== X-Gm-Message-State: AOAM530xHlem3WHNfPLC7V48a4ex5/mCedEQlTiC7PLkZTkCELdSj9lo w9fiDHLCWKdeXW1ZVKOjsIbeLcKn5bWKUiWx2BA= X-Received: by 2002:a81:9806:0:b0:2dc:5953:4d13 with SMTP id p6-20020a819806000000b002dc59534d13mr14185928ywg.233.1647147450199; Sat, 12 Mar 2022 20:57:30 -0800 (PST) MIME-Version: 1.0 References: <20220208081902.3550911-1-yuzhao@google.com> <20220208081902.3550911-5-yuzhao@google.com> In-Reply-To: From: Barry Song <21cnbao@gmail.com> Date: Sun, 13 Mar 2022 17:57:17 +1300 Message-ID: Subject: Re: [PATCH v7 04/12] mm: multigenerational LRU: groundwork To: Yu Zhao Cc: Johannes Weiner , Andrew Morton , Mel Gorman , Michal Hocko , Andi Kleen , Aneesh Kumar , Catalin Marinas , Dave Hansen , Hillf Danton , Jens Axboe , Jesse Barnes , Jonathan Corbet , Linus Torvalds , Matthew Wilcox , Michael Larabel , 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Sun, Mar 13, 2022 at 10:12 AM Yu Zhao wrote: > > On Sat, Mar 12, 2022 at 3:37 AM Barry Song <21cnbao@gmail.com> wrote: > > > > On Sat, Mar 12, 2022 at 12:45 PM Yu Zhao wrote: > > > > > > On Fri, Mar 11, 2022 at 3:16 AM Barry Song <21cnbao@gmail.com> wrote: > > > > > > > > On Tue, Feb 15, 2022 at 10:43 PM Yu Zhao wrote: > > > > > > > > > > On Thu, Feb 10, 2022 at 03:41:57PM -0500, Johannes Weiner wrote: > > > > > > > > > > Thanks for reviewing. > > > > > > > > > > > > +static inline bool lru_gen_is_active(struct lruvec *lruvec, int gen) > > > > > > > +{ > > > > > > > + unsigned long max_seq = lruvec->lrugen.max_seq; > > > > > > > + > > > > > > > + VM_BUG_ON(gen >= MAX_NR_GENS); > > > > > > > + > > > > > > > + /* see the comment on MIN_NR_GENS */ > > > > > > > + return gen == lru_gen_from_seq(max_seq) || gen == lru_gen_from_seq(max_seq - 1); > > > > > > > +} > > > > > > > > > > > > I'm still reading the series, so correct me if I'm wrong: the "active" > > > > > > set is split into two generations for the sole purpose of the > > > > > > second-chance policy for fresh faults, right? > > > > > > > > > > To be precise, the active/inactive notion on top of generations is > > > > > just for ABI compatibility, e.g., the counters in /proc/vmstat. > > > > > Otherwise, this function wouldn't be needed. > > > > > > > > Hi Yu, > > > > I am still quite confused as i am seeing both active/inactive and lru_gen. > > > > eg: > > > > > > > > root@ubuntu:~# cat /proc/vmstat | grep active > > > > nr_zone_inactive_anon 22797 > > > > nr_zone_active_anon 578405 > > > > nr_zone_inactive_file 0 > > > > nr_zone_active_file 4156 > > > > nr_inactive_anon 22800 > > > > nr_active_anon 578574 > > > > nr_inactive_file 0 > > > > nr_active_file 4215 > > > > > > Yes, this is expected. We have to maintain the ABI, i.e., the > > > *_active/inactive_* counters. > > > > > > > and: > > > > > > > > root@ubuntu:~# cat /sys//kernel/debug/lru_gen > > > > > > > > ... > > > > memcg 36 /user.slice/user-0.slice/user@0.service > > > > node 0 > > > > 20 18820 22 0 > > > > 21 7452 0 0 > > > > 22 7448 0 0 > > > > memcg 33 /user.slice/user-0.slice/user@0.service/app.slice > > > > node 0 > > > > 0 2171452 0 0 > > > > 1 2171452 0 0 > > > > 2 2171452 0 0 > > > > 3 2171452 0 0 > > > > memcg 37 /user.slice/user-0.slice/session-1.scope > > > > node 0 > > > > 42 51804 102127 0 > > > > 43 18840 275622 0 > > > > 44 16104 216805 1 > > > > > > > > Does it mean one page could be in both one of the generations and one > > > > of the active/inactive lists? > > > > > > In terms of the data structure, evictable pages are either on > > > lruvec->lists or lrugen->lists. > > > > > > > Do we have some mapping relationship between active/inactive lists > > > > with generations? > > > > > > For the counters, yes -- pages in max_seq and max_seq-1 are counted as > > > active, and the rest are inactive. > > > > > > > We used to put a faulted file page in inactive, if we access it a > > > > second time, it can be promoted > > > > to active. then in recent years, we have also applied this to anon > > > > pages while kernel adds > > > > workingset protection for anon pages. so basically both anon and file > > > > pages go into the inactive > > > > list for the 1st time, if we access it for the second time, they go to > > > > the active list. if we don't access > > > > it any more, they are likely to be reclaimed as they are inactive. > > > > we do have some special fastpath for code section, executable file > > > > pages are kept on active list > > > > as long as they are accessed. > > > > > > Yes. > > > > > > > so all of the above concerns are actually not that correct? > > > > > > They are valid concerns but I don't know any popular workloads that > > > care about them. > > > > Hi Yu, > > here we can get a workload in Kim's patchset while he added workingset > > protection > > for anon pages: > > https://patchwork.kernel.org/project/linux-mm/cover/1581401993-20041-1-git-send-email-iamjoonsoo.kim@lge.com/ > > Thanks. I wouldn't call that a workload because it's not a real > application. By popular workloads, I mean applications that the > majority of people actually run on phones, in cloud, etc. > > > anon pages used to go to active rather than inactive, but kim's patchset > > moved to use inactive first. then only after the anon page is accessed > > second time, it can move to active. > > Yes. To clarify, the A-bit doesn't really mean the first or second > access. It can be many accesses each time it's set. > > > "In current implementation, newly created or swap-in anonymous page is > > > > started on the active list. Growing the active list results in rebalancing > > active/inactive list so old pages on the active list are demoted to the > > inactive list. Hence, hot page on the active list isn't protected at all. > > > > Following is an example of this situation. > > > > Assume that 50 hot pages on active list and system can contain total > > 100 pages. Numbers denote the number of pages on active/inactive > > list (active | inactive). (h) stands for hot pages and (uo) stands for > > used-once pages. > > > > 1. 50 hot pages on active list > > 50(h) | 0 > > > > 2. workload: 50 newly created (used-once) pages > > 50(uo) | 50(h) > > > > 3. workload: another 50 newly created (used-once) pages > > 50(uo) | 50(uo), swap-out 50(h) > > > > As we can see, hot pages are swapped-out and it would cause swap-in later." > > > > Is MGLRU able to avoid the swap-out of the 50 hot pages? > > I think the real question is why the 50 hot pages can be moved to the > inactive list. If they are really hot, the A-bit should protect them. This is a good question. I guess it is probably because the current lru is trying to maintain a balance between the sizes of active and inactive lists. Thus, it can shrink active list even though pages might be still "hot" but not the recently accessed ones. 1. 50 hot pages on active list 50(h) | 0 2. workload: 50 newly created (used-once) pages 50(uo) | 50(h) 3. workload: another 50 newly created (used-once) pages 50(uo) | 50(uo), swap-out 50(h) the old kernel without anon workingset protection put workload 2 on active, so pushed 50 hot pages from active to inactive. workload 3 would further contribute to evict the 50 hot pages. it seems mglru doesn't demote pages from the youngest generation to older generation only in order to balance the list size? so mglru is probably safe in these cases. I will run some tests mentioned in Kim's patchset and report the result to you afterwards. > > > since MGLRU > > is putting faulted pages to the youngest generation directly, do we have the > > risk mentioned in Kim's patchset? > > There are always risks :) I could imagine a thousand ways to make VM > suffer, but all of them could be irrelevant to how it actually does in > production. So a concrete use case of yours would be much appreciated > for this discussion. Thanks Barry