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 X-Spam-Level: X-Spam-Status: No, score=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F6E9C433ED for ; Fri, 2 Apr 2021 00:55:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B288A610EA for ; Fri, 2 Apr 2021 00:55:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B288A610EA Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3886D6B0078; Thu, 1 Apr 2021 20:55:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 339AD6B00D4; Thu, 1 Apr 2021 20:55:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B12B6B00DC; Thu, 1 Apr 2021 20:55:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0024.hostedemail.com [216.40.44.24]) by kanga.kvack.org (Postfix) with ESMTP id EB2036B0078 for ; Thu, 1 Apr 2021 20:55:26 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id A61116D6D for ; Fri, 2 Apr 2021 00:55:26 +0000 (UTC) X-FDA: 77985608652.29.E01ECD4 Received: from mail-il1-f179.google.com (mail-il1-f179.google.com [209.85.166.179]) by imf28.hostedemail.com (Postfix) with ESMTP id E73E2200024E for ; Fri, 2 Apr 2021 00:55:25 +0000 (UTC) Received: by mail-il1-f179.google.com with SMTP id c17so3573936ilj.7 for ; Thu, 01 Apr 2021 17:55:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ggar240r8l1y1SR7kz5vR/iom4bN+ntyDx1BWqiKLWA=; b=HfUsqhL+okD5Z6DtZAvlDomFb/eZX+9XmkHddnlgl6gSKyk8ihNeBFMl/o5/uKgLJT kZJaw4s2Z++IPVOripdmiWATHKUmJLl4uP/dlVCoI595caniLn4znAZjDJf15XYwMCc+ CpgdD/nET0RYazA1I/7W712anpZmjGGROh+hqzUAQc9/AmPa/ZJTwuD0Hg/IHwagOE2H hws/CVnk+C75Z0MceafmrdCVsUUz/rCzGJomdoI7qY6vzIfJ/nkrH7m8zBX3D67ma+dB 8xKxneQyjbNzgHX3LzohQC9Bu5zpuLktXOXGUhPSa9/no+mcL9inlPqvAmOvvpiiscGC 2f6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ggar240r8l1y1SR7kz5vR/iom4bN+ntyDx1BWqiKLWA=; b=FWqHHKRlA2NXEqK9Igg3uZDXeFG7T9jvbum+Yqdu5Cx0sbsHqc40PjCXFtL9JQ/e93 ilkLUCLf8I8gCwg17nKTNeab0XjmSxLB9BmnlDADbfF+JjJh+EdvduUKoE6fpWeOwEqD RTflk5pmOzGVHjE2lrS2JG6epsT+X7UGTpploAR1+KLp0H06ZHEYf43g34PXq6C9HI7m kVWLk+UNV5OIE7kl7hCw+JcbCwrY0li4opuiC0wsnznVFsPr5yBDkAEiY7c5/Rs49Wgf m6a0jwGnFqIusZUn4gLfGwouDurowHi9vfC5H3FiS5uIKeRndmnf42FWNIh/3qYEEZCq JWdw== X-Gm-Message-State: AOAM533AY2kfM1NPebTYH1YYgMHYQohtWIp4MG7SW1R7EeSLOMQpMIpV aiZ0DFcVJJC0p/2d3Y3HgSt+YrAcQruYU9CQT8YK1A== X-Google-Smtp-Source: ABdhPJz52Elpa8MCYcBQKr2vnBLDMM40OFRVlMe3SRA4T3HZnstJIwIud5WK6sp99a2jtfaldbUB2+UTIh7apFf1O5A= X-Received: by 2002:a05:6e02:154d:: with SMTP id j13mr6792790ilu.128.1617324925442; Thu, 01 Apr 2021 17:55:25 -0700 (PDT) MIME-Version: 1.0 References: <20210401183216.443C4443@viggo.jf.intel.com> <20210401183231.8485C83D@viggo.jf.intel.com> In-Reply-To: <20210401183231.8485C83D@viggo.jf.intel.com> From: Wei Xu Date: Thu, 1 Apr 2021 17:55:13 -0700 Message-ID: Subject: Re: [PATCH 08/10] mm/vmscan: Consider anonymous pages without swap To: Dave Hansen Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, kbusch@kernel.org, shy828301@gmail.com, David Rientjes , ying.huang@intel.com, Dan Williams , david@redhat.com, osalvador@suse.de Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: E73E2200024E X-Stat-Signature: 6npxxsrymeedt35jzdhrepj5zd5pfxsj Received-SPF: none (google.com>: No applicable sender policy available) receiver=imf28; identity=mailfrom; envelope-from=""; helo=mail-il1-f179.google.com; client-ip=209.85.166.179 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617324925-883554 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Apr 1, 2021 at 11:35 AM Dave Hansen wrote: > > > From: Keith Busch > > Reclaim anonymous pages if a migration path is available now that > demotion provides a non-swap recourse for reclaiming anon pages. > > Note that this check is subtly different from the > anon_should_be_aged() checks. This mechanism checks whether a > specific page in a specific context *can* actually be reclaimed, given > current swap space and cgroup limits > > anon_should_be_aged() is a much simpler and more preliminary check > which just says whether there is a possibility of future reclaim. > > #Signed-off-by: Keith Busch > Cc: Keith Busch > Signed-off-by: Dave Hansen > Reviewed-by: Yang Shi > Cc: Wei Xu > Cc: David Rientjes > Cc: Huang Ying > Cc: Dan Williams > Cc: David Hildenbrand > Cc: osalvador > > -- > > Changes from Dave 10/2020: > * remove 'total_swap_pages' modification > > Changes from Dave 06/2020: > * rename reclaim_anon_pages()->can_reclaim_anon_pages() > > Note: Keith's Intel SoB is commented out because he is no > longer at Intel and his @intel.com mail will bounce. > --- > > b/mm/vmscan.c | 35 ++++++++++++++++++++++++++++++++--- > 1 file changed, 32 insertions(+), 3 deletions(-) > > diff -puN mm/vmscan.c~0009-mm-vmscan-Consider-anonymous-pages-without-swap mm/vmscan.c > --- a/mm/vmscan.c~0009-mm-vmscan-Consider-anonymous-pages-without-swap 2021-03-31 15:17:19.388000242 -0700 > +++ b/mm/vmscan.c 2021-03-31 15:17:19.407000242 -0700 > @@ -287,6 +287,34 @@ static bool writeback_throttling_sane(st > } > #endif > > +static inline bool can_reclaim_anon_pages(struct mem_cgroup *memcg, > + int node_id) > +{ > + if (memcg == NULL) { > + /* > + * For non-memcg reclaim, is there > + * space in any swap device? > + */ > + if (get_nr_swap_pages() > 0) > + return true; > + } else { > + /* Is the memcg below its swap limit? */ > + if (mem_cgroup_get_nr_swap_pages(memcg) > 0) > + return true; > + } > + > + /* > + * The page can not be swapped. > + * > + * Can it be reclaimed from this node via demotion? > + */ > + if (next_demotion_node(node_id) >= 0) > + return true; When neither swap space nor RECLAIM_MIGRATE is enabled, but next_demotion_node() is configured, inactive pages cannot be swapped out nor demoted. However, this check can still cause these pages to be sent to shrink_page_list() (e.g., when can_reclaim_anon_pages() is called by get_scan_count()) and make the THP pages being unnecessarily split there. One fix would be to guard this next_demotion_node() check with the RECLAIM_MIGRATE node_reclaim_mode check. This RECLAIM_MIGRATE check needs to be applied to other calls to next_demotion_node() in vmscan.c as well. > + > + /* No way to reclaim anon pages */ > + return false; > +} > + > /* > * This misses isolated pages which are not accounted for to save counters. > * As the data only determines if reclaim or compaction continues, it is > @@ -298,7 +326,7 @@ unsigned long zone_reclaimable_pages(str > > nr = zone_page_state_snapshot(zone, NR_ZONE_INACTIVE_FILE) + > zone_page_state_snapshot(zone, NR_ZONE_ACTIVE_FILE); > - if (get_nr_swap_pages() > 0) > + if (can_reclaim_anon_pages(NULL, zone_to_nid(zone))) > nr += zone_page_state_snapshot(zone, NR_ZONE_INACTIVE_ANON) + > zone_page_state_snapshot(zone, NR_ZONE_ACTIVE_ANON); > > @@ -2323,6 +2351,7 @@ enum scan_balance { > static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc, > unsigned long *nr) > { > + struct pglist_data *pgdat = lruvec_pgdat(lruvec); > struct mem_cgroup *memcg = lruvec_memcg(lruvec); > unsigned long anon_cost, file_cost, total_cost; > int swappiness = mem_cgroup_swappiness(memcg); > @@ -2333,7 +2362,7 @@ static void get_scan_count(struct lruvec > enum lru_list lru; > > /* If we have no swap space, do not bother scanning anon pages. */ > - if (!sc->may_swap || mem_cgroup_get_nr_swap_pages(memcg) <= 0) { > + if (!sc->may_swap || !can_reclaim_anon_pages(memcg, pgdat->node_id)) { Demotion of anon pages still depends on sc->may_swap. Any thoughts on decoupling demotion from swapping more completely? > scan_balance = SCAN_FILE; > goto out; > } > @@ -2708,7 +2737,7 @@ static inline bool should_continue_recla > */ > pages_for_compaction = compact_gap(sc->order); > inactive_lru_pages = node_page_state(pgdat, NR_INACTIVE_FILE); > - if (get_nr_swap_pages() > 0) > + if (can_reclaim_anon_pages(NULL, pgdat->node_id)) > inactive_lru_pages += node_page_state(pgdat, NR_INACTIVE_ANON); > > return inactive_lru_pages > pages_for_compaction; > _ >