Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp13660774rwd; Sat, 24 Jun 2023 04:31:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5su5hvSJcXjUG/N3Ssql7PLpKaJKYCtjD/evNbE13Pe7oxuH9oyuBxIqfwEzJJrmyrD9HT X-Received: by 2002:a05:6a20:8f29:b0:122:c6c4:36b1 with SMTP id b41-20020a056a208f2900b00122c6c436b1mr14429579pzk.4.1687606284046; Sat, 24 Jun 2023 04:31:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687606284; cv=none; d=google.com; s=arc-20160816; b=e0ZJmePSKDuxTJgYJ+kLcji2eVO+iTzZu9SYNzBYhAaLjhAeps4JvSnoZX5l4QmxHT I5116oFZ1peeGU6yVVCUqmUcs4A0JDncVFzIgiRLpRAl1AVkLJ2ZRfjoYgN72SHjjj3T yug7KkSC2zdlzVRp4RJBhMW04lb9w1WIxDjEnsk7WBpx988uHKlj/LoT5DviWaBwq6zc llUKiqZQukdH1rQVPrG72aD8lAXwwlT81RYdUws9J0ILRC2UcC4JIeFYFqFEc82OAV+S IVRcNDr89FprTd4T5HWPHLBqf6oNu7ac8mHbJraTfEWPFEFeaWfn0KI+jmN1YsU8+Rep VGrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=7tnz7s8ew6fhhs0dR9M9QnK0rlCy7+XAhEAWksz3vrg=; fh=i0v7ecc6Q+UoecKWFqpK2Jzzxd+HrFmXhNl+f2xsGks=; b=HZH7c3lCYvfOV0m/h+YxKxgoXA2QWIMiB4zmsKa7a/wZpj0K5meVDh4VMxFdxX8MAq tPWIxheQfL8bO57tAgVJnLJ4MhXKs27wOXRuFnpx70+z2wElXtT1W0bq586vC/WPi5mt dCUrZ4TM0wcqlmLrDOn4iNdUPeEuW2Vj84CMVZ1m21VqzRROjBrGHBw/Z0AwAUGtNIAh p81yavtoiE9eiLBJ82QZgFUQxl55GvNHRmn7bXpMpLxHA1YRbgW3Ub1EApvBv0VWyafo 6oo8d8qpx8pK744xhItckSvV+OkoCDpQWeUk/y2jqfrv1bQrCjpZMTAc01qQEMq3H/qh HKvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=UmCBKPF4; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r189-20020a632bc6000000b00502f4fd0c16si1416253pgr.653.2023.06.24.04.31.04; Sat, 24 Jun 2023 04:31:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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=@bytedance.com header.s=google header.b=UmCBKPF4; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232983AbjFXLJA (ORCPT + 99 others); Sat, 24 Jun 2023 07:09:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232931AbjFXLI5 (ORCPT ); Sat, 24 Jun 2023 07:08:57 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5ED301FDF for ; Sat, 24 Jun 2023 04:08:29 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1b693afe799so2529945ad.1 for ; Sat, 24 Jun 2023 04:08:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1687604909; x=1690196909; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=7tnz7s8ew6fhhs0dR9M9QnK0rlCy7+XAhEAWksz3vrg=; b=UmCBKPF4sv1MHFXsiXJ20hfDGRh4FqZyWNYAXvwJ4aTGGxIidAh9WvDmw+TkimJm1h mWSpmHZ6C1d0YyoGyiszU38sSq69kPhXPhm56U4+6FVITcJ1CEZHjLEmCAtp6wktOCK/ DxOdRsySk1sXqY68RWF0JOe4/zeVPJtvQ9lHfsJ6x6SdMyQcNVrIa4NXa7fRi6mlad+o t//wFgxPhT7EPECahYPUyLpil8jkwMy0/+XEXxUh0Le8+U2ufonOfsscVTgC+SrRoDCH iM7noG8OLDFE0tdGr8824/JUhvbwrqjbGrrMdkGxtRD/cnqrUyFsNqPJcdX8JFikXXu+ BdTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687604909; x=1690196909; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7tnz7s8ew6fhhs0dR9M9QnK0rlCy7+XAhEAWksz3vrg=; b=ZAZ7uh1njQVYgfLPIZ4hnOwMYJqxgdxaxgriSg/Bsan0w4uecaC4Jnz5uQAcS9034n /pq5y2+9Cp79Oq0JQy/ZK6XEvQkMnpRKyT/KK7y0wqC7MhnbezKNkOpInBStZndB6cjc XnXBJi/sGbR9AimcNcSIJBP/YRLLI9cpZVqBXz4cw6ZB/Mtk3Effgo7b8+uSaJCcZP5i B7YV3PfNzVkg6BBnRPDCxw0ayE7abiXtj/f4xMNdQoUWT29DZHlsHEDd6CFFznL3TBMU 7dSw+vMeOUlTBDVdinLNDUBVTfAvEkyEFpQcaFu0jp397uhqwgQy+ySH4t2XsEeOPk96 ygRg== X-Gm-Message-State: AC+VfDxsuwckAXZTA6SV+6/+oESCLIAPO3uTqomLRGWz0juEbWBIaPHD 2sna+yRnWo7We+G+NnSPx9RdmA== X-Received: by 2002:a17:903:32c4:b0:1b3:e352:6d88 with SMTP id i4-20020a17090332c400b001b3e3526d88mr29305254plr.6.1687604908733; Sat, 24 Jun 2023 04:08:28 -0700 (PDT) Received: from [10.4.162.153] ([139.177.225.251]) by smtp.gmail.com with ESMTPSA id bg6-20020a1709028e8600b001b3d0aff88fsm1021644plb.109.2023.06.24.04.08.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 24 Jun 2023 04:08:28 -0700 (PDT) Message-ID: Date: Sat, 24 Jun 2023 19:08:18 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH 24/29] mm: vmscan: make global slab shrink lockless To: Dave Chinner , paulmck@kernel.org Cc: Vlastimil Babka , akpm@linux-foundation.org, tkhai@ya.ru, roman.gushchin@linux.dev, djwong@kernel.org, brauner@kernel.org, tytso@mit.edu, linux-kernel@vger.kernel.org, linux-mm@kvack.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, dm-devel@redhat.com, linux-raid@vger.kernel.org, linux-bcache@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-nfs@vger.kernel.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org References: <20230622085335.77010-1-zhengqi.arch@bytedance.com> <20230622085335.77010-25-zhengqi.arch@bytedance.com> Content-Language: en-US From: Qi Zheng In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, 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-ext4@vger.kernel.org Hi Dave, On 2023/6/24 06:19, Dave Chinner wrote: > On Fri, Jun 23, 2023 at 09:10:57PM +0800, Qi Zheng wrote: >> On 2023/6/23 14:29, Dave Chinner wrote: >>> On Thu, Jun 22, 2023 at 05:12:02PM +0200, Vlastimil Babka wrote: >>>> On 6/22/23 10:53, Qi Zheng wrote: >>> Yes, I suggested the IDR route because radix tree lookups under RCU >>> with reference counted objects are a known safe pattern that we can >>> easily confirm is correct or not. Hence I suggested the unification >>> + IDR route because it makes the life of reviewers so, so much >>> easier... >> >> In fact, I originally planned to try the unification + IDR method you >> suggested at the beginning. But in the case of CONFIG_MEMCG disabled, >> the struct mem_cgroup is not even defined, and root_mem_cgroup and >> shrinker_info will not be allocated. This required more code changes, so >> I ended up keeping the shrinker_list and implementing the above pattern. > > Yes. Go back and read what I originally said needed to be done > first. In the case of CONFIG_MEMCG=n, a dummy root memcg still needs > to exist that holds all of the global shrinkers. Then shrink_slab() > is only ever passed a memcg that should be iterated. > > Yes, it needs changes external to the shrinker code itself to be > made to work. And even if memcg's are not enabled, we can still use > the memcg structures to ensure a common abstraction is used for the > shrinker tracking infrastructure.... Yeah, what I imagined before was to define a more concise struct mem_cgroup in the case of CONFIG_MEMCG=n, then allocate a dummy root memcg on system boot: #ifdef !CONFIG_MEMCG struct shrinker_info { struct rcu_head rcu; atomic_long_t *nr_deferred; unsigned long *map; int map_nr_max; }; struct mem_cgroup_per_node { struct shrinker_info __rcu *shrinker_info; }; struct mem_cgroup { struct mem_cgroup_per_node *nodeinfo[]; }; #endif But I have a concern: if all global shrinkers are tracking with the info->map of root memcg, a shrinker->id needs to be assigned to them, which will cause info->map_nr_max to become larger than before, then making the traversal of info->map slower. > >> If the above pattern is not safe, I will go back to the unification + >> IDR method. > > And that is exactly how we got into this mess in the first place.... I only found one similar pattern in the kernel: fs/smb/server/oplock.c:find_same_lease_key/smb_break_all_levII_oplock/lookup_lease_in_table But IIUC, the refcount here needs to be decremented after holding rcu lock as I did above. So regardless of whether we choose unification + IDR in the end, I still want to confirm whether the pattern I implemented above is safe. :) Thanks, Qi > > -Dave