From patchwork Wed Dec 20 04:00:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinsey Ho X-Patchwork-Id: 181439 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2403316dyi; Tue, 19 Dec 2023 20:01:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IGmLOaXBbmKMAXBs4fgo0NFcTVpqfClVhI6qNtEJ+ujla3q3asSXgCPPVfIothmFqTxIP2A X-Received: by 2002:a05:600c:5250:b0:40d:2c0d:784f with SMTP id fc16-20020a05600c525000b0040d2c0d784fmr986513wmb.75.1703044914965; Tue, 19 Dec 2023 20:01:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703044914; cv=none; d=google.com; s=arc-20160816; b=KQN20LRQIV5ya+IVmyZcQ4o8wo1ct/QY7ACNROQJdkTIHvA6ZZ2ABK3/RkklUubgGz 1n8OwUVRgX7XL4IOVwOlTl5yCch/OvP9raGg3e6YNv/e/XIUBzOd5I7b3LSUcpHeNIod IjQiHVaaJFUiTGFTdIiutFhjEBM1UIc4NjztKGmeTnisA1TNJJ6lTaGFNbhI2lc7jND9 000aYSFV+nfa4daZArZzQkxTs3G7y3k2TojDqvjoqvidQ9+e3PFMlswJZ9+gROj2QHaf Q5Abz25EfiCG6oMIeFB6fTsOEvDyHaRBwJzGNfUfbk/HbcNxQyYEwEJBRjoEttAFcM+V TtOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=eq0C6POTAn+zScnOr/3HnKmDnLhtNh9lvwfd8Bw3a74=; fh=COwL00CAVvf6HClNn9uW/acbdshq5DvvB3VM/yZ8sXw=; b=ryRN44HKK2isUUe3TXmvTgAvBy6EfJIj51b1HU/nudptNSvSYnva2l8zFaTFUG9WrI h1YN0PwQ4GH+AwvoDh0qTjP36U8cpmSa72mJPh5Xrp3V/GbHj72AWM1f0wsMp9lgAPKC fJBHDgL3vIeGVjMJ0IRgqOZjUDmv4ZFMGyo6SU7s98/PDRHN/eOVjjtJvGuddMvqvfvZ 2paPjuHuVWff6Kli8HVbHwbE4zIbf7eCtf2iL7bhShtIZ+bp8G/L0ylu9+BsCeL1teNg QQsiJnGenm05Kmg7bKT8FkuLHlPbVfYFIyW7BB+dq5JO7V4sSxgR332GLZ3tOodseqk4 6GGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=vclXodO9; spf=pass (google.com: domain of linux-kernel+bounces-6343-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6343-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id d16-20020a170906371000b00a235075a1e7si2553197ejc.493.2023.12.19.20.01.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 20:01:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6343-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=vclXodO9; spf=pass (google.com: domain of linux-kernel+bounces-6343-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6343-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 58F801F25AB5 for ; Wed, 20 Dec 2023 04:01:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 309F5156F0; Wed, 20 Dec 2023 04:01:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="vclXodO9" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18DC2125BC for ; Wed, 20 Dec 2023 04:01:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kinseyho.bounces.google.com Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-1d3e38ba362so6849445ad.2 for ; Tue, 19 Dec 2023 20:01:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1703044868; x=1703649668; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=eq0C6POTAn+zScnOr/3HnKmDnLhtNh9lvwfd8Bw3a74=; b=vclXodO9JJaBo0qFKvwHDdyJbC826Ubcielk0dMd+V7wHdNN2LgBIWEVMLeG7CtbeN f1eTbC45FNoV/81yi9G8COtiUcTy/RJUSL5T8FUg5G1LD/4amhAYXQx8Id2RYYPeHpAA /VOOjnfqWBZr4g5PCurrhzZTexm/+L1+j3XMJovYSDAt08XGqepS7BwzDbeFZQAsFN8x 7VtuTXTgCrWpitedSx4v2K9Y1artfixlZf2X+9+iK5b9Ln/VP8QP0YkN/ns9oPen2A6u rnq5867jIB232mmR34vszdF2OYlaI7EVaa81TQXombBsMSYqj+2tnLz/cyLDFnxlmUrz ZZew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703044868; x=1703649668; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=eq0C6POTAn+zScnOr/3HnKmDnLhtNh9lvwfd8Bw3a74=; b=JhhB+aezBqikwQWz3vlJ0/Ki16wxVao0cxUw2FvrybozH6URJLnp19ixPpSpx21r1f gSPMq2fOwkqiB7VUs4meSl7GFW+0tjiZgL7FmB3zG+oHUwss8ogqEoqc3Fe3J4FYXfon zhiadDVzAAB8SX9uiRxod5tPHeP8p8rgOQMU8OqmU2NvU8tLrDGY/zV4knUQ3IbuKJQT /MVfvO5jLtUqyCJP0FQZFRBsVTj4xZ/Ch71RhEseqIn6Rlp6mXDZ9inWq1YU0N55ySoX Ny4E3MI669GG08FwwxEu2W07uJ0cwe9gr0yOinesna0+ONe0hOO1Ghk2PHUZliJfC8DC YMdA== X-Gm-Message-State: AOJu0YyXRxvanwJ265uPODWGqmhG9bniwMYCv2ZJrA7Kg2wA1xSitEiu 85bou80KTwRqKTJRcYXar/ROeYX0enUrtg== X-Received: from kinseyct.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:46b]) (user=kinseyho job=sendgmr) by 2002:aa7:8486:0:b0:6d8:a6fd:dc98 with SMTP id u6-20020aa78486000000b006d8a6fddc98mr88954pfn.6.1703044868243; Tue, 19 Dec 2023 20:01:08 -0800 (PST) Date: Wed, 20 Dec 2023 04:00:36 +0000 In-Reply-To: <20231220040037.883811-1-kinseyho@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231220040037.883811-1-kinseyho@google.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Message-ID: <20231220040037.883811-4-kinseyho@google.com> Subject: [PATCH mm-unstable v1 3/4] mm/mglru: remove CONFIG_MEMCG From: Kinsey Ho To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, yuzhao@google.com, Kinsey Ho , Aneesh Kumar K V X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785772024858642970 X-GMAIL-MSGID: 1785772024858642970 Remove CONFIG_MEMCG in a refactoring to improve code readability at the cost of a few bytes in struct lru_gen_folio per node when CONFIG_MEMCG=n. Signed-off-by: Kinsey Ho Co-developed-by: Aneesh Kumar K V Signed-off-by: Aneesh Kumar K V --- include/linux/mm_types.h | 4 --- include/linux/mmzone.h | 26 ++-------------- mm/vmscan.c | 67 +++++++++++++--------------------------- 3 files changed, 23 insertions(+), 74 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 552fa2d11c57..55b7121809ff 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -1017,9 +1017,7 @@ struct lru_gen_mm_list { void lru_gen_add_mm(struct mm_struct *mm); void lru_gen_del_mm(struct mm_struct *mm); -#ifdef CONFIG_MEMCG void lru_gen_migrate_mm(struct mm_struct *mm); -#endif static inline void lru_gen_init_mm(struct mm_struct *mm) { @@ -1050,11 +1048,9 @@ static inline void lru_gen_del_mm(struct mm_struct *mm) { } -#ifdef CONFIG_MEMCG static inline void lru_gen_migrate_mm(struct mm_struct *mm) { } -#endif static inline void lru_gen_init_mm(struct mm_struct *mm) { diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index bc3f63ec4291..28665e1b8475 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -440,14 +440,12 @@ 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 { @@ -493,11 +491,6 @@ struct lru_gen_mm_walk { bool force_scan; }; -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 @@ -555,6 +548,8 @@ struct lru_gen_memcg { }; void lru_gen_init_pgdat(struct pglist_data *pgdat); +void lru_gen_init_lruvec(struct lruvec *lruvec); +void lru_gen_look_around(struct page_vma_mapped_walk *pvmw); void lru_gen_init_memcg(struct mem_cgroup *memcg); void lru_gen_exit_memcg(struct mem_cgroup *memcg); @@ -563,19 +558,6 @@ void lru_gen_offline_memcg(struct mem_cgroup *memcg); void lru_gen_release_memcg(struct mem_cgroup *memcg); void lru_gen_soft_reclaim(struct mem_cgroup *memcg, int nid); -#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) @@ -590,8 +572,6 @@ 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) { } @@ -616,8 +596,6 @@ static inline void lru_gen_soft_reclaim(struct mem_cgroup *memcg, int nid) { } -#endif /* CONFIG_MEMCG */ - #endif /* CONFIG_LRU_GEN */ struct lruvec { diff --git a/mm/vmscan.c b/mm/vmscan.c index aa7ea09ffb4c..351a0b5043c0 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4097,13 +4097,6 @@ enum { MEMCG_LRU_YOUNG, }; -#ifdef CONFIG_MEMCG - -static int lru_gen_memcg_seg(struct lruvec *lruvec) -{ - return READ_ONCE(lruvec->lrugen.seg); -} - static void lru_gen_rotate_memcg(struct lruvec *lruvec, int op) { int seg; @@ -4150,6 +4143,8 @@ static void lru_gen_rotate_memcg(struct lruvec *lruvec, int op) spin_unlock_irqrestore(&pgdat->memcg_lru.lock, flags); } +#ifdef CONFIG_MEMCG + void lru_gen_online_memcg(struct mem_cgroup *memcg) { int gen; @@ -4217,18 +4212,11 @@ void lru_gen_soft_reclaim(struct mem_cgroup *memcg, int nid) struct lruvec *lruvec = get_lruvec(memcg, nid); /* see the comment on MEMCG_NR_GENS */ - if (lru_gen_memcg_seg(lruvec) != MEMCG_LRU_HEAD) + if (READ_ONCE(lruvec->lrugen.seg) != MEMCG_LRU_HEAD) lru_gen_rotate_memcg(lruvec, MEMCG_LRU_HEAD); } -#else /* !CONFIG_MEMCG */ - -static int lru_gen_memcg_seg(struct lruvec *lruvec) -{ - return 0; -} - -#endif +#endif /* CONFIG_MEMCG */ /****************************************************************************** * the eviction @@ -4776,7 +4764,7 @@ static int shrink_one(struct lruvec *lruvec, struct scan_control *sc) if (mem_cgroup_below_low(NULL, memcg)) { /* see the comment on MEMCG_NR_GENS */ - if (lru_gen_memcg_seg(lruvec) != MEMCG_LRU_TAIL) + if (READ_ONCE(lruvec->lrugen.seg) != MEMCG_LRU_TAIL) return MEMCG_LRU_TAIL; memcg_memory_event(memcg, MEMCG_LOW); @@ -4799,12 +4787,10 @@ static int shrink_one(struct lruvec *lruvec, struct scan_control *sc) return 0; /* one retry if offlined or too small */ - return lru_gen_memcg_seg(lruvec) != MEMCG_LRU_TAIL ? + return READ_ONCE(lruvec->lrugen.seg) != MEMCG_LRU_TAIL ? MEMCG_LRU_TAIL : MEMCG_LRU_YOUNG; } -#ifdef CONFIG_MEMCG - static void shrink_many(struct pglist_data *pgdat, struct scan_control *sc) { int op; @@ -4896,20 +4882,6 @@ static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc 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; @@ -5560,6 +5532,18 @@ static const struct file_operations lru_gen_ro_fops = { * initialization ******************************************************************************/ +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_lruvec(struct lruvec *lruvec) { int i; @@ -5582,18 +5566,6 @@ 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) { struct lru_gen_mm_list *mm_list = get_mm_list(memcg); @@ -5653,14 +5625,17 @@ late_initcall(init_lru_gen); static void lru_gen_age_node(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(); } static void lru_gen_shrink_node(struct pglist_data *pgdat, struct scan_control *sc) { + BUILD_BUG(); } #endif /* CONFIG_LRU_GEN */