From patchwork Mon Jun 24 17:53:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13709937 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 B7328C2BD09 for ; Mon, 24 Jun 2024 17:53:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 461036B0397; Mon, 24 Jun 2024 13:53:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 412FA6B0399; Mon, 24 Jun 2024 13:53:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 23D2E6B039A; Mon, 24 Jun 2024 13:53:34 -0400 (EDT) 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 035C06B0397 for ; Mon, 24 Jun 2024 13:53:33 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 6C061A1B18 for ; Mon, 24 Jun 2024 17:53:33 +0000 (UTC) X-FDA: 82266529506.07.3110DDB Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by imf06.hostedemail.com (Postfix) with ESMTP id 8A0C3180015 for ; Mon, 24 Jun 2024 17:53:31 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=MkQL6evc; spf=pass (imf06.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.177 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719251597; 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=2ab8O9yxFHOBMPoIp/ZXBmJCmkgH6/kR9tzZfY+sUGE=; b=gRrdFvJZw7QY0zoQuYwXTOnvq+IrWE15dFyE3OA4IsKulZ80DW0v5Yd2l+0IIG4rWZ+ZNx XCiC0BRJuDnEJpxUIqE9km0xQvHRuN6m74TweTpoafW6G+SWHLkIKZgxkpPuqL8MkdzotB /DSSaGPf5bzqr8RYlALfWP+gVW03DJk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719251597; a=rsa-sha256; cv=none; b=ntCRHKwJMTPPGcZwxgI62L7tavD4OHXgOk1qRswQp/7kkYqix/D6pXLhfof20zIvFIxq+8 Swj36DQvuep8RrS19gQp3e60o9vNMpbSpISn/7AoPkv2/RqzcCjOwWOlTmc1/hXaYrkNuy mOS8WBwE7HGeGtPUOuOEIuXdFttKG5E= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=MkQL6evc; spf=pass (imf06.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.177 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-706680d3a25so1513085b3a.0 for ; Mon, 24 Jun 2024 10:53:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719251610; x=1719856410; 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=2ab8O9yxFHOBMPoIp/ZXBmJCmkgH6/kR9tzZfY+sUGE=; b=MkQL6evcFWfdv5F52g9w3iPM5iaZQY5aWczxbqpFwYbWehio/lfcl5j/rbATrgAyLv mVTpEhTerElPL70zXgiiHEZntnAJ6NvOPUy3doaL8wfbDHNOAgaHl+NYN2QLqv2thQRU f+EPD0ZKJH8pCylmIHGW9LEvAfQx4qyni/pmc/upy6Jl5T/Yq6WPneUnWfEX1PW0tqd3 PVtuswDOplJfQfqoO5NhL6h+XQttA6Orj8UBsxh8rJ73ynRn8mT+EImNVUtNLReyra+T ZD91ssdtsI2uu44+Kh2T+bLA0XOmB0PZr+b2OY0Hk6kKH4qQz3TxJ/xphX3+P8/zvHn/ 7rOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719251610; x=1719856410; 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=2ab8O9yxFHOBMPoIp/ZXBmJCmkgH6/kR9tzZfY+sUGE=; b=KgsZkX9CYp2kTmKFzgpKERGeQJpE1hSijEXC8gNyQKFxu2t6EIUuZcT2dHJrLjNTIS pzatkuyXraqVsNfE9Kgv4aNxS3wVYP1+WrdD5o7vlYoJ+h/pKl8AVUtZ++8OSHf6VfNd BnxANJfRTtE78rSRpVtAKiwu4VE0aWjiI490UXpJmhbmcOljF0FbmVYzePEdPs+MC7+Z pkS27SKpm0RT1+yvGx9+Vece2yXtypXAnrznTmJw5LF0Mt5f7RQulbZr9DCmlrGKDf6y ULtQFw/PV/c5XspJvK79zWyXbYlM+Btk9AgZ1QsVvoUZw85QnMxozEHXaXt0v6ImtJSK fU/Q== X-Gm-Message-State: AOJu0Yyjp+TonrrcUK5dl+Y5f7enMf+W1e8qpUpOqae6jNAtQKpGElAQ pcmcGDT8UFnOUmaNb4LputIu09xOhUKMApHvyh9it4VEPlsciHg9AK06CgdY65I= X-Google-Smtp-Source: AGHT+IEp00uStAdiJWE6i8BRDpqrzy3aSqCXj3rpTR6FEwUP03E1Y8rq3Dsam2PEu7XpvjvWHKp6CQ== X-Received: by 2002:a05:6a00:b21:b0:704:32dc:c4e4 with SMTP id d2e1a72fcca58-70670e7a958mr4909600b3a.1.1719251609855; Mon, 24 Jun 2024 10:53:29 -0700 (PDT) Received: from KASONG-MC4.tencent.com ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70662ee117asm5008049b3a.211.2024.06.24.10.53.25 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 10:53:29 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , Matthew Wilcox , Johannes Weiner , Roman Gushchin , Waiman Long , Shakeel Butt , Nhat Pham , Michal Hocko , Chengming Zhou , Qi Zheng , Muchun Song , Chris Li , Yosry Ahmed , "Huang, Ying" , Kairui Song Subject: [PATCH 2/7] mm/list_lru: don't pass unnecessary key parameters Date: Tue, 25 Jun 2024 01:53:08 +0800 Message-ID: <20240624175313.47329-3-ryncsn@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240624175313.47329-1-ryncsn@gmail.com> References: <20240624175313.47329-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 8A0C3180015 X-Stat-Signature: 3einb78w688trcmaxn3dzgiu8tqc3gti X-HE-Tag: 1719251611-526185 X-HE-Meta: U2FsdGVkX1/zHTgmfhtf90wqp4j3TQlQrOm2ufbcNWOV+QO3B8D8HSOJiHfpZanZeYsPmb2OrXjnVxUIPd8yoEXNKwWcg8MroWxqKt5CC9dmCAK4XfzARQWwPSwL8Ra3tfgZ2vcZN8nScXhlba5/8CoyFa2bik3yrI9QVF3R4sJTEFevJGWf+Sz9bPREKYu8gUjHWbC3i0Gyt8fHbTwE3d8xQvymZihzO5Q9FdyRWK86+rAnZDrLgAmeRguWhiroIHmfFpioblRYEb1VwbBOsDfYZ8lN+Go0a2Zr9F3Xt1r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hMbkgidFfF5ipggmIwWHwZXLnHXR2Ypr9QDcfvzK6Ei/ji5Vix+qi2qgA/64PmW3z5fZE+TZ79DC8KJsIpe3JZzZ3hBkIAN41ad3fwl5pxtx+kepXYSIHYiVoeeuGaMNbEwPxR9+Yls6Ti1Y6WAgAxtplKBfc6V4oQnjedyVrMIHRAnhcMXeylCED1ndedvVeMNrkG0= 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 --- 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 792b67ceb631..2e5132905f42 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 3fd64736bc45..264713caa713 100644 --- a/mm/list_lru.c +++ b/mm/list_lru.c @@ -546,8 +546,7 @@ static void memcg_destroy_list_lru(struct list_lru *lru) } #endif /* CONFIG_MEMCG_KMEM */ -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; @@ -567,8 +566,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 c22adb93622a..1801fbe5183c 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -815,8 +815,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;