From patchwork Thu Dec 22 04:18:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhao X-Patchwork-Id: 13079361 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11805C4167B for ; Thu, 22 Dec 2022 04:19:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7207D900002; Wed, 21 Dec 2022 23:19:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D05F940007; Wed, 21 Dec 2022 23:19:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 45F5E900004; Wed, 21 Dec 2022 23:19:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 326C6900002 for ; Wed, 21 Dec 2022 23:19:44 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 0C43D1C665F for ; Thu, 22 Dec 2022 04:19:44 +0000 (UTC) X-FDA: 80268638688.26.BFF333B Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf22.hostedemail.com (Postfix) with ESMTP id 70C7FC000F for ; Thu, 22 Dec 2022 04:19:42 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=bG75aKyC; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf22.hostedemail.com: domain of 33dqjYwYKCEY627piwowwotm.kwutqv25-uus3iks.wzo@flex--yuzhao.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=33dqjYwYKCEY627piwowwotm.kwutqv25-uus3iks.wzo@flex--yuzhao.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671682782; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=N4TcA/s/8t2bWWYZiBbVtrtPPkaRo7qGxumdUIvl0ek=; b=T8G5bZPSD2hS6BQHSQRkP6Gqnws+S5m18q/Hkqg0U1FoiEuzMcENHlfudWiBHTh201bq0b H40F8CElABcaxOPpNlW60w6ne1qqX1u4R7WMxVAWy/ri4/TTiI4GRdhzJzGXGZzbSYxUpf HCc2+JTC/Zdb7MxU5x5jPpESY9VhXo0= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=bG75aKyC; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf22.hostedemail.com: domain of 33dqjYwYKCEY627piwowwotm.kwutqv25-uus3iks.wzo@flex--yuzhao.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=33dqjYwYKCEY627piwowwotm.kwutqv25-uus3iks.wzo@flex--yuzhao.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671682782; a=rsa-sha256; cv=none; b=lrCpV+5oqGqvflZ9R/mIHJ/GOrOlUuC1JIBiPNk7XXQtKO245CVxZYRukPO0eBN9XFQsky JvYhvBkprLH9T2L+9Zc0dUelDD6gNKclhYggntwjtliPAByUaXViyqjVBuPsvJCwKbz354 OhkFoyYnI7U2YCHZBFWAMZcYCwVc8H0= Received: by mail-yb1-f202.google.com with SMTP id z17-20020a25e311000000b00719e04e59e1so688921ybd.10 for ; Wed, 21 Dec 2022 20:19:42 -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=N4TcA/s/8t2bWWYZiBbVtrtPPkaRo7qGxumdUIvl0ek=; b=bG75aKyCcpU6cfyYWl1zzl+PIHqX6D0BG6nxb9rq9djraywRphLGdqUWMK51qHsbkf RveqneQH3WAqaehOnRBvR2w5bCgf5mzxRado8Oh6VSctqdjsCEFrOOexrzSXs2qvgtFT kHnNKxLUvsQhwuzNWinlPQpfNWtkzLBG6zMQD9e1a1HYzJ0FaudoTt5fpMoXJZweb2/r +HNQI//INOZLvHI9743lEW9/m2zl5FHTzKUCdO9JVLWtJs8dJsrQNHLKGZEIIalz/7Jy MOQf4F4jjkErPcUB6fC56tXt6SzPyyxDgfg/2YBhz/zsqeAgAFPSOYgvaHX5Pd0F4KjU bLOw== 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=N4TcA/s/8t2bWWYZiBbVtrtPPkaRo7qGxumdUIvl0ek=; b=Hguzjk2A7iEEXZM+4Y7jNQHvO/MRdSwEpuDGO8AAeY/n/nyEcYelgCQyKOz4EtwTGg TAQdZUftxCTJyiKBA2bItiDG4qOqfRgEGd9wGu9BfpF8Q64+1186oLr7FSFSvVXPijoE u8fWbbHsyi5HVWXM40TgGpRYrf8tBjJ489WiMIKUCm6lACRtgpwcidMMs7N3y6exHXwU OWR+8GwqcHdfaKb583gcTfjIQ8HxE6xP+d1lfLz2RBqJJxuXLuk4+oJ3sVFoeeJM/AUz jBb/TJTcBVGn6Ip1rcFDEwzH7rzKYZHNboWEGOo7GLTOoWfugXJyaUBhWdDT993CMJp8 /KYQ== X-Gm-Message-State: AFqh2kqbUFe2VSXiX906e9nJ4PZdWtuT6Oqp3yhn/injEUZBlu73RsyH rF+F7LJVcZeixgsOY3E67gY8Vlb3WmE= X-Google-Smtp-Source: AMrXdXvFsC2yaW02qCDMqrDqFDN0SJMRekr525L1lxoDa69bWaQeswqLxQLsHlKx5usxhH753zJinh3PyRI= X-Received: from yuzhao.bld.corp.google.com ([2620:15c:183:200:a463:5f7b:440e:5c77]) (user=yuzhao job=sendgmr) by 2002:a0d:db8d:0:b0:329:88ec:ba20 with SMTP id d135-20020a0ddb8d000000b0032988ecba20mr499754ywe.492.1671682781586; Wed, 21 Dec 2022 20:19:41 -0800 (PST) Date: Wed, 21 Dec 2022 21:18:59 -0700 In-Reply-To: <20221222041905.2431096-1-yuzhao@google.com> Message-Id: <20221222041905.2431096-2-yuzhao@google.com> Mime-Version: 1.0 References: <20221222041905.2431096-1-yuzhao@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Subject: [PATCH mm-unstable v3 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 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 70C7FC000F X-Stat-Signature: t6nmmm51k1f7bsw67rxjwzxrikp1hqyd X-HE-Tag: 1671682782-803569 X-HE-Meta: U2FsdGVkX1/eYdnLF/ZCA4idwFdTL2r2f2eetZ762Lczv1yVWHLAI/mMa8TpMmFAMMnwGH+X8x8Jqfj8nFU/x2CJE3RYhRtegMYhWdqwD4QSlPVLL5NWY+EgBB0d0383gV5tST2Qi7tT5e0bAgtRhP4iyDwzNeC9gpxjqfgRVQ1o48i9DjzdfqDNqY0+yp5Caq78IOHtNZciMU6tFPcyy6AR90v7rjRF+97pc9CIxjT2nqwTLj+k8q9uizZZ3g7maXSKqNt1VGSbYRLh1B2mk5sKALHuy3yhP/xUyfdSJnnWtBjN13ppQzjmKhTbIppiMxR3njnL+0yU3LjRMyaIEYaj6lJ0AtDU8hq8VQKb+Rxt9fCf8FsuCAGlE48bMYlTSWFA1JV74S1PDCMFAyzFNlc/B/sJpm/J6b4ZvQHaY75ZDaW0Je948O00Kf0khRUKHH97Rhr2y57j4ruT8fiV5Jih5o24M5E+Cm0lIjqBRVFyJqgksZsnEuz8KSOp6kM8PnW7sSw2j4xG72oU+P/WqJho4jS22kOTjygeqwXmqGJvMeEmVt0k1n42YwtLPPGUAklICTEV/xL+PIG9Rb7M2dVzCwLoRG3SEu4qu77e+nwqZoc5w+bi4FetkvjejXUeNzm8AkqV2arQkNpbj5vIizTsRI8f4dF/dGiT28IbTN0HQVAN7/vImN3zUUI2HjtMhDgP+BvEwYrRA9HgjkYlYsx5suSFfCnAkXm/r0KZ9FS7Q/oRDHGSdng+HM4VyyuYRnHYr3idpTeliqm9BNNgLtHxg7QgvI7X78QdktY1O2/kSyjjGF7idZYrLa/MYk9Lgrjqt3KdF5nym8/CusNU6rH/gCtfU0sKlZbgJEt4nuhlEQhea/hGyO513NS10ON05bkgufZvEW8oFL46TePSN+0IG9jbLwMZDo1fjQdYUVZFTmGbGLb5wNSgnmoEG7fi2qJSviVBHHMbS2Rnbau 5MQ/EEZv 62KqKjE33PiRphljSBbfDqkGtArMD324e8DBKNyFLptCbHjyCovK9SG+J9Q5Np+cGV/FC+8H8Md0wB3MS4pDOGrwxRQS7NvWNfyvTAfk/hM/7QlN8rnhqfnlDdOYu0aCQzytEySzOkLQKWughtvPuLFRE/vAD6mVm/+ayd2yxAE7mbVV1Lx45TMOk46EpkzNcj+pAPHdhqJBCWNJ0B+wb/14YNiuBKieveH4w33cx6lGDh+LtM7/bnv9+5y7so0V/SOaXBSvSIqfTa3ade8jrGytq83/MkBASkouUaHW8gZXavHKw7C2eMNGi17Zl0mXsA7RPS9XoX8vejtzLMzfqe+1qRa1TjsMJF2V4c1LcQfEyDPrnnO/O1UzPxtcKQA2iT2dax+Y53UJG1f0WR+SoGH0+9X+bP0OIO8HN X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The new name lru_gen_folio will be more distinct from the coming lru_gen_memcg. Signed-off-by: Yu Zhao --- 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 *lruvec, struct folio *foli int zone = folio_zonenum(folio); int delta = folio_nr_pages(folio); enum lru_list lru = type * LRU_INACTIVE_FILE; - struct lru_gen_struct *lrugen = &lruvec->lrugen; + struct lru_gen_folio *lrugen = &lruvec->lrugen; VM_WARN_ON_ONCE(old_gen != -1 && old_gen >= MAX_NR_GENS); VM_WARN_ON_ONCE(new_gen != -1 && new_gen >= MAX_NR_GENS); @@ -224,7 +224,7 @@ static inline bool lru_gen_add_folio(struct lruvec *lruvec, struct folio *folio, int gen = folio_lru_gen(folio); int type = folio_is_file_lru(folio); int zone = folio_zonenum(folio); - struct lru_gen_struct *lrugen = &lruvec->lrugen; + struct lru_gen_folio *lrugen = &lruvec->lrugen; VM_WARN_ON_ONCE_FOLIO(gen != -1, folio); 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 therefore * 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 e83d2a74e942..42507b36698e 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3215,7 +3215,7 @@ static int get_nr_gens(struct lruvec *lruvec, int type) 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) >= MIN_NR_GENS && get_nr_gens(lruvec, LRU_GEN_FILE) <= get_nr_gens(lruvec, LRU_GEN_ANON) && get_nr_gens(lruvec, LRU_GEN_ANON) <= MAX_NR_GENS; @@ -3612,7 +3612,7 @@ struct ctrl_pos { static void read_ctrl_pos(struct lruvec *lruvec, int type, int tier, int gain, struct ctrl_pos *pos) { - struct lru_gen_struct *lrugen = &lruvec->lrugen; + struct lru_gen_folio *lrugen = &lruvec->lrugen; int hist = lru_hist_from_seq(lrugen->min_seq[type]); pos->refaulted = 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 = &lruvec->lrugen; + struct lru_gen_folio *lrugen = &lruvec->lrugen; bool clear = carryover ? NR_HIST_GENS == 1 : NR_HIST_GENS > 1; unsigned long seq = carryover ? lrugen->min_seq[type] : lrugen->max_seq + 1; @@ -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 = folio_is_file_lru(folio); - struct lru_gen_struct *lrugen = &lruvec->lrugen; + struct lru_gen_folio *lrugen = &lruvec->lrugen; int new_gen, old_gen = lru_gen_from_seq(lrugen->min_seq[type]); unsigned long new_flags, old_flags = READ_ONCE(folio->flags); @@ -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 = &lruvec->lrugen; + struct lru_gen_folio *lrugen = &lruvec->lrugen; walk->batched = 0; @@ -4263,7 +4263,7 @@ static bool inc_min_seq(struct lruvec *lruvec, int type, bool can_swap) { int zone; int remaining = MAX_LRU_BATCH; - struct lru_gen_struct *lrugen = &lruvec->lrugen; + struct lru_gen_folio *lrugen = &lruvec->lrugen; int new_gen, old_gen = lru_gen_from_seq(lrugen->min_seq[type]); if (type == LRU_GEN_ANON && !can_swap) @@ -4299,7 +4299,7 @@ static bool try_to_inc_min_seq(struct lruvec *lruvec, bool can_swap) { int gen, type, zone; bool success = false; - struct lru_gen_struct *lrugen = &lruvec->lrugen; + struct lru_gen_folio *lrugen = &lruvec->lrugen; DEFINE_MIN_SEQ(lruvec); VM_WARN_ON_ONCE(!seq_is_valid(lruvec)); @@ -4320,7 +4320,7 @@ static bool try_to_inc_min_seq(struct lruvec *lruvec, bool can_swap) ; } - /* see the comment on lru_gen_struct */ + /* see the comment on lru_gen_folio */ if (can_swap) { min_seq[LRU_GEN_ANON] = min(min_seq[LRU_GEN_ANON], min_seq[LRU_GEN_FILE]); min_seq[LRU_GEN_FILE] = max(min_seq[LRU_GEN_ANON], lrugen->min_seq[LRU_GEN_FILE]); @@ -4342,7 +4342,7 @@ static void inc_max_seq(struct lruvec *lruvec, bool can_swap, bool force_scan) { int prev, next; int type, zone; - struct lru_gen_struct *lrugen = &lruvec->lrugen; + struct lru_gen_folio *lrugen = &lruvec->lrugen; spin_lock_irq(&lruvec->lru_lock); @@ -4400,7 +4400,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 = NULL; - struct lru_gen_struct *lrugen = &lruvec->lrugen; + struct lru_gen_folio *lrugen = &lruvec->lrugen; VM_WARN_ON_ONCE(max_seq > READ_ONCE(lrugen->max_seq)); @@ -4465,7 +4465,7 @@ static bool should_run_aging(struct lruvec *lruvec, unsigned long max_seq, unsig unsigned long old = 0; unsigned long young = 0; unsigned long total = 0; - struct lru_gen_struct *lrugen = &lruvec->lrugen; + struct lru_gen_folio *lrugen = &lruvec->lrugen; struct mem_cgroup *memcg = lruvec_memcg(lruvec); for (type = !can_swap; type < ANON_AND_FILE; type++) { @@ -4750,7 +4750,7 @@ static bool sort_folio(struct lruvec *lruvec, struct folio *folio, int tier_idx) int delta = folio_nr_pages(folio); int refs = folio_lru_refs(folio); int tier = lru_tier_from_refs(refs); - struct lru_gen_struct *lrugen = &lruvec->lrugen; + struct lru_gen_folio *lrugen = &lruvec->lrugen; VM_WARN_ON_ONCE_FOLIO(gen >= MAX_NR_GENS, folio); @@ -4850,7 +4850,7 @@ static int scan_folios(struct lruvec *lruvec, struct scan_control *sc, int scanned = 0; int isolated = 0; int remaining = MAX_LRU_BATCH; - struct lru_gen_struct *lrugen = &lruvec->lrugen; + struct lru_gen_folio *lrugen = &lruvec->lrugen; struct mem_cgroup *memcg = lruvec_memcg(lruvec); VM_WARN_ON_ONCE(!list_empty(list)); @@ -5251,7 +5251,7 @@ static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc static bool __maybe_unused state_is_valid(struct lruvec *lruvec) { - struct lru_gen_struct *lrugen = &lruvec->lrugen; + struct lru_gen_folio *lrugen = &lruvec->lrugen; if (lrugen->enabled) { enum lru_list lru; @@ -5530,7 +5530,7 @@ static void lru_gen_seq_show_full(struct seq_file *m, struct lruvec *lruvec, int i; int type, tier; int hist = lru_hist_from_seq(seq); - struct lru_gen_struct *lrugen = &lruvec->lrugen; + struct lru_gen_folio *lrugen = &lruvec->lrugen; for (tier = 0; tier < MAX_NR_TIERS; tier++) { seq_printf(m, " %10d", tier); @@ -5580,7 +5580,7 @@ static int lru_gen_seq_show(struct seq_file *m, void *v) unsigned long seq; bool full = !debugfs_real_fops(m->file)->write; struct lruvec *lruvec = v; - struct lru_gen_struct *lrugen = &lruvec->lrugen; + struct lru_gen_folio *lrugen = &lruvec->lrugen; int nid = lruvec_pgdat(lruvec)->node_id; struct mem_cgroup *memcg = lruvec_memcg(lruvec); DEFINE_MAX_SEQ(lruvec); @@ -5834,7 +5834,7 @@ void lru_gen_init_lruvec(struct lruvec *lruvec) { int i; int gen, type, zone; - struct lru_gen_struct *lrugen = &lruvec->lrugen; + struct lru_gen_folio *lrugen = &lruvec->lrugen; lrugen->max_seq = MIN_NR_GENS + 1; lrugen->enabled = 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 = folio_is_file_lru(folio); int delta = folio_nr_pages(folio); int refs = 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 = folio_is_file_lru(folio); From patchwork Thu Dec 22 04:19:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhao X-Patchwork-Id: 13079362 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0144BC4708D for ; Thu, 22 Dec 2022 04:19:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3ED47940008; Wed, 21 Dec 2022 23:19:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 34FBA940007; Wed, 21 Dec 2022 23:19:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1EF4D940008; Wed, 21 Dec 2022 23:19:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 0DFC8940007 for ; Wed, 21 Dec 2022 23:19:46 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id CA63D140CC3 for ; Thu, 22 Dec 2022 04:19:45 +0000 (UTC) X-FDA: 80268638730.20.E632168 Received: from mail-il1-f201.google.com (mail-il1-f201.google.com [209.85.166.201]) by imf20.hostedemail.com (Postfix) with ESMTP id 222C61C0018 for ; Thu, 22 Dec 2022 04:19:43 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=hiWrjVIM; spf=pass (imf20.hostedemail.com: domain of 339qjYwYKCEg849rkyqyyqvo.mywvsx47-wwu5kmu.y1q@flex--yuzhao.bounces.google.com designates 209.85.166.201 as permitted sender) smtp.mailfrom=339qjYwYKCEg849rkyqyyqvo.mywvsx47-wwu5kmu.y1q@flex--yuzhao.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671682784; a=rsa-sha256; cv=none; b=ML9jRXjAU0H4XOEr8pvwo+Dqabq4QsebZmFvRgwZVSDJbvifbteP/q3f047TlBOhPCCZcE S7EvUEImKDayiIyIa4ieDJGUz/XOA4A9salz0ExGm35dx+L1dI/RLxKD7kjnvQgnqowIMl 45neVbJp2RcFaGoVW5anaM82/DEry1c= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=hiWrjVIM; spf=pass (imf20.hostedemail.com: domain of 339qjYwYKCEg849rkyqyyqvo.mywvsx47-wwu5kmu.y1q@flex--yuzhao.bounces.google.com designates 209.85.166.201 as permitted sender) smtp.mailfrom=339qjYwYKCEg849rkyqyyqvo.mywvsx47-wwu5kmu.y1q@flex--yuzhao.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671682784; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GKQYzYQslmsEvTKoQjl1Dy8mF9dw9swe45tpdyd96Iw=; b=0t82jWJH168ExSK6WwVkMINWMTqYZfRelZOuHqPQHRhNd/yMEEj2Ip+8uItxELCloYbMxk cVAUrBDKWzvl29wU1ernQUYu0Yx3xlzdXUSl2NBBri4BYXBev7S6xGu7WndmUMu7lcCbnh fVMmQdDMuKJ2b5DUMF0yzHIlEKYYAdc= Received: by mail-il1-f201.google.com with SMTP id g3-20020a056e021a2300b00305e3da9585so482497ile.16 for ; Wed, 21 Dec 2022 20:19: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=GKQYzYQslmsEvTKoQjl1Dy8mF9dw9swe45tpdyd96Iw=; b=hiWrjVIMR/8TnqO43W7ej+Q9H4D1PFrQLabYHgT2Fiz6OmgEI02DldL0TyORs8wy8n gzQMTWHm8bPRJjvpDLuxOYEX45gDXAal7JLlT/n18L6hVsg3dngAiFDK3Tn+rpAmxV6C +qEslUlp9HbFzqL4mgVM5b5RkhpgXYnyZ+ORq6Ita7eNOYYtIOGIzMuXESbtK6od4r1A jWAL37uhaZUkjPoemHffstsks18inpeSIQG+tf76sgmOk7/nZKU+GpNLKMjITNkpPHgq 53hXe1Fl0FagiNNwuieSMmO4uKwVQ6ZUaFgxxLKWXGELNgQBxX2r4plz2LGpanIqTl28 9HRA== 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=GKQYzYQslmsEvTKoQjl1Dy8mF9dw9swe45tpdyd96Iw=; b=VJq/I2bANwwrU9cii7zcoP0Pcg6f+YWxHgGMiuZnITsLfHX4Vwn2yFtBWs+4pgTRcD NgEvR8f5cz/V1I9RYAJJuP37Pi9U7Z7U6GqFF5xNtKgUJGycsf8JdIE5qaGPr0H1Ji0G 3h+3raLsNcV14ytibDbgo55/nHkcm795bQe9HLHtzkUmZ+kBhW82JJeHTGfAXZLDwF+n lIM8pI1NBGXwQxEurN90TA/W5dAHp1FywF6TDpeEEjLFlGTZr99fZAJkvEXvmIv2+I7e 6kk5oYGySifGMp10ptzCP0qaL9QTUoivYMisKpxuhHSZYcZEYtueC74qhUZ+3HlWr5g/ a8Dg== X-Gm-Message-State: AFqh2krGfpCfI2GLVwZ5jOj1GbaRIk8ESK14OCfP9SMfD03OlNlwV7NI mdO02epWd7YB0Qrxyq+qxR/G2uMDFW8= X-Google-Smtp-Source: AMrXdXulwki9nSBxGR/8kwCpRV7uTwszRsuNMgerK7fVzStawG8GMbadC6mUNc3+9DnL5KUi28j6NQ4IuKE= X-Received: from yuzhao.bld.corp.google.com ([2620:15c:183:200:a463:5f7b:440e:5c77]) (user=yuzhao job=sendgmr) by 2002:a02:881a:0:b0:38a:141d:6564 with SMTP id r26-20020a02881a000000b0038a141d6564mr112099jai.140.1671682783226; Wed, 21 Dec 2022 20:19:43 -0800 (PST) Date: Wed, 21 Dec 2022 21:19:00 -0700 In-Reply-To: <20221222041905.2431096-1-yuzhao@google.com> Message-Id: <20221222041905.2431096-3-yuzhao@google.com> Mime-Version: 1.0 References: <20221222041905.2431096-1-yuzhao@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Subject: [PATCH mm-unstable v3 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 X-Rspam-User: X-Rspamd-Queue-Id: 222C61C0018 X-Rspamd-Server: rspam01 X-Stat-Signature: pq4jtg4x7o18i1jdab551xxp19kwricr X-HE-Tag: 1671682783-581203 X-HE-Meta: U2FsdGVkX19NYu9h0DPPgt+pfornDXX1jM4qy4EolNDf+z0OVOz73ijJoANdVNqk/KDMtHWBdfqNfJFhLSBiTogx3bP0uv19GEdpsh0QBEwL7kqtcZOOBsw1Ae9jte4Ug9quoA57wF3x63Z9hmtaZ98Vnzx2rZrY1dS51LdMRRrL4Q5//CRklOmNtdjzKkkQwkHnngp29BkdyNBttmt3DdKjRZbuURXRKbqDqrEA3cZawkyhKg8vaBJMXgVmbl8tAP4RtfMADgbF3TOs1A8WjCg0o4hPecKKdLNf6PWmkFvMNqYcQGTeSYITwVDNMMr6d8BRhqH1hnxbvsbnDJIdNB2hX7ZFXYsv64m8M5EIZJRPpXZK+DiW5rqzI9EFQompwNjtQl1q6FnPrlTGk+VHC7XJBm6pHosocvNnEJ10ZX78qUMXGJkgzi0WMM/pN+Cjd3Ip/ImTp60kiysRWzuxfCJP6R3ioAI5ZVCYccjE7Tpzpw2j6vGKN6JQ68tV3hcIu8n/ehMC3AwXONc/KOaun8szmBgXVBdsZWEyGzPxc/r1h0q0Kf+8QaF8IY8sdmsU3If1mWrqxauNVD9WGVmWRLKarM0Eo4bRwZ61TkZOfBWWYXhQh2Lxce8Q1bIDJOQDh4QTApEX9uosP3PZ9DjlxXSmAC7CyCngBugbeveeQLR0rbRvYLykZ3qwsOKFxNuBU/hr9+hL+QzNGK+BrNIXJOGCpovXyePFcxtjA4Q1uRuxdaGxewGR+IVOdiz+Uj2ZJZaHbr6QF912/eM3DtGp0ASPoHUueoaWBd0u7FKw5jZABgg/tDfTpArYnBgmvt063RXiLI5/aD1wMa1RBgpCyCHAXMXp+ngEusxtmKvL0bcP3VDncxSO9iUH6+PqdgNZeYndBmxnm/wEb8ZBT5anSTzZScz7Ba+yP7X19CRvCWjZ7LW9yEvtlZeoYJ3DFHJXU3rFhzm8Lp/DrHzaPoP v79q6U0S OoQSEckLe5QljZfyzgdjQfsKiHRw9qvfv3LyFsBEGN4OgI7FjwCXStjIbxOEtsrmc3fdJX411ACvK972CJ7ik3rWd1lsD/etFOQZkc/dtwnGarQA10qD9SN71KFl4oLVNQ8dewOZavpta0d+D1yHAkXFELcIfJTiGLBEFr1Y/E8vDahgjRPgAfDu6IXL/l5FUD0F2aOOvME8WkY9RgYhsy2MW04wLeK5PAG4axZutp+HpmC43ONRCi7Ak6Yzu2/9vTHtwWLBIjiUfP0DrJQRkFdcVgJiF2UuwtCisWFW4RGZNdDUL3+5LY5VZ7XYKiH7vAWp9Iis8JusPkLNUuX1qJKNou+O2wRBT9jadY2harBzTnVLo54G3u7NQBg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: lru_gen_folio will be chained into per-node lists by the coming lrugen->list. Signed-off-by: Yu Zhao --- 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. 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. 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 *lruvec, 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]); 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[] so 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 page * considered active is isolated for non-reclaiming purposes, e.g., migration. * 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 42507b36698e..d94d9fcabf36 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4271,7 +4271,7 @@ static bool inc_min_seq(struct lruvec *lruvec, int type, bool can_swap) /* prevent cold/hot inversion if force_scan is true */ for (zone = 0; zone < MAX_NR_ZONES; zone++) { - struct list_head *head = &lrugen->lists[old_gen][type][zone]; + struct list_head *head = &lrugen->folios[old_gen][type][zone]; while (!list_empty(head)) { struct folio *folio = lru_to_folio(head); @@ -4282,7 +4282,7 @@ static bool inc_min_seq(struct lruvec *lruvec, int type, bool can_swap) VM_WARN_ON_ONCE_FOLIO(folio_zonenum(folio) != zone, folio); new_gen = 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]); if (!--remaining) return false; @@ -4310,7 +4310,7 @@ static bool try_to_inc_min_seq(struct lruvec *lruvec, bool can_swap) gen = lru_gen_from_seq(min_seq[type]); for (zone = 0; zone < MAX_NR_ZONES; zone++) { - if (!list_empty(&lrugen->lists[gen][type][zone])) + if (!list_empty(&lrugen->folios[gen][type][zone])) goto next; } @@ -4775,7 +4775,7 @@ static bool sort_folio(struct lruvec *lruvec, struct folio *folio, int tier_idx) /* promoted */ if (gen != 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; } @@ -4784,7 +4784,7 @@ static bool sort_folio(struct lruvec *lruvec, struct folio *folio, int tier_idx) int hist = lru_hist_from_seq(lrugen->min_seq[type]); gen = 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]); WRITE_ONCE(lrugen->protected[hist][type][tier - 1], lrugen->protected[hist][type][tier - 1] + delta); @@ -4796,7 +4796,7 @@ static bool sort_folio(struct lruvec *lruvec, struct folio *folio, int tier_idx) if (folio_test_locked(folio) || folio_test_writeback(folio) || (type == LRU_GEN_FILE && folio_test_dirty(folio))) { gen = 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; } @@ -4863,7 +4863,7 @@ static int scan_folios(struct lruvec *lruvec, struct scan_control *sc, for (zone = sc->reclaim_idx; zone >= 0; zone--) { LIST_HEAD(moved); int skipped = 0; - struct list_head *head = &lrugen->lists[gen][type][zone]; + struct list_head *head = &lrugen->folios[gen][type][zone]; while (!list_empty(head)) { struct folio *folio = lru_to_folio(head); @@ -5264,7 +5264,7 @@ static bool __maybe_unused state_is_valid(struct lruvec *lruvec) int gen, type, zone; 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; } } @@ -5309,7 +5309,7 @@ static bool drain_evictable(struct lruvec *lruvec) int remaining = MAX_LRU_BATCH; for_each_gen_type_zone(gen, type, zone) { - struct list_head *head = &lruvec->lrugen.lists[gen][type][zone]; + struct list_head *head = &lruvec->lrugen.folios[gen][type][zone]; while (!list_empty(head)) { bool success; @@ -5843,7 +5843,7 @@ void lru_gen_init_lruvec(struct lruvec *lruvec) lrugen->timestamps[i] = jiffies; for_each_gen_type_zone(gen, type, zone) - INIT_LIST_HEAD(&lrugen->lists[gen][type][zone]); + INIT_LIST_HEAD(&lrugen->folios[gen][type][zone]); lruvec->mm_state.seq = MIN_NR_GENS; init_waitqueue_head(&lruvec->mm_state.wait); From patchwork Thu Dec 22 04:19:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhao X-Patchwork-Id: 13079363 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67610C4332F for ; Thu, 22 Dec 2022 04:19:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5508A940009; Wed, 21 Dec 2022 23:19:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 48905940007; Wed, 21 Dec 2022 23:19:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D9A0940009; Wed, 21 Dec 2022 23:19:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 184B0940007 for ; Wed, 21 Dec 2022 23:19:47 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id DADD5404A9 for ; Thu, 22 Dec 2022 04:19:46 +0000 (UTC) X-FDA: 80268638772.17.329C8EB Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf09.hostedemail.com (Postfix) with ESMTP id 5C1EB140007 for ; Thu, 22 Dec 2022 04:19:45 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=YYDj3c5f; spf=pass (imf09.hostedemail.com: domain of 34NqjYwYKCEk95Aslzrzzrwp.nzxwty58-xxv6lnv.z2r@flex--yuzhao.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=34NqjYwYKCEk95Aslzrzzrwp.nzxwty58-xxv6lnv.z2r@flex--yuzhao.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671682785; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BDLLEQAWPiuWvu6uAw7SlKRBGnG2Q5GXtGAMB+TrPE8=; b=FW085sihti/MvpY7IpeIT27sSmPDd9xrqn3t3BNrywA9pcyYP55IxUW+EPotouUGD84yzE 8nUJiqJcxZkqvUFwU0QHzsIEaK+4gHP18xoF2oQeH2llanS/W2BH5sP734RkPm179p9HpY JvU8g0nbAU8rEC4q39p/nYvPREjy1uk= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=YYDj3c5f; spf=pass (imf09.hostedemail.com: domain of 34NqjYwYKCEk95Aslzrzzrwp.nzxwty58-xxv6lnv.z2r@flex--yuzhao.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=34NqjYwYKCEk95Aslzrzzrwp.nzxwty58-xxv6lnv.z2r@flex--yuzhao.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671682785; a=rsa-sha256; cv=none; b=dIEfqA46bGVjcJZU/S1hd3arvfGsVxNHJDwNCCPrHQDSXdYkhc55Zg0mUN9zxN6DLaFV8F azL8MJORI2NS48QN+7RCigZPJESCmJ0KZzeKYxG403xNaxTuCI8FM5Hn7WEOQk4PKCfCcV 6sTw0o0tEy5OLd0+SCVlJj51n/jn9N4= Received: by mail-yb1-f202.google.com with SMTP id y6-20020a25b9c6000000b006c1c6161716so685647ybj.8 for ; Wed, 21 Dec 2022 20:19: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=BDLLEQAWPiuWvu6uAw7SlKRBGnG2Q5GXtGAMB+TrPE8=; b=YYDj3c5fM6hkrbkgsT5AQ5QuP7PmzqKTtUZOCkQp6tMZe2KtlQXDXuSeID5qZPLv5w uekCpC4/7VqRHl3u7ovnnOyeEqj/EsywNvGk0SU8TWCKdL5T+UUJ8v4uRxtZmS6vPnl7 Wzj8lALjPQjik55Xsborgrd9EdV5KGHkidFuPRxek7BFO5jMvsBbkzoNYwVZleOoZih8 UbO7SNB2W/YpVQufPScszqS4sLh/XpytF5xvF1sxeegGQeYmCWYdyiAVgWPTJHcniUSO tcG3i3xlYkukeP0JsAW7kB7ooTJnC5WmKclKn5JT2ujNOCPHbdsDPc8vVma69pRmczRk 1nkQ== 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=BDLLEQAWPiuWvu6uAw7SlKRBGnG2Q5GXtGAMB+TrPE8=; b=BE72Rxwyi7aciYciVaamvXEXXPO1PRK8bJNoO4MELUyHeiQacGaa0+sML10cJjurFM i0lkc+tYu4WIvmGILwn4zCjx8Ot9tLpHXhxIbrRTG9FxeErE2kn9KH+a6mq1bJnvgKyx Z1NynjVeQrXEuAAM3cu9TDdN6XdTLsSffTZ4hFD7Zvt4otWLf9yZdezDjsEq5ldauS78 bTu7drn3LFv1+fzTHz0Rg/xwMrkAQN/DbFR+X05iZly0ADN1mmCyWgV4n8y+4qP+elq1 b9PGhw1S7rL3SdSBQWN3yuy5z1Q/h7HhiPnxTaVrMs4WmcgJq+6UitPKnVCm4d+zeI8f jbUg== X-Gm-Message-State: AFqh2kq2Jrtctf8/nPjjr2frfwxv2EFxr979QdlTbqMgx+70LbDgYiHC 9wJrKVpO7iMXabtTjowVl5WAZmdvvMs= X-Google-Smtp-Source: AMrXdXs9f5JEJZRSlLA1c9vebSH3Lts9X7RAt6HHv3GXYgSIKO08I/5btJz8yV9BWIG6W3F5rzxEG2SadvM= X-Received: from yuzhao.bld.corp.google.com ([2620:15c:183:200:a463:5f7b:440e:5c77]) (user=yuzhao job=sendgmr) by 2002:a25:dcc7:0:b0:6fa:5ab4:12b5 with SMTP id y190-20020a25dcc7000000b006fa5ab412b5mr381185ybe.620.1671682784642; Wed, 21 Dec 2022 20:19:44 -0800 (PST) Date: Wed, 21 Dec 2022 21:19:01 -0700 In-Reply-To: <20221222041905.2431096-1-yuzhao@google.com> Message-Id: <20221222041905.2431096-4-yuzhao@google.com> Mime-Version: 1.0 References: <20221222041905.2431096-1-yuzhao@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Subject: [PATCH mm-unstable v3 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 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 5C1EB140007 X-Stat-Signature: haeh4rwm4r4ofwjng36g4nuwspj7w5rf X-HE-Tag: 1671682785-967073 X-HE-Meta: U2FsdGVkX18U91SCoEkC2dd1gnR6grPd6WtKvnPRUva0ep4BPR7Gp1A1uY4GTfNkiGdQwjNxT4FAgjLF59VM11Emxwwns5VwyQNX/LHwhs2Cthz/mxMzpNa+LqiM5vUFdD1OeWIfZKDB/C1lw1XvVQ8fD8gZGRwQHxdfn9kV3F2QbbV74ONArUEpHMN04IMKNdshZzgkW3KSI8ksMSXyB9tAYOXxO/BDeDXj7QgXfMOt3uj/zPnJjvly6Z3il0cMkBtuc5eif75VDepnma+t3ocAD0I9I5V5cyF91hHiMmBqckJtUml74ObqZRQULcC59nq7gmF/RC9WTQWp9/BrgnwLG9KJ7Gk8AOAe3sJhHgdTTwg/UKo3QBeYIp5gvHD468tvJoP3uVZWIr9jOkgL/kQ8RQbByfRO9O8k+6AGWxx9vxhdSIlAoLiLimDNWsis5Mnhza0Je2yxi1Ce8v8wB3M1RCKLldWdu/r9nRLvZViUVv0vM1TLw4V2hG6vpI3Idn5TnBPV5DXrtbIGlUUV+qZEduX6eRKUUTJy0Z7REmB7UiDgDHnb0hFUVIa06kHp8Jjo1CLFbEKCcFpMH/DFZBAmHYTj1E2MvXzn8Bm96u0riPD7wWoaNpZ2s6GvwZpMXAR52mcFxr77zkcNTlzDBl0YKY/g4h+R3MeQgkRuyEDCkpg0FKEMhNfyZ5Hv8ltBEz1q0PcU9iT7zSNxKCNiYmEBG44SmiIf5QTGF+kY7lF8sjkIuqh24JDu4CYihDlr6fBlqiLtkc7csOK+hzHo5soE0qRiJmDNFQzIyGIIAGoUR+4iGQbsSbpzEUdgQjT84umqFDEStA9jXjDh4+4X4Tya5fcEolIwYgaSVPSILAESUgNSw1pzwxBBA3Z2sc0loyx9Z+blYoruDnklThePig+bC2wy1No8N0Mp4i+5dY+Df1k0q3k2bK++qZQWWmtV4fvXqj2i2HdoyjVLhvB ttg1GfCA NB+e8L1kGwMmNC+SwQir9UbULllbxR5C5UuLKLb43hQH/Oj2eKcntOqzSN90yJoO2RMpQ6MrpMGMCNdYFf+4ViviZ5jKiN6epYTdz7/JOe97j8U55D0D5XjR5JQ42FVl1cI9R9j7kmtwZjoK8TnN1wVPMvAsrzh7/qnhNIjdKbZq87cOTzc5YTLNupI20fWMlR5usPwq7eNRvk+HWITrSYtZeA5YzVAtQWj15mw6ofLfEfpvYln/xJV3s3qo7vbjNQ1Z1O8EyVE5jcH3baa4pYceiNrbBVTzlTPnz2LYxUNmBfc35NLf4wSTlJ3YPeD/yfiqVfk6KiTqLNxQqKpwX+SSYg7gYqgx0uC1X5T9cHF+8ygA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 --- mm/vmscan.c | 81 +++++++++++++++-------------------------------------- 1 file changed, 23 insertions(+), 58 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index d94d9fcabf36..49d7c103906a 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; } +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 available? * @sc: scan_control in question @@ -499,6 +504,11 @@ static bool cgroup_reclaim(struct scan_control *sc) return false; } +static bool global_reclaim(struct scan_control *sc) +{ + return true; +} + static bool writeback_throttling_sane(struct scan_control *sc) { return true; @@ -5006,8 +5016,7 @@ static int isolate_folios(struct lruvec *lruvec, struct scan_control *sc, int sw return scanned; } -static int evict_folios(struct lruvec *lruvec, struct scan_control *sc, int swappiness, - bool *need_swapping) +static int evict_folios(struct lruvec *lruvec, struct scan_control *sc, int swappiness) { int type; int scanned; @@ -5096,9 +5105,6 @@ static int evict_folios(struct lruvec *lruvec, struct scan_control *sc, int swap goto retry; } - if (need_swapping && type == LRU_GEN_ANON) - *need_swapping = true; - return scanned; } @@ -5138,67 +5144,26 @@ static unsigned long get_nr_to_scan(struct lruvec *lruvec, struct scan_control * return min_seq[!can_swap] + MIN_NR_GENS <= max_seq ? nr_to_scan : 0; } -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; - 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; - /* over-swapping can increase allocation latency */ - if (sc->nr_reclaimed >= 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 += 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 = 0; i <= sc->reclaim_idx; i++) { - unsigned long wmark; - struct zone *zone = lruvec_pgdat(lruvec)->node_zones + i; - - if (!managed_zone(zone)) - continue; - - wmark = 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 += MIN_LRU_BATCH; - - return true; + return max(sc->nr_to_reclaim, compact_gap(sc->order)); } static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc) { struct blk_plug plug; bool need_aging = false; - bool need_swapping = false; unsigned long scanned = 0; unsigned long reclaimed = sc->nr_reclaimed; - DEFINE_MAX_SEQ(lruvec); + unsigned long nr_to_reclaim = get_nr_to_reclaim(sc); lru_add_drain(); @@ -5222,7 +5187,7 @@ static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc if (!nr_to_scan) goto done; - delta = evict_folios(lruvec, sc, swappiness, &need_swapping); + delta = evict_folios(lruvec, sc, swappiness); if (!delta) goto done; @@ -5230,7 +5195,7 @@ static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc if (scanned >= nr_to_scan) break; - if (should_abort_scan(lruvec, max_seq, sc, need_swapping)) + if (sc->nr_reclaimed >= nr_to_reclaim) break; cond_resched(); @@ -5677,7 +5642,7 @@ static int run_eviction(struct lruvec *lruvec, unsigned long seq, struct scan_co if (sc->nr_reclaimed >= nr_to_reclaim) return 0; - if (!evict_folios(lruvec, sc, swappiness, NULL)) + if (!evict_folios(lruvec, sc, swappiness)) return 0; cond_resched(); From patchwork Thu Dec 22 04:19:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhao X-Patchwork-Id: 13079364 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24BC9C4167B for ; Thu, 22 Dec 2022 04:19:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0432494000A; Wed, 21 Dec 2022 23:19:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F0E15940007; Wed, 21 Dec 2022 23:19:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CEAFB94000A; Wed, 21 Dec 2022 23:19:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id BB86B940007 for ; Wed, 21 Dec 2022 23:19:48 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 98E491A058F for ; Thu, 22 Dec 2022 04:19:48 +0000 (UTC) X-FDA: 80268638856.10.AC1356F Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf28.hostedemail.com (Postfix) with ESMTP id 10C41C0007 for ; Thu, 22 Dec 2022 04:19:46 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=LGK8h9wz; spf=pass (imf28.hostedemail.com: domain of 34tqjYwYKCEsB7Cun1t11tyr.p1zyv07A-zzx8npx.14t@flex--yuzhao.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=34tqjYwYKCEsB7Cun1t11tyr.p1zyv07A-zzx8npx.14t@flex--yuzhao.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671682787; a=rsa-sha256; cv=none; b=2M5hSaRuihNBlfyxXUnIhpYuuEd9Y88/0MJLB24MWT4LruEEmJfNWF8SmuP2VtSq4QE+Pi qfKvxV+ZfOidVMLs3axlhhRLNun4zY612eUJxQudEo5pTowL+9LiQmJBZS1C9hUqAiO90B gE75bD+9THaNZf8Uze01sXXWLE0/2zg= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=LGK8h9wz; spf=pass (imf28.hostedemail.com: domain of 34tqjYwYKCEsB7Cun1t11tyr.p1zyv07A-zzx8npx.14t@flex--yuzhao.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=34tqjYwYKCEsB7Cun1t11tyr.p1zyv07A-zzx8npx.14t@flex--yuzhao.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671682787; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=nzLJiZ4QM5Uh21mWC41LC4GBB5ZaSED6XDHCtugxc08=; b=gVmyn+XU1S7Syc2fbDi3neqHRhliJWi+fTtsVnIDeFWDALkrDME8Y0EKJP1TS7qariFpBR 1jaq+HITLKR/PI3WLAYXwIEkXl6q1ntulXilVOAy2mjsVuyj6aeC37/rpWbjmDPeYqyLk2 t9ZNrfrfs6/hmvtHEvXCdCQqyddFJTM= Received: by mail-yb1-f201.google.com with SMTP id r7-20020a25c107000000b006ff55ac0ee7so669396ybf.15 for ; Wed, 21 Dec 2022 20:19:46 -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=nzLJiZ4QM5Uh21mWC41LC4GBB5ZaSED6XDHCtugxc08=; b=LGK8h9wzmfZbkub7vTd8RNWpNWLSzm7G1OuZlNkyjd72d/DuTcDHYUL4xBQcaqX+6a iBARPo3dG0EKbr43vnaB9kXhiLdIVarVSxPRMSmvLc3GrMSsLYLgsfAVBTIA/B44vjLs so6T2/KZM+3aQXkpITzI4UM8KbocN8LznaSbs2lDpTf74F8ww3eWoj7GwxhNNeTZDBGS 3JuGx5KWL6WL3jJU6O7VPlUhEW4+O/Q3JOV/j8eDtLU8oYPgWtWgLX5JetQCIv39UVGk 62+J38ROwufIeFkVog6el5JN4Yi8QoJ0KVmDw0YykY5v+DyL1rqOiHGd579YyrOxuB05 c1Sw== 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=nzLJiZ4QM5Uh21mWC41LC4GBB5ZaSED6XDHCtugxc08=; b=FPoMiOuo5BojukYZwEluYSzEWXHnMXZVquUzhvgRXSEbPu8Osl+4L4luo3erYWpBTO scwoHoegwQynr9GYrjzz+U/op9Vz6E/f84xOQ6oPvlGBT2IVNcKQKZyr63nMFYsYYxH/ S37cb65Ad0ICqE3LzND9upFTn1b4n7CnAunlm1kT50FAQ6WEkAlmUQFZWzRefsrUNTpw veuJ9kZBotpT8+69BKpLNAPZ+JXeLOW1q92yMkCrWewwPqo3XbT2wshjWSIznqTDdZu/ MQXgPuzDM+HnRDoVscv+4FdeSCNJEokcs0NNmFpzz0LS1+jrUYjm/QKWdLslykUjvAZ6 uJnw== X-Gm-Message-State: AFqh2kpiNBnNexGWWXtatEHLHZ7DgySfHOS0W2R6UVf/IqR3FhrF5Z/b Gt67EtdNfiSNrGAkdPLw31L5JUE3iOM= X-Google-Smtp-Source: AMrXdXu349F+GjLv+LsWuQvHnJ0vl+EFKxOrB01QlRFTB17yje2mwF78wvgJ6L9LCsoyXjHckCuxD+e8kGc= X-Received: from yuzhao.bld.corp.google.com ([2620:15c:183:200:a463:5f7b:440e:5c77]) (user=yuzhao job=sendgmr) by 2002:a05:690c:c95:b0:36c:aaa6:e571 with SMTP id cm21-20020a05690c0c9500b0036caaa6e571mr312608ywb.467.1671682786236; Wed, 21 Dec 2022 20:19:46 -0800 (PST) Date: Wed, 21 Dec 2022 21:19:02 -0700 In-Reply-To: <20221222041905.2431096-1-yuzhao@google.com> Message-Id: <20221222041905.2431096-5-yuzhao@google.com> Mime-Version: 1.0 References: <20221222041905.2431096-1-yuzhao@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Subject: [PATCH mm-unstable v3 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 X-Rspam-User: X-Rspamd-Queue-Id: 10C41C0007 X-Rspamd-Server: rspam01 X-Stat-Signature: j1a6fbugp6wsetumy5t318uu9jdkqj3s X-HE-Tag: 1671682786-149337 X-HE-Meta: U2FsdGVkX1/A3FMrpUrWhd75+RVlykDLEtbB5uEn5d2sYKoNILgoCgtiowbIYZEHJwMvNBWeVsK79YejdOOU4JgHbX3JchNHTMWh2rjx4D2sgXmyUm2GshNvYHR/W9Bmida3l0mvcNUReeHfU1Fmw8OPgS3neFApdSha3jerxlh9qCy5vLtUWJmgo/RyI8iJxRlFq5H4DDWRzIsTfNqct3okWRuH5wP07LomjY37lKJtLNQcEV9lk43zX8iC2CBAlAQ2f6HGAWJCecyKOhBgGLxfTzoaT0N2mrx+fDeVZnHTp+2bHvwTqPPkJ4ydBSxGYR6f/IjyFzo6IPAgU97g1BPRRAtMuBrxeHKjKWNLJ9tKj5jm4joAJ3F4cwkmrAzSFHjtax3+jc8NMPk2G0DQoDm56KkilGYC/A5fWun62c2g4Kuf1FtBHm9lv67auv9qdI38m2AEDMVGYisuWdmwoOIrbymrm+GyuTAQmJknuUBMcI5JMMiPN57nLF2zob+bSDOdnej2KrH1K5zsXTgXEmrrQLNmVj81fXDTNlXca40I9fU7VvlMlPnod++MpVZ9Qsb6dLdDAZPCxP3tUHtTa8c1gFcIWgzjDwQBUWeZPmSnORX2aweQ5D9MulMGK+1Jv+2YYktLviXeaSVBZ9qDG/NNEaeawrfNJ/az6OhvPZ27DW8iUpX0CNSbzIOg7j0qxDEbmpFB1AafntfAFdvr6s4Un2Kc8/r9etyFipI8XmgQfbwVaQoyf3YBr100/Fu8OGatv373bwp8flbF3vhB/wvOxykHsQIkul4W6f2f7TLCsZyuwMET5Z+3AghGYyMR6cxoVsfAl+tQcKHPQFUFw6DSBP0rYHXKofko2qkYsqiJm+BOZo8/mwBORyawotxyirOj7Pq11lk/B4yv7Z+S5HogE1mflliDexKwKb+OLfISF0m8Op9lfi5tvaKO4Adcn7eYu0m4pj7KLk+Qimb B0zDGwIX CsUXUiOPGmb6H+U1VjfE7/eLHBcC7oq+QulM0e4GZrZgMpHuSahzzuaoultF6Lppe0Xy5QL/v5Ukm+CJBEhCRI93sDM9xAyzR8etwdO1eHqcQ9vGRhSZY2IJgm34vu44AVhoLbdAxK60OEbW2OL7cQ61X+8t1glq4nSRPJX3pdyx6nk6HySzAmamhDW0t4X19rlF4UMEVpxC5kIYKfhnlW0GU4y922AKjMDaudArzV6gHR4g650tCGALLCyk/aYhYHGJaeA5VysOevj2bDuGHqgtHUcLoLUtCIyKX7SbTNU0l22Z2fB2t4Xd4IkTYT5uBordNh1E0/zDzxH/GrrToRvqBdLrqy9kSB/ow0z4mA3vgukkNfkAVaSgRMA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 --- mm/vmscan.c | 150 +++++++++++++++++++++++++--------------------------- 1 file changed, 71 insertions(+), 79 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 49d7c103906a..65cc82208b6e 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -137,7 +137,6 @@ struct scan_control { #ifdef CONFIG_LRU_GEN /* help kswapd make better choices among multiple memcgs */ - unsigned int memcgs_need_aging:1; unsigned long last_reclaimed; #endif @@ -4468,7 +4467,7 @@ static bool try_to_inc_max_seq(struct lruvec *lruvec, unsigned long max_seq, return true; } -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; @@ -4477,6 +4476,13 @@ static bool should_run_aging(struct lruvec *lruvec, unsigned long max_seq, unsig unsigned long total = 0; struct lru_gen_folio *lrugen = &lruvec->lrugen; struct mem_cgroup *memcg = 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 = 0; + return true; + } for (type = !can_swap; type < ANON_AND_FILE; type++) { unsigned long seq; @@ -4505,8 +4511,6 @@ static bool should_run_aging(struct lruvec *lruvec, unsigned 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; @@ -4525,40 +4529,54 @@ static bool should_run_aging(struct lruvec *lruvec, unsigned long max_seq, unsig return false; } -static bool age_lruvec(struct lruvec *lruvec, struct scan_control *sc, unsigned 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 = get_swappiness(lruvec, sc); + int gen, type, zone; + unsigned long total = 0; + bool can_swap = get_swappiness(lruvec, sc); + struct lru_gen_folio *lrugen = &lruvec->lrugen; struct mem_cgroup *memcg = lruvec_memcg(lruvec); DEFINE_MAX_SEQ(lruvec); DEFINE_MIN_SEQ(lruvec); + for (type = !can_swap; type < ANON_AND_FILE; type++) { + unsigned long seq; + + for (seq = min_seq[type]; seq <= max_seq; seq++) { + gen = lru_gen_from_seq(seq); + + for (zone = 0; zone < MAX_NR_ZONES; zone++) + total += 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_control *sc, + unsigned long min_ttl) +{ + int gen; + unsigned long birth; + struct mem_cgroup *memcg = lruvec_memcg(lruvec); + DEFINE_MIN_SEQ(lruvec); + VM_WARN_ON_ONCE(sc->memcg_low_reclaim); + /* see the comment on lru_gen_folio */ + gen = lru_gen_from_seq(min_seq[LRU_GEN_FILE]); + birth = 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); - if (mem_cgroup_below_min(NULL, memcg)) - return false; - - need_aging = should_run_aging(lruvec, max_seq, min_seq, sc, swappiness, &nr_to_scan); - - if (min_ttl) { - int gen = lru_gen_from_seq(min_seq[LRU_GEN_FILE]); - unsigned long birth = 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 != 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); } /* to protect the working set of the last N jiffies */ @@ -4567,46 +4585,32 @@ static unsigned long lru_gen_min_ttl __read_mostly; static void lru_gen_age_node(struct pglist_data *pgdat, struct scan_control *sc) { struct mem_cgroup *memcg; - bool success = false; unsigned long min_ttl = READ_ONCE(lru_gen_min_ttl); VM_WARN_ON_ONCE(!current_is_kswapd()); sc->last_reclaimed = sc->nr_reclaimed; - /* - * 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 = true; - return; - } - - set_mm_walk(pgdat); - - memcg = mem_cgroup_iter(NULL, NULL, NULL); - do { - struct lruvec *lruvec = mem_cgroup_lruvec(memcg, pgdat); - - if (age_lruvec(lruvec, sc, min_ttl)) - success = true; - - cond_resched(); - } while ((memcg = 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 == DEF_PRIORITY) return; + memcg = mem_cgroup_iter(NULL, NULL, NULL); + do { + struct lruvec *lruvec = mem_cgroup_lruvec(memcg, pgdat); + + if (lruvec_is_reclaimable(lruvec, sc, min_ttl)) { + mem_cgroup_iter_break(NULL, memcg); + return; + } + + cond_resched(); + } while ((memcg = 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 = { @@ -5114,34 +5118,28 @@ static int evict_folios(struct lruvec *lruvec, struct scan_control *sc, int swap * reclaim. */ static unsigned long get_nr_to_scan(struct lruvec *lruvec, struct scan_control *sc, - bool can_swap, bool *need_aging) + bool can_swap) { unsigned long nr_to_scan; struct mem_cgroup *memcg = lruvec_memcg(lruvec); DEFINE_MAX_SEQ(lruvec); - DEFINE_MIN_SEQ(lruvec); 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; - *need_aging = 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; /* skip the aging path at the default priority */ if (sc->priority == 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 <= 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; } static unsigned long get_nr_to_reclaim(struct scan_control *sc) @@ -5160,9 +5158,7 @@ static unsigned long get_nr_to_reclaim(struct scan_control *sc) static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc) { struct blk_plug plug; - bool need_aging = false; unsigned long scanned = 0; - unsigned long reclaimed = sc->nr_reclaimed; unsigned long nr_to_reclaim = get_nr_to_reclaim(sc); lru_add_drain(); @@ -5183,13 +5179,13 @@ static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc else swappiness = 0; - nr_to_scan = get_nr_to_scan(lruvec, sc, swappiness, &need_aging); + nr_to_scan = get_nr_to_scan(lruvec, sc, swappiness); if (!nr_to_scan) - goto done; + break; delta = evict_folios(lruvec, sc, swappiness); if (!delta) - goto done; + break; scanned += delta; if (scanned >= nr_to_scan) @@ -5201,10 +5197,6 @@ static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc cond_resched(); } - /* see the comment in lru_gen_age_node() */ - if (sc->nr_reclaimed - reclaimed >= MIN_LRU_BATCH && !need_aging) - sc->memcgs_need_aging = false; -done: clear_mm_walk(); blk_finish_plug(&plug); From patchwork Thu Dec 22 04:19:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhao X-Patchwork-Id: 13079365 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A029DC4332F for ; Thu, 22 Dec 2022 04:19:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B412F94000B; Wed, 21 Dec 2022 23:19:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ACA2E940007; Wed, 21 Dec 2022 23:19:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 87EF394000B; Wed, 21 Dec 2022 23:19:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 6D862940007 for ; Wed, 21 Dec 2022 23:19:50 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 45EDDA0485 for ; Thu, 22 Dec 2022 04:19:50 +0000 (UTC) X-FDA: 80268638940.04.8D450C7 Received: from mail-io1-f73.google.com (mail-io1-f73.google.com [209.85.166.73]) by imf19.hostedemail.com (Postfix) with ESMTP id A874E1A0004 for ; Thu, 22 Dec 2022 04:19:48 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=awokrXW2; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf19.hostedemail.com: domain of 349qjYwYKCEwC8Dvo2u22uzs.q20zw18B-00y9oqy.25u@flex--yuzhao.bounces.google.com designates 209.85.166.73 as permitted sender) smtp.mailfrom=349qjYwYKCEwC8Dvo2u22uzs.q20zw18B-00y9oqy.25u@flex--yuzhao.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671682788; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=S9ZuAyfwqYLskluTxeMZ1Oyj25JaC3jpnfC7bM5WyD4=; b=w0NF4mBi0CWTNy7hEMaVGxG4ei4huDnOYYg+dQJM2JP46G3wzT61gQvsifK8vVK3420RVu 8N9C/LvdZa0p1ucAw0jGOhtOq4NeJ0gXQgEltNsVHYCVSTdvFnv96/tNTsNp8P1sQOtJmq DKRHd/4ehYV9ebRdtIDbEeiaQ5TrPcg= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=awokrXW2; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf19.hostedemail.com: domain of 349qjYwYKCEwC8Dvo2u22uzs.q20zw18B-00y9oqy.25u@flex--yuzhao.bounces.google.com designates 209.85.166.73 as permitted sender) smtp.mailfrom=349qjYwYKCEwC8Dvo2u22uzs.q20zw18B-00y9oqy.25u@flex--yuzhao.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671682788; a=rsa-sha256; cv=none; b=r4xljuh1ThHh3qqmO8Qk0lxTUvOPiXfoARPM+QcudJiFnggapRfGYdlCacp7T9sZrGfU4s JlWdS+ssX1LDZ7dazxK+1+P0JSNEhyiL59e5oniUy59vdHg+oCc/+CkUY2+sLHssPZYEGN 5+2/9QbMXMnXO457VQrqG/noVnzClWA= Received: by mail-io1-f73.google.com with SMTP id z9-20020a6be009000000b006e0577c3686so340127iog.0 for ; Wed, 21 Dec 2022 20:19:48 -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=S9ZuAyfwqYLskluTxeMZ1Oyj25JaC3jpnfC7bM5WyD4=; b=awokrXW2IaKsda0feV8JW/aYhMrUqKzEHQX+f5UsTBU2+8KVpH/XEmCKdVW/3j64+P LX4/xKKwf3yGaOd1RMWjLx+SBKbq5b79RaWXbvO3uvqC1rK19G2lTd+XOyNc4OAudt0G BNVuAfZmPTiS12q4Pp+vrGp7KjeUeKAD9fMxEibkXqvB9XoQo6+4i1rCFGj5s/wHCCxE YvcF1Rui1WagXwkNShtpDS8/0ZLm9UBhXa7tsws0qPh8YIdTW6gtnBpxOGzSDL8IeNie vd507zZFTZU4yPE5FV0HqFBmaZ/37IUyHVnBJLcsj1LUs4dMyMtEtQhrG/k+tqR6EKRe 4JXw== 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=S9ZuAyfwqYLskluTxeMZ1Oyj25JaC3jpnfC7bM5WyD4=; b=n/07zFBin2Gd1CtW5WPQBnE9RGWWVkluBJ6KITjybh6TfC3Su9ixIVB4wHhhTg1d+g Ftg3fPj4Fvp2+jkYrQbGrGf5//8lz/vm8AgpErEYcOt2o5Hf24rq/QnGAbc9Y7DdqUQg qWDbh8/Blh5A3IrStdq6tmgiIQjZ7Cf6CGm2dofY2FUqx9SXUebsUZUPTPE4aWDbk0l8 YME7Y1N/M5kXSbx1d4V1cehXyNiG6yycxDcYJlXxDGZMSDNkgkoccluUxTjdevbF34h5 CtRI5bn29jmG4pThRa+ztUSssdAW9WYz2xWaOGKWVhGbFf+zcg61Dtx04GPjZpKKuINh tkHA== X-Gm-Message-State: AFqh2krN5crQl1h+Dpskq7JBjnhNwWJhfdhDfiVdadYuKglRO0fu13rW cvBLmGHZ9+yamOXQo4DkFMSc4E7UR5A= X-Google-Smtp-Source: AMrXdXuEY3YkuSyiXYaG/rF71AtXpvUi99HGEHzJyq69UdzONGfza3jeMcIIHRBjZ3l13oxwVLYTLfNu04M= X-Received: from yuzhao.bld.corp.google.com ([2620:15c:183:200:a463:5f7b:440e:5c77]) (user=yuzhao job=sendgmr) by 2002:a92:cb42:0:b0:305:eba6:78ab with SMTP id f2-20020a92cb42000000b00305eba678abmr300227ilq.316.1671682787850; Wed, 21 Dec 2022 20:19:47 -0800 (PST) Date: Wed, 21 Dec 2022 21:19:03 -0700 In-Reply-To: <20221222041905.2431096-1-yuzhao@google.com> Message-Id: <20221222041905.2431096-6-yuzhao@google.com> Mime-Version: 1.0 References: <20221222041905.2431096-1-yuzhao@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Subject: [PATCH mm-unstable v3 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 X-Rspamd-Queue-Id: A874E1A0004 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: rbk9ta6e96y8kiosi3j61pbunh9agnae X-HE-Tag: 1671682788-215688 X-HE-Meta: U2FsdGVkX1+M3HnGePsXkyIZJgJ2gAq3hDe/HtHxqbmcky4xQ5Wg+4k4gnQjRcHdV32dpLA5pnR4Qkz06IeGwrXBhtc2wlcU2bu0t6+3TpGv815C0PztRdzSa246+hRw1xiFqss/FJv0LRitiWK3i5itvLf9zoN7cD9fcWaVb2dDuMb2kZohQaZ9mow9LFGq5tOmpz0kD4UJCvEqH71PAmzr1pHQgl3k0nCT0u8SnxTT9ll8W5kCkMw3XjDAlyDm8UHcnvJCYY37pMUrCqd8bLDqla1+0qCYJgn2BRfojLlDI5ZfKI/sI9nwmQG8L9kdKniT31Hk7aMhkACJGalO5bZPe/PvyXS0cGVH+7HWZp8OIV2JSRG9zMFXk4kby138XWGhMO4e9PDjbeMR51su2HeoOGj568I5NlAIKV3YBVGzGCJmNp1Zg8VQLd8FNNtfIXHymBQ235tPB3ojmh9g1za8UEhySr/yY3knixDPadMkFlTUAIt96OEsy9kfAwUxOutUv4Utq2m3cN31KCzQnBImk2iWsk3W2vA6FdrPHr2aLneQX34FnDiFOsdlMgKdqg5U3ST/f58uVWJXHvlMuTdHyHjfRqdyqXlR5+j0+d61lDUDrZLp0HZcFajc1vv9qOhuEul3rDUokzkFdFqnIPY9MkWyv7I5HVRlM9FCLzxstL3jgH3Fz8h56ChY1lPDy73bFDWF5QTiEcO09KUnkE4rU4D+Eb9+vyxA1Akirupp6W35qaZEZIMY+uC5rKKN3rLEjJDk7ZgNiOUF0YL2MojmCl8Bc8FTU9ZViifr61OrZGtW95p6qcbkvRE27EEiFUX5s1I5+UkdYIm4RuG6K/8pwMdF8HhAInMkF7af90fzgk8Xs4XTEBNI8WmuseypyuOBnwspw/WJc8hAB0l3OfTwNcp53B4WzVwsO/UaqMNkwG6gbc4DmpExzI7UVrN3upwgCzbSv2ZbiHSLexj JGXlikm4 zYDm803ro6kWeuJew/Ebt88sjQW7I1bDlc7zWtP64vgNoUt+VhaOfHhyzVpbcs+KXaM6ZW2RsV196I4Jo8WMqwX7z1G/QLQvUigydHcYreJajxP9/0kRJVls02vXWkMjgYwzTTAWIxfHLa1fh+E88tantjWn0ZONK+lRvggTPYDeqXacExjZLPsW5cWcGXH3/izvPlVBnx6MHJHXYByZt4ILIz9k2VnMkcC+/3wbcZimPCWPctCdyuJcO7k2uN4EG7/k/MUAE/P0ciFgZ0AJjykqM2/CnClg9ovoSybniYS/EnUqRGXpQCq/kMkST7VkLAR0agYYvQA+Iu8tG7aQZKNzI/YcWt5O3s5+gCxpIiLApSJX4egkeHwOT2OmztUsjvTsQpasg73EoTmpqWkGBciEiMhrq+NSz1dnH X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Move should_run_aging() next to its only caller left. Signed-off-by: Yu Zhao --- mm/vmscan.c | 124 ++++++++++++++++++++++++++-------------------------- 1 file changed, 62 insertions(+), 62 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 65cc82208b6e..dd9f7b7abe1c 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4467,68 +4467,6 @@ static bool try_to_inc_max_seq(struct lruvec *lruvec, unsigned long max_seq, return true; } -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 = 0; - unsigned long young = 0; - unsigned long total = 0; - struct lru_gen_folio *lrugen = &lruvec->lrugen; - struct mem_cgroup *memcg = 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 = 0; - return true; - } - - for (type = !can_swap; type < ANON_AND_FILE; type++) { - unsigned long seq; - - for (seq = min_seq[type]; seq <= max_seq; seq++) { - unsigned long size = 0; - - gen = lru_gen_from_seq(seq); - - for (zone = 0; zone < MAX_NR_ZONES; zone++) - size += max(READ_ONCE(lrugen->nr_pages[gen][type][zone]), 0L); - - total += size; - if (seq == max_seq) - young += size; - else if (seq + MIN_NR_GENS == max_seq) - old += size; - } - } - - /* try to scrape all its memory if this memcg was deleted */ - *nr_to_scan = mem_cgroup_online(memcg) ? (total >> sc->priority) : total; - - /* - * 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; @@ -5112,6 +5050,68 @@ static int evict_folios(struct lruvec *lruvec, struct scan_control *sc, int swap return scanned; } +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 = 0; + unsigned long young = 0; + unsigned long total = 0; + struct lru_gen_folio *lrugen = &lruvec->lrugen; + struct mem_cgroup *memcg = 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 = 0; + return true; + } + + for (type = !can_swap; type < ANON_AND_FILE; type++) { + unsigned long seq; + + for (seq = min_seq[type]; seq <= max_seq; seq++) { + unsigned long size = 0; + + gen = lru_gen_from_seq(seq); + + for (zone = 0; zone < MAX_NR_ZONES; zone++) + size += max(READ_ONCE(lrugen->nr_pages[gen][type][zone]), 0L); + + total += size; + if (seq == max_seq) + young += size; + else if (seq + MIN_NR_GENS == max_seq) + old += size; + } + } + + /* try to scrape all its memory if this memcg was deleted */ + *nr_to_scan = mem_cgroup_online(memcg) ? (total >> sc->priority) : total; + + /* + * 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 From patchwork Thu Dec 22 04:19:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhao X-Patchwork-Id: 13079366 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 329BBC4167B for ; Thu, 22 Dec 2022 04:19:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 571DF94000C; Wed, 21 Dec 2022 23:19:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4FC62940007; Wed, 21 Dec 2022 23:19:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D86294000C; Wed, 21 Dec 2022 23:19:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 1833B940007 for ; Wed, 21 Dec 2022 23:19:52 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id DD3B9A0485 for ; Thu, 22 Dec 2022 04:19:51 +0000 (UTC) X-FDA: 80268638982.22.A78B6AD Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf02.hostedemail.com (Postfix) with ESMTP id 48EBC80003 for ; Thu, 22 Dec 2022 04:19:50 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=gVk09z+m; spf=pass (imf02.hostedemail.com: domain of 35dqjYwYKCE4EAFxq4w44w1u.s421y3AD-220Bqs0.47w@flex--yuzhao.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=35dqjYwYKCE4EAFxq4w44w1u.s421y3AD-220Bqs0.47w@flex--yuzhao.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671682790; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=QjWoCnNqJvghgGM5xTq+UZn44MWyzd/ooNIjEotcyzA=; b=U8xWFp7oh1tA+1ngm4zLvGD8nB09x7aE8kOpb/FepTU1l5M7NE68NsytoPE2b/g1FDkgTM QefWLOj635DtcoUysYcuV1pzHiLwNrXm9s2iSPC4QEkitcQ4iNYQL0fK3N834+VB1KYcSm TDZqK80I1EjsqFfdT48Ie6QrUkL1Qhs= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=gVk09z+m; spf=pass (imf02.hostedemail.com: domain of 35dqjYwYKCE4EAFxq4w44w1u.s421y3AD-220Bqs0.47w@flex--yuzhao.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=35dqjYwYKCE4EAFxq4w44w1u.s421y3AD-220Bqs0.47w@flex--yuzhao.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671682790; a=rsa-sha256; cv=none; b=l1mA7ba8WigLsAmpiw27Zx15kw+Z3BMDQut9M+2TK31jW2RbHzIlzi94gCNOLmYQmsiLAG 7GCs6RoKxkmtsyA/n1X3EXlbkzg3bOS+9lc0L8mDHF7ZynhvnTPKqqNG8uAYgYH9JXKuw5 tbH62LZCQgBT4oKSkkVC6LNUsddL/N4= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-349423f04dbso9580987b3.13 for ; Wed, 21 Dec 2022 20:19:50 -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=QjWoCnNqJvghgGM5xTq+UZn44MWyzd/ooNIjEotcyzA=; b=gVk09z+meyISg3VNqxt5i7DDOmbulc2ogiSqR7HhEgg8qNueR1ZAOmFWTdW3mwkeeQ IvEDmXNlqlKFrpRcz2ljGW8kWPN+h3qdjnYAptEnAV1jH0bDsA4vYJ+91Sb2idREYo1j +efmSy6zYsa+g/tMMmiPYuElmaiJ47XK9c8G/dbPrOgQ/EpDV0o1wlf4494YHu86U1yL 8YMhav2fmfTLN/no9ZGrYYAK7rxYzs/9S4GrQyAQoJv2WmMKhBQxAFt1Y6im40/IF1bC +/7vaB8LjBU2OoDnzmMmg82U7BAcrIC+s33gtUCKePMPVtx0OEr9dxpmGjmEGk+9bjdJ JtLg== 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=QjWoCnNqJvghgGM5xTq+UZn44MWyzd/ooNIjEotcyzA=; b=70IPZD7maMz6Sax5/CzyhcujUyS3W1RJ3ZjOOhicJbpC/DSwUYTZs9UzLk7vSXjBae tM4c25FDaC55URSl/dUG+4o3mOGLVmlfhroAyoiZNQufn9TRT0QBh2BNmtbRMvLh9m7M X7ZRQa3rtZCC1+PNaTd44WjhJtVOCBet7oKQHgeRQ51stu5AdCLUnh5tzOUAdadVBA71 kaDWvqjzfwnJnRW4bzcz0jbn5q9pPYL+dhxUUD+iGCfixAJFJHIlw1yO0SPsfIeI/0QU Yvw26p3kfUGVyKiSfbAEvkDvBTsi5NG2xG1I3sCItlTlr9wpiTjKV6yle7Kx8bMZF/Tv q+LQ== X-Gm-Message-State: AFqh2krbFo/VECHGys4NFsmH71/8Vc40OsoulYizWGuRTxtmNKUCxXSf z4qOaG5bHlQAZ8wfrBedkAQ6FC5EdsU= X-Google-Smtp-Source: AMrXdXu6MLU36MR7Wmyx5EZalLxbE9elTeO/qB32Kp9eR42Wvc0UXcJxCD+Vc4NU6y1HfeFn+akh/l3nnzU= X-Received: from yuzhao.bld.corp.google.com ([2620:15c:183:200:a463:5f7b:440e:5c77]) (user=yuzhao job=sendgmr) by 2002:a25:bc8b:0:b0:6fb:efbb:f588 with SMTP id e11-20020a25bc8b000000b006fbefbbf588mr429922ybk.395.1671682789357; Wed, 21 Dec 2022 20:19:49 -0800 (PST) Date: Wed, 21 Dec 2022 21:19:04 -0700 In-Reply-To: <20221222041905.2431096-1-yuzhao@google.com> Message-Id: <20221222041905.2431096-7-yuzhao@google.com> Mime-Version: 1.0 References: <20221222041905.2431096-1-yuzhao@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Subject: [PATCH mm-unstable v3 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 X-Stat-Signature: e681yxgj35zrdfgo9ab4m9uzzayqsz7y X-Rspam-User: X-Rspamd-Queue-Id: 48EBC80003 X-Rspamd-Server: rspam06 X-HE-Tag: 1671682790-111945 X-HE-Meta: U2FsdGVkX1/jagAB50GfRegKfIiqZN5u4QFd9I4w+a+Ou4m8SpHTHcbtYjJYZ3yzWTBCjUefSm62qogbb0Z9mCFCWGVA3HjIptfdJGqlcErBHzPjXYfLf+UYIi7E4yZEAHfWi9GKNF2VTgDcDElJWq02XsblcIae2G0IPEMr0UsZ1vO6YAHhACqwlUNcpH3QB2TRHjSaWHWcBg+/SlnjJbDSnfCQFeTZMlHkkkRiC976uq3DNpIZwEPYCpBS5x8e5qnTOcPJ5XnF2YTBEHfFW6wImgmY7yfdSRy6I4fdS5kBp+6MWrBJVTa7T44gSE4vPCeI/rTODXq450EAQTr9v1N5/tyJNhNsTk1pw1agZ17WWZbgqVo9eVmfnuu/NcJyOqnNA2UvpYtjxcen9UNMLaPseFrLvj0R7Ube2BVi7VZ6Df10lhUh/y7wRG3FZd1VY9pVF6ju5VOGsfKJ0MyFY44aCi18xtem8kTMIcxas9IMHqVT0LYLNx6vgyIpqiQGHfWRtV0zM3SQjpG2l6hLj4zWKBeA8xeD89NmyMyQRR2tcd7bMjK35IR6GmgqFfSK5gmbQdAKIxoTKWs+jsa52QT5OSy0KvUvKWXY/K6eHkvBHEdlYBMn/RXQbXCfdKyzHR83roR/pLgj1zRQZ1f24mdX8DzzwlkBaG1jw9LMkU5IKEacGhB+NJvGAL88EwvW716f+J10f2xCV/5hUciFI5J3+S/5PGUjOoKrFlLUds11f2nVJbQw10GP+Zi5OTEM9qgTbztZ7p6pa4av4H4BESTIB0/vcv403AiqsipT746kJEAp8/S0QzUnwXEBwAg2reUGrR0a4lgKgjg90Yp2xSR/LY5sRLvCdU7cIKKI8Y/Ldm7xH5vSwLl2bafH6ac3yuMVYWy6avURECfOJqvqrIto7FWp0dlkGfxi1xgw57dWTdm3QMO2LLF1S42xbfPJp1xRQFJ9xh0v9H8MXpL A5ALn7hY bnMiSlGU7UK79q82SdwGAtktBCkgc4agB5ZGti9Jq9miAauAsZv1/kzNbQO8tqyZp1t7c/ZR8XEbk7xhqAE3IZCZXxIY5yEcPATIfWInX8D0iqTdEeX015mEPBNTRQ+bplqU538OyjbL/isDoUFihDB6V8j4GtepQr/SZeiUd0KZdIOi/sainwUUWFyMVMVngZi1eFE2d1CxR88vOnUllfma2UdQcITVwRUPDiGSvN30CqGyvqtdwTaATmn7uaiNrsRt80klKCwRAoY8JwsNlcTzpIZ1wjvxK4dR2z02Kvi9W+hH7WYf7sN6Xev1G1CyFCvmeQLKYHHW0yG4E8zPU2idAQ98XM9uhyt8RZcsEEmsvSC+HiSM89Kon5zHoAjWsb6Iav4C6waSKIKrvTNUwRVE6EGUyC/x8WqEn X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 --- 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 | 374 +++++++++++++++++++++++++++++++++---- 6 files changed, 500 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 *objcg) percpu_ref_put(&objcg->refcnt); } +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) { } +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; } +#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; } +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 @@ #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) +/* 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 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 }; enum { @@ -479,12 +497,87 @@ void lru_gen_init_lruvec(struct lruvec *lruvec); void lru_gen_look_around(struct page_vma_mapped_walk *pvmw); #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 bins + * to improve scalability. For each bin, the 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 MEMCG_NR_GENS) 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(). + */ +#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 */ #else /* !CONFIG_LRU_GEN */ +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) } #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_cgroup *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 */ #endif /* CONFIG_LRU_GEN */ @@ -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 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; + if (lru_gen_enabled()) { + struct lruvec *lruvec = &memcg->nodeinfo[nid]->lruvec; + + /* see the comment on MEMCG_NR_GENS */ + if (soft_limit_excess(memcg) && lru_gen_memcg_seg(lruvec) != MEMCG_LRU_HEAD) + lru_gen_rotate_memcg(lruvec, MEMCG_LRU_HEAD); + + return; + } + mctz = 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; + if (lru_gen_enabled()) + return 0; + if (order > 0) return 0; @@ -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_subsys_state *css) memcg_offline_kmem(memcg); reparent_shrinker_deferred(memcg); wb_memcg_offline(memcg); + lru_gen_offline_memcg(memcg); drain_all_stock(memcg); @@ -5428,6 +5443,7 @@ static void mem_cgroup_css_released(struct cgroup_subsys_state *css) struct mem_cgroup *memcg = mem_cgroup_from_css(css); invalidate_reclaim_iterators(memcg); + lru_gen_release_memcg(memcg); } 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); free_area_init_core(pgdat); + lru_gen_init_pgdat(pgdat); } static void __init free_area_init_memoryless_node(int nid) diff --git a/mm/vmscan.c b/mm/vmscan.c index dd9f7b7abe1c..f22c8876473e 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -55,6 +55,8 @@ #include #include #include +#include +#include #include #include @@ -135,11 +137,6 @@ struct scan_control { /* Always discard instead of demoting to lower tier memory */ unsigned int no_demotion:1; -#ifdef CONFIG_LRU_GEN - /* help kswapd make better choices among multiple memcgs */ - unsigned long last_reclaimed; -#endif - /* Allocation order */ s8 order; @@ -3185,6 +3182,9 @@ DEFINE_STATIC_KEY_ARRAY_FALSE(lru_gen_caps, NR_LRU_GEN_CAPS); for ((type) = 0; (type) < ANON_AND_FILE; (type)++) \ for ((zone) = 0; (zone) < MAX_NR_ZONES; (zone)++) +#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 = NODE_DATA(nid); @@ -4453,8 +4453,7 @@ static bool try_to_inc_max_seq(struct lruvec *lruvec, unsigned long max_seq, if (sc->priority <= 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; } VM_WARN_ON_ONCE(max_seq != READ_ONCE(lrugen->max_seq)); @@ -4527,8 +4526,6 @@ static void lru_gen_age_node(struct pglist_data *pgdat, struct scan_control *sc) VM_WARN_ON_ONCE(!current_is_kswapd()); - sc->last_reclaimed = sc->nr_reclaimed; - /* check the order to exclude compaction-induced reclaim */ if (!min_ttl || sc->order || sc->priority == DEF_PRIORITY) return; @@ -5117,8 +5114,7 @@ static bool should_run_aging(struct lruvec *lruvec, unsigned 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_control *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 = lruvec_memcg(lruvec); @@ -5136,10 +5132,8 @@ static unsigned long get_nr_to_scan(struct lruvec *lruvec, struct scan_control * if (sc->priority == DEF_PRIORITY) return nr_to_scan; - 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; } static unsigned long get_nr_to_reclaim(struct scan_control *sc) @@ -5148,29 +5142,18 @@ static unsigned long get_nr_to_reclaim(struct scan_control *sc) if (!global_reclaim(sc)) return -1; - /* 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)); } -static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc) +static bool try_to_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc) { - struct blk_plug plug; + long nr_to_scan; unsigned long scanned = 0; unsigned long nr_to_reclaim = get_nr_to_reclaim(sc); - lru_add_drain(); - - blk_start_plug(&plug); - - set_mm_walk(lruvec_pgdat(lruvec)); - while (true) { int delta; int swappiness; - unsigned long nr_to_scan; if (sc->may_swap) swappiness = get_swappiness(lruvec, sc); @@ -5180,7 +5163,7 @@ static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc swappiness = 0; nr_to_scan = get_nr_to_scan(lruvec, sc, swappiness); - if (!nr_to_scan) + if (nr_to_scan <= 0) break; delta = evict_folios(lruvec, sc, swappiness); @@ -5197,10 +5180,251 @@ static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc cond_resched(); } + /* 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 = sc->nr_scanned; + unsigned long reclaimed = sc->nr_reclaimed; + int seg = lru_gen_memcg_seg(lruvec); + struct mem_cgroup *memcg = lruvec_memcg(lruvec); + struct pglist_data *pgdat = lruvec_pgdat(lruvec); + + /* see the comment on MEMCG_NR_GENS */ + if (!lruvec_is_sizable(lruvec, sc)) + return seg != 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 != MEMCG_LRU_TAIL) + return MEMCG_LRU_TAIL; + + memcg_memory_event(memcg, MEMCG_LOW); + } + + success = 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 += current->reclaim_state->reclaimed_slab; + current->reclaim_state->reclaimed_slab = 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 = 0; + struct mem_cgroup *memcg = NULL; + unsigned long nr_to_reclaim = get_nr_to_reclaim(sc); + + bin = first_bin = get_random_u32_below(MEMCG_NR_BINS); +restart: + gen = 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][bin], list) { + if (op) + lru_gen_rotate_memcg(lruvec, op); + + mem_cgroup_put(memcg); + + lruvec = container_of(lrugen, struct lruvec, lrugen); + memcg = lruvec_memcg(lruvec); + + if (!mem_cgroup_tryget(memcg)) { + op = 0; + memcg = NULL; + continue; + } + + rcu_read_unlock(); + + op = shrink_one(lruvec, sc); + + if (sc->nr_reclaimed >= nr_to_reclaim) + goto success; + + rcu_read_lock(); + } + + rcu_read_unlock(); + + /* restart if raced with lru_gen_rotate_memcg() */ + if (gen != get_nulls_value(pos)) + goto restart; + + /* try the rest of the bins of the current generation */ + bin = get_memcg_bin(bin + 1); + if (bin != 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_control *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_control *sc) +{ + BUILD_BUG(); +} + +#endif + +static void set_initial_priority(struct pglist_data *pgdat, struct scan_control *sc) +{ + int priority; + unsigned long reclaimable; + struct lruvec *lruvec = mem_cgroup_lruvec(NULL, pgdat); + + if (sc->priority != 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 = nr_to_reclaim, where the + * estimated reclaimed_to_scanned_ratio = inactive / total. + */ + reclaimable = node_page_state(pgdat, NR_INACTIVE_FILE); + if (get_swappiness(lruvec, sc)) + reclaimable += node_page_state(pgdat, NR_INACTIVE_ANON); + + reclaimable /= MEMCG_NR_GENS; + + /* round down reclaimable and round up sc->nr_to_reclaim */ + priority = fls_long(reclaimable) - 1 - fls_long(sc->nr_to_reclaim - 1); + + sc->priority = clamp(priority, 0, DEF_PRIORITY); +} + +static void lru_gen_shrink_node(struct pglist_data *pgdat, struct scan_control *sc) +{ + struct blk_plug plug; + unsigned long reclaimed = 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 = 0; + + if (mem_cgroup_disabled()) + shrink_one(&pgdat->__lruvec, sc); + else + shrink_many(pgdat, sc); + + if (current_is_kswapd()) + sc->nr_reclaimed += reclaimed; + clear_mm_walk(); blk_finish_plug(&plug); + + /* kswapd should never fail */ + pgdat->kswapd_failures = 0; +} + +#ifdef CONFIG_MEMCG +void lru_gen_rotate_memcg(struct lruvec *lruvec, int op) +{ + int seg; + int old, new; + int bin = get_random_u32_below(MEMCG_NR_BINS); + struct pglist_data *pgdat = lruvec_pgdat(lruvec); + + spin_lock(&pgdat->memcg_lru.lock); + + VM_WARN_ON_ONCE(hlist_nulls_unhashed(&lruvec->lrugen.list)); + + seg = 0; + new = old = lruvec->lrugen.gen; + + /* see the comment on MEMCG_NR_GENS */ + if (op == MEMCG_LRU_HEAD) + seg = MEMCG_LRU_HEAD; + else if (op == MEMCG_LRU_TAIL) + seg = MEMCG_LRU_TAIL; + else if (op == MEMCG_LRU_OLD) + new = get_memcg_gen(pgdat->memcg_lru.seq); + else if (op == MEMCG_LRU_YOUNG) + new = get_memcg_gen(pgdat->memcg_lru.seq + 1); + else + VM_WARN_ON_ONCE(true); + + hlist_nulls_del_rcu(&lruvec->lrugen.list); + + if (op == MEMCG_LRU_HEAD || op == MEMCG_LRU_OLD) + hlist_nulls_add_head_rcu(&lruvec->lrugen.list, &pgdat->memcg_lru.fifo[new][bin]); + else + hlist_nulls_add_tail_rcu(&lruvec->lrugen.list, &pgdat->memcg_lru.fifo[new][bin]); + + pgdat->memcg_lru.nr_memcgs[old]--; + pgdat->memcg_lru.nr_memcgs[new]++; + + lruvec->lrugen.gen = new; + WRITE_ONCE(lruvec->lrugen.seg, seg); + + if (!pgdat->memcg_lru.nr_memcgs[old] && old == 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 /****************************************************************************** * state change @@ -5655,11 +5879,11 @@ static int run_cmd(char cmd, int memcg_id, int nid, unsigned long seq, if (!mem_cgroup_disabled()) { rcu_read_lock(); + memcg = mem_cgroup_from_id(memcg_id); -#ifdef CONFIG_MEMCG - if (memcg && !css_tryget(&memcg->css)) + if (!mem_cgroup_tryget(memcg)) memcg = NULL; -#endif + rcu_read_unlock(); if (!memcg) @@ -5807,6 +6031,19 @@ void lru_gen_init_lruvec(struct lruvec *lruvec) } #ifdef CONFIG_MEMCG + +void lru_gen_init_pgdat(struct pglist_data *pgdat) +{ + int i, j; + + spin_lock_init(&pgdat->memcg_lru.lock); + + for (i = 0; i < MEMCG_NR_GENS; i++) { + for (j = 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); @@ -5830,7 +6067,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 = get_random_u32_below(MEMCG_NR_BINS); + + for_each_node(nid) { + struct pglist_data *pgdat = NODE_DATA(nid); + struct lruvec *lruvec = get_lruvec(memcg, nid); + + spin_lock(&pgdat->memcg_lru.lock); + + VM_WARN_ON_ONCE(!hlist_nulls_unhashed(&lruvec->lrugen.list)); + + gen = get_memcg_gen(pgdat->memcg_lru.seq); + + hlist_nulls_add_tail_rcu(&lruvec->lrugen.list, &pgdat->memcg_lru.fifo[gen][bin]); + pgdat->memcg_lru.nr_memcgs[gen]++; + + lruvec->lrugen.gen = 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 = 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 = NODE_DATA(nid); + struct lruvec *lruvec = get_lruvec(memcg, nid); + + spin_lock(&pgdat->memcg_lru.lock); + + VM_WARN_ON_ONCE(hlist_nulls_unhashed(&lruvec->lrugen.list)); + + gen = lruvec->lrugen.gen; + + hlist_nulls_del_rcu(&lruvec->lrugen.list); + pgdat->memcg_lru.nr_memcgs[gen]--; + + if (!pgdat->memcg_lru.nr_memcgs[gen] && gen == 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 */ static int __init init_lru_gen(void) { @@ -5857,6 +6156,10 @@ static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc { } +static void lru_gen_shrink_node(struct pglist_data *pgdat, struct scan_control *sc) +{ +} + #endif /* CONFIG_LRU_GEN */ static void shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc) @@ -5870,7 +6173,7 @@ static void shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc) bool proportional_reclaim; struct blk_plug plug; - if (lru_gen_enabled()) { + if (lru_gen_enabled() && !global_reclaim(sc)) { lru_gen_shrink_lruvec(lruvec, sc); return; } @@ -6113,6 +6416,11 @@ static void shrink_node(pg_data_t *pgdat, struct scan_control *sc) struct lruvec *target_lruvec; bool reclaimable = false; + if (lru_gen_enabled() && global_reclaim(sc)) { + lru_gen_shrink_node(pgdat, sc); + return; + } + target_lruvec = mem_cgroup_lruvec(sc->target_mem_cgroup, pgdat); again: From patchwork Thu Dec 22 04:19:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhao X-Patchwork-Id: 13079367 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2BF42C4332F for ; Thu, 22 Dec 2022 04:19:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B8DAC94000D; Wed, 21 Dec 2022 23:19:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A7A93940007; Wed, 21 Dec 2022 23:19:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8595594000D; Wed, 21 Dec 2022 23:19:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6D001940007 for ; Wed, 21 Dec 2022 23:19:54 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3B5CB120440 for ; Thu, 22 Dec 2022 04:19:54 +0000 (UTC) X-FDA: 80268639108.20.1385F1C Received: from mail-il1-f201.google.com (mail-il1-f201.google.com [209.85.166.201]) by imf12.hostedemail.com (Postfix) with ESMTP id 9E14B40002 for ; Thu, 22 Dec 2022 04:19:51 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=KVc8L16V; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of 35tqjYwYKCE8FBGyr5x55x2v.t532z4BE-331Crt1.58x@flex--yuzhao.bounces.google.com designates 209.85.166.201 as permitted sender) smtp.mailfrom=35tqjYwYKCE8FBGyr5x55x2v.t532z4BE-331Crt1.58x@flex--yuzhao.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671682791; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=beHmgSLzXbJpunP6/l/NxN2gRkL01SNlutgba3N1Qk4=; b=rkGLV4p3XKKWgoJecj+QlgnS5fZ1zOfbVkoUZxO8X+dmWhwnay5SVCfntBwsD18B9nNfdq gx/gGgBIRrfHeBVSHxrxnx1JVnQyRpvtyOF0J0N7LkOLC+VmMf2lQglwq9h5Gah5X+y3op JnOKulHrcKD1iI80O5+E//lZEeHbRog= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=KVc8L16V; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of 35tqjYwYKCE8FBGyr5x55x2v.t532z4BE-331Crt1.58x@flex--yuzhao.bounces.google.com designates 209.85.166.201 as permitted sender) smtp.mailfrom=35tqjYwYKCE8FBGyr5x55x2v.t532z4BE-331Crt1.58x@flex--yuzhao.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671682791; a=rsa-sha256; cv=none; b=sJI5NgC/TnE5R3ka4OgIB1Bkhseq7WWcr3rjuHpFSnHbdJ5obfT23CQcc5Pe+Wrz6ei1Mh jNoz/mWRmHU40q0NK7ADg5WVgj4lobQNKFSDhpTJBvHEeT4vwxGrV5qaARBkY48vF2Opm9 KFOV4kIU2u8QGNcF/2JUtVLuRMDEPtg= Received: by mail-il1-f201.google.com with SMTP id a13-20020a056e0208ad00b003034c36b8b5so491298ilt.9 for ; Wed, 21 Dec 2022 20:19:51 -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=beHmgSLzXbJpunP6/l/NxN2gRkL01SNlutgba3N1Qk4=; b=KVc8L16VLUlCC+NuT6JsPGih4l/R7AmDZj1lk/UOA7MArp9oW8qRRRAEE/CHL9JFRE k6OsWrqWjs+QpUdCZOasfSH0W/8vTYtZg4cIuIuZakFH3G4roLVmeOi6mhpvzf9Rr5Pm sG5fevrhs8sxV9/VRvNIlM/H7Jgms4DgL73qCf1rTYOzPm5XuvhBd0DzLtCuuYYtxdBA J1jv7wKED+6OqtgdXvWWjtKi1MH+Ffly5IDAHlnvtXC9SvYAIXhRiM6OkvNDWfvhZlSl 5hLGMSmwhFx6HT88lIBYT9dimMWP19Q8HexyCSyXhoj/OTlnPqL1UW4y0l5Xa0C+5wwP 8Www== 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=beHmgSLzXbJpunP6/l/NxN2gRkL01SNlutgba3N1Qk4=; b=V/LTw3mL8cwS/9HkmsxvVOkvqBBG9UzVcJgf8RkgfOywsM0+20miKirUXAC5Qw7iGL 7cLZoGidH6wFVDofWRzg8G1WovAH8QdapGJianhTNjWPNfXwdnA2RQHosswLB706j/hr sZazfxwQyG4j8R8AgStgOqcTQsO8Lyi7E+2+nlqOI3UsFQOHRSqGkNnwfT7bPs6kWbAg 8IuN3cMcUNdEtQOafVgEJNUHxdN23SUEXaOKcrgb4KnjJ+VF5yLmj6yiPNCxR4KKPrku pEa3BHhl9/wPgLagZeoEbIEDJyK3qDPomiHwQJx+xjanucjOEPcka/QGdzs1fLbvV4r+ 8QNA== X-Gm-Message-State: AFqh2kraoAvyiNjN/vTeKVTtrEPYiyLkoyvWOlpvdEg9TvghWjcQYMk/ hP7gXn06hiWbWvhF10a8UEaM46fpLhk= X-Google-Smtp-Source: AMrXdXvUCUZtzccxqK7kgdP2DV3G+AxrfRMA4CYtUSyCFpt/vaQ9J1+I6DbC09S/08Y40JAtOCDqp8u0BPU= X-Received: from yuzhao.bld.corp.google.com ([2620:15c:183:200:a463:5f7b:440e:5c77]) (user=yuzhao job=sendgmr) by 2002:a05:6602:88a:b0:6df:5f05:40b6 with SMTP id f10-20020a056602088a00b006df5f0540b6mr286712ioz.74.1671682790897; Wed, 21 Dec 2022 20:19:50 -0800 (PST) Date: Wed, 21 Dec 2022 21:19:05 -0700 In-Reply-To: <20221222041905.2431096-1-yuzhao@google.com> Message-Id: <20221222041905.2431096-8-yuzhao@google.com> Mime-Version: 1.0 References: <20221222041905.2431096-1-yuzhao@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Subject: [PATCH mm-unstable v3 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 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 9E14B40002 X-Stat-Signature: nkjtwf1paoq1tu536j759txes8kknchh X-HE-Tag: 1671682791-652779 X-HE-Meta: U2FsdGVkX1/e88NbPEiO06YKCN9oyljwaOkAYI10zweXem077vqWxzr4YJo2LIK5zYQ0APQKB07VYtKB/GSjktroFG6dDkEZRzBd5wnZtUKrYBV2W7vyTfWQI1VVOwwwQM7VzS909xauQGTCK79PUwLockeMJNc14xv9Ihkm9Krw4viWhSemJtvMPy65lCjqRIEb6SnG54/8h49Gw17cwKPhSg9X9Rcq0UzkNlyN7heQcdg8ZesbXQQ6WcfgNsH943YcLuZuqm9IfekB8hQ3J13qs7rIv0w7WOJThciXZIXv9TC+UVAKVgByi7IhvhckQ6D0f2AihrLg7+XWbHqgB2II4fZAkLuOSjzHUeeyLXACSG2Ntj+PDfIvoTce5eeK0BbUMdPUiqCeAdavKfCFHgTe03HavymBZF9gihtICsIVEhpKxF3SaswiJDEwfUxmw8DjmbjBV7M/wN6fxOsXupI/8YWesexkpzFF/rcdYYsIlB0E0HJXK+JATj5ZCOJNh2LAUIGS6WxRUKkNdPRJy2PQ1EuliWMuTnOzCPDdTDk4SNgG5E36pm/t/VzL3dGxJuH6DeTeKdSxqKzP3h0EMY3j1yccBu+xIpTpcxgthVJV2a+2fDf6dIh57N6rW/AJF8L5I1wNeVq1IK/Hj/4tmek9OV0sfCLXuwmU9zgV7ceNxRjPpZZWwI0ei2RatiMcH0Pr57bPxmMSKmuo+AtVhfhjmrN/ZRKGNOzbrsx66DCa935uDnwAsHK39oHLce7TO6avc2W/cgrBJDd9J7h4ktFjePmAIHpPmKycsKmGePIYD9d7OuwNy5CJiADyIeAfjJi49zxgjI4UdwDnzLtDCJUO+Py4Tl/gMCVoY9kDM9VPEeGMynWQxxmagw/H5sgsTTZEENF+ZE+XRQ065nT/2CJ71Y29osxkSnoogc16EysZ4IjFwtQ7MRLOdVwq8KCz6ND8kvAe4bmjQ1n/dX5 o2CGMl22 PUejezK6KfSuDlDiT+SaJqS75UMMBadLjh5CkrRKfINRMRTpWvpBkUB4PAJSYKDg8D+j1PzUYC7moF1/OVxxKxY3r7PJDzR+Rxa+OswDdJCr9PZDNelpKUTN5OL8HunCisd9BnBmhKClqFVpKw7kKYwi7HMa3lOdVq8QsXJLIH7WL1KMoz9TYijqd4DZE9Q2qIvS0cP8wCsJOCcsqaDOwyFrFmQBPE0GkePo7ZUpgpWZCfygWG0/dZPO3Xwan0Y40KRz/8lxKv55HAEPNMUZSIal0eIQMjSlT3K95384I7M7cvMSsxQIBowOZXtLoThKFF87owtTOKQ+ltHdpTquEIvv+LQteNyIncKF3X9b2WZI9GgxTmxlfJwDRusmmi4XRUKW3zYenuhrcZQtm+syUc5QnZD/GLnHktPQ3 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 --- mm/vmscan.c | 56 ++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index f22c8876473e..a9b318e1bdc2 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3210,6 +3210,9 @@ static int get_swappiness(struct lruvec *lruvec, struct scan_control *sc) struct mem_cgroup *memcg = lruvec_memcg(lruvec); struct pglist_data *pgdat = lruvec_pgdat(lruvec); + 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; @@ -4236,7 +4239,7 @@ static void walk_mm(struct lruvec *lruvec, struct mm_struct *mm, struct lru_gen_ } while (err == -EAGAIN); } -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 = current->reclaim_state->mm_walk; @@ -4244,7 +4247,7 @@ static struct lru_gen_mm_walk *set_mm_walk(struct pglist_data *pgdat) VM_WARN_ON_ONCE(walk); walk = &pgdat->mm_walk; - } else if (!pgdat && !walk) { + } else if (!walk && force_alloc) { VM_WARN_ON_ONCE(current_is_kswapd()); walk = kzalloc(sizeof(*walk), __GFP_HIGH | __GFP_NOMEMALLOC | __GFP_NOWARN); @@ -4430,7 +4433,7 @@ static bool try_to_inc_max_seq(struct lruvec *lruvec, unsigned long max_seq, goto done; } - walk = set_mm_walk(NULL); + walk = set_mm_walk(NULL, true); if (!walk) { success = iterate_mm_list_nowalk(lruvec, max_seq); goto done; @@ -4499,8 +4502,6 @@ static bool lruvec_is_reclaimable(struct lruvec *lruvec, struct scan_control *sc struct mem_cgroup *memcg = lruvec_memcg(lruvec); DEFINE_MIN_SEQ(lruvec); - VM_WARN_ON_ONCE(sc->memcg_low_reclaim); - /* see the comment on lru_gen_folio */ gen = lru_gen_from_seq(min_seq[LRU_GEN_FILE]); birth = READ_ONCE(lruvec->lrugen.timestamps[gen]); @@ -4756,12 +4757,8 @@ static bool isolate_folio(struct lruvec *lruvec, struct folio *folio, struct sca { bool success; - /* 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; @@ -4858,9 +4855,8 @@ static int scan_folios(struct lruvec *lruvec, struct scan_control *sc, __count_vm_events(PGSCAN_ANON + type, isolated); /* - * 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; } @@ -5120,9 +5116,7 @@ static long get_nr_to_scan(struct lruvec *lruvec, struct scan_control *sc, bool struct mem_cgroup *memcg = lruvec_memcg(lruvec); DEFINE_MAX_SEQ(lruvec); - 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; if (!should_run_aging(lruvec, max_seq, sc, can_swap, &nr_to_scan)) @@ -5150,17 +5144,14 @@ static bool try_to_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc) long nr_to_scan; unsigned long scanned = 0; unsigned long nr_to_reclaim = get_nr_to_reclaim(sc); + int swappiness = get_swappiness(lruvec, sc); + + /* clean file folios are more likely to exist */ + if (swappiness && !(sc->gfp_mask & __GFP_IO)) + swappiness = 1; while (true) { int delta; - int swappiness; - - if (sc->may_swap) - swappiness = get_swappiness(lruvec, sc); - else if (!cgroup_reclaim(sc) && get_swappiness(lruvec, sc)) - swappiness = 1; - else - swappiness = 0; nr_to_scan = get_nr_to_scan(lruvec, sc, swappiness); if (nr_to_scan <= 0) @@ -5291,12 +5282,13 @@ static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc struct blk_plug plug; VM_WARN_ON_ONCE(global_reclaim(sc)); + VM_WARN_ON_ONCE(!sc->may_writepage || !sc->may_unmap); lru_add_drain(); blk_start_plug(&plug); - set_mm_walk(lruvec_pgdat(lruvec)); + set_mm_walk(NULL, sc->proactive); if (try_to_shrink_lruvec(lruvec, sc)) lru_gen_rotate_memcg(lruvec, MEMCG_LRU_YOUNG); @@ -5352,11 +5344,19 @@ static void lru_gen_shrink_node(struct pglist_data *pgdat, struct scan_control * VM_WARN_ON_ONCE(!global_reclaim(sc)); + /* + * 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(); blk_start_plug(&plug); - set_mm_walk(pgdat); + set_mm_walk(pgdat, sc->proactive); set_initial_priority(pgdat, sc); @@ -5374,7 +5374,7 @@ static void lru_gen_shrink_node(struct pglist_data *pgdat, struct scan_control * clear_mm_walk(); blk_finish_plug(&plug); - +done: /* kswapd should never fail */ pgdat->kswapd_failures = 0; } @@ -5943,7 +5943,7 @@ static ssize_t lru_gen_seq_write(struct file *file, const char __user *src, set_task_reclaim_state(current, &sc.reclaim_state); flags = memalloc_noreclaim_save(); blk_start_plug(&plug); - if (!set_mm_walk(NULL)) { + if (!set_mm_walk(NULL, true)) { err = -ENOMEM; goto done; } From patchwork Thu Dec 22 04:19:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhao X-Patchwork-Id: 13079368 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0978C46467 for ; Thu, 22 Dec 2022 04:19:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4AE6C94000E; Wed, 21 Dec 2022 23:19:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 437D6940007; Wed, 21 Dec 2022 23:19:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 23E6E94000E; Wed, 21 Dec 2022 23:19:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 12CD8940007 for ; Wed, 21 Dec 2022 23:19:55 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id D0B5780DE2 for ; Thu, 22 Dec 2022 04:19:54 +0000 (UTC) X-FDA: 80268639108.09.D5CA72E Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf06.hostedemail.com (Postfix) with ESMTP id 4789A180002 for ; Thu, 22 Dec 2022 04:19:53 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=FaAk0+Io; spf=pass (imf06.hostedemail.com: domain of 36NqjYwYKCFEHDI0t7z77z4x.v75416DG-553Etv3.7Az@flex--yuzhao.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=36NqjYwYKCFEHDI0t7z77z4x.v75416DG-553Etv3.7Az@flex--yuzhao.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671682793; a=rsa-sha256; cv=none; b=TAWOK1omFjxUbdViX1oBZV30dNibmxxfeUdg2m++lKwdBAFR2PTnUze1252g/XMQUiVjBY Qpir9JVpFmKAfFiJLItFjoYnCLKVZWcT0o1IPk3XRhH6JwedSFsxCCeYgi7wXbGL3Zm/Va gUMF3Hd3d7XvRX1dsW4lBOhe+7hPbkQ= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=FaAk0+Io; spf=pass (imf06.hostedemail.com: domain of 36NqjYwYKCFEHDI0t7z77z4x.v75416DG-553Etv3.7Az@flex--yuzhao.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=36NqjYwYKCFEHDI0t7z77z4x.v75416DG-553Etv3.7Az@flex--yuzhao.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671682793; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wqbMgd0zowymzGskr7701SDcBxSEYhpmKyp2L4CmwQc=; b=j3IMDlzNolebg6hRMoToUmysdhCabhhXJ8oBordXNhuwGHQlutF76JFz3ZY/a+Y61iWA0O Mh6jvWGTTgLJAW2oTFVTEPllDzknn9q/lE8Hv0RUVBk8KQI9/JZTmBumwUmqJm4MLS+yPy z/FxmB/YNNGCTVFb5cqnchT+V/dtjk0= Received: by mail-yb1-f201.google.com with SMTP id u17-20020a25f811000000b007647eca7d01so129858ybd.14 for ; Wed, 21 Dec 2022 20:19:53 -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=wqbMgd0zowymzGskr7701SDcBxSEYhpmKyp2L4CmwQc=; b=FaAk0+IovKrA30gqzGnUXCgvxnAEqM9RNUrx6/qbk2dXbMev+aX6+TBCBI++qJqoJh DHNBFkCo27K0mtm3kCypi0Ii7FLQEyOoUcXG+t83h3xzdMvkNUCkZTP8OrqRsYYWm0el eWwdtsGBlfK8BfaDX27IjQxVLcqXb9rSOW0ntCxNjAM2Cim1CHaEVKSL6BfOAxE/zGHv zshIYCJIZ+wR/JAB7hswAHRV8jE3CLxEuhhNl1iaGkZYIJeIjSv9yuHWpAemQnptTj9G AsAn5TBRtcqHkkCAS4JOx0xwOehAeuT/Kj0REFHOiEd6bNs1NdquJnCAzj9joH3GCGp1 aNTQ== 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=wqbMgd0zowymzGskr7701SDcBxSEYhpmKyp2L4CmwQc=; b=qEb4UI4ieccy5mQfLiUjX38EnMFwH+J7Hqbexbi2XVu0v9BVcxfHiFpxocJF45AGHw VK2RkwxZmrLsuFAjiySNMcupkSYwQLl1tu4cKqOL9zA8yy9DNSrvnXbtCStxbYZOx2OT DQBiIcTfSsAZ6eciL4YpTETZsh065hwfzSnG86OkNfx3m/Q4FAgDKcCJhVyT0+D3MMvR DjTo9pwzr/0psbJ5qsz971GkPAv864fPJnrteBy3UmQG2FX0exMwUnK9iNoY/6SvY6NH hXWShYL96DlvICZH2rjcaicSAbxIwVJW+YiXhKe716vD2sLnnhUPyC2Upe1xrvrZCyKs Idvg== X-Gm-Message-State: AFqh2koGh01AmZ3UVTDULiEPVcImP/YVs02KVf/mBlWg7Ho1UBeEpwxT vQ4rbvYyIcAvzA4ju770ZBla+6kHDGI= X-Google-Smtp-Source: AMrXdXtoQV2nYQsCRHGYe9z8m7Uo+pjFU+YdC4C/Y+Mib9s2WlE6ZwrTFMZkcNSCiAcHyEFs+f2bQg5UyD0= X-Received: from yuzhao.bld.corp.google.com ([2620:15c:183:200:a463:5f7b:440e:5c77]) (user=yuzhao job=sendgmr) by 2002:a25:3c85:0:b0:6dc:b9ec:7c87 with SMTP id j127-20020a253c85000000b006dcb9ec7c87mr460947yba.322.1671682792499; Wed, 21 Dec 2022 20:19:52 -0800 (PST) Date: Wed, 21 Dec 2022 21:19:06 -0700 In-Reply-To: <20221222041905.2431096-1-yuzhao@google.com> Message-Id: <20221222041905.2431096-9-yuzhao@google.com> Mime-Version: 1.0 References: <20221222041905.2431096-1-yuzhao@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Subject: [PATCH mm-unstable v3 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 X-Rspam-User: X-Rspamd-Queue-Id: 4789A180002 X-Rspamd-Server: rspam01 X-Stat-Signature: q38635cjxjjwoyygtmen3hso755qtpfa X-HE-Tag: 1671682793-715919 X-HE-Meta: U2FsdGVkX19qxZgHCDyB+sxv4MzLsIYILRd8I9TgOxXiW+JLIFugsc+atCaNfMKHJjTD3kJdM/HBytEA4VH8co4EdkBqAb397OgjZvLAsv9z+Izl7shtC33v4vnoBgukf50I6Bbde4ZliTPD135kRcgtrZqym2zVd/gSggn2CNrP22augU6upYaS9VJ8Qf0MjZKjKUESIUHFaJ6/J2Zbq4mV9i06SntbMoxp7e9+xG8HhY/3zLcGZRWD9uM1oqB5FthD+hvWrcdpHfCK9Ugig6G0Q/NtmbriFK3I0cwfeVO+onWRh61KwgrS9jdBb3JIHolixl+Arf2jejI5QRB+dU2N3x0aNzXsLO9BU5qXeVatGZ8qdKXZzXRUUy43p1KURLKxmDjSVJX14UN3rgUlkpX9RwYct9L/FJugkNcBmQdmF/pSx/OZY40+sR/4CcDh7VwrmtLLYK4X/KlB4WjzJ7JhR8IzGACjdsHE6TJWfV7oMx+DXLSPbrhyv3pl9Hgd76n7aq9TSzCgDBNB+UvV2yUhcfCJKAcWg36U9IU2QJLf1SjdjyNc3B4Hp2gb/9Pi9TLCRW8GLbKdoNiJc64lM3muRcswVx5qB+BxwRAV3ZkcIdjtCKoHROl7Totw+HcQXhmV33sE6fjqd2SL0biSBR7Ge4EoME6ihKltnDludvZbtoEz2aj165gRmvkYz63NJvQMEVENj9UgPTENidJdgz90bSteoXj4kGjrrAxriNhoosKdXmPeoFY3SnBWcr/5SSocovoN7oKCxeH0xteIJuo4yHRQ7TMyBVZtV7qUuFCWQ/Ru2GUMXJnaBszEdSKEKJR0bk3aldIKIfjov9BFhfM5QooqQoCMGZc2HpwIDFSZY4gvgFT3mfnjsGlYJiwfUsRE45Q1KdbraPkDCsx4BGyKB3qIGCu/5J/HyzfLu6W9L6pJcDhm6mwstQQmynxTHNP2ZFfF6UNP3w1RXtG d/kLIcd2 /OMst2qIFaBp9SG+Rbi6dGsuCdPAcKfRCXvFe7UxUdRGQugvIabb9qK2RDqP7ENi0aSNwzVmaVdLcytEg+4z/W11ci9vOKRHjHmJ0tvwW5JHSBclHJZHt3vdJhKlgYhcPo0+REHnmFiP1L0pMUct3/0otbpzQH51HfnaymKAJ0pVqCNz39+xTBm8s1pyVoXa98YHmw8NPsmb0hAD9vZ5j1VHGHFqVv2gJQgKnzC8EEEKGLdBCOBVik1dnbou8ib7mm865tcgZxZYlA56byWaoTOvgU3j8c6tOxFhPrMq2nokBoSBd/xlHXokFaUZEayoz/nnO2Hv+Yq56OdF+7tx1oxe+DjG14URxeFilh1BX8yOFKWbo1caLjxbHxBpMreiNbVe1wanvro3TY15LW9XpG764GVd45bG/fGgq X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Scanning page tables when hardware does not set the accessed bit has no real use cases. Signed-off-by: Yu Zhao --- mm/vmscan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index a9b318e1bdc2..71d13c969b52 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4428,7 +4428,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 = iterate_mm_list_nowalk(lruvec, max_seq); goto done; }