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++g3LIZxH191Remj3bXIDCL/BKdJ6gR8abK+AbaF8kOK470XkWjQVsCjEi/lrR3NKZySR3z7z2NBv2gsC5T6ZnwA0lQN7rMTdhIOzUET1Z2KnCkwBQDhn+dZZz/Fdo2HElmWdx3GtP48SS25QsW4yTcDoxWqSobIabQgCOXNlHLzbAFtp2qdqwHjZuv/d1nKxtD3MsQMYxq+G++C5bf4ONNPMHRxSp5M72ikYPYJ9GDNTJTIYE5/eYmRkCLoELx5lu4Yq4rt79Y41lltBMYkCbldUvJPUQtQ+zHdKVQfiGY4hmaIQN8N/8YxMIYAAKiXgGpU457Ng0fpE3oFe+QYRc30V93V2XK9kczVZfax8DDrIpHotuij8aCq+92u0+YlfBBamy+YjN8U6n2Sw56Z/cLaBhPkxnGrASvHthJUlZU9AAgghYMoKzXzq51ul25q830h6zGvBxW4sLfg9ujBC/pnL0a4FqQKX3I+U+82kBvNM8RzBXIuEtl9uDTTGfmYX64WlKvjCBf9ykwds1oEwK3ySGbmmQ7n3tFOvaL92CQBthBd5gjdKzThYt+CJKP8IXSz0o8/AD6OtS0T6S0J8Nh6I5vTLSssLq/f23/x3P4JLrrxEUi/PstIpW7BuSM/9LLWN2o+HXDQJIikphW jJB6AYnJ EFa/HRVx/AB0VLBsS7l86fUftYx7PzdG0FNyaZ7DSPixASdALeKpngYHYna83zomwhZAQspzaFBy/hmbdIfElSiNNkOnFxfNOir48+iWUUUqrnFiMl+8jZ4kVklzZHm0N+k9AWIDZGkc18W7X8SBlY48lqm3LEifzUAW/PyZbstnUbmRC2XATcI7A4q5ufFtAt0z6J0/Y1tBOpZIVf9Q0O3PuHVd//vGEpyCDk5YXBb3XysjnWWc6d8OWGcN4laKQhPhemPXn939xMUiYunCJm7VtkDUpFFl9cwgqHZ6F3ZP2SJYk6qmW08sVWpyKf5Af7aBHbKF7zAgnvHTNmCd20UvFInA46rn/DsrswTePjTzBiG1W6MAxDBTm4sM/0Ha79EJuSPdfo2dniRjysVqoB11u+oNfiS9VBlOixH3EKSO/Gdn/vREzuTAbtC2SBBc9E/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; From patchwork Wed Sep 25 17:10:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13812337 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 006E0CCF9E7 for ; Wed, 25 Sep 2024 17:10:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 703FF6B00B6; Wed, 25 Sep 2024 13:10:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 68D7D6B00B7; Wed, 25 Sep 2024 13:10:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 52F6E6B00B8; Wed, 25 Sep 2024 13:10:38 -0400 (EDT) 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 2A9616B00B6 for ; Wed, 25 Sep 2024 13:10:38 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A8A651C5DD5 for ; Wed, 25 Sep 2024 17:10:37 +0000 (UTC) X-FDA: 82603899714.23.086B4BA Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by imf01.hostedemail.com (Postfix) with ESMTP id C29984000A for ; Wed, 25 Sep 2024 17:10:35 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=HGDAuc+O; spf=pass (imf01.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.176 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=1727284199; 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=ugkeyXgfTV0GO7RmkzRXo60Me1ZfzTFWOxUy6uNr4Bw=; b=0BlVAPGkjpYGm8JD6ALZvxHsZ8tpZUGoUGTYKU7/SGuiwYI3uvocjXxtyaliZRS3TAqn44 TdyNBEd9gGR+QtffdfME8C5NVS8pBje5pVu8QMBczPjwMXdmA6G1WJQJOnFuWnxk59Dpyh MidHu51Szq6GxZhcWu0z97kwDpg6xuM= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=HGDAuc+O; spf=pass (imf01.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.176 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727284199; a=rsa-sha256; cv=none; b=0gAjrU9+aLuFFY/5MMT45DF0vU5ZFYGLNPzIojyJTN8yuZxDGzREvEo8xZHEFNtoaqALTD NoWJyQjXekkh/FN9xtilUi/WYEx/9sYi13tfpbOZP0V3v1vl20KkMo6LZMAfifI2fNmUEY uupDzbhzjrfPSvXAdr0m/Xigsme8KGU= Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-71957eb256bso105842b3a.3 for ; Wed, 25 Sep 2024 10:10:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727284234; x=1727889034; 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=ugkeyXgfTV0GO7RmkzRXo60Me1ZfzTFWOxUy6uNr4Bw=; b=HGDAuc+OX3jVcn3c3By2pallueSKEmmgxvghB5EwH2hVluEgNDaUBT42orvtGGZem4 xsrpEdjsHqvLXc9cDNiY9ormSTS+3vmqF6EnKzm+20+IZGkSGgpvvSuH5crEgio9Kft3 rsestrUGnEJy1QHP7Q3CFZy6qc/HaApiAGKid1aO4gFp0drBsMbdFe9FtPzTmcaNKBFN IqiaKwxYkeJZd+0a7gS5aqFOOD0dN59ENd2g4OzjYcZWxO3bD9t0hOT7F3IHdcYEyf19 B27A9N0XxbIgwNhkxz6IZgqf4IbGwlhUUDl00YiXXpXI0Gq0NApMCzMeN7wkb+INYyTn 3JrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727284234; x=1727889034; 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=ugkeyXgfTV0GO7RmkzRXo60Me1ZfzTFWOxUy6uNr4Bw=; b=fU009lpAjseisIG7xti2IPUpIICpV9GixHAXnoimfkS/UpbzoZBjKN+tW5R2umKqFB dxrg1IfEe42jeGxIBhQ+rhfLVMtOgoqKEVYyU2As8/rptcdq9OpQSEyyBsiLWXKib8ag VkFM+fn5krpp3ypuTaWxFZhmhA6adUg/4JrCeAbeul/OL+eYhtw6seovReWNlE+A0LVT Xwt/w4TZmemelNGgDFxr5vOkb79PfV/+mSYPLM3N42Tc9xmBmVNXHQBFPCxIGLI83qr6 OrpufWPu95X2PSgBBgMqBYtXve2gnnLtUiPi54lTpCyy1RFjeBOGfU2vrhslam5RHP6G WNSw== X-Gm-Message-State: AOJu0Yx2JQEEuRPq53oBHkhcNo+/BJWdVQ+KcgPSQdwqxF9ndSHc69kT 5dR2zwXA3oHf348Y1uId8dTxEikbm5fWDSqp0zmMZtJ+JBVQN6YjPV7kSBbQ X-Google-Smtp-Source: AGHT+IFAyzUsheEdhZ4GI1PJggXUZfoNdvdbvfOd6wDhSIhQicKIC94taAErChTkVetCABaeqdHROw== X-Received: by 2002:a05:6a00:3c83:b0:706:29e6:2ed2 with SMTP id d2e1a72fcca58-71b0aaa58efmr5161421b3a.5.1727284233275; Wed, 25 Sep 2024 10:10:33 -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.30 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 25 Sep 2024 10:10:32 -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 2/6] mm/list_lru: don't export list_lru_add Date: Thu, 26 Sep 2024 01:10:16 +0800 Message-ID: <20240925171020.32142-3-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-Rspam-User: X-Stat-Signature: dyqyegg94tnw3uaujnmrh69dwz8hmx8t X-Rspamd-Queue-Id: C29984000A X-Rspamd-Server: rspam11 X-HE-Tag: 1727284235-504864 X-HE-Meta: U2FsdGVkX18wUntJjSaRH4dTXLKzhbQ3SHR0HbzdIETbC+HMb+RIAtPM5DXvGzSghQsVSRyfXoFtyZHJWC6Y/o0RVm1kjYyl6xBIMviRbNpfmsyE29MP6m7M7tVnmFPiO5s45Tj7Xnl2okEm83jtQkEg3vTTDYwoCuosyxaGznJVggdRcjU4zs/XezyRIzmO3G21Cl14Qt9KE2cpzzWfmXvJ74nPfYg1KfykDZwmtK9095mTzyYqqRTeKMRSnBOz1OY3NrLk/0WwZPDoBSMhnCtisrc2RtU+q2HXbCj0KzSIn25ohfosFzUd4G9vjoA50XQ/5Dj/UWhx+uFrvCskX6I4DUYzEof6kN6GHafyiYvCvMXhiGGPhocjNGEsEEjaYMBPQvoN6gTlVBqSHpFkg9a92WYW05dagRlXEM+4nhqUgO6jbiTEF2PYoeVKTxRyL0fw3cXlVsey0K/mX0gtQCiGfH64X//EN+T1LNb3khElFgx3Xt/esIl/DSWXD7TZDHWFpZ6W0IGtR/G0lGKz3Bug/ENGAzHzBBP83EYCdLXJeEtd9Rb7oXxEphcI7R4JmlvkdXolOH8J1oYDjOHTeNsWNY4FAOOD7HAUSw+mCqHZP5yWdTJxJi9I3VcoSHH2tCZhS2yHsgTtxWCrA/xEua86WqJfsXm10nyBW1GWI0LU34OC76kleqCQ5L3xanX4fAWMVPisTKm/Wn2igF6HP2OyLVpkZIMN7mBqfEboxeYYI8impZy43eXerNXhKk/pg1JeYqPeIgVcooOp0zG77ziC0CueiiYtk5p9iN87dXD9ZoOGU+ivGdRanZS/PtUf8/X8njFouz971fZ58iqeqeBHzY5Hu59d1XYjMqWbbwO+4shMV3pDXxolUb+K5bV6tyJqSpwgJBNritEq3I13OTM3c0u36WRkUxRGoFUu0GQwRcyKzpUvcvu6d9YeW0Z9BfCeRsCLhuZWt1rv1GV lJlgCUAJ qjnalg0jbc9MfrgrX/M24AkCUhGfN/aQPDUD6PTTxcxH5aCY+knIDdYyGntLZpVpAgVDFw3zfm8YhPA3d0jLjMwOaErw6v/jbhQSYf9qvuHFp+R54rcxvnyogM4PPlU4Gq8Ozl5BgMLJcZXMbUBmTwcKay/Z2gw84BrLQuV8BLTDElE52A/UOW/XxjhaGnaLmaTnKy3p1XHJdfOB0XTSifsaKnFHgAxb2Q4OWeymEMnl1HSbuT4KKpD6j8yirYzMfCIc4p6t3p72+qy/7CU+wopAYJ+6L+S2mH390ZLrKpKKsgo6/pVn8Q0m1Mao7fSN3bsdy5bazUMIM0DoHQVvjtqNJgI/yDNPxt6NehgWNjoJA3kAoDtdXhztx6U+b4cJHJHew+12kQBb7M0jiEh8kK0KSgFGL1/bxgZBikgXcznhSn/eMOuhNn7i3ZIQiL67iv7XGLrITt4qiO1LbWVmszzaOGWMytryS0O3nz9o55xsE8Fko4NYnDQ68Ayo6DNM2nio9QW0dsp0e5g3R20qzerCVQqMcqKuBQNiZWnpREH3NWosyrlI7ThJKruDFNrO40/4y X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, 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 It's no longer used by any module, just remove it. Signed-off-by: Kairui Song Reviewed-by: Muchun Song Acked-by: Shakeel Butt --- mm/list_lru.c | 1 - 1 file changed, 1 deletion(-) diff --git a/mm/list_lru.c b/mm/list_lru.c index ea7dc9fa4d05..a798e7624f69 100644 --- a/mm/list_lru.c +++ b/mm/list_lru.c @@ -106,7 +106,6 @@ bool list_lru_add(struct list_lru *lru, struct list_head *item, int nid, spin_unlock(&nlru->lock); return false; } -EXPORT_SYMBOL_GPL(list_lru_add); bool list_lru_add_obj(struct list_lru *lru, struct list_head *item) { From patchwork Wed Sep 25 17:10:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13812338 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 5223DCCF9E8 for ; Wed, 25 Sep 2024 17:10:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF8D86B00B8; Wed, 25 Sep 2024 13:10:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C81936B00B9; Wed, 25 Sep 2024 13:10:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD2EC6B00BA; Wed, 25 Sep 2024 13:10:41 -0400 (EDT) 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 8B0C86B00B8 for ; Wed, 25 Sep 2024 13:10:41 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 526FE160524 for ; Wed, 25 Sep 2024 17:10:41 +0000 (UTC) X-FDA: 82603899882.23.98ED026 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf04.hostedemail.com (Postfix) with ESMTP id 6FFF440003 for ; Wed, 25 Sep 2024 17:10:39 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="KoO2wbS/"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727284141; a=rsa-sha256; cv=none; b=XxsWSlLXB1f+252T6XbxnmOhoG4Z/9cYE3BtakkfLaK45ndSS2ID7waw/UXpAs/2Efts0d fbi8dSCFSxgAutQpFYx8QVDlqsd5yb17SnTkGKi47172hJxQWY+OKmRKEwrpz87wRxlVj3 yUdUq/vgGK3TjWojhP3yXsoOd9WH1XA= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="KoO2wbS/"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.180 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=1727284141; 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=V5rpPame40tPuYqilRt6PKKEmhwrT8TBQfaU/Nj3qXg=; b=oVzxAPco2NwnSZ6akQwRjxzNhJBeCZLq/2CKPq/iVZ9HtDbBNqM27k0RnACfXhP1+onMIh lVWNDH09f1qrpwwY1gZ8RdP4FbdiSzh1YICma9vMlA0BQukiaAuNd+fehU41jaivmxWkz7 rKTyplzUldOda0f6U9xUcgPSPjw79uQ= Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-7198de684a7so101604b3a.2 for ; Wed, 25 Sep 2024 10:10:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727284238; x=1727889038; 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=V5rpPame40tPuYqilRt6PKKEmhwrT8TBQfaU/Nj3qXg=; b=KoO2wbS/pXRiD9wt96FnbIekklv6FrSdsnetmBev/acbWrcmIp8Yo6iUeGvpP7vBaC eE4BeLhabUI+12gRTYD11vAbtZttNFrDd08PVC68Hjuh8mGC2WtlDbSR8dQP9SFrfwFn 3lIxhfi0y1zKd9OZ063FFwnZyouIt/eAoVt/35uNsLxOCqfjvGy0quzTRgMF8x+U6oTF D/JW/adv+WOAbNqG7EnaF7WYRvjVKLATYfO2fBjbOUGp86TlanbytQ/3dVWSwgNX/NDC kUIrK4yXRGOw0NnyCac4+m3DoNnDI1L9x21MV1W4KXJIMmjjBRfRMsOrQgmLRRSJPJZC MqxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727284238; x=1727889038; 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=V5rpPame40tPuYqilRt6PKKEmhwrT8TBQfaU/Nj3qXg=; b=Oov5+yxvDGl7pbgmpmDeA0cw+Un12Mv8jRXrLL7oMcYLjbK9yui7NWECuNyqUlHPKd YnGKjzxtdbceujVG7ACYWiw+/YQhFceshsPPFoL2QNtIbwqI/GeHBLgxWc+cbijt3xeg 2SjVCbHoW31SRrTWoZe8P40L/cWv3oxRWtfEfT0dK/Rjp77yz7LDI8EUNKB6vJfkbSuR Vai7KbldAOvM0WVgDqV9MT9OYcnxzonpoj3l7qSLLFxRovSC3kFZ3akXjj6EDCZdXRuL YWcqYTZRpC0Qxn1aK7yqigKJSniK68wihBJAbsX2vtgeHdEmGA5THYv6SOWx8VSahIEk CNFQ== X-Gm-Message-State: AOJu0YzVKgPgI5qPBGr3MB76FsK/0K3TQmDIWfA1biRejt2DwN8bbSIp Q5QDyJCar8OTSPflM3WNV/Z9qKrFKoYr5N+Of5PRpcKqCXVy1PfK8HmJjyDe X-Google-Smtp-Source: AGHT+IGf2FiqU8wh6uDCOV7YyLhTSsPhlKdicE3S39+oA0aW8f9anu6q8aRA1unBV1HOXQVQQld2ig== X-Received: by 2002:aa7:93ac:0:b0:718:e188:fdf1 with SMTP id d2e1a72fcca58-71b0ac5157bmr3694049b3a.20.1727284236763; Wed, 25 Sep 2024 10:10:36 -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.33 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 25 Sep 2024 10:10:36 -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 3/6] mm/list_lru: code clean up for reparenting Date: Thu, 26 Sep 2024 01:10:17 +0800 Message-ID: <20240925171020.32142-4-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: rspam12 X-Rspamd-Queue-Id: 6FFF440003 X-Stat-Signature: xuscrxm6ngxkt8brrfseh69wkacc6w6p X-Rspam-User: X-HE-Tag: 1727284239-431363 X-HE-Meta: U2FsdGVkX19rPqLa9e4Z2ty7vqfvsQYsbhH6x+hnGH2pA5tFkXT4RgFEqsQ2okyjI/glux/bbh12fnglhanBZ6iQPhj6zubFQnavBuKhfwzUMWm5tHnLy/E4YlMB+djXXnuR/MPot/VYOb4zp/O3bU2WS6oEqwJk+yA2EGignPUS/+10QnYZ1AJB2z8jn9NPTct6574OVtgSRp3XssE/DRuQ1fcbc+jCQ8ku4Mn35coK6g8RYPZFZpMEPmVHR9mm12/vFM0xbhBz4PVj8f1NSKQSGBMOJ4TVHdLqUJAG43SE6mMwljY02S97LZuWpQ9uwuzJGoFz5Lh0xXPr+4WrpkT22+ASGF/6mVIlWFtg7+yYLXOWowU8c38A8OJBjwuJc+Ft/GqRPBwaRmQOxpdbEMfdqk4ZD8auPe8fpBTP4CN29UtswmNTUv/CTII7kfmBD0cFGQfFyTvSrUuKyPWnJWuKCbgpf7Ol4HTFdj9QC4SW4vylvL7WPQH6sduUBohdItvKPQZueg3tnaGuza6GaK3TUw+9NiFZNZZe850xprQ2X6llMolChCQfBpkUPnUq8iqMHWwIhhWnE0E4bXHgK3p7DmuR4ql0vbyjq35A2UOGfL3fYUptYWiLmU59s3J3finOYRS2Neq1EPpCV5Z2UJlhkBHu1WFO0tNYu7GRx8PjPSmQrI1xJgng9/xq388qlW0KM8XImOrf9XWuaXxQqNnymKHLzQfFqiA6gyCz8Q1/9N1J/0ug+PSP8+ucWmkjZqSelvekTeCI9VnB7f5aTSq1ktY1YRxgZLTWS/r9nHqH2Pd+w5MqYmiz6P8hjVEg9Kn4fReAvgSozKBIvzHkUufKhVMx0O7t9i/gLw1lG9/myCqJltj1hCVgvwmMkmDFGSzUGrmWu36ahVEDEgP1C+LApsTWuxIEhRpTsDCIRkwPYbpu9v/h01aKpNmWue3cYNU/5TSqFaTVuHhT3h5 3QQyTlvJ FW8OH41rg72YXh5PMmfQvRwOgGPQH4Z6J/Wlq6nFlkLkWfh02k4HTSee/lasb6Fp2O/zwnEm3iWgbSEkn53JplABACa7gqnB09heaavyUr+3L65gnFj3BvRwOmRxsyfPmOpKT/corrmyIfMoD+M7lm2p8wJGEd3v+FYs7NgGT0ptXTxMP2KuwaWC0c9So2Wbsy9xislujgRmvW3gUxFwhPSdWsqWda85HjXEhANQgtaBfnkrSeRUe5YhfZtOrG8kjGhsktgx083fObnCq7ARsJSIuN/0wmwgWmgSO3Scs972qq9QlmtAXzP9M5EP8D9IowOdPvIEzCtonZ9KzWl7TfJvzOOWTzOfikz3+pAQzKI650/mZ0SFK3k9LXBnmkoG7YVh1lqSXKHFinHKMcGs1jJd0YrHsLbJZJBdsaZ09MMcJyQXBV/fvhPfWxXUzW5Tx865J5SA+jiyqcMQlNgNOoIDySeuFl2h69KENmzABd+4dRLtI9U93VtP44EVev1Kw/nOJ8aWjPVQOBUAKMJD7+9mm2Vr+QTjDCzMNZagq8MbFP4S5fP+0/accYgIxS/auXMUb 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 No feature change, just change of code structure and fix comment. The list lrus are not empty until memcg_reparent_list_lru_node() calls are all done, so the comments in memcg_offline_kmem were slightly inaccurate. Signed-off-by: Kairui Song Reviewed-by: Muchun Song Acked-by: Shakeel Butt --- mm/list_lru.c | 39 +++++++++++++++++---------------------- mm/memcontrol.c | 7 ------- 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/mm/list_lru.c b/mm/list_lru.c index a798e7624f69..b54f092d4d65 100644 --- a/mm/list_lru.c +++ b/mm/list_lru.c @@ -421,35 +421,16 @@ static void memcg_reparent_list_lru_node(struct list_lru *lru, int nid, spin_unlock_irq(&nlru->lock); } -static void memcg_reparent_list_lru(struct list_lru *lru, - int src_idx, struct mem_cgroup *dst_memcg) -{ - int i; - - for_each_node(i) - memcg_reparent_list_lru_node(lru, i, src_idx, dst_memcg); - - memcg_list_lru_free(lru, src_idx); -} - void memcg_reparent_list_lrus(struct mem_cgroup *memcg, struct mem_cgroup *parent) { struct cgroup_subsys_state *css; struct list_lru *lru; - int src_idx = memcg->kmemcg_id; + int src_idx = memcg->kmemcg_id, i; /* * Change kmemcg_id of this cgroup and all its descendants to the * parent's id, and then move all entries from this cgroup's list_lrus * to ones of the parent. - * - * After we have finished, all list_lrus corresponding to this cgroup - * are guaranteed to remain empty. So we can safely free this cgroup's - * list lrus in memcg_list_lru_free(). - * - * Changing ->kmemcg_id to the parent can prevent memcg_list_lru_alloc() - * from allocating list lrus for this cgroup after memcg_list_lru_free() - * call. */ rcu_read_lock(); css_for_each_descendant_pre(css, &memcg->css) { @@ -460,9 +441,23 @@ void memcg_reparent_list_lrus(struct mem_cgroup *memcg, struct mem_cgroup *paren } rcu_read_unlock(); + /* + * With kmemcg_id set to parent, holding the lock of each list_lru_node + * below can prevent list_lru_{add,del,isolate} from touching the lru, + * safe to reparent. + */ mutex_lock(&list_lrus_mutex); - list_for_each_entry(lru, &memcg_list_lrus, list) - memcg_reparent_list_lru(lru, src_idx, parent); + list_for_each_entry(lru, &memcg_list_lrus, list) { + for_each_node(i) + memcg_reparent_list_lru_node(lru, i, src_idx, parent); + + /* + * Here all list_lrus corresponding to the cgroup are guaranteed + * to remain empty, we can safely free this lru, any further + * memcg_list_lru_alloc() call will simply bail out. + */ + memcg_list_lru_free(lru, src_idx); + } mutex_unlock(&list_lrus_mutex); } diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 7845c64a2c57..8e90aa026c47 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3099,13 +3099,6 @@ static void memcg_offline_kmem(struct mem_cgroup *memcg) parent = root_mem_cgroup; memcg_reparent_objcgs(memcg, parent); - - /* - * After we have finished memcg_reparent_objcgs(), all list_lrus - * corresponding to this cgroup are guaranteed to remain empty. - * The ordering is imposed by list_lru_node->lock taken by - * memcg_reparent_list_lrus(). - */ memcg_reparent_list_lrus(memcg, parent); } From patchwork Wed Sep 25 17:10:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13812339 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 70897CCF9E7 for ; Wed, 25 Sep 2024 17:10:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0009D6B00BA; Wed, 25 Sep 2024 13:10:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ECA9D6B00BB; Wed, 25 Sep 2024 13:10:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1E066B00BC; Wed, 25 Sep 2024 13:10:44 -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 AB77A6B00BA for ; Wed, 25 Sep 2024 13:10:44 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 623FA1C441F for ; Wed, 25 Sep 2024 17:10:44 +0000 (UTC) X-FDA: 82603900008.05.8571269 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf22.hostedemail.com (Postfix) with ESMTP id 76F7CC000D for ; Wed, 25 Sep 2024 17:10:42 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Gws4B9O4; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf22.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727284226; a=rsa-sha256; cv=none; b=cq2xU6PsxhiKmecoYsWDC+R7gPn/86BV4iRt+WiMjIZ+ALH6wZjEPRUNRqwry4p32z6U7a rWC8g7P8prDPK4OUUir5DAmNk9BqAQQF5BMN8vKx2ybQtcDmru7gIKDavhQelbzUhP01IO lZ+PQADmfRgeP+CAREn77YNZK9IZlKo= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Gws4B9O4; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf22.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.175 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=1727284226; 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=eLsxaOIfoQivSOjlmGHEUGtgy/OnwR5U8Z8UVuFepyI=; b=RHdHJsLEwfDusnvMSj5RajGLfMyNhcdYe2g4/qUEDqXn85bTTruHT+r6cGg1dS3noClzfv yeOTneLaDA9wevwOofxeFug5GISsZ5U5vv/EGir4Er2xN0/xkicIrRzKP2wjtPYAb3MYJz 0+omFylh7x51Nj2oekF1g2lpHSkZOT0= Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-7179069d029so108348b3a.2 for ; Wed, 25 Sep 2024 10:10:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727284241; x=1727889041; 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=eLsxaOIfoQivSOjlmGHEUGtgy/OnwR5U8Z8UVuFepyI=; b=Gws4B9O4kmO2CAEoF+UOsvDq3TUbdJiocB8AdqlzNfE7n5D5wHx7fsTWnHAqrlhkGo 01RcMOlDQndYXCQ+5/mc+yXEhNbA7M3VD/RKVCplab2TT9LzSNthV+TGz2Ou/7hdcM11 Pj4zZ8rPyoxXL0Vr2Br/8B4NRlJPEnY3o7G7GxrcAtRhvwoJ80ymgZ6/hCHIB5JxMUpL n3NCrokkyOY+5r45ksHpZIvs7WXePJ7OKxknuxHpVM1wYYkiEigxc2TOiJzHz8Wlgn5m BNYGaULsAZQFKBvSQfITHrP16Hk35S0FiVB5yz8UerpXpNZZd9nIRa1buPfwUpr6BMTu CGrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727284241; x=1727889041; 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=eLsxaOIfoQivSOjlmGHEUGtgy/OnwR5U8Z8UVuFepyI=; b=UD15IhmAlY9w/bus8xMngK3Gmm/t957yeU5Xo+K4JbJXlUJbcmtGMTwPQoO0CkaK+9 mxZ1EAq5kjJ00rlbkNMDA+8VVk9TGtE3gGAsr/k5r3gscVkG1q+q5VEGSR9iWqNYO7L6 fJioe1HGDpq0D/2DwGWi2RnCNK8jZzOrhrxKb3klqn7TZ8L+iVOS6mN+kW9lZsF7s16S ElU5vL1K5mdQsgii5IwXyGc5+5iMOoAOoW7/8/3Sn+ICkjJL0nOVjdRoQXAksQMyZB2x zftp5PwhZDfA90zY9spaH1r3r3w+E/GoXPiwp22AvP52SMSuiqrRFQ2kjL8RdpD3mUGB Xzkw== X-Gm-Message-State: AOJu0Yx7kZG/DsGOvhzw3ttimDgNeaX93Wx8GrQXbQ4dLlrUXriYgjGs 0Bzn4U5dtSRcYzJnlwKT99tNP2t4Hq6m30DJHHu595t/U352lZa8jBX2ZywT X-Google-Smtp-Source: AGHT+IGCY98J4UUFHErBPNttuT/k9GAjpJknUsJQjnf9gUlRn4cQ8ORRz/CstFqvhiI7cD0KN8IdZw== X-Received: by 2002:a05:6a20:d497:b0:1d0:56b1:1c59 with SMTP id adf61e73a8af0-1d4d4b860c3mr4704612637.32.1727284240487; Wed, 25 Sep 2024 10:10:40 -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.37 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 25 Sep 2024 10:10:40 -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 4/6] mm/list_lru: simplify reparenting and initial allocation Date: Thu, 26 Sep 2024 01:10:18 +0800 Message-ID: <20240925171020.32142-5-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-Rspam-User: X-Stat-Signature: wuxysrn3xe6oaud4wjjkr7uxp8crgfeu X-Rspamd-Queue-Id: 76F7CC000D X-Rspamd-Server: rspam02 X-HE-Tag: 1727284242-126161 X-HE-Meta: U2FsdGVkX19XxlK1O6NIe1+Gpum3YDisp+RwfWkQa9BZbAL7NioK4KyI9m/qlqpLzHmIrkTyrXAVFFBPh9TK2Q/ELnZunR/fC2WF0OnM8o0KG3zI32BJeVxjxveGXSiOkY+qephE9+BJPPbONh8yLMmzUff6XvZsKn1cosYy0w+Di9z82WGqhB2nhx21glw2G9FVHCS0j9DFqOYGV1mTqthXxFmcQ+o5xuip1iPP9+4QEyzO/vRMYsOXUd06NxA7oj0bdfuDgiF62cnAFVwmx+pXC3VRXl8y/7QSPIPBr90n9TrE9f0YIT0iO4aRqvZlwWdFqvMOvA00OcYReyu1goilnqNJ+2ldhTH3lTRCG32VRPwyFzYHKXZhIZ4B1z+OhAuHmNB14CpSzSHQbT2DayWEmvNY4Qs6Xa7iwP9BzUELXodBdbxioApGaQfFKub6MgU1736b/I9M55xjl9s36raLwf6Apl+wnbkwH+N0lEQHTVeZzvvh/aAQjvzfcxEVpiQQKmN3gYXm0k+vJe5pDJj/NYRwUHwes3jUnBIvId2J/N63XvO3Ddxqs/u7SZjJiXQiqd3zR4L+X7uuA3WE5ilY7D+KDmh8MReaZ4vOvbfJ7qFE9kVafdYo57zjJqhWbuDWjUPAan1KuQIe9w5DARJFslVzOuhp5d99+VE5VHck3juNBxoBg9lLPzgN5gV+yI1FPSpPOnouNH8Wm1yRAyYpXXvD4fA0h7nN4rUe7wKeZTGHbaInjtyCLkRxDYttQXjsGWM/kE6WMmnGrcejnIYia1KsxJMeoHUDGnrax2biql/zp+3GBC3giEZXzbO3vBHhG20Vz77yL5k+ssadAaO4DEv5+8M30PpAVwb2blK/DIzoce1Q9IUH00Z6wLaoy0gH8bAqUiinbZXHNUfTOHCc5T83zx2AMgGcbx5cJn0SPBHDg5VC2LvC5tnsca31Sp6qamA8PF3HtNmZLU1 4usGYUOy fuLlssYXqvMbUsOrWPlc1bsMVLdkxWAxGNSs7vGXtap2Hk8fGW/C4vvw24FIHqv8vCkH+8uKyWmR7AkYdnVkImCByFw3uXZu3XBOZUmespBhj1ndHVKCdHe7+4E0X6uioaR7mz6+qYA8b2nGJvtS3Veca70kSSpfX8rq+jef8yw0TIF32yxaOPl8x9oDUDu/aTwwWM+bKrIEqMrONWbOSnQ9goq/mBjd9E+W7bj/omb8SAkyUkLFJpEOsZSfdnJVRxbQsU3S/Y9CmbSM2R3YgREQAzqRQ/MGzmDwP+TsIPZedH3ymOC1W0hmRrUiNZ/uI+sUXW/yCSqx1DHwk0w5ZzAfBYHEIE9zRYzYW3PY3JIgncxhsQSTkUfNjtlawmGQ6WbPtiyBGxg3fhKaw+FmL2km+lgmNWDvBdWpboBGlQCcyC+QjnbUTA2l5J0lHRLlELU0qy1FOluH1iJWVjVXx4HQAKvre+kson0qpyR2BVXfy3C+fFAFXRwSViHYkpdNWwRQkD4q7KFNVKsfg5rCu5kD7JeoFVaPwtMCJAZ2x3hp0IXDsRZi09Y44lBJWyvZ4kdHu 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 Currently, there is a lot of code for detecting reparent racing using kmemcg_id as the synchronization flag. And an intermediate table is required to record and compare the kmemcg_id. We can simplify this by just checking the cgroup css status, skip if cgroup is being offlined. On the reparenting side, ensure no more allocation is on going and no further allocation will occur by using the XArray lock as barrier. Combined with a O(n^2) top-down walk for the allocation, we get rid of the intermediate table allocation completely. Despite being O(n^2), it should be actually faster because it's not practical to have a very deep cgroup level, and in most cases the parent cgroup should have been allocated already. This also avoided changing kmemcg_id before reparenting, making cgroups have a stable index for list_lru_memcg. After this change it's possible that a dying cgroup will see a NULL value in XArray corresponding to the kmemcg_id, because the kmemcg_id will point to an empty slot. In such case, just fallback to use its parent. As a result the code is simpler, following test also showed a very slight performance gain (12 test runs): prepare() { mkdir /tmp/test-fs modprobe brd rd_nr=1 rd_size=16777216 mkfs.xfs -f /dev/ram0 mount -t xfs /dev/ram0 /tmp/test-fs for i in $(seq 10000); do seq 8000 > "/tmp/test-fs/$i" done mkdir -p /sys/fs/cgroup/system.slice/bench/test/1 echo +memory > /sys/fs/cgroup/system.slice/bench/cgroup.subtree_control echo +memory > /sys/fs/cgroup/system.slice/bench/test/cgroup.subtree_control echo +memory > /sys/fs/cgroup/system.slice/bench/test/1/cgroup.subtree_control echo 768M > /sys/fs/cgroup/system.slice/bench/memory.max } do_test() { read_worker() { mkdir -p "/sys/fs/cgroup/system.slice/bench/test/1/$1" echo $BASHPID > "/sys/fs/cgroup/system.slice/bench/test/1/$1/cgroup.procs" read -r __TMP < "/tmp/test-fs/$1"; } read_in_all() { for i in $(seq 10000); do read_worker "$i" & done; wait } echo 3 > /proc/sys/vm/drop_caches time read_in_all for i in $(seq 1 10000); do rmdir "/sys/fs/cgroup/system.slice/bench/test/1/$i" &>/dev/null done } Before: real 0m3.498s user 0m11.037s sys 0m35.872s real 1m33.860s user 0m11.593s sys 3m1.169s real 1m31.883s user 0m11.265s sys 2m59.198s real 1m32.394s user 0m11.294s sys 3m1.616s real 1m31.017s user 0m11.379s sys 3m1.349s real 1m31.931s user 0m11.295s sys 2m59.863s real 1m32.758s user 0m11.254s sys 2m59.538s real 1m35.198s user 0m11.145s sys 3m1.123s real 1m30.531s user 0m11.393s sys 2m58.089s real 1m31.142s user 0m11.333s sys 3m0.549s After: real 0m3.489s user 0m10.943s sys 0m36.036s real 1m10.893s user 0m11.495s sys 2m38.545s real 1m29.129s user 0m11.382s sys 3m1.601s real 1m29.944s user 0m11.494s sys 3m1.575s real 1m31.208s user 0m11.451s sys 2m59.693s real 1m25.944s user 0m11.327s sys 2m56.394s real 1m28.599s user 0m11.312s sys 3m0.162s real 1m26.746s user 0m11.538s sys 2m55.462s real 1m30.668s user 0m11.475s sys 3m2.075s real 1m29.258s user 0m11.292s sys 3m0.780s Which is slightly faster in real time. Signed-off-by: Kairui Song --- mm/list_lru.c | 178 +++++++++++++++++++++----------------------------- mm/zswap.c | 7 +- 2 files changed, 77 insertions(+), 108 deletions(-) diff --git a/mm/list_lru.c b/mm/list_lru.c index b54f092d4d65..172b16146e15 100644 --- a/mm/list_lru.c +++ b/mm/list_lru.c @@ -59,6 +59,20 @@ list_lru_from_memcg_idx(struct list_lru *lru, int nid, int idx) } return &lru->node[nid].lru; } + +static inline struct list_lru_one * +list_lru_from_memcg(struct list_lru *lru, int nid, struct mem_cgroup *memcg) +{ + struct list_lru_one *l; +again: + l = list_lru_from_memcg_idx(lru, nid, memcg_kmem_id(memcg)); + if (likely(l)) + return l; + + memcg = parent_mem_cgroup(memcg); + VM_WARN_ON(!css_is_dying(&memcg->css)); + goto again; +} #else static void list_lru_register(struct list_lru *lru) { @@ -83,6 +97,12 @@ list_lru_from_memcg_idx(struct list_lru *lru, int nid, int idx) { return &lru->node[nid].lru; } + +static inline struct list_lru_one * +list_lru_from_memcg(struct list_lru *lru, int nid, int idx) +{ + return &lru->node[nid].lru; +} #endif /* CONFIG_MEMCG */ /* The caller must ensure the memcg lifetime. */ @@ -94,7 +114,7 @@ bool list_lru_add(struct list_lru *lru, struct list_head *item, int nid, spin_lock(&nlru->lock); if (list_empty(item)) { - l = list_lru_from_memcg_idx(lru, nid, memcg_kmem_id(memcg)); + l = list_lru_from_memcg(lru, nid, memcg); list_add_tail(item, &l->list); /* Set shrinker bit if the first element was added */ if (!l->nr_items++) @@ -133,7 +153,7 @@ bool list_lru_del(struct list_lru *lru, struct list_head *item, int nid, spin_lock(&nlru->lock); if (!list_empty(item)) { - l = list_lru_from_memcg_idx(lru, nid, memcg_kmem_id(memcg)); + l = list_lru_from_memcg(lru, nid, memcg); list_del_init(item); l->nr_items--; nlru->nr_items--; @@ -355,20 +375,6 @@ static struct list_lru_memcg *memcg_init_list_lru_one(gfp_t gfp) return mlru; } -static void memcg_list_lru_free(struct list_lru *lru, int src_idx) -{ - struct list_lru_memcg *mlru = xa_erase_irq(&lru->xa, src_idx); - - /* - * The __list_lru_walk_one() can walk the list of this node. - * We need kvfree_rcu() here. And the walking of the list - * is under lru->node[nid]->lock, which can serve as a RCU - * read-side critical section. - */ - if (mlru) - kvfree_rcu(mlru, rcu); -} - static inline void memcg_init_list_lru(struct list_lru *lru, bool memcg_aware) { if (memcg_aware) @@ -393,22 +399,18 @@ static void memcg_destroy_list_lru(struct list_lru *lru) } static void memcg_reparent_list_lru_node(struct list_lru *lru, int nid, - int src_idx, struct mem_cgroup *dst_memcg) + struct list_lru_one *src, + struct mem_cgroup *dst_memcg) { struct list_lru_node *nlru = &lru->node[nid]; - int dst_idx = dst_memcg->kmemcg_id; - struct list_lru_one *src, *dst; + struct list_lru_one *dst; /* * Since list_lru_{add,del} may be called under an IRQ-safe lock, * we have to use IRQ-safe primitives here to avoid deadlock. */ spin_lock_irq(&nlru->lock); - - src = list_lru_from_memcg_idx(lru, nid, src_idx); - if (!src) - goto out; - dst = list_lru_from_memcg_idx(lru, nid, dst_idx); + dst = list_lru_from_memcg_idx(lru, nid, memcg_kmem_id(dst_memcg)); list_splice_init(&src->list, &dst->list); @@ -417,46 +419,43 @@ static void memcg_reparent_list_lru_node(struct list_lru *lru, int nid, set_shrinker_bit(dst_memcg, nid, lru_shrinker_id(lru)); src->nr_items = 0; } -out: spin_unlock_irq(&nlru->lock); } void memcg_reparent_list_lrus(struct mem_cgroup *memcg, struct mem_cgroup *parent) { - struct cgroup_subsys_state *css; struct list_lru *lru; - int src_idx = memcg->kmemcg_id, i; - - /* - * Change kmemcg_id of this cgroup and all its descendants to the - * parent's id, and then move all entries from this cgroup's list_lrus - * to ones of the parent. - */ - rcu_read_lock(); - css_for_each_descendant_pre(css, &memcg->css) { - struct mem_cgroup *child; - - child = mem_cgroup_from_css(css); - WRITE_ONCE(child->kmemcg_id, parent->kmemcg_id); - } - rcu_read_unlock(); + int i; - /* - * With kmemcg_id set to parent, holding the lock of each list_lru_node - * below can prevent list_lru_{add,del,isolate} from touching the lru, - * safe to reparent. - */ mutex_lock(&list_lrus_mutex); list_for_each_entry(lru, &memcg_list_lrus, list) { + struct list_lru_memcg *mlru; + XA_STATE(xas, &lru->xa, memcg->kmemcg_id); + + /* + * Lock the Xarray to ensure no on going list_lru_memcg + * allocation and further allocation will see css_is_dying(). + */ + xas_lock_irq(&xas); + mlru = xas_store(&xas, NULL); + xas_unlock_irq(&xas); + if (!mlru) + continue; + + /* + * With Xarray value set to NULL, holding the lru lock below + * prevents list_lru_{add,del,isolate} from touching the lru, + * safe to reparent. + */ for_each_node(i) - memcg_reparent_list_lru_node(lru, i, src_idx, parent); + memcg_reparent_list_lru_node(lru, i, &mlru->node[i], parent); /* * Here all list_lrus corresponding to the cgroup are guaranteed * to remain empty, we can safely free this lru, any further * memcg_list_lru_alloc() call will simply bail out. */ - memcg_list_lru_free(lru, src_idx); + kvfree_rcu(mlru, rcu); } mutex_unlock(&list_lrus_mutex); } @@ -472,77 +471,48 @@ static inline bool memcg_list_lru_allocated(struct mem_cgroup *memcg, int memcg_list_lru_alloc(struct mem_cgroup *memcg, struct list_lru *lru, gfp_t gfp) { - int i; unsigned long flags; - struct list_lru_memcg_table { - struct list_lru_memcg *mlru; - struct mem_cgroup *memcg; - } *table; + struct list_lru_memcg *mlru; + struct mem_cgroup *pos, *parent; XA_STATE(xas, &lru->xa, 0); if (!list_lru_memcg_aware(lru) || memcg_list_lru_allocated(memcg, lru)) return 0; gfp &= GFP_RECLAIM_MASK; - table = kmalloc_array(memcg->css.cgroup->level, sizeof(*table), gfp); - if (!table) - return -ENOMEM; - /* * Because the list_lru can be reparented to the parent cgroup's * list_lru, we should make sure that this cgroup and all its * ancestors have allocated list_lru_memcg. */ - for (i = 0; memcg; memcg = parent_mem_cgroup(memcg), i++) { - if (memcg_list_lru_allocated(memcg, lru)) - break; - - table[i].memcg = memcg; - table[i].mlru = memcg_init_list_lru_one(gfp); - if (!table[i].mlru) { - while (i--) - kfree(table[i].mlru); - kfree(table); - return -ENOMEM; + do { + /* + * Keep finding the farest parent that wasn't populated + * until found memcg itself. + */ + pos = memcg; + parent = parent_mem_cgroup(pos); + while (!memcg_list_lru_allocated(parent, lru)) { + pos = parent; + parent = parent_mem_cgroup(pos); } - } - - xas_lock_irqsave(&xas, flags); - while (i--) { - int index = READ_ONCE(table[i].memcg->kmemcg_id); - struct list_lru_memcg *mlru = table[i].mlru; - xas_set(&xas, index); -retry: - if (unlikely(index < 0 || xas_error(&xas) || xas_load(&xas))) { - kfree(mlru); - } else { - xas_store(&xas, mlru); - if (xas_error(&xas) == -ENOMEM) { - xas_unlock_irqrestore(&xas, flags); - if (xas_nomem(&xas, gfp)) - xas_set_err(&xas, 0); - xas_lock_irqsave(&xas, flags); - /* - * The xas lock has been released, this memcg - * can be reparented before us. So reload - * memcg id. More details see the comments - * in memcg_reparent_list_lrus(). - */ - index = READ_ONCE(table[i].memcg->kmemcg_id); - if (index < 0) - xas_set_err(&xas, 0); - else if (!xas_error(&xas) && index != xas.xa_index) - xas_set(&xas, index); - goto retry; + mlru = memcg_init_list_lru_one(gfp); + if (!mlru) + return -ENOMEM; + xas_set(&xas, pos->kmemcg_id); + do { + xas_lock_irqsave(&xas, flags); + if (!xas_load(&xas) && !css_is_dying(&pos->css)) { + xas_store(&xas, mlru); + if (!xas_error(&xas)) + mlru = NULL; } - } - } - /* xas_nomem() is used to free memory instead of memory allocation. */ - if (xas.xa_alloc) - xas_nomem(&xas, gfp); - xas_unlock_irqrestore(&xas, flags); - kfree(table); + xas_unlock_irqrestore(&xas, flags); + } while (xas_nomem(&xas, gfp)); + if (mlru) + kfree(mlru); + } while (pos != memcg && !css_is_dying(&pos->css)); return xas_error(&xas); } diff --git a/mm/zswap.c b/mm/zswap.c index 449914ea9919..95a28301b7cd 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -704,12 +704,11 @@ static void zswap_lru_add(struct list_lru *list_lru, struct zswap_entry *entry) /* * Note that it is safe to use rcu_read_lock() here, even in the face of - * concurrent memcg offlining. Thanks to the memcg->kmemcg_id indirection - * used in list_lru lookup, only two scenarios are possible: + * concurrent memcg offlining: * - * 1. list_lru_add() is called before memcg->kmemcg_id is updated. The + * 1. list_lru_add() is called before list_lru_memcg is erased. The * new entry will be reparented to memcg's parent's list_lru. - * 2. list_lru_add() is called after memcg->kmemcg_id is updated. The + * 2. list_lru_add() is called after list_lru_memcg is erased. The * new entry will be added directly to memcg's parent's list_lru. * * Similar reasoning holds for list_lru_del(). From patchwork Wed Sep 25 17:10:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13812340 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 25E20CCF9E7 for ; Wed, 25 Sep 2024 17:10:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A892F6B00BB; Wed, 25 Sep 2024 13:10:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A10906B00BC; Wed, 25 Sep 2024 13:10:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7EE776B00BD; Wed, 25 Sep 2024 13:10:48 -0400 (EDT) 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 522A56B00BB for ; Wed, 25 Sep 2024 13:10:48 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 16344140514 for ; Wed, 25 Sep 2024 17:10:48 +0000 (UTC) X-FDA: 82603900176.23.1551E74 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by imf11.hostedemail.com (Postfix) with ESMTP id 0A8034001F for ; Wed, 25 Sep 2024 17:10:45 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=FI5ia8DX; spf=pass (imf11.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.174 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=1727284185; 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=91pGC7UhHYrZG8U8mTWFeIlYDkmoRgXvK0ZL4GQEbB8=; b=OCXF+eptjP7RspS2KDKcYsvD41PxNiGWhz4hgbsgvxqa8RwOS4WmUvqBvG7yihVsCdIZty +Pfs20Zrm4GWyBJYbVcuAsGpz7RFmYpD468C7N2OTnh5SBHXPYxQT2006MKXH6BFg0ysCH GOaMWMVqY7vsjzWExZLvZMzTtZlflkA= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=FI5ia8DX; spf=pass (imf11.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.174 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727284185; a=rsa-sha256; cv=none; b=1eekKgO+3u2ZiB45gvAP8FAq7fNzG5zdZOUVafDe/HfG0pOZCRft6JY0x9xvJRdweB0Tee Omdzsbub/w2QWLBNvJQxlOtY4clDEX/63uX/LeKMM/kedwgU1EPNc370bCfSt2wgPGjCiW jcd45BKxMCGUvizTf4X718a6Wv6GrSk= Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-718e2855479so114981b3a.1 for ; Wed, 25 Sep 2024 10:10:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727284244; x=1727889044; 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=91pGC7UhHYrZG8U8mTWFeIlYDkmoRgXvK0ZL4GQEbB8=; b=FI5ia8DXyPbI6a/fOnb/yth6A6OPIfWzN+n8o2RI9QwCdonQXlZv6BbwN3OA+k5/p5 ViT8qWCKlt/RYfaRxg5DtYFe7p2twCyfJOppMUMWMnG8P72xvtZiPrKFfIp24sUAMfPj gvUExVZcoHq+KQyG0H/+17+Q/fbzOYj44kvZgajBbxKnfwd68YJgE/Fs7pAxMH+txjYC sSq7MLmd4pw/jE/Ws1CHRDEwbcx2ZVvLm30XOBqe4dQXnqk2Ks3chwk3h5Fr6hy8XYsm YEFAHKFzlOLVEZPEU+Xdh0SJVyQemIYUDWjgaDdgObSaJHghhLO5nI4vbKYauYvdGl/M HS4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727284244; x=1727889044; 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=91pGC7UhHYrZG8U8mTWFeIlYDkmoRgXvK0ZL4GQEbB8=; b=GFJfvTHQ03P3QpwJCqC9KzAdnQLTPd8tm3+9NxWlLRqidxPciVQJhdKHszF5iFVq3V 1o1DJtASdYHULfywKgYH8RP/rdbfPVix52RNxyHGK9QMzqIsDcMCJrL44D7j2WluoDBZ yth4oSuFLVN7a3xOwxCsnzW4Pyvg8NS/twFpa78O6fqPwgBz4RXi8ogTFl+VXicP8ioK lerJxrjuADx3IwKyI2jsAFX+PEvPcD9zRPsXr7WttbqxuyBfVBsyqcRM3tWVEMxybjfB LPZyav6QwR6f1KqXBck781I4IguNkDJxMo3geyQVxBo+fVZKr1YbZuSY0a/ZIMXhuZcY dgKg== X-Gm-Message-State: AOJu0YxFDnYbRKwyanLQBRIio2W/wRJajMacJtPsNleF8erfBRMotG6D 0Z1jKfKnLsuvrj+kOWetR4zSKtpKgLHhT38J4pW61/vwa7eoSYWhChmnVKGk X-Google-Smtp-Source: AGHT+IF/P6uCxsPnmh+Iyr4oZKd26dI3Xr0+/R6nTvKKyRrKWSNV0eeDDmGrGJ+oOJ61ewGvGrEGLQ== X-Received: by 2002:a05:6a20:9c8e:b0:1cf:2d62:8584 with SMTP id adf61e73a8af0-1d4d4aaee26mr4723255637.11.1727284244134; Wed, 25 Sep 2024 10:10:44 -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.40 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 25 Sep 2024 10:10:43 -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 5/6] mm/list_lru: split the lock to per-cgroup scope Date: Thu, 26 Sep 2024 01:10:19 +0800 Message-ID: <20240925171020.32142-6-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: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 0A8034001F X-Stat-Signature: ajgwc6pcxd3u7i3s9peiwjxawkzenafg X-HE-Tag: 1727284245-719080 X-HE-Meta: U2FsdGVkX1+3qbVFOs7fqqw9CQL6k3HpM9B+PxUGDMzFC/0MhGUw82ErWMbWJDpf7A7P/yhmKJ3/Ih+Mi0LznMMnVMBYrT3Pp10ggz3WW+3awNqFrOkduxzsjhSpR2PtmH79HgkPHBzqGm5hM3kp4dP5RFS15GVmiYwfb2hN4mInUwV39E+NH9SV7g7GUZeYnWydCYTkoR3GmBirVWRKUUOjum2ehS8wtdyuti6XSVDf6sRUFDfiPOtMHMowdQjorkWCZ+O92eVrVrVgOT9vt2WEvvOMHyXlsjn04XEitN2ZdYtKcuIOnTYIGBc6WR/t95b8U8eXMrcZDFe2RYsQjWPGpW7OMUL1LcNJ9JdvcGAvjL11GucFiZKxvye/E1JDUxRAfoBKEmgRT2Kj/10LTHI11UvEfVrZaTfDSpv7SnjpUUDcf+AV+aHE/989m6YcxQM2CBH+N3fc2DNOwbDhxPy8LEbRscpRKQemLThI7XYfXiCV8c5afz88EEscuCCR4exqkLnzdIl9QsoOasLPgxSXLE14RQEI7cx9B680n2QE38LUnmf0JWcL6s9oyh9xGhYDINGf/o1xUw3rPxveHt/HLzaknU2xNTXaI3L6lmmeIcLTWe1swtis2CIt3tjmWOVLf8Rl3icozqvhiXUzQeoIw9T9JGykuMF1laD1To9VhyufwztZ5E4R2lI/ZvFAHCffBVRpINFUQ2n3lfwgAH4xeVYqgSjOvGmIow+H1227znBTHvH+c9yZyb25b3hJZPRCw0Y48Zwr7LnfjZTAintT8+VwuKaGQx4bOh848FXfdDu4OLvHpyfBGTHmzuXme/nUvOi6MGRuQkcxs2gu2p2usMzOiV+FUVH767RJ6i8KE47U0t+938OtfQX3gg7Gdd6k5vhm0ZMVOMajn2X4Ke5R1Eu0tIrvP6vYokIfG+zF5JHwpj3mOQz9nut73mW0PTZJEkUXDgpqtx4ygNg wTK9jT/+ +b7Y4z4OJj3PlT/xfnbc0p/EHeYoRt4hVf9q3igbylOGSQ/AxiioZmS5GI/w+J8dCrSrILHGmOFQ1gGzWSp+x7DykI2xZcsg2P2ll8+kavFpulGy5Uyat6FlTItBHZvVN2sooKzMwlmS3HzK6bPyusYLw2nmbBaPe5CEXXMYIKuJK3GEy3cuAM5kQXRD8RxDzf9geS5Sb15+5Vew2mSrBUk9TjOYOJnRvRyiUll4fU37m8Hyw8BRg1xtSMqQcxCxD3delBW4WNhUWxcHDGdQ45khgr+ZJHuTb4RcQ5gyBlFbnMxDasWLRAFgdZJzgf/4JomYaFm6mw9RlGrz1piMq6ScEV1eqVlWFlqHatzs7lq0tSlF6uxsaPzMT+iZftyfYIMOasLl5zlQVavIDtDq6/Pb58e3ElLYd/v8gFxAH9jt/c7aJgPR0m6LIcLnYxikH/raWNhXvOV2lS8nHYvApcTADES7t74/HxNd2C5tWolm5R5aD6TA4pWtzqRt+zYoy+PumRgRdtpOwlWcUe9KPTPqj349TweTdi2GZawE5r5IfnRe5iIx/JSamAB8nMosIoKb8 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 Currently, every list_lru has a per-node lock that protects adding, deletion, isolation, and reparenting of all list_lru_one instances belonging to this list_lru on this node. This lock contention is heavy when multiple cgroups modify the same list_lru. This lock can be split into per-cgroup scope to reduce contention. To achieve this, we need a stable list_lru_one for every cgroup. This commit adds a lock to each list_lru_one and introduced a helper function lock_list_lru_of_memcg, making it possible to pin the list_lru of a memcg. Then reworked the reparenting process. Reparenting will switch the list_lru_one instances one by one. By locking each instance and marking it dead using the nr_items counter, reparenting ensures that all items in the corresponding cgroup (on-list or not, because items have a stable cgroup, see below) will see the list_lru_one switch synchronously. Objcg reparent is also moved after list_lru reparent so items will have a stable mem cgroup until all list_lru_one instances are drained. The only caller that doesn't work the *_obj interfaces are direct calls to list_lru_{add,del}. But it's only used by zswap and that's also based on objcg, so it's fine. This also changes the bahaviour of the isolation function when LRU_RETRY or LRU_REMOVED_RETRY is returned, because now releasing the lock could unblock reparenting and free the list_lru_one, isolation function will have to return withoug re-lock the lru. prepare() { mkdir /tmp/test-fs modprobe brd rd_nr=1 rd_size=33554432 mkfs.xfs -f /dev/ram0 mount -t xfs /dev/ram0 /tmp/test-fs for i in $(seq 1 512); do mkdir "/tmp/test-fs/$i" for j in $(seq 1 10240); do echo TEST-CONTENT > "/tmp/test-fs/$i/$j" done & done; wait } do_test() { read_worker() { sleep 1 tar -cv "$1" &>/dev/null } read_in_all() { cd "/tmp/test-fs" && ls for i in $(seq 1 512); do (exec sh -c 'echo "$PPID"') > "/sys/fs/cgroup/benchmark/$i/cgroup.procs" read_worker "$i" & done; wait } for i in $(seq 1 512); do mkdir -p "/sys/fs/cgroup/benchmark/$i" done echo +memory > /sys/fs/cgroup/benchmark/cgroup.subtree_control echo 512M > /sys/fs/cgroup/benchmark/memory.max echo 3 > /proc/sys/vm/drop_caches time read_in_all } Above script simulates compression of small files in multiple cgroups with memory pressure. Run prepare() then do_test for 6 times: Before: real 0m7.762s user 0m11.340s sys 3m11.224s real 0m8.123s user 0m11.548s sys 3m2.549s real 0m7.736s user 0m11.515s sys 3m11.171s real 0m8.539s user 0m11.508s sys 3m7.618s real 0m7.928s user 0m11.349s sys 3m13.063s real 0m8.105s user 0m11.128s sys 3m14.313s After this commit (about ~15% faster): real 0m6.953s user 0m11.327s sys 2m42.912s real 0m7.453s user 0m11.343s sys 2m51.942s real 0m6.916s user 0m11.269s sys 2m43.957s real 0m6.894s user 0m11.528s sys 2m45.346s real 0m6.911s user 0m11.095s sys 2m43.168s real 0m6.773s user 0m11.518s sys 2m40.774s Signed-off-by: Kairui Song --- drivers/android/binder_alloc.c | 1 - fs/inode.c | 1 - fs/xfs/xfs_qm.c | 1 - include/linux/list_lru.h | 6 +- mm/list_lru.c | 215 +++++++++++++++++++-------------- mm/memcontrol.c | 7 +- mm/workingset.c | 1 - mm/zswap.c | 5 +- 8 files changed, 134 insertions(+), 103 deletions(-) diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index b3acbc4174fb..86bbe40f4bcd 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -1106,7 +1106,6 @@ enum lru_status binder_alloc_free_page(struct list_head *item, mmput_async(mm); __free_page(page_to_free); - spin_lock(lock); return LRU_REMOVED_RETRY; err_invalid_vma: diff --git a/fs/inode.c b/fs/inode.c index 471ae4a31549..b95d80cb140b 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -932,7 +932,6 @@ static enum lru_status inode_lru_isolate(struct list_head *item, mm_account_reclaimed_pages(reap); } inode_unpin_lru_isolating(inode); - spin_lock(lru_lock); return LRU_RETRY; } diff --git a/fs/xfs/xfs_qm.c b/fs/xfs/xfs_qm.c index 7e2307921deb..665d26990b78 100644 --- a/fs/xfs/xfs_qm.c +++ b/fs/xfs/xfs_qm.c @@ -496,7 +496,6 @@ xfs_qm_dquot_isolate( trace_xfs_dqreclaim_busy(dqp); XFS_STATS_INC(dqp->q_mount, xs_qm_dqreclaim_misses); xfs_dqunlock(dqp); - spin_lock(lru_lock); return LRU_RETRY; } diff --git a/include/linux/list_lru.h b/include/linux/list_lru.h index eba93f6511f3..10ba9a54d42c 100644 --- a/include/linux/list_lru.h +++ b/include/linux/list_lru.h @@ -32,6 +32,8 @@ struct list_lru_one { struct list_head list; /* may become negative during memcg reparenting */ long nr_items; + /* protects all fields above */ + spinlock_t lock; }; struct list_lru_memcg { @@ -41,11 +43,9 @@ struct list_lru_memcg { }; struct list_lru_node { - /* protects all lists on the node, including per cgroup */ - spinlock_t lock; /* global list, used for the root cgroup in cgroup aware lrus */ struct list_lru_one lru; - long nr_items; + atomic_long_t nr_items; } ____cacheline_aligned_in_smp; struct list_lru { diff --git a/mm/list_lru.c b/mm/list_lru.c index 172b16146e15..6d1c187d9019 100644 --- a/mm/list_lru.c +++ b/mm/list_lru.c @@ -61,18 +61,48 @@ list_lru_from_memcg_idx(struct list_lru *lru, int nid, int idx) } static inline struct list_lru_one * -list_lru_from_memcg(struct list_lru *lru, int nid, struct mem_cgroup *memcg) +lock_list_lru_of_memcg(struct list_lru *lru, int nid, struct mem_cgroup *memcg, + bool irq, bool skip_empty) { struct list_lru_one *l; + rcu_read_lock(); again: l = list_lru_from_memcg_idx(lru, nid, memcg_kmem_id(memcg)); - if (likely(l)) - return l; - - memcg = parent_mem_cgroup(memcg); + if (likely(l)) { + if (irq) + spin_lock_irq(&l->lock); + else + spin_lock(&l->lock); + if (likely(READ_ONCE(l->nr_items) != LONG_MIN)) { + WARN_ON(l->nr_items < 0); + rcu_read_unlock(); + return l; + } + if (irq) + spin_unlock_irq(&l->lock); + else + spin_unlock(&l->lock); + } + /* + * Caller may simply bail out if raced with reparenting or + * may iterate through the list_lru and expect empty slots. + */ + if (skip_empty) { + rcu_read_unlock(); + return NULL; + } VM_WARN_ON(!css_is_dying(&memcg->css)); + memcg = parent_mem_cgroup(memcg); goto again; } + +static inline void unlock_list_lru(struct list_lru_one *l, bool irq_off) +{ + if (irq_off) + spin_unlock_irq(&l->lock); + else + spin_unlock(&l->lock); +} #else static void list_lru_register(struct list_lru *lru) { @@ -99,31 +129,48 @@ list_lru_from_memcg_idx(struct list_lru *lru, int nid, int idx) } static inline struct list_lru_one * -list_lru_from_memcg(struct list_lru *lru, int nid, int idx) +lock_list_lru_of_memcg(struct list_lru *lru, int nid, struct mem_cgroup *memcg, + bool irq, bool skip_empty) { - return &lru->node[nid].lru; + struct list_lru_one *l = &lru->node[nid].lru; + + if (irq) + spin_lock_irq(&l->lock); + else + spin_lock(&l->lock); + + return l; +} + +static inline void unlock_list_lru(struct list_lru_one *l, bool irq_off) +{ + if (irq_off) + spin_unlock_irq(&l->lock); + else + spin_unlock(&l->lock); } #endif /* CONFIG_MEMCG */ /* The caller must ensure the memcg lifetime. */ bool list_lru_add(struct list_lru *lru, struct list_head *item, int nid, - struct mem_cgroup *memcg) + struct mem_cgroup *memcg) { struct list_lru_node *nlru = &lru->node[nid]; struct list_lru_one *l; - spin_lock(&nlru->lock); + l = lock_list_lru_of_memcg(lru, nid, memcg, false, false); + if (!l) + return false; if (list_empty(item)) { - l = list_lru_from_memcg(lru, nid, memcg); list_add_tail(item, &l->list); /* Set shrinker bit if the first element was added */ if (!l->nr_items++) set_shrinker_bit(memcg, nid, lru_shrinker_id(lru)); - nlru->nr_items++; - spin_unlock(&nlru->lock); + unlock_list_lru(l, false); + atomic_long_inc(&nlru->nr_items); return true; } - spin_unlock(&nlru->lock); + unlock_list_lru(l, false); return false; } @@ -146,24 +193,23 @@ EXPORT_SYMBOL_GPL(list_lru_add_obj); /* The caller must ensure the memcg lifetime. */ bool list_lru_del(struct list_lru *lru, struct list_head *item, int nid, - struct mem_cgroup *memcg) + struct mem_cgroup *memcg) { struct list_lru_node *nlru = &lru->node[nid]; struct list_lru_one *l; - - spin_lock(&nlru->lock); + l = lock_list_lru_of_memcg(lru, nid, memcg, false, false); + if (!l) + return false; if (!list_empty(item)) { - l = list_lru_from_memcg(lru, nid, memcg); list_del_init(item); l->nr_items--; - nlru->nr_items--; - spin_unlock(&nlru->lock); + unlock_list_lru(l, false); + atomic_long_dec(&nlru->nr_items); return true; } - spin_unlock(&nlru->lock); + unlock_list_lru(l, false); return false; } -EXPORT_SYMBOL_GPL(list_lru_del); bool list_lru_del_obj(struct list_lru *lru, struct list_head *item) { @@ -220,25 +266,24 @@ unsigned long list_lru_count_node(struct list_lru *lru, int nid) struct list_lru_node *nlru; nlru = &lru->node[nid]; - return nlru->nr_items; + return atomic_long_read(&nlru->nr_items); } EXPORT_SYMBOL_GPL(list_lru_count_node); static unsigned long -__list_lru_walk_one(struct list_lru *lru, int nid, int memcg_idx, +__list_lru_walk_one(struct list_lru *lru, int nid, struct mem_cgroup *memcg, list_lru_walk_cb isolate, void *cb_arg, - unsigned long *nr_to_walk) + unsigned long *nr_to_walk, bool irq_off) { struct list_lru_node *nlru = &lru->node[nid]; - struct list_lru_one *l; + struct list_lru_one *l = NULL; struct list_head *item, *n; unsigned long isolated = 0; restart: - l = list_lru_from_memcg_idx(lru, nid, memcg_idx); + l = lock_list_lru_of_memcg(lru, nid, memcg, irq_off, true); if (!l) - goto out; - + return isolated; list_for_each_safe(item, n, &l->list) { enum lru_status ret; @@ -250,19 +295,20 @@ __list_lru_walk_one(struct list_lru *lru, int nid, int memcg_idx, break; --*nr_to_walk; - ret = isolate(item, l, &nlru->lock, cb_arg); + ret = isolate(item, l, &l->lock, cb_arg); switch (ret) { + /* + * LRU_RETRY and LRU_REMOVED_RETRY will drop the lru lock, + * the list traversal will be invalid and have to restart from + * scratch. + */ + case LRU_RETRY: + goto restart; case LRU_REMOVED_RETRY: - assert_spin_locked(&nlru->lock); fallthrough; case LRU_REMOVED: isolated++; - nlru->nr_items--; - /* - * If the lru lock has been dropped, our list - * traversal is now invalid and so we have to - * restart from scratch. - */ + atomic_long_dec(&nlru->nr_items); if (ret == LRU_REMOVED_RETRY) goto restart; break; @@ -271,21 +317,15 @@ __list_lru_walk_one(struct list_lru *lru, int nid, int memcg_idx, break; case LRU_SKIP: break; - case LRU_RETRY: - /* - * The lru lock has been dropped, our list traversal is - * now invalid and so we have to restart from scratch. - */ - assert_spin_locked(&nlru->lock); - goto restart; case LRU_STOP: - assert_spin_locked(&nlru->lock); + assert_spin_locked(&l->lock); goto out; default: BUG(); } } out: + unlock_list_lru(l, irq_off); return isolated; } @@ -294,14 +334,8 @@ list_lru_walk_one(struct list_lru *lru, int nid, struct mem_cgroup *memcg, list_lru_walk_cb isolate, void *cb_arg, unsigned long *nr_to_walk) { - struct list_lru_node *nlru = &lru->node[nid]; - unsigned long ret; - - spin_lock(&nlru->lock); - ret = __list_lru_walk_one(lru, nid, memcg_kmem_id(memcg), isolate, - cb_arg, nr_to_walk); - spin_unlock(&nlru->lock); - return ret; + return __list_lru_walk_one(lru, nid, memcg, isolate, + cb_arg, nr_to_walk, false); } EXPORT_SYMBOL_GPL(list_lru_walk_one); @@ -310,14 +344,8 @@ list_lru_walk_one_irq(struct list_lru *lru, int nid, struct mem_cgroup *memcg, list_lru_walk_cb isolate, void *cb_arg, unsigned long *nr_to_walk) { - struct list_lru_node *nlru = &lru->node[nid]; - unsigned long ret; - - spin_lock_irq(&nlru->lock); - ret = __list_lru_walk_one(lru, nid, memcg_kmem_id(memcg), isolate, - cb_arg, nr_to_walk); - spin_unlock_irq(&nlru->lock); - return ret; + return __list_lru_walk_one(lru, nid, memcg, isolate, + cb_arg, nr_to_walk, true); } unsigned long list_lru_walk_node(struct list_lru *lru, int nid, @@ -332,16 +360,21 @@ unsigned long list_lru_walk_node(struct list_lru *lru, int nid, #ifdef CONFIG_MEMCG if (*nr_to_walk > 0 && list_lru_memcg_aware(lru)) { struct list_lru_memcg *mlru; + struct mem_cgroup *memcg; unsigned long index; xa_for_each(&lru->xa, index, mlru) { - struct list_lru_node *nlru = &lru->node[nid]; - - spin_lock(&nlru->lock); - isolated += __list_lru_walk_one(lru, nid, index, + rcu_read_lock(); + memcg = mem_cgroup_from_id(index); + if (!mem_cgroup_tryget(memcg)) { + rcu_read_unlock(); + continue; + } + rcu_read_unlock(); + isolated += __list_lru_walk_one(lru, nid, memcg, isolate, cb_arg, - nr_to_walk); - spin_unlock(&nlru->lock); + nr_to_walk, false); + mem_cgroup_put(memcg); if (*nr_to_walk <= 0) break; @@ -353,14 +386,19 @@ unsigned long list_lru_walk_node(struct list_lru *lru, int nid, } EXPORT_SYMBOL_GPL(list_lru_walk_node); -static void init_one_lru(struct list_lru_one *l) +static void init_one_lru(struct list_lru *lru, struct list_lru_one *l) { INIT_LIST_HEAD(&l->list); + spin_lock_init(&l->lock); l->nr_items = 0; +#ifdef CONFIG_LOCKDEP + if (lru->key) + lockdep_set_class(&l->lock, lru->key); +#endif } #ifdef CONFIG_MEMCG -static struct list_lru_memcg *memcg_init_list_lru_one(gfp_t gfp) +static struct list_lru_memcg *memcg_init_list_lru_one(struct list_lru *lru, gfp_t gfp) { int nid; struct list_lru_memcg *mlru; @@ -370,7 +408,7 @@ static struct list_lru_memcg *memcg_init_list_lru_one(gfp_t gfp) return NULL; for_each_node(nid) - init_one_lru(&mlru->node[nid]); + init_one_lru(lru, &mlru->node[nid]); return mlru; } @@ -398,28 +436,27 @@ static void memcg_destroy_list_lru(struct list_lru *lru) xas_unlock_irq(&xas); } -static void memcg_reparent_list_lru_node(struct list_lru *lru, int nid, - struct list_lru_one *src, - struct mem_cgroup *dst_memcg) +static void memcg_reparent_list_lru_one(struct list_lru *lru, int nid, + struct list_lru_one *src, + struct mem_cgroup *dst_memcg) { - struct list_lru_node *nlru = &lru->node[nid]; + int dst_idx = dst_memcg->kmemcg_id; struct list_lru_one *dst; - /* - * Since list_lru_{add,del} may be called under an IRQ-safe lock, - * we have to use IRQ-safe primitives here to avoid deadlock. - */ - spin_lock_irq(&nlru->lock); - dst = list_lru_from_memcg_idx(lru, nid, memcg_kmem_id(dst_memcg)); + spin_lock_irq(&src->lock); + dst = list_lru_from_memcg_idx(lru, nid, dst_idx); + spin_lock_nested(&dst->lock, SINGLE_DEPTH_NESTING); list_splice_init(&src->list, &dst->list); - if (src->nr_items) { dst->nr_items += src->nr_items; set_shrinker_bit(dst_memcg, nid, lru_shrinker_id(lru)); - src->nr_items = 0; } - spin_unlock_irq(&nlru->lock); + /* Mark the list_lru_one dead */ + src->nr_items = LONG_MIN; + + spin_unlock(&dst->lock); + spin_unlock_irq(&src->lock); } void memcg_reparent_list_lrus(struct mem_cgroup *memcg, struct mem_cgroup *parent) @@ -448,7 +485,7 @@ void memcg_reparent_list_lrus(struct mem_cgroup *memcg, struct mem_cgroup *paren * safe to reparent. */ for_each_node(i) - memcg_reparent_list_lru_node(lru, i, &mlru->node[i], parent); + memcg_reparent_list_lru_one(lru, i, &mlru->node[i], parent); /* * Here all list_lrus corresponding to the cgroup are guaranteed @@ -497,7 +534,7 @@ int memcg_list_lru_alloc(struct mem_cgroup *memcg, struct list_lru *lru, parent = parent_mem_cgroup(pos); } - mlru = memcg_init_list_lru_one(gfp); + mlru = memcg_init_list_lru_one(lru, gfp); if (!mlru) return -ENOMEM; xas_set(&xas, pos->kmemcg_id); @@ -544,14 +581,8 @@ int __list_lru_init(struct list_lru *lru, bool memcg_aware, struct shrinker *shr if (!lru->node) return -ENOMEM; - for_each_node(i) { - spin_lock_init(&lru->node[i].lock); -#ifdef CONFIG_LOCKDEP - if (lru->key) - lockdep_set_class(&lru->node[i].lock, lru->key); -#endif - init_one_lru(&lru->node[i].lru); - } + for_each_node(i) + init_one_lru(lru, &lru->node[i].lru); memcg_init_list_lru(lru, memcg_aware); list_lru_register(lru); diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 8e90aa026c47..f421dfcfe8a1 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3098,8 +3098,13 @@ static void memcg_offline_kmem(struct mem_cgroup *memcg) if (!parent) parent = root_mem_cgroup; - memcg_reparent_objcgs(memcg, parent); memcg_reparent_list_lrus(memcg, parent); + + /* + * Objcg's reparenting must be after list_lru's, make sure list_lru + * helpers won't use parent's list_lru until child is drained. + */ + memcg_reparent_objcgs(memcg, parent); } #ifdef CONFIG_CGROUP_WRITEBACK diff --git a/mm/workingset.c b/mm/workingset.c index df3937c5eedc..8c4b6738dcad 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -777,7 +777,6 @@ static enum lru_status shadow_lru_isolate(struct list_head *item, ret = LRU_REMOVED_RETRY; out: cond_resched(); - spin_lock_irq(lru_lock); return ret; } diff --git a/mm/zswap.c b/mm/zswap.c index 95a28301b7cd..cb37a25fd00c 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -706,9 +706,9 @@ static void zswap_lru_add(struct list_lru *list_lru, struct zswap_entry *entry) * Note that it is safe to use rcu_read_lock() here, even in the face of * concurrent memcg offlining: * - * 1. list_lru_add() is called before list_lru_memcg is erased. The + * 1. list_lru_add() is called before list_lru_one is dead. The * new entry will be reparented to memcg's parent's list_lru. - * 2. list_lru_add() is called after list_lru_memcg is erased. The + * 2. list_lru_add() is called after list_lru_one is dead. The * new entry will be added directly to memcg's parent's list_lru. * * Similar reasoning holds for list_lru_del(). @@ -1173,7 +1173,6 @@ static enum lru_status shrink_memcg_cb(struct list_head *item, struct list_lru_o zswap_written_back_pages++; } - spin_lock(lock); return ret; } From patchwork Wed Sep 25 17:10:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13812341 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 7D662CCF9E8 for ; Wed, 25 Sep 2024 17:10:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 162746B0082; Wed, 25 Sep 2024 13:10:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 011436B00BE; Wed, 25 Sep 2024 13:10:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D94AF6B00BF; Wed, 25 Sep 2024 13:10:51 -0400 (EDT) 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 B54C16B00BD for ; Wed, 25 Sep 2024 13:10:51 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 68A061A04E5 for ; Wed, 25 Sep 2024 17:10:51 +0000 (UTC) X-FDA: 82603900302.09.1CE1022 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by imf27.hostedemail.com (Postfix) with ESMTP id 85E184000E for ; Wed, 25 Sep 2024 17:10:49 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Inj0Spkm; spf=pass (imf27.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.181 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=1727284129; 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=tHDnLKuWCJO8lD59bH5pDYUmAjiCtEIbfbAcM4YyCyY=; b=UnSwJzTCqN+u2HEg90ETbnN677CzwFN+XgNaHTVNWf7F1zl5nOYGG8J5BaG944SSe2CtT6 4f7hTMkDXiPbPzphWF6NdbhOnN5GQYP5ENEViLbf2/SLTb8tiDkI4vRAEI90swGB3xOsij C1HW228zQZlz8jOP/MGXJnq/vvoWb8M= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727284129; a=rsa-sha256; cv=none; b=HaV3K03czNxiXEuW7dZpJO7xA2nAC8FASA9gXrbraGgrBT0hYuiA7dIOU6gIUhv5fPxd4B JVOuEgyHUx+Udh87gUjPbIQvH9arL2pAM8MA1ypVJlhR94OkHsH0zyPx4MlMtJNBJ1GjuE 9qm/WzkDByNEQ1GbUl2Jgy70towBP2A= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Inj0Spkm; spf=pass (imf27.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.181 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-71798a15ce5so953969b3a.0 for ; Wed, 25 Sep 2024 10:10:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727284248; x=1727889048; 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=tHDnLKuWCJO8lD59bH5pDYUmAjiCtEIbfbAcM4YyCyY=; b=Inj0SpkmJtneLD/uWfj+uEfGo4xD7eKy2UJezl1YXlV/klQzcPVjL8/Y4dFQrYeHpy K01PnpoyFEbaQnFjxppocgSGGu4Qru9FVgPognkAMi8wwcRGRWPZO0XuLkegvHwv4DSq rBYdpG59mX1aIrcwPT6vCsQzIEQ2tib007dZX+M0doulDfoHHA/FssvP1Y+XN2/kpf87 Cwi7mQCPfwYJVx4Y64bLPpU0lyyiMhN9Y13UmmSDeAGh/vYdo/1fXK90Srd6Y5K+DVdx akTCu2liICwYpb0ssAaF8CxpjXLlQNLBC5fUKLXkjFiymc1hvDswzzDcaBiSJeJ6A0Br xgYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727284248; x=1727889048; 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=tHDnLKuWCJO8lD59bH5pDYUmAjiCtEIbfbAcM4YyCyY=; b=uVH9WcXyDk+inqtm/aErdutm3Zz/Wb/NJR6zjgvIFaMRNHdEv3JOGR8PemLguqGumq euuT+vkqhUtNsVuuLTPxQELoM4mJ/PPmWhRGjKIPMgsRrttyXvAUTPEIlD+4WRdbml/f Jw7KawLqCTSTr4EZGv+4lTv9Cp08wak9WmB7Wg7/CEt/UGYKuhdr7mqmQ3do+jyuUJPj Hg8oEMMc3PUEMJc3hQuVANQEZnBG9ZFaWzmVIdpPwp8/T0Hglx1t98n2acW6ZVGdJzv3 ZO3XImRR+pp8jz1M0yrp0yd5+k3eGO/42gUy9vi+otogCEn28Yewzxy1+G/XWfOIHPc8 aq5A== X-Gm-Message-State: AOJu0YxwEJv2I8BcHo0J4DfwEgx8PLwllxthNDLuIeSa4pNNyBRF8r43 1zV+Ffjlj8EdTeRWfPSh3F/QtKT/pUKVAyI53ULh94M6MieghNH27cog6j/Q X-Google-Smtp-Source: AGHT+IHl5TlJGqUV7QZcRMHcoyLSb9layNcgIUW2Mhg5L2SzE46tJMBi/RiISzclYIlyjHoys1XewQ== X-Received: by 2002:a05:6a20:4391:b0:1d2:e793:cc0 with SMTP id adf61e73a8af0-1d4ebe3560dmr487927637.7.1727284247785; Wed, 25 Sep 2024 10:10:47 -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.44 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 25 Sep 2024 10:10:47 -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 6/6] mm/list_lru: Simplify the list_lru walk callback function Date: Thu, 26 Sep 2024 01:10:20 +0800 Message-ID: <20240925171020.32142-7-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-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 85E184000E X-Stat-Signature: 4tkxirppjgixtwb6kb79wac79e9k8jyi X-HE-Tag: 1727284249-310215 X-HE-Meta: U2FsdGVkX19A4Q95CdQVZsQBrCsyhmwHGkGdcGPtvhlQetG6GFBCgrab3Q9kUntpycJL30uhNYRtw+pRbP1QG7RPvQiHSqVrjKow8IFK7hJh7WJi+j2ttjj1knENBdhF10i3n/X+FzsPz0OYgsCtYaxMDFMZ4DaHqS+hAJckgFHtdw/s87gJ3O/b4vfsxHMhfennXCuWc1aXnUZ8aoT41Y8exbYkUwF+gJ1D96oCPd+lLjhhBmLox5luOGb2YuRrQVxPCf5X8bomsShc5RxtnyysCbXjV5ZreXcgxLgkR/OCSUgIcnBLAe7tJKSgqV5kQ3CFYVoqU/hCzf6cgbOxiS1M5+lZv65txxmsmCAJogH+MuApmHMcMD6gq7XiB+zR/vwVeeVSm3MbXzpxZ8fN/zwriCvsfKaotFt/V6gM8KLZFNe0nFFLbxA4VYmRfCEyI7Y+GtEm3g33STc/gBiflg6/bv/uvr8tXpHO4w7iajx3gfNllZI8QdV3tAOuc0k7FRKI9EWg9yPlK48/jJFtgoLqiyMAmWdSdoBfo6g0y3XD29Gv2hy8jpiu09AIH/4ASkZaofwln+oHISG/AcE5t3P5hHyQASIHZpICzH2YfO8m8ZB2JGoCYWEeYrQtZlCmim0qJ8aXDWJFDb1c9wH+68L9anXgqSIZdJoSyO9XgcDl7OU1ZSMQ1K3lbbadpkT8QTiWuoRW7kACYbyb6BSbU5DsyeNm7GJDYzR8+32W2qb3ltT4ulJQZccg2wam84ev9eIDcSPL9P4ZXTcHU2YXcLzTA8tiNFBgJ1ABGBhNKgAPz9rFAjSE2mX59L1PETFrrTz38SCpbfL4w/st+OjAQcUqFokDnTYxgBa4GvFaVxdPBq//v8sia76GDy2vFhg6KzVPXsi4J9jAGsfxiZNuWcnO46/onMNwnMTYRAOgPRiJincyk41UNv8UaEvs8E9G8DazrsWjsOGSr1xxWPu avh8xRWO 1Mh+qp1zaeYQBsPxw5w9MQ2roKjbOLfG/almJR8oc+eXn6fB+Ulsw7YUEv8zDn9ryUojp7doNWnHG1zhBUB8A/JrEIHAKS9UWb4rQiffJsxGpJHCPcZRZPyPL3jJR3zH0g5ikr2NlH9fx++yaPvDzKM4AIt9CD7ULdA9+L4p6fn2aUdByEcWAxCE+Vave3otYT8RBHOqW3BsDGTLHklxB1D+xJrHAK2RVX5CUYFkcEFxU9mbsj80AMoOI3q3Q15DsLTOPkXMihJoc0ymPnVfyTddnYcJxCWKrPoxNOTEbnxHKUSg0HN1EPeBg4RE5fjp85A0tykv/VdlR62HCnoH93bVcnoulFvuXUI4Er9xQZ/v/9xY2oV79cR/ar3qnfFTUScSRpkHHiF34vaqq0R5e9C4rZ197eLZdEN8tdvaJ7INcPt/SJDOUsEU1G0Os2nxyenm9/TzNIjHX6OQdWwM0KJBzXGTnyWkTMVhuok+i3PCWSrlRFCEt6/waUz1XlLfa1z4e4qnw19vEKSPgv2WeUuZNBTwe86e3QqH552Qq+mNoizjAtqjrLWXMSF0UHzlj+CGH 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 Now isolation no longer takes the list_lru global node lock, only use the per-cgroup lock instead. And this lock is inside the list_lru_one being walked, no longer needed to pass the lock explicitly. Signed-off-by: Kairui Song --- drivers/android/binder_alloc.c | 7 +++---- drivers/android/binder_alloc.h | 2 +- fs/dcache.c | 4 ++-- fs/gfs2/quota.c | 2 +- fs/inode.c | 4 ++-- fs/nfs/nfs42xattr.c | 4 ++-- fs/nfsd/filecache.c | 5 +---- fs/xfs/xfs_buf.c | 2 -- fs/xfs/xfs_qm.c | 5 ++--- include/linux/list_lru.h | 2 +- mm/list_lru.c | 2 +- mm/workingset.c | 15 +++++++-------- mm/zswap.c | 4 ++-- 13 files changed, 25 insertions(+), 33 deletions(-) diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index 86bbe40f4bcd..a738e7745865 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -1047,7 +1047,7 @@ void binder_alloc_vma_close(struct binder_alloc *alloc) /** * binder_alloc_free_page() - shrinker callback to free pages * @item: item to free - * @lock: lock protecting the item + * @lru: list_lru instance of the item * @cb_arg: callback argument * * Called from list_lru_walk() in binder_shrink_scan() to free @@ -1055,9 +1055,8 @@ void binder_alloc_vma_close(struct binder_alloc *alloc) */ enum lru_status binder_alloc_free_page(struct list_head *item, struct list_lru_one *lru, - spinlock_t *lock, void *cb_arg) - __must_hold(lock) + __must_hold(&lru->lock) { struct binder_lru_page *page = container_of(item, typeof(*page), lru); struct binder_alloc *alloc = page->alloc; @@ -1092,7 +1091,7 @@ enum lru_status binder_alloc_free_page(struct list_head *item, list_lru_isolate(lru, item); spin_unlock(&alloc->lock); - spin_unlock(lock); + spin_unlock(&lru->lock); if (vma) { trace_binder_unmap_user_start(alloc, index); diff --git a/drivers/android/binder_alloc.h b/drivers/android/binder_alloc.h index 70387234477e..c02c8ebcb466 100644 --- a/drivers/android/binder_alloc.h +++ b/drivers/android/binder_alloc.h @@ -118,7 +118,7 @@ static inline void binder_selftest_alloc(struct binder_alloc *alloc) {} #endif enum lru_status binder_alloc_free_page(struct list_head *item, struct list_lru_one *lru, - spinlock_t *lock, void *cb_arg); + void *cb_arg); struct binder_buffer *binder_alloc_new_buf(struct binder_alloc *alloc, size_t data_size, size_t offsets_size, diff --git a/fs/dcache.c b/fs/dcache.c index 0f6b16ba30d0..d7f6866f5f52 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -1089,7 +1089,7 @@ void shrink_dentry_list(struct list_head *list) } static enum lru_status dentry_lru_isolate(struct list_head *item, - struct list_lru_one *lru, spinlock_t *lru_lock, void *arg) + struct list_lru_one *lru, void *arg) { struct list_head *freeable = arg; struct dentry *dentry = container_of(item, struct dentry, d_lru); @@ -1170,7 +1170,7 @@ long prune_dcache_sb(struct super_block *sb, struct shrink_control *sc) } static enum lru_status dentry_lru_isolate_shrink(struct list_head *item, - struct list_lru_one *lru, spinlock_t *lru_lock, void *arg) + struct list_lru_one *lru, void *arg) { struct list_head *freeable = arg; struct dentry *dentry = container_of(item, struct dentry, d_lru); diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index 2e6bc77f4f81..72b48f6f5561 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -149,7 +149,7 @@ static void gfs2_qd_list_dispose(struct list_head *list) static enum lru_status gfs2_qd_isolate(struct list_head *item, - struct list_lru_one *lru, spinlock_t *lru_lock, void *arg) + struct list_lru_one *lru, void *arg) { struct list_head *dispose = arg; struct gfs2_quota_data *qd = diff --git a/fs/inode.c b/fs/inode.c index b95d80cb140b..e88c199111ea 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -879,7 +879,7 @@ void invalidate_inodes(struct super_block *sb) * with this flag set because they are the inodes that are out of order. */ static enum lru_status inode_lru_isolate(struct list_head *item, - struct list_lru_one *lru, spinlock_t *lru_lock, void *arg) + struct list_lru_one *lru, void *arg) { struct list_head *freeable = arg; struct inode *inode = container_of(item, struct inode, i_lru); @@ -921,7 +921,7 @@ static enum lru_status inode_lru_isolate(struct list_head *item, if (inode_has_buffers(inode) || !mapping_empty(&inode->i_data)) { inode_pin_lru_isolating(inode); spin_unlock(&inode->i_lock); - spin_unlock(lru_lock); + spin_unlock(&lru->lock); if (remove_inode_buffers(inode)) { unsigned long reap; reap = invalidate_mapping_pages(&inode->i_data, 0, -1); diff --git a/fs/nfs/nfs42xattr.c b/fs/nfs/nfs42xattr.c index b6e3d8f77b91..37d79400e5f4 100644 --- a/fs/nfs/nfs42xattr.c +++ b/fs/nfs/nfs42xattr.c @@ -802,7 +802,7 @@ static struct shrinker *nfs4_xattr_large_entry_shrinker; static enum lru_status cache_lru_isolate(struct list_head *item, - struct list_lru_one *lru, spinlock_t *lru_lock, void *arg) + struct list_lru_one *lru, void *arg) { struct list_head *dispose = arg; struct inode *inode; @@ -867,7 +867,7 @@ nfs4_xattr_cache_count(struct shrinker *shrink, struct shrink_control *sc) static enum lru_status entry_lru_isolate(struct list_head *item, - struct list_lru_one *lru, spinlock_t *lru_lock, void *arg) + struct list_lru_one *lru, void *arg) { struct list_head *dispose = arg; struct nfs4_xattr_bucket *bucket; diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index 24e8f1fbcebb..18d82e258853 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -459,7 +459,6 @@ void nfsd_file_net_dispose(struct nfsd_net *nn) * nfsd_file_lru_cb - Examine an entry on the LRU list * @item: LRU entry to examine * @lru: controlling LRU - * @lock: LRU list lock (unused) * @arg: dispose list * * Return values: @@ -469,9 +468,7 @@ void nfsd_file_net_dispose(struct nfsd_net *nn) */ static enum lru_status nfsd_file_lru_cb(struct list_head *item, struct list_lru_one *lru, - spinlock_t *lock, void *arg) - __releases(lock) - __acquires(lock) + void *arg) { struct list_head *head = arg; struct nfsd_file *nf = list_entry(item, struct nfsd_file, nf_lru); diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c index aa4dbda7b536..43b914c1f621 100644 --- a/fs/xfs/xfs_buf.c +++ b/fs/xfs/xfs_buf.c @@ -1857,7 +1857,6 @@ static enum lru_status xfs_buftarg_drain_rele( struct list_head *item, struct list_lru_one *lru, - spinlock_t *lru_lock, void *arg) { @@ -1956,7 +1955,6 @@ static enum lru_status xfs_buftarg_isolate( struct list_head *item, struct list_lru_one *lru, - spinlock_t *lru_lock, void *arg) { struct xfs_buf *bp = container_of(item, struct xfs_buf, b_lru); diff --git a/fs/xfs/xfs_qm.c b/fs/xfs/xfs_qm.c index 665d26990b78..8413ac368042 100644 --- a/fs/xfs/xfs_qm.c +++ b/fs/xfs/xfs_qm.c @@ -412,9 +412,8 @@ static enum lru_status xfs_qm_dquot_isolate( struct list_head *item, struct list_lru_one *lru, - spinlock_t *lru_lock, void *arg) - __releases(lru_lock) __acquires(lru_lock) + __releases(&lru->lock) __acquires(&lru->lock) { struct xfs_dquot *dqp = container_of(item, struct xfs_dquot, q_lru); @@ -460,7 +459,7 @@ xfs_qm_dquot_isolate( trace_xfs_dqreclaim_dirty(dqp); /* we have to drop the LRU lock to flush the dquot */ - spin_unlock(lru_lock); + spin_unlock(&lru->lock); error = xfs_qm_dqflush(dqp, &bp); if (error) diff --git a/include/linux/list_lru.h b/include/linux/list_lru.h index 10ba9a54d42c..05c166811f6b 100644 --- a/include/linux/list_lru.h +++ b/include/linux/list_lru.h @@ -184,7 +184,7 @@ void list_lru_isolate_move(struct list_lru_one *list, struct list_head *item, struct list_head *head); typedef enum lru_status (*list_lru_walk_cb)(struct list_head *item, - struct list_lru_one *list, spinlock_t *lock, void *cb_arg); + struct list_lru_one *list, void *cb_arg); /** * list_lru_walk_one: walk a @lru, isolating and disposing freeable items. diff --git a/mm/list_lru.c b/mm/list_lru.c index 6d1c187d9019..79c2d21504a2 100644 --- a/mm/list_lru.c +++ b/mm/list_lru.c @@ -295,7 +295,7 @@ __list_lru_walk_one(struct list_lru *lru, int nid, struct mem_cgroup *memcg, break; --*nr_to_walk; - ret = isolate(item, l, &l->lock, cb_arg); + ret = isolate(item, l, cb_arg); switch (ret) { /* * LRU_RETRY and LRU_REMOVED_RETRY will drop the lru lock, diff --git a/mm/workingset.c b/mm/workingset.c index 8c4b6738dcad..4b58ef535a17 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -712,8 +712,7 @@ static unsigned long count_shadow_nodes(struct shrinker *shrinker, static enum lru_status shadow_lru_isolate(struct list_head *item, struct list_lru_one *lru, - spinlock_t *lru_lock, - void *arg) __must_hold(lru_lock) + void *arg) __must_hold(lru->lock) { struct xa_node *node = container_of(item, struct xa_node, private_list); struct address_space *mapping; @@ -722,20 +721,20 @@ static enum lru_status shadow_lru_isolate(struct list_head *item, /* * Page cache insertions and deletions synchronously maintain * the shadow node LRU under the i_pages lock and the - * lru_lock. Because the page cache tree is emptied before - * the inode can be destroyed, holding the lru_lock pins any + * &lru->lock. Because the page cache tree is emptied before + * the inode can be destroyed, holding the &lru->lock pins any * address_space that has nodes on the LRU. * * We can then safely transition to the i_pages lock to * pin only the address_space of the particular node we want - * to reclaim, take the node off-LRU, and drop the lru_lock. + * to reclaim, take the node off-LRU, and drop the &lru->lock. */ mapping = container_of(node->array, struct address_space, i_pages); /* Coming from the list, invert the lock order */ if (!xa_trylock(&mapping->i_pages)) { - spin_unlock_irq(lru_lock); + spin_unlock_irq(&lru->lock); ret = LRU_RETRY; goto out; } @@ -744,7 +743,7 @@ static enum lru_status shadow_lru_isolate(struct list_head *item, if (mapping->host != NULL) { if (!spin_trylock(&mapping->host->i_lock)) { xa_unlock(&mapping->i_pages); - spin_unlock_irq(lru_lock); + spin_unlock_irq(&lru->lock); ret = LRU_RETRY; goto out; } @@ -753,7 +752,7 @@ static enum lru_status shadow_lru_isolate(struct list_head *item, list_lru_isolate(lru, item); __dec_node_page_state(virt_to_page(node), WORKINGSET_NODES); - spin_unlock(lru_lock); + spin_unlock(&lru->lock); /* * The nodes should only contain one or more shadow entries, diff --git a/mm/zswap.c b/mm/zswap.c index cb37a25fd00c..efad4e941e44 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1096,7 +1096,7 @@ static int zswap_writeback_entry(struct zswap_entry *entry, * for reclaim by this ratio. */ static enum lru_status shrink_memcg_cb(struct list_head *item, struct list_lru_one *l, - spinlock_t *lock, void *arg) + void *arg) { struct zswap_entry *entry = container_of(item, struct zswap_entry, lru); bool *encountered_page_in_swapcache = (bool *)arg; @@ -1152,7 +1152,7 @@ static enum lru_status shrink_memcg_cb(struct list_head *item, struct list_lru_o * It's safe to drop the lock here because we return either * LRU_REMOVED_RETRY or LRU_RETRY. */ - spin_unlock(lock); + spin_unlock(&l->lock); writeback_result = zswap_writeback_entry(entry, swpentry);