From patchwork Wed Sep 25 17:10:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13812370 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 EB5EBCCF9E7 for ; Wed, 25 Sep 2024 17:18:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6476D6B00BF; Wed, 25 Sep 2024 13:18:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5F6E16B00C0; Wed, 25 Sep 2024 13:18:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4BE8A6B00C1; Wed, 25 Sep 2024 13:18:52 -0400 (EDT) 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 2E7326B00BF for ; Wed, 25 Sep 2024 13:18:52 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C9348140EC9 for ; Wed, 25 Sep 2024 17:18:51 +0000 (UTC) X-FDA: 82603920462.01.F9E5DC2 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by imf05.hostedemail.com (Postfix) with ESMTP id E314A10000A for ; Wed, 25 Sep 2024 17:18:49 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=hF0HiU4E; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.171 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727284597; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=moXnkNvjiaOxjintf/FUPb0Y5ujsNv3Im5KOb4Ghejk=; b=YULnE2rA1SIziTDNPqPyN04AyODCsTp3cj0xWc1xSz1xio2DVES/dJvvCCL31SKXjdsuai vx86luVoaB0/5D3GhY3CXGmIx+OcXv+Zf5cYvHTZyj/YlEnA5+rdbYjil9lEn8CUBiePX3 JDw3FoXsfde1liAt5Z0h2lFFGYn0sfI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727284597; a=rsa-sha256; cv=none; b=x++xBNlqU3sjexWt0i/efb84kNxaMV4cAQR4aKjiJBJ5KrsvgdcP+n4DbWWOLoOLL5z7O4 tTC1S6q2IFm26RoGOd/EIGHFoYkFR+oUMpR8g67BGKZI2MJjovpTJn7DFjKDkCptoEWt/y LNR/Jj+kGUrMTub9tsMjGDNK/6zv4Ok= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=hF0HiU4E; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.171 as permitted sender) smtp.mailfrom=ryncsn@gmail.com Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2055136b612so540475ad.0 for ; Wed, 25 Sep 2024 10:18:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727284727; x=1727889527; darn=kvack.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=moXnkNvjiaOxjintf/FUPb0Y5ujsNv3Im5KOb4Ghejk=; b=hF0HiU4ErJYcPkWOyjTBgEb9AbAFYo2oFE8P6G5LfzfqHU3vQTA+qQ8dVYXZY1TZJq 1TmykxIM3QuEFZ9813U532/aoMyjDUAXi1kxpA07UNCviYmkxJIIDYzwqud1CinWuqDH 5vSQ8XMn/FxQyl3DyMveFn8Arf+LGjiCO5z0eGtkxJbBKfFmKZiHOdnuaZraATksUCBq qe2k2ZbuV7uN+4i5nRPz5HhUD78S8PUN3WdwNObzsWfQ1m1jyfnfTK1Aly12Tjy1xPse T/UmARbR4em5iDL9AtS/IAovNgy2HdhnGKOYrANmN07hbl53BN9NMi226e7zYKhEeACq tkVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727284727; x=1727889527; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=moXnkNvjiaOxjintf/FUPb0Y5ujsNv3Im5KOb4Ghejk=; b=CtSnstuC3GWYLkWcXHaVyjOsF+Z/glRn26xgZP0pn4NR4zDow0KBooIVCErPF75t4k ESyM4DWpMViF479wDQ1Rq/pphcbM05cN01U4+b8kSkwXXw9vOwz4NkQumBY4IXugAho6 wXSCY8y1x6LF55fxoMcrPTmHMwwwAS7nQZhhSrA8hsuzdwg371yDVh2sL5dagGJBJSU4 wvaiOQMa2OmZAK1Tnh/VTnu4iYiIjJighS0EHD9X5mqiAMNCdp69Vx4zP9TnHPcZ+Csv a9jwikPdIL293kCKrpNcknPWxTWOCSuYPZYdbOE0IHLnaFUij5lysV0LG2iYtmcxd3wL qSVQ== X-Gm-Message-State: AOJu0Yxm7UKAs6RFXwF2N8VgWswrC9G1fMQaDLg4gyiXaz/0gKaFQLgt bpBHHdVeoIjHsBl97l+95ctvvmhBh1wSLIclrIsL1Tcl6fF3xJ2OgN7QQb2W X-Google-Smtp-Source: AGHT+IGJJM/ZH8NnbLJUWNAfXKQT8DUVTKbTHFP4pApQC9ycUrCjMRpAdMTcEOrhhZpDeH6Im2Y1Tg== X-Received: by 2002:a05:6a00:390e:b0:717:8ee0:4ea1 with SMTP id d2e1a72fcca58-71b0a91241fmr5933106b3a.0.1727284229828; Wed, 25 Sep 2024 10:10:29 -0700 (PDT) Received: from KASONG-MC4.tencent.com ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71b032eb4f7sm2437900b3a.181.2024.09.25.10.10.26 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 25 Sep 2024 10:10:29 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , Matthew Wilcox , Johannes Weiner , Roman Gushchin , Waiman Long , Shakeel Butt , Michal Hocko , Chengming Zhou , Qi Zheng , Muchun Song , Kairui Song Subject: [PATCH v2 1/6] mm/list_lru: don't pass unnecessary key parameters Date: Thu, 26 Sep 2024 01:10:15 +0800 Message-ID: <20240925171020.32142-2-ryncsn@gmail.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20240925171020.32142-1-ryncsn@gmail.com> References: <20240925171020.32142-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: E314A10000A X-Stat-Signature: ee15kzxbc6fqmktbam4iggzfyjdwwxir X-Rspam-User: X-HE-Tag: 1727284729-734212 X-HE-Meta: U2FsdGVkX1+KBetu6O/HwqVtIrF4kmZ23Ko6miuZZ0RUbZYukxQrEi6/J0btYVOwUP9jiJ30QnqZiBqRZR/KNol+O1HKr0VCLFvYqKQpwRfmf0U2B7BQHFgcL/US5Gn3ZojLaLItP/0ojWmQIS1CmBu5VYv7BOg8me8sgGT9Tl0wwIqCG6c+CJJJJl0CW93vjBhsEaaM8TwoB9lTN1ir8S6JGmmocRfWB1uCkf1pJL+4RUQ096g8PZ0nT5Vi9KUznMrqTScrTLuL0oSKN/2S07sZ8hlKLUDrqYviYSlmNEvfHNy33DuyVerLVQ/UWxV8++g3LIZxH191Remj3b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uTAbtC2SBBc9E/wot2l7YNpkESqBUbl0ZMCNC3p2Ga7+gi84FjYMmH6eJVosXet8ZS8v4GdXTIV2Uo9NNB7ukr9uP3yANcRrZK/wrVA7Evwgc9BbvKpI7Iy5MHVRZSn2UsyT+5rxc2SRVOgO 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: List-Subscribe: List-Unsubscribe: From: Kairui Song When LOCKDEP is not enabled, lock_class_key is an empty struct that is never used. But the list_lru initialization function still takes a placeholder pointer as parameter, and the compiler cannot optimize it because the function is not static and exported. Remove this parameter and move it inside the list_lru struct. Only use it when LOCKDEP is enabled. Kernel builds with LOCKDEP will be slightly larger, while !LOCKDEP builds without it will be slightly smaller (the common case). Signed-off-by: Kairui Song Acked-by: Shakeel Butt --- include/linux/list_lru.h | 18 +++++++++++++++--- mm/list_lru.c | 9 +++++---- mm/workingset.c | 4 ++-- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/include/linux/list_lru.h b/include/linux/list_lru.h index 5099a8ccd5f4..eba93f6511f3 100644 --- a/include/linux/list_lru.h +++ b/include/linux/list_lru.h @@ -56,16 +56,28 @@ struct list_lru { bool memcg_aware; struct xarray xa; #endif +#ifdef CONFIG_LOCKDEP + struct lock_class_key *key; +#endif }; void list_lru_destroy(struct list_lru *lru); int __list_lru_init(struct list_lru *lru, bool memcg_aware, - struct lock_class_key *key, struct shrinker *shrinker); + struct shrinker *shrinker); #define list_lru_init(lru) \ - __list_lru_init((lru), false, NULL, NULL) + __list_lru_init((lru), false, NULL) #define list_lru_init_memcg(lru, shrinker) \ - __list_lru_init((lru), true, NULL, shrinker) + __list_lru_init((lru), true, shrinker) + +static inline int list_lru_init_memcg_key(struct list_lru *lru, struct shrinker *shrinker, + struct lock_class_key *key) +{ +#ifdef CONFIG_LOCKDEP + lru->key = key; +#endif + return list_lru_init_memcg(lru, shrinker); +} int memcg_list_lru_alloc(struct mem_cgroup *memcg, struct list_lru *lru, gfp_t gfp); diff --git a/mm/list_lru.c b/mm/list_lru.c index 9b7ff06e9d32..ea7dc9fa4d05 100644 --- a/mm/list_lru.c +++ b/mm/list_lru.c @@ -562,8 +562,7 @@ static void memcg_destroy_list_lru(struct list_lru *lru) } #endif /* CONFIG_MEMCG */ -int __list_lru_init(struct list_lru *lru, bool memcg_aware, - struct lock_class_key *key, struct shrinker *shrinker) +int __list_lru_init(struct list_lru *lru, bool memcg_aware, struct shrinker *shrinker) { int i; @@ -583,8 +582,10 @@ int __list_lru_init(struct list_lru *lru, bool memcg_aware, for_each_node(i) { spin_lock_init(&lru->node[i].lock); - if (key) - lockdep_set_class(&lru->node[i].lock, key); +#ifdef CONFIG_LOCKDEP + if (lru->key) + lockdep_set_class(&lru->node[i].lock, lru->key); +#endif init_one_lru(&lru->node[i].lru); } diff --git a/mm/workingset.c b/mm/workingset.c index a2b28e356e68..df3937c5eedc 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -823,8 +823,8 @@ static int __init workingset_init(void) if (!workingset_shadow_shrinker) goto err; - ret = __list_lru_init(&shadow_nodes, true, &shadow_nodes_key, - workingset_shadow_shrinker); + ret = list_lru_init_memcg_key(&shadow_nodes, workingset_shadow_shrinker, + &shadow_nodes_key); if (ret) goto err_list_lru;