From nobody Wed Sep 17 07:58:45 2025 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 F2475C4332F for ; Wed, 21 Dec 2022 00:13:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234167AbiLUANA (ORCPT ); Tue, 20 Dec 2022 19:13:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234214AbiLUAMn (ORCPT ); Tue, 20 Dec 2022 19:12:43 -0500 Received: from mail-il1-x14a.google.com (mail-il1-x14a.google.com [IPv6:2607:f8b0:4864:20::14a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F30F201BC for ; Tue, 20 Dec 2022 16:12:37 -0800 (PST) Received: by mail-il1-x14a.google.com with SMTP id x10-20020a056e021bca00b00302b6c0a683so9332672ilv.23 for ; Tue, 20 Dec 2022 16:12:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=x7hqwzZvz2lgYCROSGHPyAOjnAXLbIm00pvWJTo+FHY=; b=Y99krAxU+g6T25oGmPipeCWre53NFTuJA+DF0scSa6pVzx7mXz7QcRs4zj3Vl9HPUP tRBIUnIfjLKRhffplM9obWzr4hel+aA8KfE7YGeKIyJFgO8ieeYe689GCoDHNY2gpMbi zM4b5sdTiFZxfWyeTTDtHmyZ3KxDS29e9pBwXEAyARnePnRmobGsBdEh1yOqIqhgKc1a A6uogABkcc5cE5LeJndJvYQP3gvIMBmlhEP3b2yEq96hHoG+8AgIbcjB5BTclwI/Qy2B Dq4+gEK53lcx/Q8/KoZGnlUM5QopFlIwhp4GhqYF6UK/aB/azCbUMD3B1AEeV7oLuxja Qnrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=x7hqwzZvz2lgYCROSGHPyAOjnAXLbIm00pvWJTo+FHY=; b=jdRFiu1H9qtX1wvK/jMFlNzumtum9oaDJrCHFldmiIz6eAWdGC2E62NR/8Jj/1rIWy cAzNK/mALBwruMpcU4D05tECYeXkVqzfY6pgmnY69GdH6G0H4uvadZWYTs6IyWLYzkAj pcsIyLsQSISv+m+aWdT+oS3ztGCa5PMKe/UwraXqHR5kAQIchKaWE4cTuo0voVKdbcCB 43laTr7OMnLepggE0sOxZjIQ+tbUr3OAhTBCOYdHC8Xs+GW/uoKQ21JB7denOgUmYBxB UMvXEBJ2FuA2uo+gTH/WZEZiEP0yf5wQ/ZTgiDcA4mSrqOuhGxMUMAxO0AHz9T3xrEke V+JQ== X-Gm-Message-State: ANoB5pkyGLzyRU4MCxXdMyWsC+m2qUybfLGDq4EV+lHAG6E2mKQq854J rmz/pAEByaeGXGGIEyfGWtzT8VM57EQ= X-Google-Smtp-Source: AA0mqf6uw7KuVqvxq95bcw+r3WruBA/v608j3gUgEyvlJRm3jjlnvNsHzE5a8wwOhKy0j7TuaZOuPLg+a5E= X-Received: from yuzhao.bld.corp.google.com ([2620:15c:183:200:a589:30f2:2daa:4ab7]) (user=yuzhao job=sendgmr) by 2002:a02:b01d:0:b0:38a:3421:be23 with SMTP id p29-20020a02b01d000000b0038a3421be23mr14395612jah.288.1671581556605; Tue, 20 Dec 2022 16:12:36 -0800 (PST) Date: Tue, 20 Dec 2022 17:12:01 -0700 In-Reply-To: <20221221001207.1376119-1-yuzhao@google.com> Message-Id: <20221221001207.1376119-2-yuzhao@google.com> Mime-Version: 1.0 References: <20221221001207.1376119-1-yuzhao@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Subject: [PATCH mm-unstable v2 1/8] mm: multi-gen LRU: rename lru_gen_struct to lru_gen_folio From: Yu Zhao To: Andrew Morton Cc: Johannes Weiner , Jonathan Corbet , Michael Larabel , Michal Hocko , Mike Rapoport , Roman Gushchin , Suren Baghdasaryan , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-mm@google.com, Yu Zhao Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The new name lru_gen_folio will be more distinct from the coming lru_gen_memcg. Signed-off-by: Yu Zhao Change-Id: Ic714d328df239f569fe37c3f1fac44a01549883c --- include/linux/mm_inline.h | 4 ++-- include/linux/mmzone.h | 6 +++--- mm/vmscan.c | 34 +++++++++++++++++----------------- mm/workingset.c | 4 ++-- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h index e8ed225d8f7c..f63968bd7de5 100644 --- a/include/linux/mm_inline.h +++ b/include/linux/mm_inline.h @@ -178,7 +178,7 @@ static inline void lru_gen_update_size(struct lruvec *l= ruvec, struct folio *foli int zone =3D folio_zonenum(folio); int delta =3D folio_nr_pages(folio); enum lru_list lru =3D type * LRU_INACTIVE_FILE; - struct lru_gen_struct *lrugen =3D &lruvec->lrugen; + struct lru_gen_folio *lrugen =3D &lruvec->lrugen; =20 VM_WARN_ON_ONCE(old_gen !=3D -1 && old_gen >=3D MAX_NR_GENS); VM_WARN_ON_ONCE(new_gen !=3D -1 && new_gen >=3D MAX_NR_GENS); @@ -224,7 +224,7 @@ static inline bool lru_gen_add_folio(struct lruvec *lru= vec, struct folio *folio, int gen =3D folio_lru_gen(folio); int type =3D folio_is_file_lru(folio); int zone =3D folio_zonenum(folio); - struct lru_gen_struct *lrugen =3D &lruvec->lrugen; + struct lru_gen_folio *lrugen =3D &lruvec->lrugen; =20 VM_WARN_ON_ONCE_FOLIO(gen !=3D -1, folio); =20 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index cd28a100d9e4..1686fcc4ed01 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -404,7 +404,7 @@ enum { * The number of pages in each generation is eventually consistent and the= refore * can be transiently negative when reset_batch_size() is pending. */ -struct lru_gen_struct { +struct lru_gen_folio { /* the aging increments the youngest generation number */ unsigned long max_seq; /* the eviction increments the oldest generation numbers */ @@ -461,7 +461,7 @@ struct lru_gen_mm_state { struct lru_gen_mm_walk { /* the lruvec under reclaim */ struct lruvec *lruvec; - /* unstable max_seq from lru_gen_struct */ + /* unstable max_seq from lru_gen_folio */ unsigned long max_seq; /* the next address within an mm to scan */ unsigned long next_addr; @@ -524,7 +524,7 @@ struct lruvec { unsigned long flags; #ifdef CONFIG_LRU_GEN /* evictable pages divided into generations */ - struct lru_gen_struct lrugen; + struct lru_gen_folio lrugen; /* to concurrently iterate lru_gen_mm_list */ struct lru_gen_mm_state mm_state; #endif diff --git a/mm/vmscan.c b/mm/vmscan.c index 546540bc770a..c0c4b0cd2fe2 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3215,7 +3215,7 @@ static int get_nr_gens(struct lruvec *lruvec, int typ= e) =20 static bool __maybe_unused seq_is_valid(struct lruvec *lruvec) { - /* see the comment on lru_gen_struct */ + /* see the comment on lru_gen_folio */ return get_nr_gens(lruvec, LRU_GEN_FILE) >=3D MIN_NR_GENS && get_nr_gens(lruvec, LRU_GEN_FILE) <=3D get_nr_gens(lruvec, LRU_GEN= _ANON) && get_nr_gens(lruvec, LRU_GEN_ANON) <=3D MAX_NR_GENS; @@ -3612,7 +3612,7 @@ struct ctrl_pos { static void read_ctrl_pos(struct lruvec *lruvec, int type, int tier, int g= ain, struct ctrl_pos *pos) { - struct lru_gen_struct *lrugen =3D &lruvec->lrugen; + struct lru_gen_folio *lrugen =3D &lruvec->lrugen; int hist =3D lru_hist_from_seq(lrugen->min_seq[type]); =20 pos->refaulted =3D lrugen->avg_refaulted[type][tier] + @@ -3627,7 +3627,7 @@ static void read_ctrl_pos(struct lruvec *lruvec, int = type, int tier, int gain, static void reset_ctrl_pos(struct lruvec *lruvec, int type, bool carryover) { int hist, tier; - struct lru_gen_struct *lrugen =3D &lruvec->lrugen; + struct lru_gen_folio *lrugen =3D &lruvec->lrugen; bool clear =3D carryover ? NR_HIST_GENS =3D=3D 1 : NR_HIST_GENS > 1; unsigned long seq =3D carryover ? lrugen->min_seq[type] : lrugen->max_seq= + 1; =20 @@ -3704,7 +3704,7 @@ static int folio_update_gen(struct folio *folio, int = gen) static int folio_inc_gen(struct lruvec *lruvec, struct folio *folio, bool = reclaiming) { int type =3D folio_is_file_lru(folio); - struct lru_gen_struct *lrugen =3D &lruvec->lrugen; + struct lru_gen_folio *lrugen =3D &lruvec->lrugen; int new_gen, old_gen =3D lru_gen_from_seq(lrugen->min_seq[type]); unsigned long new_flags, old_flags =3D READ_ONCE(folio->flags); =20 @@ -3749,7 +3749,7 @@ static void update_batch_size(struct lru_gen_mm_walk = *walk, struct folio *folio, static void reset_batch_size(struct lruvec *lruvec, struct lru_gen_mm_walk= *walk) { int gen, type, zone; - struct lru_gen_struct *lrugen =3D &lruvec->lrugen; + struct lru_gen_folio *lrugen =3D &lruvec->lrugen; =20 walk->batched =3D 0; =20 @@ -4266,7 +4266,7 @@ static bool inc_min_seq(struct lruvec *lruvec, int ty= pe, bool can_swap) { int zone; int remaining =3D MAX_LRU_BATCH; - struct lru_gen_struct *lrugen =3D &lruvec->lrugen; + struct lru_gen_folio *lrugen =3D &lruvec->lrugen; int new_gen, old_gen =3D lru_gen_from_seq(lrugen->min_seq[type]); =20 if (type =3D=3D LRU_GEN_ANON && !can_swap) @@ -4302,7 +4302,7 @@ static bool try_to_inc_min_seq(struct lruvec *lruvec,= bool can_swap) { int gen, type, zone; bool success =3D false; - struct lru_gen_struct *lrugen =3D &lruvec->lrugen; + struct lru_gen_folio *lrugen =3D &lruvec->lrugen; DEFINE_MIN_SEQ(lruvec); =20 VM_WARN_ON_ONCE(!seq_is_valid(lruvec)); @@ -4323,7 +4323,7 @@ static bool try_to_inc_min_seq(struct lruvec *lruvec,= bool can_swap) ; } =20 - /* see the comment on lru_gen_struct */ + /* see the comment on lru_gen_folio */ if (can_swap) { min_seq[LRU_GEN_ANON] =3D min(min_seq[LRU_GEN_ANON], min_seq[LRU_GEN_FIL= E]); min_seq[LRU_GEN_FILE] =3D max(min_seq[LRU_GEN_ANON], lrugen->min_seq[LRU= _GEN_FILE]); @@ -4345,7 +4345,7 @@ static void inc_max_seq(struct lruvec *lruvec, bool c= an_swap, bool force_scan) { int prev, next; int type, zone; - struct lru_gen_struct *lrugen =3D &lruvec->lrugen; + struct lru_gen_folio *lrugen =3D &lruvec->lrugen; =20 spin_lock_irq(&lruvec->lru_lock); =20 @@ -4403,7 +4403,7 @@ static bool try_to_inc_max_seq(struct lruvec *lruvec,= unsigned long max_seq, bool success; struct lru_gen_mm_walk *walk; struct mm_struct *mm =3D NULL; - struct lru_gen_struct *lrugen =3D &lruvec->lrugen; + struct lru_gen_folio *lrugen =3D &lruvec->lrugen; =20 VM_WARN_ON_ONCE(max_seq > READ_ONCE(lrugen->max_seq)); =20 @@ -4468,7 +4468,7 @@ static bool should_run_aging(struct lruvec *lruvec, u= nsigned long max_seq, unsig unsigned long old =3D 0; unsigned long young =3D 0; unsigned long total =3D 0; - struct lru_gen_struct *lrugen =3D &lruvec->lrugen; + struct lru_gen_folio *lrugen =3D &lruvec->lrugen; struct mem_cgroup *memcg =3D lruvec_memcg(lruvec); =20 for (type =3D !can_swap; type < ANON_AND_FILE; type++) { @@ -4753,7 +4753,7 @@ static bool sort_folio(struct lruvec *lruvec, struct = folio *folio, int tier_idx) int delta =3D folio_nr_pages(folio); int refs =3D folio_lru_refs(folio); int tier =3D lru_tier_from_refs(refs); - struct lru_gen_struct *lrugen =3D &lruvec->lrugen; + struct lru_gen_folio *lrugen =3D &lruvec->lrugen; =20 VM_WARN_ON_ONCE_FOLIO(gen >=3D MAX_NR_GENS, folio); =20 @@ -4853,7 +4853,7 @@ static int scan_folios(struct lruvec *lruvec, struct = scan_control *sc, int scanned =3D 0; int isolated =3D 0; int remaining =3D MAX_LRU_BATCH; - struct lru_gen_struct *lrugen =3D &lruvec->lrugen; + struct lru_gen_folio *lrugen =3D &lruvec->lrugen; struct mem_cgroup *memcg =3D lruvec_memcg(lruvec); =20 VM_WARN_ON_ONCE(!list_empty(list)); @@ -5254,7 +5254,7 @@ static void lru_gen_shrink_lruvec(struct lruvec *lruv= ec, struct scan_control *sc =20 static bool __maybe_unused state_is_valid(struct lruvec *lruvec) { - struct lru_gen_struct *lrugen =3D &lruvec->lrugen; + struct lru_gen_folio *lrugen =3D &lruvec->lrugen; =20 if (lrugen->enabled) { enum lru_list lru; @@ -5533,7 +5533,7 @@ static void lru_gen_seq_show_full(struct seq_file *m,= struct lruvec *lruvec, int i; int type, tier; int hist =3D lru_hist_from_seq(seq); - struct lru_gen_struct *lrugen =3D &lruvec->lrugen; + struct lru_gen_folio *lrugen =3D &lruvec->lrugen; =20 for (tier =3D 0; tier < MAX_NR_TIERS; tier++) { seq_printf(m, " %10d", tier); @@ -5583,7 +5583,7 @@ static int lru_gen_seq_show(struct seq_file *m, void = *v) unsigned long seq; bool full =3D !debugfs_real_fops(m->file)->write; struct lruvec *lruvec =3D v; - struct lru_gen_struct *lrugen =3D &lruvec->lrugen; + struct lru_gen_folio *lrugen =3D &lruvec->lrugen; int nid =3D lruvec_pgdat(lruvec)->node_id; struct mem_cgroup *memcg =3D lruvec_memcg(lruvec); DEFINE_MAX_SEQ(lruvec); @@ -5837,7 +5837,7 @@ void lru_gen_init_lruvec(struct lruvec *lruvec) { int i; int gen, type, zone; - struct lru_gen_struct *lrugen =3D &lruvec->lrugen; + struct lru_gen_folio *lrugen =3D &lruvec->lrugen; =20 lrugen->max_seq =3D MIN_NR_GENS + 1; lrugen->enabled =3D lru_gen_enabled(); diff --git a/mm/workingset.c b/mm/workingset.c index 1a86645b7b3c..fd666584515c 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -223,7 +223,7 @@ static void *lru_gen_eviction(struct folio *folio) unsigned long token; unsigned long min_seq; struct lruvec *lruvec; - struct lru_gen_struct *lrugen; + struct lru_gen_folio *lrugen; int type =3D folio_is_file_lru(folio); int delta =3D folio_nr_pages(folio); int refs =3D folio_lru_refs(folio); @@ -252,7 +252,7 @@ static void lru_gen_refault(struct folio *folio, void *= shadow) unsigned long token; unsigned long min_seq; struct lruvec *lruvec; - struct lru_gen_struct *lrugen; + struct lru_gen_folio *lrugen; struct mem_cgroup *memcg; struct pglist_data *pgdat; int type =3D folio_is_file_lru(folio); --=20 2.39.0.314.g84b9a713c41-goog From nobody Wed Sep 17 07:58:45 2025 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 3026DC4332F for ; Wed, 21 Dec 2022 00:13:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234298AbiLUANF (ORCPT ); Tue, 20 Dec 2022 19:13:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234252AbiLUAMq (ORCPT ); Tue, 20 Dec 2022 19:12:46 -0500 Received: from mail-oo1-xc49.google.com (mail-oo1-xc49.google.com [IPv6:2607:f8b0:4864:20::c49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E52B820357 for ; Tue, 20 Dec 2022 16:12:38 -0800 (PST) Received: by mail-oo1-xc49.google.com with SMTP id w18-20020a4a6d52000000b0049f209d84bbso6158169oof.7 for ; Tue, 20 Dec 2022 16:12:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=gUYK6iVE8NyMy+ADEXjGNSzP24X8eYlgIjWsftpIbpg=; b=COBa/Wmi0UcxSY0BUzCvzZSg4FdxLNKz22ZgMbaxMfNqGEwpnSzK+Ad+FmIUryr6eD hrvb+id173KoljBaCO6ipPfL22rnaj9lF2DyB8tH/BSRRrNnR2DEJAUpA4gNsiZ6FlUc 9HZPbwK4HzsTPIPRO9gNO96gKLjojmVvKA7YaNzfORXUGx/AUbGwKTYiOdvcUazPysOC RVTg6rZoSWlPvMoi58ZR0BbdLKUE04gIzuDoW6fpxTCkbueXJZsu7T+TVfsMZwmTtFgV N+JSbUk0w5cKXD/XclOTxPcIVANu4eZylI/VRfKjcol9oGuLvaY+QWoSz4BSy92hlMpb IPuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gUYK6iVE8NyMy+ADEXjGNSzP24X8eYlgIjWsftpIbpg=; b=3i8RrR6Vx+FkxTlZK6Y10kfxFBRZ3ZBxwgF7Qkb9jV0hOQxF7EMmNPF7N+ldWXbMsX BjvwYI9dec1j+z3TJBltyI44RmgE34Pw3S6ig/9XdYmlLKkXYCOif3MmCnOnyiN5crkB VPksZuPC0/7x6f+Fcl4/qBklNHM9TzR8f1c95n42aAjeiUwJQY8erti3kvmQ2Dk3ZVEe W5ksv93wt4jWgB1C6RQrj0Y1Lb8coV1UvR+rBW59bpYj1phb2Rhnh3pg9gLxETyTBtzB pV60l5itDdHpOF0ET6hRircjL92nFmaBHp5VpfdaQ9iKaCG2ZEtg9mUnRdLsZQk49BzD sD5Q== X-Gm-Message-State: AFqh2kqaFbMfj2cLQLmdPgqOSrbZB67NHYJa0N9fJKnTb0JDRXO+ovXR 6PlkqXTzM0uKfaTOIJYflppyITmjxrc= X-Google-Smtp-Source: AA0mqf4/rwvL7nj+AYw5nim+vzF9pRGefJw2rUsq83pO0l/l8ORY4gc6wDzcNVgSfgwxkSSHUd1IdMkHbhA= X-Received: from yuzhao.bld.corp.google.com ([2620:15c:183:200:a589:30f2:2daa:4ab7]) (user=yuzhao job=sendgmr) by 2002:a05:6870:30e:b0:144:74f1:173d with SMTP id m14-20020a056870030e00b0014474f1173dmr2117657oaf.241.1671581558131; Tue, 20 Dec 2022 16:12:38 -0800 (PST) Date: Tue, 20 Dec 2022 17:12:02 -0700 In-Reply-To: <20221221001207.1376119-1-yuzhao@google.com> Message-Id: <20221221001207.1376119-3-yuzhao@google.com> Mime-Version: 1.0 References: <20221221001207.1376119-1-yuzhao@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Subject: [PATCH mm-unstable v2 2/8] mm: multi-gen LRU: rename lrugen->lists[] to lrugen->folios[] From: Yu Zhao To: Andrew Morton Cc: Johannes Weiner , Jonathan Corbet , Michael Larabel , Michal Hocko , Mike Rapoport , Roman Gushchin , Suren Baghdasaryan , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-mm@google.com, Yu Zhao Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" lru_gen_folio will be chained into per-node lists by the coming lrugen->list. Signed-off-by: Yu Zhao Change-Id: Ib1bee101fd6b73da5409d32e67409fa6475d8cc6 --- Documentation/mm/multigen_lru.rst | 8 ++++---- include/linux/mm_inline.h | 4 ++-- include/linux/mmzone.h | 8 ++++---- mm/vmscan.c | 20 ++++++++++---------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Documentation/mm/multigen_lru.rst b/Documentation/mm/multigen_= lru.rst index d7062c6a8946..d8f721f98868 100644 --- a/Documentation/mm/multigen_lru.rst +++ b/Documentation/mm/multigen_lru.rst @@ -89,15 +89,15 @@ variables are monotonically increasing. =20 Generation numbers are truncated into ``order_base_2(MAX_NR_GENS+1)`` bits in order to fit into the gen counter in ``folio->flags``. Each -truncated generation number is an index to ``lrugen->lists[]``. The +truncated generation number is an index to ``lrugen->folios[]``. The sliding window technique is used to track at least ``MIN_NR_GENS`` and at most ``MAX_NR_GENS`` generations. The gen counter stores a value within ``[1, MAX_NR_GENS]`` while a page is on one of -``lrugen->lists[]``; otherwise it stores zero. +``lrugen->folios[]``; otherwise it stores zero. =20 Each generation is divided into multiple tiers. A page accessed ``N`` times through file descriptors is in tier ``order_base_2(N)``. Unlike -generations, tiers do not have dedicated ``lrugen->lists[]``. In +generations, tiers do not have dedicated ``lrugen->folios[]``. In contrast to moving across generations, which requires the LRU lock, moving across tiers only involves atomic operations on ``folio->flags`` and therefore has a negligible cost. A feedback loop @@ -127,7 +127,7 @@ page mapped by this PTE to ``(max_seq%MAX_NR_GENS)+1``. Eviction -------- The eviction consumes old generations. Given an ``lruvec``, it -increments ``min_seq`` when ``lrugen->lists[]`` indexed by +increments ``min_seq`` when ``lrugen->folios[]`` indexed by ``min_seq%MAX_NR_GENS`` becomes empty. To select a type and a tier to evict from, it first compares ``min_seq[]`` to select the older type. If both types are equally old, it selects the one whose first tier has diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h index f63968bd7de5..da38e3d962e2 100644 --- a/include/linux/mm_inline.h +++ b/include/linux/mm_inline.h @@ -256,9 +256,9 @@ static inline bool lru_gen_add_folio(struct lruvec *lru= vec, struct folio *folio, lru_gen_update_size(lruvec, folio, -1, gen); /* for folio_rotate_reclaimable() */ if (reclaiming) - list_add_tail(&folio->lru, &lrugen->lists[gen][type][zone]); + list_add_tail(&folio->lru, &lrugen->folios[gen][type][zone]); else - list_add(&folio->lru, &lrugen->lists[gen][type][zone]); + list_add(&folio->lru, &lrugen->folios[gen][type][zone]); =20 return true; } diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 1686fcc4ed01..6c96ee823dbd 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -312,7 +312,7 @@ enum lruvec_flags { * They form a sliding window of a variable size [MIN_NR_GENS, MAX_NR_GENS= ]. An * offset within MAX_NR_GENS, i.e., gen, indexes the LRU list of the * corresponding generation. The gen counter in folio->flags stores gen+1 = while - * a page is on one of lrugen->lists[]. Otherwise it stores 0. + * a page is on one of lrugen->folios[]. Otherwise it stores 0. * * A page is added to the youngest generation on faulting. The aging needs= to * check the accessed bit at least twice before handing this page over to = the @@ -324,8 +324,8 @@ enum lruvec_flags { * rest of generations, if they exist, are considered inactive. See * lru_gen_is_active(). * - * PG_active is always cleared while a page is on one of lrugen->lists[] s= o that - * the aging needs not to worry about it. And it's set again when a page + * PG_active is always cleared while a page is on one of lrugen->folios[] = so + * that the aging needs not to worry about it. And it's set again when a p= age * considered active is isolated for non-reclaiming purposes, e.g., migrat= ion. * See lru_gen_add_folio() and lru_gen_del_folio(). * @@ -412,7 +412,7 @@ struct lru_gen_folio { /* the birth time of each generation in jiffies */ unsigned long timestamps[MAX_NR_GENS]; /* the multi-gen LRU lists, lazily sorted on eviction */ - struct list_head lists[MAX_NR_GENS][ANON_AND_FILE][MAX_NR_ZONES]; + struct list_head folios[MAX_NR_GENS][ANON_AND_FILE][MAX_NR_ZONES]; /* the multi-gen LRU sizes, eventually consistent */ long nr_pages[MAX_NR_GENS][ANON_AND_FILE][MAX_NR_ZONES]; /* the exponential moving average of refaulted */ diff --git a/mm/vmscan.c b/mm/vmscan.c index c0c4b0cd2fe2..94477894b226 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4274,7 +4274,7 @@ static bool inc_min_seq(struct lruvec *lruvec, int ty= pe, bool can_swap) =20 /* prevent cold/hot inversion if force_scan is true */ for (zone =3D 0; zone < MAX_NR_ZONES; zone++) { - struct list_head *head =3D &lrugen->lists[old_gen][type][zone]; + struct list_head *head =3D &lrugen->folios[old_gen][type][zone]; =20 while (!list_empty(head)) { struct folio *folio =3D lru_to_folio(head); @@ -4285,7 +4285,7 @@ static bool inc_min_seq(struct lruvec *lruvec, int ty= pe, bool can_swap) VM_WARN_ON_ONCE_FOLIO(folio_zonenum(folio) !=3D zone, folio); =20 new_gen =3D folio_inc_gen(lruvec, folio, false); - list_move_tail(&folio->lru, &lrugen->lists[new_gen][type][zone]); + list_move_tail(&folio->lru, &lrugen->folios[new_gen][type][zone]); =20 if (!--remaining) return false; @@ -4313,7 +4313,7 @@ static bool try_to_inc_min_seq(struct lruvec *lruvec,= bool can_swap) gen =3D lru_gen_from_seq(min_seq[type]); =20 for (zone =3D 0; zone < MAX_NR_ZONES; zone++) { - if (!list_empty(&lrugen->lists[gen][type][zone])) + if (!list_empty(&lrugen->folios[gen][type][zone])) goto next; } =20 @@ -4778,7 +4778,7 @@ static bool sort_folio(struct lruvec *lruvec, struct = folio *folio, int tier_idx) =20 /* promoted */ if (gen !=3D lru_gen_from_seq(lrugen->min_seq[type])) { - list_move(&folio->lru, &lrugen->lists[gen][type][zone]); + list_move(&folio->lru, &lrugen->folios[gen][type][zone]); return true; } =20 @@ -4787,7 +4787,7 @@ static bool sort_folio(struct lruvec *lruvec, struct = folio *folio, int tier_idx) int hist =3D lru_hist_from_seq(lrugen->min_seq[type]); =20 gen =3D folio_inc_gen(lruvec, folio, false); - list_move_tail(&folio->lru, &lrugen->lists[gen][type][zone]); + list_move_tail(&folio->lru, &lrugen->folios[gen][type][zone]); =20 WRITE_ONCE(lrugen->protected[hist][type][tier - 1], lrugen->protected[hist][type][tier - 1] + delta); @@ -4799,7 +4799,7 @@ static bool sort_folio(struct lruvec *lruvec, struct = folio *folio, int tier_idx) if (folio_test_locked(folio) || folio_test_writeback(folio) || (type =3D=3D LRU_GEN_FILE && folio_test_dirty(folio))) { gen =3D folio_inc_gen(lruvec, folio, true); - list_move(&folio->lru, &lrugen->lists[gen][type][zone]); + list_move(&folio->lru, &lrugen->folios[gen][type][zone]); return true; } =20 @@ -4866,7 +4866,7 @@ static int scan_folios(struct lruvec *lruvec, struct = scan_control *sc, for (zone =3D sc->reclaim_idx; zone >=3D 0; zone--) { LIST_HEAD(moved); int skipped =3D 0; - struct list_head *head =3D &lrugen->lists[gen][type][zone]; + struct list_head *head =3D &lrugen->folios[gen][type][zone]; =20 while (!list_empty(head)) { struct folio *folio =3D lru_to_folio(head); @@ -5267,7 +5267,7 @@ static bool __maybe_unused state_is_valid(struct lruv= ec *lruvec) int gen, type, zone; =20 for_each_gen_type_zone(gen, type, zone) { - if (!list_empty(&lrugen->lists[gen][type][zone])) + if (!list_empty(&lrugen->folios[gen][type][zone])) return false; } } @@ -5312,7 +5312,7 @@ static bool drain_evictable(struct lruvec *lruvec) int remaining =3D MAX_LRU_BATCH; =20 for_each_gen_type_zone(gen, type, zone) { - struct list_head *head =3D &lruvec->lrugen.lists[gen][type][zone]; + struct list_head *head =3D &lruvec->lrugen.folios[gen][type][zone]; =20 while (!list_empty(head)) { bool success; @@ -5846,7 +5846,7 @@ void lru_gen_init_lruvec(struct lruvec *lruvec) lrugen->timestamps[i] =3D jiffies; =20 for_each_gen_type_zone(gen, type, zone) - INIT_LIST_HEAD(&lrugen->lists[gen][type][zone]); + INIT_LIST_HEAD(&lrugen->folios[gen][type][zone]); =20 lruvec->mm_state.seq =3D MIN_NR_GENS; init_waitqueue_head(&lruvec->mm_state.wait); --=20 2.39.0.314.g84b9a713c41-goog From nobody Wed Sep 17 07:58:45 2025 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 C4DB0C4332F for ; Wed, 21 Dec 2022 00:13:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234347AbiLUANJ (ORCPT ); Tue, 20 Dec 2022 19:13:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234180AbiLUAMq (ORCPT ); Tue, 20 Dec 2022 19:12:46 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A8322035F for ; Tue, 20 Dec 2022 16:12:40 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id r7-20020a25c107000000b006ff55ac0ee7so15830836ybf.15 for ; Tue, 20 Dec 2022 16:12:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=y306PH8Q0yp+xWizSY/ux8ywn6bxHcRrOk54D5HB2aU=; b=GlPiUBTF+eOAUqdbrju+L1+Kh2wEO8CK+cMwhM7K6Y1IUVWqKXq6Srl0dPkE6NZEHM NvnzPFwFsuQL7HH8D4QeVAltwJBOXQAXNpJV2tlNz2kzmGWq9+RWxmJgjzKJ7BDlJTx8 BqlrCKIq6REydAxMtmiIG1Wk7yRm/0MIuq/sGKpU/qThTOiFIb8txt0eAaelMAUKVpmt xnWEPSQG7j+mL+CH22sZaicYWYgO9eV7VsqFV55qrg9aMH2v/OL9Z3KNrB4iBvpBGcTS 1auKzt2mFvRdMGB4k6qPXceTvJwVKzP3vKVe4g+/uaB/gSrnSFHF0RKsFAdGd7PY39hz SECQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=y306PH8Q0yp+xWizSY/ux8ywn6bxHcRrOk54D5HB2aU=; b=yLXe85sFcWQ+lTY69chNbFJy9oQRAZz8Zp0htpwf36wt1wjf2xpBAWaWWHvTNbOAXw Sk0KIYadyDhz9dSygAj+7NgDkdjhAYREaZgzOVna14/RfliR/oZLCM/AFgKrQGNiciyF L6H33oC4VBKJMg4vSKjIoRm4eghwTXjuGeJd+ewGiX5c0QTCvDoe5mtSJ4wIyJ6lhqOl M8sXkjr9b7paroDrJB0soPIxVw5tvHOEVBa1FsKmK/iy1UYeUefADUCIo82quF0CuZwE 9FBYKcFusbzqpcdx4Lnfkh/6RvQiOebRV2RN5sSfWu6a25Oq0c7NbBHYiV25NhQ7fCva 4Avw== X-Gm-Message-State: ANoB5pkSk8IgB7NbLezUw+foAV4UokKmJf9wL22DSgDeSCXT8I98IC79 vldZGW3NxTC9cT5dI/tVr96RGMqVAHg= X-Google-Smtp-Source: AA0mqf4kmUm3Oml4SQcszfQyWi0BIkPzgCXt6tJS052cJtMI6HpR2ijMRjA//FRRHQ1i3YBOkd6DUZjJlrY= X-Received: from yuzhao.bld.corp.google.com ([2620:15c:183:200:a589:30f2:2daa:4ab7]) (user=yuzhao job=sendgmr) by 2002:a05:690c:903:b0:3b7:e501:90cf with SMTP id cb3-20020a05690c090300b003b7e50190cfmr5497843ywb.501.1671581559741; Tue, 20 Dec 2022 16:12:39 -0800 (PST) Date: Tue, 20 Dec 2022 17:12:03 -0700 In-Reply-To: <20221221001207.1376119-1-yuzhao@google.com> Message-Id: <20221221001207.1376119-4-yuzhao@google.com> Mime-Version: 1.0 References: <20221221001207.1376119-1-yuzhao@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Subject: [PATCH mm-unstable v2 3/8] mm: multi-gen LRU: remove eviction fairness safeguard From: Yu Zhao To: Andrew Morton Cc: Johannes Weiner , Jonathan Corbet , Michael Larabel , Michal Hocko , Mike Rapoport , Roman Gushchin , Suren Baghdasaryan , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-mm@google.com, Yu Zhao Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Recall that the eviction consumes the oldest generation: first it bucket-sorts folios whose gen counters were updated by the aging and reclaims the rest; then it increments lrugen->min_seq. The current eviction fairness safeguard for global reclaim has a dilemma: when there are multiple eligible memcgs, should it continue or stop upon meeting the reclaim goal? If it continues, it overshoots and increases direct reclaim latency; if it stops, it loses fairness between memcgs it has taken memory away from and those it has yet to. With memcg LRU, the eviction, while ensuring eventual fairness, will stop upon meeting its goal. Therefore the current eviction fairness safeguard for global reclaim will not be needed. Note that memcg LRU only applies to global reclaim. For memcg reclaim, the eviction will continue, even if it is overshooting. This becomes unconditional due to code simplification. Signed-off-by: Yu Zhao Change-Id: Ieb2a658c8d441ec11348d2985c7c4d6b72106f6a --- mm/vmscan.c | 81 +++++++++++++++-------------------------------------- 1 file changed, 23 insertions(+), 58 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 94477894b226..9655b3b3a95e 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -449,6 +449,11 @@ static bool cgroup_reclaim(struct scan_control *sc) return sc->target_mem_cgroup; } =20 +static bool global_reclaim(struct scan_control *sc) +{ + return !sc->target_mem_cgroup || mem_cgroup_is_root(sc->target_mem_cgroup= ); +} + /** * writeback_throttling_sane - is the usual dirty throttling mechanism ava= ilable? * @sc: scan_control in question @@ -499,6 +504,11 @@ static bool cgroup_reclaim(struct scan_control *sc) return false; } =20 +static bool global_reclaim(struct scan_control *sc) +{ + return true; +} + static bool writeback_throttling_sane(struct scan_control *sc) { return true; @@ -5009,8 +5019,7 @@ static int isolate_folios(struct lruvec *lruvec, stru= ct scan_control *sc, int sw return scanned; } =20 -static int evict_folios(struct lruvec *lruvec, struct scan_control *sc, in= t swappiness, - bool *need_swapping) +static int evict_folios(struct lruvec *lruvec, struct scan_control *sc, in= t swappiness) { int type; int scanned; @@ -5099,9 +5108,6 @@ static int evict_folios(struct lruvec *lruvec, struct= scan_control *sc, int swap goto retry; } =20 - if (need_swapping && type =3D=3D LRU_GEN_ANON) - *need_swapping =3D true; - return scanned; } =20 @@ -5141,67 +5147,26 @@ static unsigned long get_nr_to_scan(struct lruvec *= lruvec, struct scan_control * return min_seq[!can_swap] + MIN_NR_GENS <=3D max_seq ? nr_to_scan : 0; } =20 -static bool should_abort_scan(struct lruvec *lruvec, unsigned long seq, - struct scan_control *sc, bool need_swapping) +static unsigned long get_nr_to_reclaim(struct scan_control *sc) { - int i; - DEFINE_MAX_SEQ(lruvec); + /* don't abort memcg reclaim to ensure fairness */ + if (!global_reclaim(sc)) + return -1; =20 - if (!current_is_kswapd()) { - /* age each memcg at most once to ensure fairness */ - if (max_seq - seq > 1) - return true; + /* discount the previous progress for kswapd */ + if (current_is_kswapd()) + return sc->nr_to_reclaim + sc->last_reclaimed; =20 - /* over-swapping can increase allocation latency */ - if (sc->nr_reclaimed >=3D sc->nr_to_reclaim && need_swapping) - return true; - - /* give this thread a chance to exit and free its memory */ - if (fatal_signal_pending(current)) { - sc->nr_reclaimed +=3D MIN_LRU_BATCH; - return true; - } - - if (cgroup_reclaim(sc)) - return false; - } else if (sc->nr_reclaimed - sc->last_reclaimed < sc->nr_to_reclaim) - return false; - - /* keep scanning at low priorities to ensure fairness */ - if (sc->priority > DEF_PRIORITY - 2) - return false; - - /* - * A minimum amount of work was done under global memory pressure. For - * kswapd, it may be overshooting. For direct reclaim, the allocation - * may succeed if all suitable zones are somewhat safe. In either case, - * it's better to stop now, and restart later if necessary. - */ - for (i =3D 0; i <=3D sc->reclaim_idx; i++) { - unsigned long wmark; - struct zone *zone =3D lruvec_pgdat(lruvec)->node_zones + i; - - if (!managed_zone(zone)) - continue; - - wmark =3D current_is_kswapd() ? high_wmark_pages(zone) : low_wmark_pages= (zone); - if (wmark > zone_page_state(zone, NR_FREE_PAGES)) - return false; - } - - sc->nr_reclaimed +=3D MIN_LRU_BATCH; - - return true; + return max(sc->nr_to_reclaim, compact_gap(sc->order)); } =20 static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_contr= ol *sc) { struct blk_plug plug; bool need_aging =3D false; - bool need_swapping =3D false; unsigned long scanned =3D 0; unsigned long reclaimed =3D sc->nr_reclaimed; - DEFINE_MAX_SEQ(lruvec); + unsigned long nr_to_reclaim =3D get_nr_to_reclaim(sc); =20 lru_add_drain(); =20 @@ -5225,7 +5190,7 @@ static void lru_gen_shrink_lruvec(struct lruvec *lruv= ec, struct scan_control *sc if (!nr_to_scan) goto done; =20 - delta =3D evict_folios(lruvec, sc, swappiness, &need_swapping); + delta =3D evict_folios(lruvec, sc, swappiness); if (!delta) goto done; =20 @@ -5233,7 +5198,7 @@ static void lru_gen_shrink_lruvec(struct lruvec *lruv= ec, struct scan_control *sc if (scanned >=3D nr_to_scan) break; =20 - if (should_abort_scan(lruvec, max_seq, sc, need_swapping)) + if (sc->nr_reclaimed >=3D nr_to_reclaim) break; =20 cond_resched(); @@ -5680,7 +5645,7 @@ static int run_eviction(struct lruvec *lruvec, unsign= ed long seq, struct scan_co if (sc->nr_reclaimed >=3D nr_to_reclaim) return 0; =20 - if (!evict_folios(lruvec, sc, swappiness, NULL)) + if (!evict_folios(lruvec, sc, swappiness)) return 0; =20 cond_resched(); --=20 2.39.0.314.g84b9a713c41-goog From nobody Wed Sep 17 07:58:45 2025 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 8132FC4332F for ; Wed, 21 Dec 2022 00:13:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234363AbiLUANP (ORCPT ); Tue, 20 Dec 2022 19:13:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234274AbiLUAMr (ORCPT ); Tue, 20 Dec 2022 19:12:47 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3A78201A5 for ; Tue, 20 Dec 2022 16:12:41 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 195-20020a2505cc000000b0071163981d18so15962962ybf.13 for ; Tue, 20 Dec 2022 16:12:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=W215O6nVZQSEsqpHqtb/vUKPzkuQ3oMopgbAZLI2Y6k=; b=eG/fUD4zGkFUZK+ZF+HvzoNHr/U2E6OCu8wDseqLAQ7XetG2/d97LSGE+vjDKJW/8T 55c6gGFY7rbXkizJhVfunHV+jAKiBzVpXbBFN3tFXqv08tKo4j5tbJdoIFIVw8yuZZEd ze4WDTwcwXETWVT8Z2vGRdjfiisp9rSc1HLiCfPkE6vpTXTeOalRHGAvgdBLPNLdEZx2 jkxOB+JW7wkH/evopjYD7Zl4/gzUQ+yv9/VY+Ad2IDAebHIFWEaxMQI2vQiJqEidlS4M B0fpb9bK118a9RvoRkIDcjCWKNmiMIf1PgLrjubYfLSYbJNQvRTJ++80oy6hzbiOWW49 rdWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=W215O6nVZQSEsqpHqtb/vUKPzkuQ3oMopgbAZLI2Y6k=; b=1JU8p5Vi2Fp6ZQ79fv05/X1WspVZxf65gnXpPWkMGeFsalbjUy1UX87f0o0Lp0MTxz tjvuemn6wfpJ2XP9DxA+lAGuyqOLyI4evbd5PQPObY7CTB7DmykMV64nsr62YSH4hLAE Bon9i6DSha/CW4xtToE6Z/kHAZw1KMG6UvmxV6VhO2/JxBqzDHJP4f2n6FkrYxSbfA21 V346cOmLZyYg9yRGd5LokO4glm+qKkD2ko6jjP1T1Khxed7AesQmtriYU0ihQhmiwJw3 lipWrchuKICV9qX+Vs1yJj10oHOzql/+n3N44oUu8YelWnBAiTCGpQlIyutifCbC4SY3 VZ/Q== X-Gm-Message-State: AFqh2koUI9g2cFGCx/rb7g0IkeNowJ6yJvOiohPecaWTZAuAuF6A59d7 73tn341AiZTmfs5W57yes/KOCdHs5aA= X-Google-Smtp-Source: AMrXdXv0COwLPwkTS0Vl7hKGmMXAA1gr18YJ0e5zARRIGHI8mnjrVM8t0QekFFd4Y0N7jJ2180yJ1mZynA4= X-Received: from yuzhao.bld.corp.google.com ([2620:15c:183:200:a589:30f2:2daa:4ab7]) (user=yuzhao job=sendgmr) by 2002:a25:9d8c:0:b0:733:4d8d:f01a with SMTP id v12-20020a259d8c000000b007334d8df01amr3223932ybp.399.1671581561148; Tue, 20 Dec 2022 16:12:41 -0800 (PST) Date: Tue, 20 Dec 2022 17:12:04 -0700 In-Reply-To: <20221221001207.1376119-1-yuzhao@google.com> Message-Id: <20221221001207.1376119-5-yuzhao@google.com> Mime-Version: 1.0 References: <20221221001207.1376119-1-yuzhao@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Subject: [PATCH mm-unstable v2 4/8] mm: multi-gen LRU: remove aging fairness safeguard From: Yu Zhao To: Andrew Morton Cc: Johannes Weiner , Jonathan Corbet , Michael Larabel , Michal Hocko , Mike Rapoport , Roman Gushchin , Suren Baghdasaryan , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-mm@google.com, Yu Zhao Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Recall that the aging produces the youngest generation: first it scans for accessed folios and updates their gen counters; then it increments lrugen->max_seq. The current aging fairness safeguard for kswapd uses two passes to ensure the fairness to multiple eligible memcgs. On the first pass, which is shared with the eviction, it checks whether all eligible memcgs are low on cold folios. If so, it requires a second pass, on which it ages all those memcgs at the same time. With memcg LRU, the aging, while ensuring eventual fairness, will run when necessary. Therefore the current aging fairness safeguard for kswapd will not be needed. Note that memcg LRU only applies to global reclaim. For memcg reclaim, the aging can be unfair to different memcgs, i.e., their lrugen->max_seq can be incremented at different paces. Signed-off-by: Yu Zhao Change-Id: I66c70bd31d5276c710ad9209f0a74b1c24a0eda9 --- mm/vmscan.c | 150 +++++++++++++++++++++++++--------------------------- 1 file changed, 71 insertions(+), 79 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 9655b3b3a95e..a2f71400b8be 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -137,7 +137,6 @@ struct scan_control { =20 #ifdef CONFIG_LRU_GEN /* help kswapd make better choices among multiple memcgs */ - unsigned int memcgs_need_aging:1; unsigned long last_reclaimed; #endif =20 @@ -4471,7 +4470,7 @@ static bool try_to_inc_max_seq(struct lruvec *lruvec,= unsigned long max_seq, return true; } =20 -static bool should_run_aging(struct lruvec *lruvec, unsigned long max_seq,= unsigned long *min_seq, +static bool should_run_aging(struct lruvec *lruvec, unsigned long max_seq, struct scan_control *sc, bool can_swap, unsigned long *nr_to_scan) { int gen, type, zone; @@ -4480,6 +4479,13 @@ static bool should_run_aging(struct lruvec *lruvec, = unsigned long max_seq, unsig unsigned long total =3D 0; struct lru_gen_folio *lrugen =3D &lruvec->lrugen; struct mem_cgroup *memcg =3D lruvec_memcg(lruvec); + DEFINE_MIN_SEQ(lruvec); + + /* whether this lruvec is completely out of cold folios */ + if (min_seq[!can_swap] + MIN_NR_GENS > max_seq) { + *nr_to_scan =3D 0; + return true; + } =20 for (type =3D !can_swap; type < ANON_AND_FILE; type++) { unsigned long seq; @@ -4508,8 +4514,6 @@ static bool should_run_aging(struct lruvec *lruvec, u= nsigned long max_seq, unsig * stalls when the number of generations reaches MIN_NR_GENS. Hence, the * ideal number of generations is MIN_NR_GENS+1. */ - if (min_seq[!can_swap] + MIN_NR_GENS > max_seq) - return true; if (min_seq[!can_swap] + MIN_NR_GENS < max_seq) return false; =20 @@ -4528,40 +4532,54 @@ static bool should_run_aging(struct lruvec *lruvec,= unsigned long max_seq, unsig return false; } =20 -static bool age_lruvec(struct lruvec *lruvec, struct scan_control *sc, uns= igned long min_ttl) +static bool lruvec_is_sizable(struct lruvec *lruvec, struct scan_control *= sc) { - bool need_aging; - unsigned long nr_to_scan; - int swappiness =3D get_swappiness(lruvec, sc); + int gen, type, zone; + unsigned long total =3D 0; + bool can_swap =3D get_swappiness(lruvec, sc); + struct lru_gen_folio *lrugen =3D &lruvec->lrugen; struct mem_cgroup *memcg =3D lruvec_memcg(lruvec); DEFINE_MAX_SEQ(lruvec); DEFINE_MIN_SEQ(lruvec); =20 + for (type =3D !can_swap; type < ANON_AND_FILE; type++) { + unsigned long seq; + + for (seq =3D min_seq[type]; seq <=3D max_seq; seq++) { + gen =3D lru_gen_from_seq(seq); + + for (zone =3D 0; zone < MAX_NR_ZONES; zone++) + total +=3D max(READ_ONCE(lrugen->nr_pages[gen][type][zone]), 0L); + } + } + + /* whether the size is big enough to be helpful */ + return mem_cgroup_online(memcg) ? (total >> sc->priority) : total; +} + +static bool lruvec_is_reclaimable(struct lruvec *lruvec, struct scan_contr= ol *sc, + unsigned long min_ttl) +{ + int gen; + unsigned long birth; + struct mem_cgroup *memcg =3D lruvec_memcg(lruvec); + DEFINE_MIN_SEQ(lruvec); + VM_WARN_ON_ONCE(sc->memcg_low_reclaim); =20 + /* see the comment on lru_gen_folio */ + gen =3D lru_gen_from_seq(min_seq[LRU_GEN_FILE]); + birth =3D READ_ONCE(lruvec->lrugen.timestamps[gen]); + + if (time_is_after_jiffies(birth + min_ttl)) + return false; + + if (!lruvec_is_sizable(lruvec, sc)) + return false; + mem_cgroup_calculate_protection(NULL, memcg); =20 - if (mem_cgroup_below_min(NULL, memcg)) - return false; - - need_aging =3D should_run_aging(lruvec, max_seq, min_seq, sc, swappiness,= &nr_to_scan); - - if (min_ttl) { - int gen =3D lru_gen_from_seq(min_seq[LRU_GEN_FILE]); - unsigned long birth =3D READ_ONCE(lruvec->lrugen.timestamps[gen]); - - if (time_is_after_jiffies(birth + min_ttl)) - return false; - - /* the size is likely too small to be helpful */ - if (!nr_to_scan && sc->priority !=3D DEF_PRIORITY) - return false; - } - - if (need_aging) - try_to_inc_max_seq(lruvec, max_seq, sc, swappiness, false); - - return true; + return !mem_cgroup_below_min(NULL, memcg); } =20 /* to protect the working set of the last N jiffies */ @@ -4570,46 +4588,32 @@ static unsigned long lru_gen_min_ttl __read_mostly; static void lru_gen_age_node(struct pglist_data *pgdat, struct scan_contro= l *sc) { struct mem_cgroup *memcg; - bool success =3D false; unsigned long min_ttl =3D READ_ONCE(lru_gen_min_ttl); =20 VM_WARN_ON_ONCE(!current_is_kswapd()); =20 sc->last_reclaimed =3D sc->nr_reclaimed; =20 - /* - * To reduce the chance of going into the aging path, which can be - * costly, optimistically skip it if the flag below was cleared in the - * eviction path. This improves the overall performance when multiple - * memcgs are available. - */ - if (!sc->memcgs_need_aging) { - sc->memcgs_need_aging =3D true; - return; - } - - set_mm_walk(pgdat); - - memcg =3D mem_cgroup_iter(NULL, NULL, NULL); - do { - struct lruvec *lruvec =3D mem_cgroup_lruvec(memcg, pgdat); - - if (age_lruvec(lruvec, sc, min_ttl)) - success =3D true; - - cond_resched(); - } while ((memcg =3D mem_cgroup_iter(NULL, memcg, NULL))); - - clear_mm_walk(); - /* check the order to exclude compaction-induced reclaim */ - if (success || !min_ttl || sc->order) + if (!min_ttl || sc->order || sc->priority =3D=3D DEF_PRIORITY) return; =20 + memcg =3D mem_cgroup_iter(NULL, NULL, NULL); + do { + struct lruvec *lruvec =3D mem_cgroup_lruvec(memcg, pgdat); + + if (lruvec_is_reclaimable(lruvec, sc, min_ttl)) { + mem_cgroup_iter_break(NULL, memcg); + return; + } + + cond_resched(); + } while ((memcg =3D mem_cgroup_iter(NULL, memcg, NULL))); + /* * The main goal is to OOM kill if every generation from all memcgs is * younger than min_ttl. However, another possibility is all memcgs are - * either below min or empty. + * either too small or below min. */ if (mutex_trylock(&oom_lock)) { struct oom_control oc =3D { @@ -5117,34 +5121,28 @@ static int evict_folios(struct lruvec *lruvec, stru= ct scan_control *sc, int swap * reclaim. */ static unsigned long get_nr_to_scan(struct lruvec *lruvec, struct scan_con= trol *sc, - bool can_swap, bool *need_aging) + bool can_swap) { unsigned long nr_to_scan; struct mem_cgroup *memcg =3D lruvec_memcg(lruvec); DEFINE_MAX_SEQ(lruvec); - DEFINE_MIN_SEQ(lruvec); =20 if (mem_cgroup_below_min(sc->target_mem_cgroup, memcg) || (mem_cgroup_below_low(sc->target_mem_cgroup, memcg) && !sc->memcg_low_reclaim)) return 0; =20 - *need_aging =3D should_run_aging(lruvec, max_seq, min_seq, sc, can_swap, = &nr_to_scan); - if (!*need_aging) + if (!should_run_aging(lruvec, max_seq, sc, can_swap, &nr_to_scan)) return nr_to_scan; =20 /* skip the aging path at the default priority */ if (sc->priority =3D=3D DEF_PRIORITY) - goto done; - - /* leave the work to lru_gen_age_node() */ - if (current_is_kswapd()) - return 0; - - if (try_to_inc_max_seq(lruvec, max_seq, sc, can_swap, false)) return nr_to_scan; -done: - return min_seq[!can_swap] + MIN_NR_GENS <=3D max_seq ? nr_to_scan : 0; + + try_to_inc_max_seq(lruvec, max_seq, sc, can_swap, false); + + /* skip this lruvec as it's low on cold folios */ + return 0; } =20 static unsigned long get_nr_to_reclaim(struct scan_control *sc) @@ -5163,9 +5161,7 @@ static unsigned long get_nr_to_reclaim(struct scan_co= ntrol *sc) static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_contr= ol *sc) { struct blk_plug plug; - bool need_aging =3D false; unsigned long scanned =3D 0; - unsigned long reclaimed =3D sc->nr_reclaimed; unsigned long nr_to_reclaim =3D get_nr_to_reclaim(sc); =20 lru_add_drain(); @@ -5186,13 +5182,13 @@ static void lru_gen_shrink_lruvec(struct lruvec *lr= uvec, struct scan_control *sc else swappiness =3D 0; =20 - nr_to_scan =3D get_nr_to_scan(lruvec, sc, swappiness, &need_aging); + nr_to_scan =3D get_nr_to_scan(lruvec, sc, swappiness); if (!nr_to_scan) - goto done; + break; =20 delta =3D evict_folios(lruvec, sc, swappiness); if (!delta) - goto done; + break; =20 scanned +=3D delta; if (scanned >=3D nr_to_scan) @@ -5204,10 +5200,6 @@ static void lru_gen_shrink_lruvec(struct lruvec *lru= vec, struct scan_control *sc cond_resched(); } =20 - /* see the comment in lru_gen_age_node() */ - if (sc->nr_reclaimed - reclaimed >=3D MIN_LRU_BATCH && !need_aging) - sc->memcgs_need_aging =3D false; -done: clear_mm_walk(); =20 blk_finish_plug(&plug); --=20 2.39.0.314.g84b9a713c41-goog From nobody Wed Sep 17 07:58:45 2025 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 DD8BBC4332F for ; Wed, 21 Dec 2022 00:13:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234378AbiLUANW (ORCPT ); Tue, 20 Dec 2022 19:13:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234297AbiLUAMs (ORCPT ); Tue, 20 Dec 2022 19:12:48 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37CFD20365 for ; Tue, 20 Dec 2022 16:12:43 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id i10-20020a25f20a000000b006ea4f43c0ddso16056099ybe.21 for ; Tue, 20 Dec 2022 16:12:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=5gz0YgVLNDGFuqc3Lh4NnPiIlhtb3z+cq+FKhQZOoZk=; b=pYjtLo94emkX9HO5dNLwhnNl1q+/QkmPT4BV1Q2CYxKbEqjmuBFe+6E8hDAD23TmkJ rM8E5hVkIT1iJndDE4GFfnTHJmPy8rBNDiU6xKV12vavnbPR7PD/inFgUi8kelq6KFXs 0OyI9IPv8w8vh7ij2xerLvGSfzs7TWadUGqYgShpNGJ5FVlZQd8389NLfnqGGFtFYhZ5 yMAQh71Vn5/4k+ix3kKLG2LnpGcKhFJb6ylWem23nVTzY3PJF0dMSMUj/ohq835xZL4p HniHGo7EmzRDdAifMnyP6l1XmBjesx3FTwryw+4a+i46NpHmyyWubfVZzsndi55Y/SZd SgAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5gz0YgVLNDGFuqc3Lh4NnPiIlhtb3z+cq+FKhQZOoZk=; b=kglMooeIGQ6Fd4xNyKy73FLgcdYGLiQo8DY+MBhGQkikv1GwPl+TDd8WgjD1fuO8HZ xSQuH8wMX39UJw3U1UmdiiB9VVSz3Q6Dwqe+5S0nf6E0ySp6ABLt0KBxLW/iMt2xwExx ru9f/vWz1YaSZfKv06qzDg/Ys4Yy1PoOzLlt2qz594OzfcsjmwQtZeudjO5mr+M9wwyL 9a2Ig6wmO26tbJlZlOQuYCCQ0fTfNIgfO8uxdaHssNT8GdtJsmAfKi0p0jtbitW5DZn+ YVnbxisWibqzF9a6PSwio3lD/P1FNWRJR9jrMj22JycgyaXVxVV+6mf6CyJkP9T3SCWs +jTg== X-Gm-Message-State: ANoB5pmDuLs3lShyj3HvLD/T0+5ZHIthaLGzBJAktgdge3fSHclzjSUk OJXa7ahTTqGABkf/GpWQ0Oggs08KuSU= X-Google-Smtp-Source: AA0mqf5J92WPjbmjq0S0/8L8nqyD/H5zHMKEWJbsreI8pJ3tp81Dmd741SGe/PrsNv8NhFNSwOv39dKlDJo= X-Received: from yuzhao.bld.corp.google.com ([2620:15c:183:200:a589:30f2:2daa:4ab7]) (user=yuzhao job=sendgmr) by 2002:a81:4d07:0:b0:427:c319:1abe with SMTP id a7-20020a814d07000000b00427c3191abemr3853654ywb.328.1671581562522; Tue, 20 Dec 2022 16:12:42 -0800 (PST) Date: Tue, 20 Dec 2022 17:12:05 -0700 In-Reply-To: <20221221001207.1376119-1-yuzhao@google.com> Message-Id: <20221221001207.1376119-6-yuzhao@google.com> Mime-Version: 1.0 References: <20221221001207.1376119-1-yuzhao@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Subject: [PATCH mm-unstable v2 5/8] mm: multi-gen LRU: shuffle should_run_aging() From: Yu Zhao To: Andrew Morton Cc: Johannes Weiner , Jonathan Corbet , Michael Larabel , Michal Hocko , Mike Rapoport , Roman Gushchin , Suren Baghdasaryan , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-mm@google.com, Yu Zhao Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move should_run_aging() next to its only caller left. Signed-off-by: Yu Zhao Change-Id: I07e5372b98ca28c003861fdeddadde4304abcfe4 --- mm/vmscan.c | 124 ++++++++++++++++++++++++++-------------------------- 1 file changed, 62 insertions(+), 62 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index a2f71400b8be..c424cc06f8c6 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4470,68 +4470,6 @@ static bool try_to_inc_max_seq(struct lruvec *lruvec= , unsigned long max_seq, return true; } =20 -static bool should_run_aging(struct lruvec *lruvec, unsigned long max_seq, - struct scan_control *sc, bool can_swap, unsigned long *nr_to_scan) -{ - int gen, type, zone; - unsigned long old =3D 0; - unsigned long young =3D 0; - unsigned long total =3D 0; - struct lru_gen_folio *lrugen =3D &lruvec->lrugen; - struct mem_cgroup *memcg =3D lruvec_memcg(lruvec); - DEFINE_MIN_SEQ(lruvec); - - /* whether this lruvec is completely out of cold folios */ - if (min_seq[!can_swap] + MIN_NR_GENS > max_seq) { - *nr_to_scan =3D 0; - return true; - } - - for (type =3D !can_swap; type < ANON_AND_FILE; type++) { - unsigned long seq; - - for (seq =3D min_seq[type]; seq <=3D max_seq; seq++) { - unsigned long size =3D 0; - - gen =3D lru_gen_from_seq(seq); - - for (zone =3D 0; zone < MAX_NR_ZONES; zone++) - size +=3D max(READ_ONCE(lrugen->nr_pages[gen][type][zone]), 0L); - - total +=3D size; - if (seq =3D=3D max_seq) - young +=3D size; - else if (seq + MIN_NR_GENS =3D=3D max_seq) - old +=3D size; - } - } - - /* try to scrape all its memory if this memcg was deleted */ - *nr_to_scan =3D mem_cgroup_online(memcg) ? (total >> sc->priority) : tota= l; - - /* - * The aging tries to be lazy to reduce the overhead, while the eviction - * stalls when the number of generations reaches MIN_NR_GENS. Hence, the - * ideal number of generations is MIN_NR_GENS+1. - */ - if (min_seq[!can_swap] + MIN_NR_GENS < max_seq) - return false; - - /* - * It's also ideal to spread pages out evenly, i.e., 1/(MIN_NR_GENS+1) - * of the total number of pages for each generation. A reasonable range - * for this average portion is [1/MIN_NR_GENS, 1/(MIN_NR_GENS+2)]. The - * aging cares about the upper bound of hot pages, while the eviction - * cares about the lower bound of cold pages. - */ - if (young * MIN_NR_GENS > total) - return true; - if (old * (MIN_NR_GENS + 2) < total) - return true; - - return false; -} - static bool lruvec_is_sizable(struct lruvec *lruvec, struct scan_control *= sc) { int gen, type, zone; @@ -5115,6 +5053,68 @@ static int evict_folios(struct lruvec *lruvec, struc= t scan_control *sc, int swap return scanned; } =20 +static bool should_run_aging(struct lruvec *lruvec, unsigned long max_seq, + struct scan_control *sc, bool can_swap, unsigned long *nr_to_scan) +{ + int gen, type, zone; + unsigned long old =3D 0; + unsigned long young =3D 0; + unsigned long total =3D 0; + struct lru_gen_folio *lrugen =3D &lruvec->lrugen; + struct mem_cgroup *memcg =3D lruvec_memcg(lruvec); + DEFINE_MIN_SEQ(lruvec); + + /* whether this lruvec is completely out of cold folios */ + if (min_seq[!can_swap] + MIN_NR_GENS > max_seq) { + *nr_to_scan =3D 0; + return true; + } + + for (type =3D !can_swap; type < ANON_AND_FILE; type++) { + unsigned long seq; + + for (seq =3D min_seq[type]; seq <=3D max_seq; seq++) { + unsigned long size =3D 0; + + gen =3D lru_gen_from_seq(seq); + + for (zone =3D 0; zone < MAX_NR_ZONES; zone++) + size +=3D max(READ_ONCE(lrugen->nr_pages[gen][type][zone]), 0L); + + total +=3D size; + if (seq =3D=3D max_seq) + young +=3D size; + else if (seq + MIN_NR_GENS =3D=3D max_seq) + old +=3D size; + } + } + + /* try to scrape all its memory if this memcg was deleted */ + *nr_to_scan =3D mem_cgroup_online(memcg) ? (total >> sc->priority) : tota= l; + + /* + * The aging tries to be lazy to reduce the overhead, while the eviction + * stalls when the number of generations reaches MIN_NR_GENS. Hence, the + * ideal number of generations is MIN_NR_GENS+1. + */ + if (min_seq[!can_swap] + MIN_NR_GENS < max_seq) + return false; + + /* + * It's also ideal to spread pages out evenly, i.e., 1/(MIN_NR_GENS+1) + * of the total number of pages for each generation. A reasonable range + * for this average portion is [1/MIN_NR_GENS, 1/(MIN_NR_GENS+2)]. The + * aging cares about the upper bound of hot pages, while the eviction + * cares about the lower bound of cold pages. + */ + if (young * MIN_NR_GENS > total) + return true; + if (old * (MIN_NR_GENS + 2) < total) + return true; + + return false; +} + /* * For future optimizations: * 1. Defer try_to_inc_max_seq() to workqueues to reduce latency for memcg --=20 2.39.0.314.g84b9a713c41-goog From nobody Wed Sep 17 07:58:45 2025 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 7631AC4332F for ; Wed, 21 Dec 2022 00:13:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234417AbiLUANq (ORCPT ); Tue, 20 Dec 2022 19:13:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234227AbiLUAMu (ORCPT ); Tue, 20 Dec 2022 19:12:50 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96E592036A for ; Tue, 20 Dec 2022 16:12:44 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id f11-20020a5b01cb000000b0070374b66537so15968577ybp.14 for ; Tue, 20 Dec 2022 16:12:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=9RaF+jsgl78F4GBrxUC5NFR9ONl7CxKbRAdYv2n4r6w=; b=codeYwy+3WhegyKvjhf4lUEgs7xctF0KP/3pv3spz94RHy1bRHbB8jKCb97UGUOalS KKDVWrvMFW2rphd+ZI0JSoJY9Y7mTw0WGdchgryFQADd9AGx4vcMwqYPhTI8/OXwHnbP H5Qbt6g84Cl44k6CS3i+ry19zUKF3Fsxejw5SRrV79PFh5FHR7Z8Qz/EOWGtPb9uKNj3 zwwel3UXeFTLAbral6+S+Oi9qDmV7cjTKdXqmWGxKYUoBdVy/YrHwpE2s25PKDc2T3ao BFE2IZiPiTrFSn9apFczgMUF+GWJQAt4FznOi//kGIHTXJlUDg3lzzanVGGRrZsrko/s mDEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9RaF+jsgl78F4GBrxUC5NFR9ONl7CxKbRAdYv2n4r6w=; b=LD2oozAxm8YlYGLQBIfavH8bnORj3i/giZjDRc1JwAF4901UqXPELk8IPR+5GMt4Gv IdnBXbKJ2KshPrfsN4MncKCJFBFXci6Q0Eq6TtnBwqP8AyyCLxWEfLDhFGzu50h2KaLJ 7FRW3s0i1JiGCntu4X80qbgod1yYb5QXpPjUug9Kh2iJeqEncJvbctWIAn4JsNocGT4Y IH4/s1FEhOxLE8vsZLsCxFT6cz7Pz8m/t/kjvR4C7VTlRhZ5bDHXttFKFEFGB8ciQNa8 cTZztLOgLWQK9I0zR1e/lPnNOvdjrcXkKqIGXYb/UWtheaonir1xyx+xR+/IaS6ou1dy Z0Ig== X-Gm-Message-State: ANoB5pnENkXnSRyhuMHBUXQ43c8vqHvcaiknf1zia9txIn9kIEqw5+6R 3vBBo6HwrZ9raGQGOjxii1kYnUj1Dnk= X-Google-Smtp-Source: AA0mqf7uAAg/m7pbYV9kmIBLSnvfL8glYEfVXInZT2H+UAcmDJBY8hVnUYkB5BKQtF8O+eTGM7YJG+bxu80= X-Received: from yuzhao.bld.corp.google.com ([2620:15c:183:200:a589:30f2:2daa:4ab7]) (user=yuzhao job=sendgmr) by 2002:a0d:dd8a:0:b0:391:c415:f872 with SMTP id g132-20020a0ddd8a000000b00391c415f872mr12456349ywe.318.1671581563815; Tue, 20 Dec 2022 16:12:43 -0800 (PST) Date: Tue, 20 Dec 2022 17:12:06 -0700 In-Reply-To: <20221221001207.1376119-1-yuzhao@google.com> Message-Id: <20221221001207.1376119-7-yuzhao@google.com> Mime-Version: 1.0 References: <20221221001207.1376119-1-yuzhao@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Subject: [PATCH mm-unstable v2 6/8] mm: multi-gen LRU: per-node lru_gen_folio lists From: Yu Zhao To: Andrew Morton Cc: Johannes Weiner , Jonathan Corbet , Michael Larabel , Michal Hocko , Mike Rapoport , Roman Gushchin , Suren Baghdasaryan , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-mm@google.com, Yu Zhao Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For each node, memcgs are divided into two generations: the old and the young. For each generation, memcgs are randomly sharded into multiple bins to improve scalability. For each bin, an RCU hlist_nulls is virtually divided into three segments: the head, the tail and the default. An onlining memcg is added to the tail of a random bin in the old generation. The eviction starts at the head of a random bin in the old generation. The per-node memcg generation counter, whose reminder (mod 2) indexes the old generation, is incremented when all its bins become empty. There are four operations: 1. MEMCG_LRU_HEAD, which moves an memcg to the head of a random bin in its current generation (old or young) and updates its "seg" to "head"; 2. MEMCG_LRU_TAIL, which moves an memcg to the tail of a random bin in its current generation (old or young) and updates its "seg" to "tail"; 3. MEMCG_LRU_OLD, which moves an memcg to the head of a random bin in the old generation, updates its "gen" to "old" and resets its "seg" to "default"; 4. MEMCG_LRU_YOUNG, which moves an memcg to the tail of a random bin in the young generation, updates its "gen" to "young" and resets its "seg" to "default". The events that trigger the above operations are: 1. Exceeding the soft limit, which triggers MEMCG_LRU_HEAD; 2. The first attempt to reclaim an memcg below low, which triggers MEMCG_LRU_TAIL; 3. The first attempt to reclaim an memcg below reclaimable size threshold, which triggers MEMCG_LRU_TAIL; 4. The second attempt to reclaim an memcg below reclaimable size threshold, which triggers MEMCG_LRU_YOUNG; 5. Attempting to reclaim an memcg below min, which triggers MEMCG_LRU_YOUNG; 6. Finishing the aging on the eviction path, which triggers MEMCG_LRU_YOUNG; 7. Offlining an memcg, which triggers MEMCG_LRU_OLD. Note that memcg LRU only applies to global reclaim, and the round-robin incrementing of their max_seq counters ensures the eventual fairness to all eligible memcgs. For memcg reclaim, it still relies on mem_cgroup_iter(). Signed-off-by: Yu Zhao Change-Id: I65cba82fc667920a3cfac8870d1f6ca250fc3804 --- include/linux/memcontrol.h | 10 + include/linux/mm_inline.h | 17 ++ include/linux/mmzone.h | 117 +++++++++++- mm/memcontrol.c | 16 ++ mm/page_alloc.c | 1 + mm/vmscan.c | 373 +++++++++++++++++++++++++++++++++---- 6 files changed, 499 insertions(+), 35 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index d3c8203cab6c..2e08b05bc6bf 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -794,6 +794,11 @@ static inline void obj_cgroup_put(struct obj_cgroup *o= bjcg) percpu_ref_put(&objcg->refcnt); } =20 +static inline bool mem_cgroup_tryget(struct mem_cgroup *memcg) +{ + return !memcg || css_tryget(&memcg->css); +} + static inline void mem_cgroup_put(struct mem_cgroup *memcg) { if (memcg) @@ -1301,6 +1306,11 @@ static inline void obj_cgroup_put(struct obj_cgroup = *objcg) { } =20 +static inline bool mem_cgroup_tryget(struct mem_cgroup *memcg) +{ + return true; +} + static inline void mem_cgroup_put(struct mem_cgroup *memcg) { } diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h index da38e3d962e2..c1fd3922dc5d 100644 --- a/include/linux/mm_inline.h +++ b/include/linux/mm_inline.h @@ -122,6 +122,18 @@ static inline bool lru_gen_in_fault(void) return current->in_lru_fault; } =20 +#ifdef CONFIG_MEMCG +static inline int lru_gen_memcg_seg(struct lruvec *lruvec) +{ + return READ_ONCE(lruvec->lrugen.seg); +} +#else +static inline int lru_gen_memcg_seg(struct lruvec *lruvec) +{ + return 0; +} +#endif + static inline int lru_gen_from_seq(unsigned long seq) { return seq % MAX_NR_GENS; @@ -297,6 +309,11 @@ static inline bool lru_gen_in_fault(void) return false; } =20 +static inline int lru_gen_memcg_seg(struct lruvec *lruvec) +{ + return 0; +} + static inline bool lru_gen_add_folio(struct lruvec *lruvec, struct folio *= folio, bool reclaiming) { return false; diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 6c96ee823dbd..815c7c2edf45 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -7,6 +7,7 @@ =20 #include #include +#include #include #include #include @@ -367,6 +368,15 @@ struct page_vma_mapped_walk; #define LRU_GEN_MASK ((BIT(LRU_GEN_WIDTH) - 1) << LRU_GEN_PGOFF) #define LRU_REFS_MASK ((BIT(LRU_REFS_WIDTH) - 1) << LRU_REFS_PGOFF) =20 +/* see the comment on MEMCG_NR_GENS */ +enum { + MEMCG_LRU_NOP, + MEMCG_LRU_HEAD, + MEMCG_LRU_TAIL, + MEMCG_LRU_OLD, + MEMCG_LRU_YOUNG, +}; + #ifdef CONFIG_LRU_GEN =20 enum { @@ -426,6 +436,14 @@ struct lru_gen_folio { atomic_long_t refaulted[NR_HIST_GENS][ANON_AND_FILE][MAX_NR_TIERS]; /* whether the multi-gen LRU is enabled */ bool enabled; +#ifdef CONFIG_MEMCG + /* the memcg generation this lru_gen_folio belongs to */ + u8 gen; + /* the list segment this lru_gen_folio belongs to */ + u8 seg; + /* per-node lru_gen_folio list for global reclaim */ + struct hlist_nulls_node list; +#endif }; =20 enum { @@ -479,12 +497,87 @@ void lru_gen_init_lruvec(struct lruvec *lruvec); void lru_gen_look_around(struct page_vma_mapped_walk *pvmw); =20 #ifdef CONFIG_MEMCG + +/* + * For each node, memcgs are divided into two generations: the old and the + * young. For each generation, memcgs are randomly sharded into multiple b= ins + * to improve scalability. For each bin, the hlist_nulls is virtually divi= ded + * into three segments: the head, the tail and the default. + * + * An onlining memcg is added to the tail of a random bin in the old gener= ation. + * The eviction starts at the head of a random bin in the old generation. = The + * per-node memcg generation counter, whose reminder (mod MEMCG_NR_GENS) i= ndexes + * the old generation, is incremented when all its bins become empty. + * + * There are four operations: + * 1. MEMCG_LRU_HEAD, which moves an memcg to the head of a random bin in = its + * current generation (old or young) and updates its "seg" to "head"; + * 2. MEMCG_LRU_TAIL, which moves an memcg to the tail of a random bin in = its + * current generation (old or young) and updates its "seg" to "tail"; + * 3. MEMCG_LRU_OLD, which moves an memcg to the head of a random bin in t= he old + * generation, updates its "gen" to "old" and resets its "seg" to "defa= ult"; + * 4. MEMCG_LRU_YOUNG, which moves an memcg to the tail of a random bin in= the + * young generation, updates its "gen" to "young" and resets its "seg" = to + * "default". + * + * The events that trigger the above operations are: + * 1. Exceeding the soft limit, which triggers MEMCG_LRU_HEAD; + * 2. The first attempt to reclaim an memcg below low, which triggers + * MEMCG_LRU_TAIL; + * 3. The first attempt to reclaim an memcg below reclaimable size thresho= ld, + * which triggers MEMCG_LRU_TAIL; + * 4. The second attempt to reclaim an memcg below reclaimable size thresh= old, + * which triggers MEMCG_LRU_YOUNG; + * 5. Attempting to reclaim an memcg below min, which triggers MEMCG_LRU_Y= OUNG; + * 6. Finishing the aging on the eviction path, which triggers MEMCG_LRU_Y= OUNG; + * 7. Offlining an memcg, which triggers MEMCG_LRU_OLD. + * + * Note that memcg LRU only applies to global reclaim, and the round-robin + * incrementing of their max_seq counters ensures the eventual fairness to= all + * eligible memcgs. For memcg reclaim, it still relies on mem_cgroup_iter(= ). + */ +#define MEMCG_NR_GENS 2 +#define MEMCG_NR_BINS 8 + +struct lru_gen_memcg { + /* the per-node memcg generation counter */ + unsigned long seq; + /* each memcg has one lru_gen_folio per node */ + unsigned long nr_memcgs[MEMCG_NR_GENS]; + /* per-node lru_gen_folio list for global reclaim */ + struct hlist_nulls_head fifo[MEMCG_NR_GENS][MEMCG_NR_BINS]; + /* protects the above */ + spinlock_t lock; +}; + +void lru_gen_init_pgdat(struct pglist_data *pgdat); + void lru_gen_init_memcg(struct mem_cgroup *memcg); void lru_gen_exit_memcg(struct mem_cgroup *memcg); -#endif +void lru_gen_online_memcg(struct mem_cgroup *memcg); +void lru_gen_offline_memcg(struct mem_cgroup *memcg); +void lru_gen_release_memcg(struct mem_cgroup *memcg); +void lru_gen_rotate_memcg(struct lruvec *lruvec, int op); + +#else /* !CONFIG_MEMCG */ + +#define MEMCG_NR_GENS 1 + +struct lru_gen_memcg { +}; + +static inline void lru_gen_init_pgdat(struct pglist_data *pgdat) +{ +} + +#endif /* CONFIG_MEMCG */ =20 #else /* !CONFIG_LRU_GEN */ =20 +static inline void lru_gen_init_pgdat(struct pglist_data *pgdat) +{ +} + static inline void lru_gen_init_lruvec(struct lruvec *lruvec) { } @@ -494,6 +587,7 @@ static inline void lru_gen_look_around(struct page_vma_= mapped_walk *pvmw) } =20 #ifdef CONFIG_MEMCG + static inline void lru_gen_init_memcg(struct mem_cgroup *memcg) { } @@ -501,7 +595,24 @@ static inline void lru_gen_init_memcg(struct mem_cgrou= p *memcg) static inline void lru_gen_exit_memcg(struct mem_cgroup *memcg) { } -#endif + +static inline void lru_gen_online_memcg(struct mem_cgroup *memcg) +{ +} + +static inline void lru_gen_offline_memcg(struct mem_cgroup *memcg) +{ +} + +static inline void lru_gen_release_memcg(struct mem_cgroup *memcg) +{ +} + +static inline void lru_gen_rotate_memcg(struct lruvec *lruvec, int op) +{ +} + +#endif /* CONFIG_MEMCG */ =20 #endif /* CONFIG_LRU_GEN */ =20 @@ -1243,6 +1354,8 @@ typedef struct pglist_data { #ifdef CONFIG_LRU_GEN /* kswap mm walk data */ struct lru_gen_mm_walk mm_walk; + /* lru_gen_folio list */ + struct lru_gen_memcg memcg_lru; #endif =20 CACHELINE_PADDING(_pad2_); diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 92f319ef6c99..36200a1a448f 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -477,6 +477,16 @@ static void mem_cgroup_update_tree(struct mem_cgroup *= memcg, int nid) struct mem_cgroup_per_node *mz; struct mem_cgroup_tree_per_node *mctz; =20 + if (lru_gen_enabled()) { + struct lruvec *lruvec =3D &memcg->nodeinfo[nid]->lruvec; + + /* see the comment on MEMCG_NR_GENS */ + if (soft_limit_excess(memcg) && lru_gen_memcg_seg(lruvec) !=3D MEMCG_LRU= _HEAD) + lru_gen_rotate_memcg(lruvec, MEMCG_LRU_HEAD); + + return; + } + mctz =3D soft_limit_tree.rb_tree_per_node[nid]; if (!mctz) return; @@ -3526,6 +3536,9 @@ unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t= *pgdat, int order, struct mem_cgroup_tree_per_node *mctz; unsigned long excess; =20 + if (lru_gen_enabled()) + return 0; + if (order > 0) return 0; =20 @@ -5386,6 +5399,7 @@ static int mem_cgroup_css_online(struct cgroup_subsys= _state *css) if (unlikely(mem_cgroup_is_root(memcg))) queue_delayed_work(system_unbound_wq, &stats_flush_dwork, 2UL*HZ); + lru_gen_online_memcg(memcg); return 0; offline_kmem: memcg_offline_kmem(memcg); @@ -5417,6 +5431,7 @@ static void mem_cgroup_css_offline(struct cgroup_subs= ys_state *css) memcg_offline_kmem(memcg); reparent_shrinker_deferred(memcg); wb_memcg_offline(memcg); + lru_gen_offline_memcg(memcg); =20 drain_all_stock(memcg); =20 @@ -5428,6 +5443,7 @@ static void mem_cgroup_css_released(struct cgroup_sub= sys_state *css) struct mem_cgroup *memcg =3D mem_cgroup_from_css(css); =20 invalidate_reclaim_iterators(memcg); + lru_gen_release_memcg(memcg); } =20 static void mem_cgroup_css_free(struct cgroup_subsys_state *css) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 7d980dc0000e..5668c1a2de49 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -7941,6 +7941,7 @@ static void __init free_area_init_node(int nid) pgdat_set_deferred_range(pgdat); =20 free_area_init_core(pgdat); + lru_gen_init_pgdat(pgdat); } =20 static void __init free_area_init_memoryless_node(int nid) diff --git a/mm/vmscan.c b/mm/vmscan.c index c424cc06f8c6..fd837a13617c 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -55,6 +55,7 @@ #include #include #include +#include =20 #include #include @@ -135,11 +136,6 @@ struct scan_control { /* Always discard instead of demoting to lower tier memory */ unsigned int no_demotion:1; =20 -#ifdef CONFIG_LRU_GEN - /* help kswapd make better choices among multiple memcgs */ - unsigned long last_reclaimed; -#endif - /* Allocation order */ s8 order; =20 @@ -3185,6 +3181,9 @@ DEFINE_STATIC_KEY_ARRAY_FALSE(lru_gen_caps, NR_LRU_GE= N_CAPS); for ((type) =3D 0; (type) < ANON_AND_FILE; (type)++) \ for ((zone) =3D 0; (zone) < MAX_NR_ZONES; (zone)++) =20 +#define get_memcg_gen(seq) ((seq) % MEMCG_NR_GENS) +#define get_memcg_bin(bin) ((bin) % MEMCG_NR_BINS) + static struct lruvec *get_lruvec(struct mem_cgroup *memcg, int nid) { struct pglist_data *pgdat =3D NODE_DATA(nid); @@ -4456,8 +4455,7 @@ static bool try_to_inc_max_seq(struct lruvec *lruvec,= unsigned long max_seq, if (sc->priority <=3D DEF_PRIORITY - 2) wait_event_killable(lruvec->mm_state.wait, max_seq < READ_ONCE(lrugen->max_seq)); - - return max_seq < READ_ONCE(lrugen->max_seq); + return false; } =20 VM_WARN_ON_ONCE(max_seq !=3D READ_ONCE(lrugen->max_seq)); @@ -4530,8 +4528,6 @@ static void lru_gen_age_node(struct pglist_data *pgda= t, struct scan_control *sc) =20 VM_WARN_ON_ONCE(!current_is_kswapd()); =20 - sc->last_reclaimed =3D sc->nr_reclaimed; - /* check the order to exclude compaction-induced reclaim */ if (!min_ttl || sc->order || sc->priority =3D=3D DEF_PRIORITY) return; @@ -5120,8 +5116,7 @@ static bool should_run_aging(struct lruvec *lruvec, u= nsigned long max_seq, * 1. Defer try_to_inc_max_seq() to workqueues to reduce latency for memcg * reclaim. */ -static unsigned long get_nr_to_scan(struct lruvec *lruvec, struct scan_con= trol *sc, - bool can_swap) +static long get_nr_to_scan(struct lruvec *lruvec, struct scan_control *sc,= bool can_swap) { unsigned long nr_to_scan; struct mem_cgroup *memcg =3D lruvec_memcg(lruvec); @@ -5139,10 +5134,8 @@ static unsigned long get_nr_to_scan(struct lruvec *l= ruvec, struct scan_control * if (sc->priority =3D=3D DEF_PRIORITY) return nr_to_scan; =20 - try_to_inc_max_seq(lruvec, max_seq, sc, can_swap, false); - /* skip this lruvec as it's low on cold folios */ - return 0; + return try_to_inc_max_seq(lruvec, max_seq, sc, can_swap, false) ? -1 : 0; } =20 static unsigned long get_nr_to_reclaim(struct scan_control *sc) @@ -5151,29 +5144,18 @@ static unsigned long get_nr_to_reclaim(struct scan_= control *sc) if (!global_reclaim(sc)) return -1; =20 - /* discount the previous progress for kswapd */ - if (current_is_kswapd()) - return sc->nr_to_reclaim + sc->last_reclaimed; - return max(sc->nr_to_reclaim, compact_gap(sc->order)); } =20 -static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_contr= ol *sc) +static bool try_to_shrink_lruvec(struct lruvec *lruvec, struct scan_contro= l *sc) { - struct blk_plug plug; + long nr_to_scan; unsigned long scanned =3D 0; unsigned long nr_to_reclaim =3D get_nr_to_reclaim(sc); =20 - lru_add_drain(); - - blk_start_plug(&plug); - - set_mm_walk(lruvec_pgdat(lruvec)); - while (true) { int delta; int swappiness; - unsigned long nr_to_scan; =20 if (sc->may_swap) swappiness =3D get_swappiness(lruvec, sc); @@ -5183,7 +5165,7 @@ static void lru_gen_shrink_lruvec(struct lruvec *lruv= ec, struct scan_control *sc swappiness =3D 0; =20 nr_to_scan =3D get_nr_to_scan(lruvec, sc, swappiness); - if (!nr_to_scan) + if (nr_to_scan <=3D 0) break; =20 delta =3D evict_folios(lruvec, sc, swappiness); @@ -5200,10 +5182,251 @@ static void lru_gen_shrink_lruvec(struct lruvec *l= ruvec, struct scan_control *sc cond_resched(); } =20 + /* whether try_to_inc_max_seq() was successful */ + return nr_to_scan < 0; +} + +static int shrink_one(struct lruvec *lruvec, struct scan_control *sc) +{ + bool success; + unsigned long scanned =3D sc->nr_scanned; + unsigned long reclaimed =3D sc->nr_reclaimed; + int seg =3D lru_gen_memcg_seg(lruvec); + struct mem_cgroup *memcg =3D lruvec_memcg(lruvec); + struct pglist_data *pgdat =3D lruvec_pgdat(lruvec); + + /* see the comment on MEMCG_NR_GENS */ + if (!lruvec_is_sizable(lruvec, sc)) + return seg !=3D MEMCG_LRU_TAIL ? MEMCG_LRU_TAIL : MEMCG_LRU_YOUNG; + + mem_cgroup_calculate_protection(NULL, memcg); + + if (mem_cgroup_below_min(NULL, memcg)) + return MEMCG_LRU_YOUNG; + + if (mem_cgroup_below_low(NULL, memcg)) { + /* see the comment on MEMCG_NR_GENS */ + if (seg !=3D MEMCG_LRU_TAIL) + return MEMCG_LRU_TAIL; + + memcg_memory_event(memcg, MEMCG_LOW); + } + + success =3D try_to_shrink_lruvec(lruvec, sc); + + shrink_slab(sc->gfp_mask, pgdat->node_id, memcg, sc->priority); + + if (!sc->proactive) + vmpressure(sc->gfp_mask, memcg, false, sc->nr_scanned - scanned, + sc->nr_reclaimed - reclaimed); + + sc->nr_reclaimed +=3D current->reclaim_state->reclaimed_slab; + current->reclaim_state->reclaimed_slab =3D 0; + + return success ? MEMCG_LRU_YOUNG : 0; +} + +#ifdef CONFIG_MEMCG + +static void shrink_many(struct pglist_data *pgdat, struct scan_control *sc) +{ + int gen; + int bin; + int first_bin; + struct lruvec *lruvec; + struct lru_gen_folio *lrugen; + const struct hlist_nulls_node *pos; + int op =3D 0; + struct mem_cgroup *memcg =3D NULL; + unsigned long nr_to_reclaim =3D get_nr_to_reclaim(sc); + + bin =3D first_bin =3D prandom_u32_max(MEMCG_NR_BINS); +restart: + gen =3D get_memcg_gen(READ_ONCE(pgdat->memcg_lru.seq)); + + rcu_read_lock(); + + hlist_nulls_for_each_entry_rcu(lrugen, pos, &pgdat->memcg_lru.fifo[gen][b= in], list) { + if (op) + lru_gen_rotate_memcg(lruvec, op); + + mem_cgroup_put(memcg); + + lruvec =3D container_of(lrugen, struct lruvec, lrugen); + memcg =3D lruvec_memcg(lruvec); + + if (!mem_cgroup_tryget(memcg)) { + op =3D 0; + memcg =3D NULL; + continue; + } + + rcu_read_unlock(); + + op =3D shrink_one(lruvec, sc); + + if (sc->nr_reclaimed >=3D nr_to_reclaim) + goto success; + + rcu_read_lock(); + } + + rcu_read_unlock(); + + /* restart if raced with lru_gen_rotate_memcg() */ + if (gen !=3D get_nulls_value(pos)) + goto restart; + + /* try the rest of the bins of the current generation */ + bin =3D get_memcg_bin(bin + 1); + if (bin !=3D first_bin) + goto restart; +success: + if (op) + lru_gen_rotate_memcg(lruvec, op); + + mem_cgroup_put(memcg); +} + +static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_contr= ol *sc) +{ + struct blk_plug plug; + + VM_WARN_ON_ONCE(global_reclaim(sc)); + + lru_add_drain(); + + blk_start_plug(&plug); + + set_mm_walk(lruvec_pgdat(lruvec)); + + if (try_to_shrink_lruvec(lruvec, sc)) + lru_gen_rotate_memcg(lruvec, MEMCG_LRU_YOUNG); + + clear_mm_walk(); + + blk_finish_plug(&plug); +} + +#else /* !CONFIG_MEMCG */ + +static void shrink_many(struct pglist_data *pgdat, struct scan_control *sc) +{ + BUILD_BUG(); +} + +static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_contr= ol *sc) +{ + BUILD_BUG(); +} + +#endif + +static void set_initial_priority(struct pglist_data *pgdat, struct scan_co= ntrol *sc) +{ + int priority; + unsigned long reclaimable; + struct lruvec *lruvec =3D mem_cgroup_lruvec(NULL, pgdat); + + if (sc->priority !=3D DEF_PRIORITY || sc->nr_to_reclaim < MIN_LRU_BATCH) + return; + /* + * Determine the initial priority based on ((total / MEMCG_NR_GENS) >> + * priority) * reclaimed_to_scanned_ratio =3D nr_to_reclaim, where the + * estimated reclaimed_to_scanned_ratio =3D inactive / total. + */ + reclaimable =3D node_page_state(pgdat, NR_INACTIVE_FILE); + if (get_swappiness(lruvec, sc)) + reclaimable +=3D node_page_state(pgdat, NR_INACTIVE_ANON); + + reclaimable /=3D MEMCG_NR_GENS; + + /* round down reclaimable and round up sc->nr_to_reclaim */ + priority =3D fls_long(reclaimable) - 1 - fls_long(sc->nr_to_reclaim - 1); + + sc->priority =3D clamp(priority, 0, DEF_PRIORITY); +} + +static void lru_gen_shrink_node(struct pglist_data *pgdat, struct scan_con= trol *sc) +{ + struct blk_plug plug; + unsigned long reclaimed =3D sc->nr_reclaimed; + + VM_WARN_ON_ONCE(!global_reclaim(sc)); + + lru_add_drain(); + + blk_start_plug(&plug); + + set_mm_walk(pgdat); + + set_initial_priority(pgdat, sc); + + if (current_is_kswapd()) + sc->nr_reclaimed =3D 0; + + if (mem_cgroup_disabled()) + shrink_one(&pgdat->__lruvec, sc); + else + shrink_many(pgdat, sc); + + if (current_is_kswapd()) + sc->nr_reclaimed +=3D reclaimed; + clear_mm_walk(); =20 blk_finish_plug(&plug); + + /* kswapd should never fail */ + pgdat->kswapd_failures =3D 0; +} + +#ifdef CONFIG_MEMCG +void lru_gen_rotate_memcg(struct lruvec *lruvec, int op) +{ + int seg; + int old, new; + int bin =3D prandom_u32_max(MEMCG_NR_BINS); + struct pglist_data *pgdat =3D lruvec_pgdat(lruvec); + + spin_lock(&pgdat->memcg_lru.lock); + + VM_WARN_ON_ONCE(hlist_nulls_unhashed(&lruvec->lrugen.list)); + + seg =3D 0; + new =3D old =3D lruvec->lrugen.gen; + + /* see the comment on MEMCG_NR_GENS */ + if (op =3D=3D MEMCG_LRU_HEAD) + seg =3D MEMCG_LRU_HEAD; + else if (op =3D=3D MEMCG_LRU_TAIL) + seg =3D MEMCG_LRU_TAIL; + else if (op =3D=3D MEMCG_LRU_OLD) + new =3D get_memcg_gen(pgdat->memcg_lru.seq); + else if (op =3D=3D MEMCG_LRU_YOUNG) + new =3D get_memcg_gen(pgdat->memcg_lru.seq + 1); + else + VM_WARN_ON_ONCE(true); + + hlist_nulls_del_rcu(&lruvec->lrugen.list); + + if (op =3D=3D MEMCG_LRU_HEAD || op =3D=3D MEMCG_LRU_OLD) + hlist_nulls_add_head_rcu(&lruvec->lrugen.list, &pgdat->memcg_lru.fifo[ne= w][bin]); + else + hlist_nulls_add_tail_rcu(&lruvec->lrugen.list, &pgdat->memcg_lru.fifo[ne= w][bin]); + + pgdat->memcg_lru.nr_memcgs[old]--; + pgdat->memcg_lru.nr_memcgs[new]++; + + lruvec->lrugen.gen =3D new; + WRITE_ONCE(lruvec->lrugen.seg, seg); + + if (!pgdat->memcg_lru.nr_memcgs[old] && old =3D=3D get_memcg_gen(pgdat->m= emcg_lru.seq)) + WRITE_ONCE(pgdat->memcg_lru.seq, pgdat->memcg_lru.seq + 1); + + spin_unlock(&pgdat->memcg_lru.lock); } +#endif =20 /*************************************************************************= ***** * state change @@ -5658,11 +5881,11 @@ static int run_cmd(char cmd, int memcg_id, int nid,= unsigned long seq, =20 if (!mem_cgroup_disabled()) { rcu_read_lock(); + memcg =3D mem_cgroup_from_id(memcg_id); -#ifdef CONFIG_MEMCG - if (memcg && !css_tryget(&memcg->css)) + if (!mem_cgroup_tryget(memcg)) memcg =3D NULL; -#endif + rcu_read_unlock(); =20 if (!memcg) @@ -5810,6 +6033,19 @@ void lru_gen_init_lruvec(struct lruvec *lruvec) } =20 #ifdef CONFIG_MEMCG + +void lru_gen_init_pgdat(struct pglist_data *pgdat) +{ + int i, j; + + spin_lock_init(&pgdat->memcg_lru.lock); + + for (i =3D 0; i < MEMCG_NR_GENS; i++) { + for (j =3D 0; j < MEMCG_NR_BINS; j++) + INIT_HLIST_NULLS_HEAD(&pgdat->memcg_lru.fifo[i][j], i); + } +} + void lru_gen_init_memcg(struct mem_cgroup *memcg) { INIT_LIST_HEAD(&memcg->mm_list.fifo); @@ -5833,7 +6069,69 @@ void lru_gen_exit_memcg(struct mem_cgroup *memcg) } } } -#endif + +void lru_gen_online_memcg(struct mem_cgroup *memcg) +{ + int gen; + int nid; + int bin =3D prandom_u32_max(MEMCG_NR_BINS); + + for_each_node(nid) { + struct pglist_data *pgdat =3D NODE_DATA(nid); + struct lruvec *lruvec =3D get_lruvec(memcg, nid); + + spin_lock(&pgdat->memcg_lru.lock); + + VM_WARN_ON_ONCE(!hlist_nulls_unhashed(&lruvec->lrugen.list)); + + gen =3D get_memcg_gen(pgdat->memcg_lru.seq); + + hlist_nulls_add_tail_rcu(&lruvec->lrugen.list, &pgdat->memcg_lru.fifo[ge= n][bin]); + pgdat->memcg_lru.nr_memcgs[gen]++; + + lruvec->lrugen.gen =3D gen; + + spin_unlock(&pgdat->memcg_lru.lock); + } +} + +void lru_gen_offline_memcg(struct mem_cgroup *memcg) +{ + int nid; + + for_each_node(nid) { + struct lruvec *lruvec =3D get_lruvec(memcg, nid); + + lru_gen_rotate_memcg(lruvec, MEMCG_LRU_OLD); + } +} + +void lru_gen_release_memcg(struct mem_cgroup *memcg) +{ + int gen; + int nid; + + for_each_node(nid) { + struct pglist_data *pgdat =3D NODE_DATA(nid); + struct lruvec *lruvec =3D get_lruvec(memcg, nid); + + spin_lock(&pgdat->memcg_lru.lock); + + VM_WARN_ON_ONCE(hlist_nulls_unhashed(&lruvec->lrugen.list)); + + gen =3D lruvec->lrugen.gen; + + hlist_nulls_del_rcu(&lruvec->lrugen.list); + pgdat->memcg_lru.nr_memcgs[gen]--; + + if (!pgdat->memcg_lru.nr_memcgs[gen] && gen =3D=3D get_memcg_gen(pgdat->= memcg_lru.seq)) + WRITE_ONCE(pgdat->memcg_lru.seq, pgdat->memcg_lru.seq + 1); + + spin_unlock(&pgdat->memcg_lru.lock); + } +} + +#endif /* CONFIG_MEMCG */ =20 static int __init init_lru_gen(void) { @@ -5860,6 +6158,10 @@ static void lru_gen_shrink_lruvec(struct lruvec *lru= vec, struct scan_control *sc { } =20 +static void lru_gen_shrink_node(struct pglist_data *pgdat, struct scan_con= trol *sc) +{ +} + #endif /* CONFIG_LRU_GEN */ =20 static void shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc) @@ -5873,7 +6175,7 @@ static void shrink_lruvec(struct lruvec *lruvec, stru= ct scan_control *sc) bool proportional_reclaim; struct blk_plug plug; =20 - if (lru_gen_enabled()) { + if (lru_gen_enabled() && !global_reclaim(sc)) { lru_gen_shrink_lruvec(lruvec, sc); return; } @@ -6116,6 +6418,11 @@ static void shrink_node(pg_data_t *pgdat, struct sca= n_control *sc) struct lruvec *target_lruvec; bool reclaimable =3D false; =20 + if (lru_gen_enabled() && global_reclaim(sc)) { + lru_gen_shrink_node(pgdat, sc); + return; + } + target_lruvec =3D mem_cgroup_lruvec(sc->target_mem_cgroup, pgdat); =20 again: --=20 2.39.0.314.g84b9a713c41-goog From nobody Wed Sep 17 07:58:45 2025 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 EAA2AC4332F for ; Wed, 21 Dec 2022 00:13:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234398AbiLUANd (ORCPT ); Tue, 20 Dec 2022 19:13:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234079AbiLUAMu (ORCPT ); Tue, 20 Dec 2022 19:12:50 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE3661EC56 for ; Tue, 20 Dec 2022 16:12:45 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-45e2e1d6d2fso11542357b3.0 for ; Tue, 20 Dec 2022 16:12:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=gzZZ7Pl3axic12Be6+Sv18aJSfohVNrr9lclEYQlfdA=; b=BCLok8Tn1XTfQ1A8R6b7C5Ad/joLM/zJ52a9in4TvZQxFue8D9E+7yIFrIer98Eqj4 IT7c2Y7QptfbqvSrriBtpoLImc2rymZxl/aSRPL6iprTxYnoZ8GkLd6dpko1fT3qYpl3 j5aIasFOsO6exHTJNjrCfB/WGow8hUzKcSXoqt+CqvmuLFzcGhf9io/+i2C6Ss/e2mQV laXDGRPFMp9s74HpTyKqXCKzcyFji0RrSIXbOT0lve1VJZR/j3f6ef/UFnLZwT02BvE1 YIHTiq2hbzPBFT/mmXk6dbtrE2QduGkU5U0EBz06MoDqQSe1Flej1GG8CgMufMWwSm9d /umw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gzZZ7Pl3axic12Be6+Sv18aJSfohVNrr9lclEYQlfdA=; b=HRQpnSJ32ZsK5JXbnS4BTt4fSNQvA5It+vycF3WXox6EN52oqv3ZEBoegxPkwC4mmn jJmfnQeMQbQZBJaAed6QCm47KMN/aCqOtTwRBnofWsN0LhbM2xh5BgL/NQEgVYJK7aBq /6dOY6NuZ1J7J40LTN/hE9hwanvxqDI2qhnNEyZz1BjXuBl7vSOXG8S+ZuH+d7oRpYC0 YQ3/uPlVaNj6/WquJY/18qGO2YzLiwBoIZ9ESNdJ3ijtD3bUepZ12Mm7Ma7QaSJwdGzu IXPW9tQmnST/doG+0nNP60TWvUarEZ/8pfTsas3argfY7j0mTKx4wyTerIzapw3qwKgV 7OLw== X-Gm-Message-State: ANoB5plkFUNSEzCWB5Q8BDKQ7p0iW0lcKD0zW9BsoeWsPjYb4sLVTuYR YM6ATquCMM+B0yJlklVEAv3aasyJgd8= X-Google-Smtp-Source: AA0mqf6rnjM1gkiEH2cSoCaqtQ9HV2F4qXN/ljYPU8+/Y/VmAHrOUkrolCEScMqy2/MGCZCUbXIT85hA/c0= X-Received: from yuzhao.bld.corp.google.com ([2620:15c:183:200:a589:30f2:2daa:4ab7]) (user=yuzhao job=sendgmr) by 2002:a81:f90d:0:b0:404:7030:e1c0 with SMTP id x13-20020a81f90d000000b004047030e1c0mr6939777ywm.53.1671581565140; Tue, 20 Dec 2022 16:12:45 -0800 (PST) Date: Tue, 20 Dec 2022 17:12:07 -0700 In-Reply-To: <20221221001207.1376119-1-yuzhao@google.com> Message-Id: <20221221001207.1376119-8-yuzhao@google.com> Mime-Version: 1.0 References: <20221221001207.1376119-1-yuzhao@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Subject: [PATCH mm-unstable v2 7/8] mm: multi-gen LRU: clarify scan_control flags From: Yu Zhao To: Andrew Morton Cc: Johannes Weiner , Jonathan Corbet , Michael Larabel , Michal Hocko , Mike Rapoport , Roman Gushchin , Suren Baghdasaryan , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-mm@google.com, Yu Zhao Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Among the flags in scan_control: 1. sc->may_swap, which indicates swap constraint due to memsw.max, is supported as usual. 2. sc->proactive, which indicates reclaim by memory.reclaim, may not opportunistically skip the aging path, since it is considered less latency sensitive. 3. !(sc->gfp_mask & __GFP_IO), which indicates IO constraint, lowers swappiness to prioritize file LRU, since clean file folios are more likely to exist. 4. sc->may_writepage and sc->may_unmap, which indicates opportunistic reclaim, are rejected, since unmapped clean folios are already prioritized. Scanning for more of them is likely futile and can cause high reclaim latency when there is a large number of memcgs. The rest are handled by the existing code. Signed-off-by: Yu Zhao Change-Id: Ic3b1a13ad1f88853427962b37669aa99942c9fb5 --- mm/vmscan.c | 56 ++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index fd837a13617c..308c3c16d81d 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3209,6 +3209,9 @@ static int get_swappiness(struct lruvec *lruvec, stru= ct scan_control *sc) struct mem_cgroup *memcg =3D lruvec_memcg(lruvec); struct pglist_data *pgdat =3D lruvec_pgdat(lruvec); =20 + if (!sc->may_swap) + return 0; + if (!can_demote(pgdat->node_id, sc) && mem_cgroup_get_nr_swap_pages(memcg) < MIN_LRU_BATCH) return 0; @@ -4238,7 +4241,7 @@ static void walk_mm(struct lruvec *lruvec, struct mm_= struct *mm, struct lru_gen_ } while (err =3D=3D -EAGAIN); } =20 -static struct lru_gen_mm_walk *set_mm_walk(struct pglist_data *pgdat) +static struct lru_gen_mm_walk *set_mm_walk(struct pglist_data *pgdat, bool= force_alloc) { struct lru_gen_mm_walk *walk =3D current->reclaim_state->mm_walk; =20 @@ -4246,7 +4249,7 @@ static struct lru_gen_mm_walk *set_mm_walk(struct pgl= ist_data *pgdat) VM_WARN_ON_ONCE(walk); =20 walk =3D &pgdat->mm_walk; - } else if (!pgdat && !walk) { + } else if (!walk && force_alloc) { VM_WARN_ON_ONCE(current_is_kswapd()); =20 walk =3D kzalloc(sizeof(*walk), __GFP_HIGH | __GFP_NOMEMALLOC | __GFP_NO= WARN); @@ -4432,7 +4435,7 @@ static bool try_to_inc_max_seq(struct lruvec *lruvec,= unsigned long max_seq, goto done; } =20 - walk =3D set_mm_walk(NULL); + walk =3D set_mm_walk(NULL, true); if (!walk) { success =3D iterate_mm_list_nowalk(lruvec, max_seq); goto done; @@ -4501,8 +4504,6 @@ static bool lruvec_is_reclaimable(struct lruvec *lruv= ec, struct scan_control *sc struct mem_cgroup *memcg =3D lruvec_memcg(lruvec); DEFINE_MIN_SEQ(lruvec); =20 - VM_WARN_ON_ONCE(sc->memcg_low_reclaim); - /* see the comment on lru_gen_folio */ gen =3D lru_gen_from_seq(min_seq[LRU_GEN_FILE]); birth =3D READ_ONCE(lruvec->lrugen.timestamps[gen]); @@ -4758,12 +4759,8 @@ static bool isolate_folio(struct lruvec *lruvec, str= uct folio *folio, struct sca { bool success; =20 - /* unmapping inhibited */ - if (!sc->may_unmap && folio_mapped(folio)) - return false; - /* swapping inhibited */ - if (!(sc->may_writepage && (sc->gfp_mask & __GFP_IO)) && + if (!(sc->gfp_mask & __GFP_IO) && (folio_test_dirty(folio) || (folio_test_anon(folio) && !folio_test_swapcache(folio)))) return false; @@ -4860,9 +4857,8 @@ static int scan_folios(struct lruvec *lruvec, struct = scan_control *sc, __count_vm_events(PGSCAN_ANON + type, isolated); =20 /* - * There might not be eligible pages due to reclaim_idx, may_unmap and - * may_writepage. Check the remaining to prevent livelock if it's not - * making progress. + * There might not be eligible folios due to reclaim_idx. Check the + * remaining to prevent livelock if it's not making progress. */ return isolated || !remaining ? scanned : 0; } @@ -5122,9 +5118,7 @@ static long get_nr_to_scan(struct lruvec *lruvec, str= uct scan_control *sc, bool struct mem_cgroup *memcg =3D lruvec_memcg(lruvec); DEFINE_MAX_SEQ(lruvec); =20 - if (mem_cgroup_below_min(sc->target_mem_cgroup, memcg) || - (mem_cgroup_below_low(sc->target_mem_cgroup, memcg) && - !sc->memcg_low_reclaim)) + if (mem_cgroup_below_min(sc->target_mem_cgroup, memcg)) return 0; =20 if (!should_run_aging(lruvec, max_seq, sc, can_swap, &nr_to_scan)) @@ -5152,17 +5146,14 @@ static bool try_to_shrink_lruvec(struct lruvec *lru= vec, struct scan_control *sc) long nr_to_scan; unsigned long scanned =3D 0; unsigned long nr_to_reclaim =3D get_nr_to_reclaim(sc); + int swappiness =3D get_swappiness(lruvec, sc); + + /* clean file folios are more likely to exist */ + if (swappiness && !(sc->gfp_mask & __GFP_IO)) + swappiness =3D 1; =20 while (true) { int delta; - int swappiness; - - if (sc->may_swap) - swappiness =3D get_swappiness(lruvec, sc); - else if (!cgroup_reclaim(sc) && get_swappiness(lruvec, sc)) - swappiness =3D 1; - else - swappiness =3D 0; =20 nr_to_scan =3D get_nr_to_scan(lruvec, sc, swappiness); if (nr_to_scan <=3D 0) @@ -5293,12 +5284,13 @@ static void lru_gen_shrink_lruvec(struct lruvec *lr= uvec, struct scan_control *sc struct blk_plug plug; =20 VM_WARN_ON_ONCE(global_reclaim(sc)); + VM_WARN_ON_ONCE(!sc->may_writepage || !sc->may_unmap); =20 lru_add_drain(); =20 blk_start_plug(&plug); =20 - set_mm_walk(lruvec_pgdat(lruvec)); + set_mm_walk(NULL, sc->proactive); =20 if (try_to_shrink_lruvec(lruvec, sc)) lru_gen_rotate_memcg(lruvec, MEMCG_LRU_YOUNG); @@ -5354,11 +5346,19 @@ static void lru_gen_shrink_node(struct pglist_data = *pgdat, struct scan_control * =20 VM_WARN_ON_ONCE(!global_reclaim(sc)); =20 + /* + * Unmapped clean folios are already prioritized. Scanning for more of + * them is likely futile and can cause high reclaim latency when there + * is a large number of memcgs. + */ + if (!sc->may_writepage || !sc->may_unmap) + goto done; + lru_add_drain(); =20 blk_start_plug(&plug); =20 - set_mm_walk(pgdat); + set_mm_walk(pgdat, sc->proactive); =20 set_initial_priority(pgdat, sc); =20 @@ -5376,7 +5376,7 @@ static void lru_gen_shrink_node(struct pglist_data *p= gdat, struct scan_control * clear_mm_walk(); =20 blk_finish_plug(&plug); - +done: /* kswapd should never fail */ pgdat->kswapd_failures =3D 0; } @@ -5945,7 +5945,7 @@ static ssize_t lru_gen_seq_write(struct file *file, c= onst char __user *src, set_task_reclaim_state(current, &sc.reclaim_state); flags =3D memalloc_noreclaim_save(); blk_start_plug(&plug); - if (!set_mm_walk(NULL)) { + if (!set_mm_walk(NULL, true)) { err =3D -ENOMEM; goto done; } --=20 2.39.0.314.g84b9a713c41-goog From nobody Wed Sep 17 07:58:45 2025 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 43F5AC4332F for ; Wed, 21 Dec 2022 00:13:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234407AbiLUANh (ORCPT ); Tue, 20 Dec 2022 19:13:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234223AbiLUAMu (ORCPT ); Tue, 20 Dec 2022 19:12:50 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B2B8201AC for ; Tue, 20 Dec 2022 16:12:47 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-3b102317668so160931177b3.23 for ; Tue, 20 Dec 2022 16:12:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=XaREnfCRyQU3ad5Wd1iK/L1d7XHMzN1hNI71g9W9Aqc=; b=K59wK9Xmrz3Bi5vvMVhN1G0pDO7CebJ60f+DjHwvBqntIUvRaRf11KCBF3IsW1uuCm LmdCEuyR6sl4QvqXqpqJlFmXBaasCbZ9nmXW6MTluImHgbKMWTiBxrs1SJxF+2QwuG8Y n3lT/WRDW8kZrenttBA6PiXNPTJQt4eM3DyDoOliigATORAsfTFpRCXSul0pGuAI9MlF xvpQD3dmjMzt8YndE3tmefxjvQ2G/DucE0e/w5OXs/Vyk/ThipPMV2jWTndUm75lJJeN Y5SOmz71wirINtVmmU6GITMwX4RwAhx/qeWMh267Z+OXa2GTQYBVO7aJK80W77QZ+2mh Zn+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XaREnfCRyQU3ad5Wd1iK/L1d7XHMzN1hNI71g9W9Aqc=; b=Nnz/KOgZ+1tJNMTPj2GK25bCczu3tpBcIXUl7ft4Wxh0LUqv1GJVexrHDzFS9teHXV 2TS4XxJS1uA6t+hk357b1ozkwNeTsKZImBEUeJ94c5K7wcIe8rysDT4W5hK/doZF1Wud 5jLqW5BgEDzcqiIsu/YnojNow3ucyjIlwyqm8tKiE3FEhrlSy8s734YZFSrm/7wX9r4b 1VDUGLcsdO9C3D+hKNogwFGYW0fRSkdz1LTNs0u3t9lIWf2qNf5wD9SZ9mASfS8vKplc KrTvJeOWivoCJSn6RzFEoOjebsl5peoD7EhmInc4iYqFgFPY4k1H/dgb4IdlyxWvbREU QJIw== X-Gm-Message-State: AFqh2kp6VpLQ6jIvZxtW2OPocxZwheeFAJGSaPW5sPTs20cU/QT3E/Yb CQQWlQPL+t/wkuCZArkduzOyOYDxkbQ= X-Google-Smtp-Source: AMrXdXur6oRo558EHTCVqmu2nmkUYNqNZaoP17m0xPtqeSBL8ltbKO3K5SoD9CmsnhBaHILyzV33vTOZCRs= X-Received: from yuzhao.bld.corp.google.com ([2620:15c:183:200:a589:30f2:2daa:4ab7]) (user=yuzhao job=sendgmr) by 2002:a0d:cbd7:0:b0:388:7d2:575d with SMTP id n206-20020a0dcbd7000000b0038807d2575dmr768501ywd.21.1671581566428; Tue, 20 Dec 2022 16:12:46 -0800 (PST) Date: Tue, 20 Dec 2022 17:12:08 -0700 In-Reply-To: <20221221001207.1376119-1-yuzhao@google.com> Message-Id: <20221221001207.1376119-9-yuzhao@google.com> Mime-Version: 1.0 References: <20221221001207.1376119-1-yuzhao@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Subject: [PATCH mm-unstable v2 8/8] mm: multi-gen LRU: simplify arch_has_hw_pte_young() check From: Yu Zhao To: Andrew Morton Cc: Johannes Weiner , Jonathan Corbet , Michael Larabel , Michal Hocko , Mike Rapoport , Roman Gushchin , Suren Baghdasaryan , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-mm@google.com, Yu Zhao Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Scanning page tables when hardware does not set the accessed bit has no real use cases. Signed-off-by: Yu Zhao Change-Id: I414310f1cf642d305a16045518517f09ce0eda23 --- mm/vmscan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 308c3c16d81d..88948f4c8d18 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4430,7 +4430,7 @@ static bool try_to_inc_max_seq(struct lruvec *lruvec,= unsigned long max_seq, * handful of PTEs. Spreading the work out over a period of time usually * is less efficient, but it avoids bursty page faults. */ - if (!force_scan && !(arch_has_hw_pte_young() && get_cap(LRU_GEN_MM_WALK))= ) { + if (!arch_has_hw_pte_young() || !get_cap(LRU_GEN_MM_WALK)) { success =3D iterate_mm_list_nowalk(lruvec, max_seq); goto done; } --=20 2.39.0.314.g84b9a713c41-goog