From mboxrd@z Thu Jan 1 00:00:00 1970 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 CF176EB64DD for ; Sat, 24 Jun 2023 11:08:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 241BE8D0002; Sat, 24 Jun 2023 07:08:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1CB778D0001; Sat, 24 Jun 2023 07:08:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 046398D0002; Sat, 24 Jun 2023 07:08:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E1A9D8D0001 for ; Sat, 24 Jun 2023 07:08:32 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A7F8C4105F for ; Sat, 24 Jun 2023 11:08:32 +0000 (UTC) X-FDA: 80937368064.16.A23DD89 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf27.hostedemail.com (Postfix) with ESMTP id 4484140008 for ; Sat, 24 Jun 2023 11:08:30 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=UmCBKPF4; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf27.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687604910; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7tnz7s8ew6fhhs0dR9M9QnK0rlCy7+XAhEAWksz3vrg=; b=xXps6vIGzxCrJlfswieU60DxQARCewGVHelKmMVp47fGGOYUg+fxTxdwW0OF3ij/0KNBjr 3Tl4nnt1YUaneAuXaHJO7e5rse+z3h49e8A3hrfP9/lS3xIg0nq3MZwuLz4bjI6ym1gkLi BzTydrYTZxdyJlAC8kRQO4ZaHJpNs44= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=UmCBKPF4; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf27.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687604910; a=rsa-sha256; cv=none; b=aTKfMpK1b7i5lriVjeP3bj9zRGa5wRSNRgqv/Xr/MTy38JC0NQN7yxm5r0mMO4AAIYuNZb 1DFnjT/1ROZdEob8QcI9c8qmnF2xJSgsYJmpPd40gsoEUU7dH7+2KQdM2o9IG5NyT39RoG 0HED/umhBw6jFQLM1hWlg9SF8E+CToM= Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1b693afe799so2529995ad.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=hvIxHRa+6CLvwbwKY4gwjtcFvY/rD8tprwHwjPFaqojE+qO15Wp1PuClkG8wyLNkb6 jwOJEHlaSXMZLrPv5btcIMZwiXzJgYYNb7tQ6uVyT1vXWy/NZzZK+3uGmLWKpYENiVJ/ +6ISF3pqHGj+wifPT3Zgsudl1sl3RlRe7QTXwJWV6n2ejuDUL0/nOfT0Slzu+gUJjs9q Z3hvfYGyxDsIn3aWPSwF8fZKG1eq8l5ekVGK3/FASDelixzESCBiRa3pQsSTUCSeXoGj 7EY920EHrPRck3TrXBOS8tVbLpMa3IM41lYmHyizgtXdix43QhvDeNwP4Rp3NhjBbi67 47tA== X-Gm-Message-State: AC+VfDxWVWtvR6mJQfBBcLrqq4wqaPlDkCPZAPcHIrwMQa+6aXR9rPgY 3P6J4XN9CL21Uw+tfeJLeX1qLA== X-Google-Smtp-Source: ACHHUZ48xugwBy1Yb59MA7iADNA4mtjxjJVDK/TEG1GiFnnp8kgPq3uDjFXVnvd+Ayx9tItAR27KLA== 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-Rspam-User: X-Stat-Signature: bkzmyw7ksp6e9e8jf679rcactg59fujz X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 4484140008 X-HE-Tag: 1687604910-255652 X-HE-Meta: U2FsdGVkX18b6vHAPidlRAjTRkML5lK0ldLVlJ5DGKARJ38Jj/x9fy1Rf8/y3opNf1MU6D7YAYzNVs/zGh/ZiFxlMqmvV1q0TCi9AaLIA9T0T6jaYm+PxP1ti2sTIXTWbnpPCcSg80QtM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NIn+59hLm2Y9c4jS/++vOsXIjCuKI3P1uDoodyz4UFZeeOYefMvuFBbWnsRhhjP+rjDHroZnUX17G5j6TqzJNGHctMA4L/F182nl4UxJWs+fz9vOZylo3bFWXUmV9t12GzeXhAqrQKKXnouw== 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: 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