Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1760946rwd; Fri, 9 Jun 2023 01:32:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ65OpA49ihFfKkZjmn58ep+kpuFq70x/OxSp4KPtcVdavvdx/mte8sE68dZQKq3QZ9ZZDUb X-Received: by 2002:a05:6358:f1e:b0:129:94e6:7069 with SMTP id b30-20020a0563580f1e00b0012994e67069mr793923rwj.0.1686299575219; Fri, 09 Jun 2023 01:32:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686299575; cv=none; d=google.com; s=arc-20160816; b=Gv2qBlEN77Kh3AA/BIb0oQrWmpsSfkHhypdlo4FO7/TNi4MLUwsWdnqjsOZ178SXcN FcV7wDpmykIVmuOeDXGHArudBnnoMuepE4TELCtzNk7LT+Uy+hWxBFoyjL1z6EAtP4Iu lJuXTCfGsC/WlRziQZFrXACXImd7p91WTj/csNUXyuQsvUeZm1YGxWss99afGGMOptk6 Bz3QPDI3VCHwpaqCUh7HEUPB+hKCnylwuQSoTCFYISM73H9Bk0/Dl44Dwi7FuOzNGfQb KcSHzoFeRU0LJChRb2wMdyw+/B/uXjvKIuaUP9+kzuwVLAuECJ9CHINFtXNrlD10uodG CH5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fW5UuGuy06FRX8Px/N9YG/QTNF0coGlqdNSj4AuBaaM=; b=YeW3o8ufym53BXNsiCIXzL+GAp/Uo8HhSrCrzpQd45t8TX8yEcQRARGaV3GWPOMY7D JxHOwByWS8op19rbLhlQgGAbzY4wMQ6sYf825feiHku3ZwIUgJSSh2qva/e9uds2sTdG XnoCd0ZwMmOTDfoSqTnY8WQPRDKXtxFXctoixnyDUFx45GbtXHxm3M2/1GZmil7Xzj1d oiOLl3Kw9W4aoPk88UF3GOrVOplOPq3nFRmntQ1GLZb27mCmvpTp/CJIVc4lq/6BBBSN VW2GfBEMRKzsIqgdpIvUN7UPlS1pbBxCaYAvlkc2h8mfenW9ZQvZfIpjONyxma1aZB/e pj8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=tddMOX9h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y2-20020a63ad42000000b00548e140a1a4si1033962pgo.644.2023.06.09.01.32.39; Fri, 09 Jun 2023 01:32:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=tddMOX9h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240504AbjFIISc (ORCPT + 99 others); Fri, 9 Jun 2023 04:18:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240324AbjFIIRv (ORCPT ); Fri, 9 Jun 2023 04:17:51 -0400 Received: from out-21.mta0.migadu.com (out-21.mta0.migadu.com [91.218.175.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A94463AA4 for ; Fri, 9 Jun 2023 01:17:23 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1686298638; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fW5UuGuy06FRX8Px/N9YG/QTNF0coGlqdNSj4AuBaaM=; b=tddMOX9hrmBcUy1TaN6PYmjZr8N6htWv1AKIwBbCiMwwdMPB0GeJMYgG8Z8I93aOe/HBvd 5BXFnyv6bfT5hursOmsbSE208IL5wiQKL+bwZlti5+T99GzbUZ4tm7iuHx6iPsFe8QHCGt jtNfOoIRqSFtiW109WCZ6dTaNr7m36M= From: Qi Zheng To: akpm@linux-foundation.org Cc: david@fromorbit.com, tkhai@ya.ru, roman.gushchin@linux.dev, vbabka@suse.cz, muchun.song@linux.dev, yujie.liu@intel.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Qi Zheng Subject: [PATCH 4/7] Revert "mm: shrinkers: make count and scan in shrinker debugfs lockless" Date: Fri, 9 Jun 2023 08:15:15 +0000 Message-Id: <20230609081518.3039120-5-qi.zheng@linux.dev> In-Reply-To: <20230609081518.3039120-1-qi.zheng@linux.dev> References: <20230609081518.3039120-1-qi.zheng@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Qi Zheng This reverts commit 20cd1892fcc3efc10a7ac327cc3790494bec46b5. Kernel test robot reports -88.8% regression in stress-ng.ramfs.ops_per_sec test case [1], which is caused by commit f95bdb700bc6 ("mm: vmscan: make global slab shrink lockless"). The root cause is that SRCU has to be careful to not frequently check for SRCU read-side critical section exits. Therefore, even if no one is currently in the SRCU read-side critical section, synchronize_srcu() cannot return quickly. That's why unregister_shrinker() has become slower. We will try to use the refcount+RCU method [2] proposed by Dave Chinner to continue to re-implement the lockless slab shrink. So revert the shrinker_srcu related changes first. [1]. https://lore.kernel.org/lkml/202305230837.db2c233f-yujie.liu@intel.com/ [2]. https://lore.kernel.org/lkml/ZIJhou1d55d4H1s0@dread.disaster.area/ Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202305230837.db2c233f-yujie.liu@intel.com Signed-off-by: Qi Zheng --- mm/shrinker_debug.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/mm/shrinker_debug.c b/mm/shrinker_debug.c index 2be15b8a6d0b..3ab53fad8876 100644 --- a/mm/shrinker_debug.c +++ b/mm/shrinker_debug.c @@ -5,12 +5,10 @@ #include #include #include -#include /* defined in vmscan.c */ extern struct rw_semaphore shrinker_rwsem; extern struct list_head shrinker_list; -extern struct srcu_struct shrinker_srcu; static DEFINE_IDA(shrinker_debugfs_ida); static struct dentry *shrinker_debugfs_root; @@ -51,13 +49,18 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v) struct mem_cgroup *memcg; unsigned long total; bool memcg_aware; - int ret = 0, nid, srcu_idx; + int ret, nid; count_per_node = kcalloc(nr_node_ids, sizeof(unsigned long), GFP_KERNEL); if (!count_per_node) return -ENOMEM; - srcu_idx = srcu_read_lock(&shrinker_srcu); + ret = down_read_killable(&shrinker_rwsem); + if (ret) { + kfree(count_per_node); + return ret; + } + rcu_read_lock(); memcg_aware = shrinker->flags & SHRINKER_MEMCG_AWARE; @@ -88,7 +91,8 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v) } } while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL); - srcu_read_unlock(&shrinker_srcu, srcu_idx); + rcu_read_unlock(); + up_read(&shrinker_rwsem); kfree(count_per_node); return ret; @@ -111,8 +115,9 @@ static ssize_t shrinker_debugfs_scan_write(struct file *file, .gfp_mask = GFP_KERNEL, }; struct mem_cgroup *memcg = NULL; - int nid, srcu_idx; + int nid; char kbuf[72]; + ssize_t ret; read_len = size < (sizeof(kbuf) - 1) ? size : (sizeof(kbuf) - 1); if (copy_from_user(kbuf, buf, read_len)) @@ -141,7 +146,11 @@ static ssize_t shrinker_debugfs_scan_write(struct file *file, return -EINVAL; } - srcu_idx = srcu_read_lock(&shrinker_srcu); + ret = down_read_killable(&shrinker_rwsem); + if (ret) { + mem_cgroup_put(memcg); + return ret; + } sc.nid = nid; sc.memcg = memcg; @@ -150,7 +159,7 @@ static ssize_t shrinker_debugfs_scan_write(struct file *file, shrinker->scan_objects(shrinker, &sc); - srcu_read_unlock(&shrinker_srcu, srcu_idx); + up_read(&shrinker_rwsem); mem_cgroup_put(memcg); return size; -- 2.30.2