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 48D7FEB64DA for ; Sun, 25 Jun 2023 03:15:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9872B8D0002; Sat, 24 Jun 2023 23:15:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9371B8D0001; Sat, 24 Jun 2023 23:15:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7FF768D0002; Sat, 24 Jun 2023 23:15:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 70E998D0001 for ; Sat, 24 Jun 2023 23:15:15 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3B27FB06C2 for ; Sun, 25 Jun 2023 03:15:15 +0000 (UTC) X-FDA: 80939804190.24.9B0311D Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf27.hostedemail.com (Postfix) with ESMTP id 1B70340004 for ; Sun, 25 Jun 2023 03:15:11 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=ZAMx9Z9f; spf=pass (imf27.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687662912; 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=TKI5JnbDIC0GxIDWgHq4O/cOoJK+mFi4lHzSLMfVTqU=; b=0tN8gSw0uH7NXpF9XMvrNcH4/W+SEtLEaMIsMsWkXRXbS9osHGz0OrAnsMLwArl5OJHJxK eYozm+cB7Z7TOvxdGl1IwWOItzmnLbxS/S6pw8H2h/Nu5Xp/MN3JcjeG0sij4MvmUtjgfu djSz7JM4CT5DZTgozFNAuaktSgYAUFc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687662912; a=rsa-sha256; cv=none; b=AdSyQD5oTLPGQLP2I5v7Z+Pn84r7RR/SNHYeO2nCPsx7e2Ig0MyEyZLS8hHC3deNK8+Vk4 kBs2MrRBEeTmfPWolYe50t/UEdiRGPdd97Lfc2MddjQqP5S6zr6WSpun9riHjxfeKRv5e3 MOsp4LmmV+GgW47zeaAlzgHzlSOB79s= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=ZAMx9Z9f; spf=pass (imf27.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-6687b209e5aso495388b3a.0 for ; Sat, 24 Jun 2023 20:15:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1687662910; x=1690254910; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=TKI5JnbDIC0GxIDWgHq4O/cOoJK+mFi4lHzSLMfVTqU=; b=ZAMx9Z9f9sidua+INHohqUOzi6qohVG8u4jVCH5kW+5KNZXm213btXme0+oY3eiFas kJ1eg2nzkYdYzNdOe7oa9qHmaJUnXCYxjS+yzRkh4fKBRaJsJ8sThwNTH8lHQfNkQNAM VzcFUF7+yXpjBTL7GbZNoITLErtoJw0Vjk1rTp/DbKRrvAbdhI1W9mMFrodUhQiTOgU4 x87qi5B+whZkF6jL19/UUqYgrCxdv27BCv4u4d4gCY3C0TEpHKxxaHXbF0gjifwSN242 21vqEHW8Cm8PCiF/LjQeQL8d9CMETY+gbtFossFoUbQJa5ZrwnE/J5ioBpxXDyTlqBxM qigg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687662910; x=1690254910; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TKI5JnbDIC0GxIDWgHq4O/cOoJK+mFi4lHzSLMfVTqU=; b=J4PcVY7C0PYkl2oXR2Nqql4kZZFirbXh2Di1XpSsylLBgchCHn+LBv40y3i7O1orDI cW8IN7kzHgyaD0u75q/H26Bx/Hd1pWHsPZUYfO5fLPS1hRtho6yRtKO1e+wcFDpx4TJe ZsUp4ShIWn3onKyK01iRBKBOI4pf5WQyj77+LT7BT+OhPdtyXvvEqwtrKTryvz5MPM6+ T4XzregOGxzgGZUuuPpt7I+C4OSv75ZqqoTkZ3BwpeXXz10UJVSQnyRF4ddy1PzFDaX0 zXSVSgCNj7OYp6eoYLD5RYB3Rskc1E4m/fFqABpO167wvDIlYeBMYXwkQ1ny2D3E5MUJ vrmw== X-Gm-Message-State: AC+VfDzgkLAY94aJjMFy4BkqbtUHBDLiPmm7x4N32F7G8jrlCVp2YMyf GqsmUSZ0jYm3OJuvMYABJV1kkA== X-Google-Smtp-Source: ACHHUZ4cDGND46+rMO/jpoItKK6gyWoVPMpHTImOruhTgKiq3D9MdRMxw7KZsaNY9vtDgu3MtWReMw== X-Received: by 2002:a05:6a20:8426:b0:11f:7829:6d6c with SMTP id c38-20020a056a20842600b0011f78296d6cmr28507253pzd.3.1687662910560; Sat, 24 Jun 2023 20:15:10 -0700 (PDT) Received: from [10.70.252.135] ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id r9-20020a62e409000000b0066642f95bc5sm1648412pfh.35.2023.06.24.20.15.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 24 Jun 2023 20:15:10 -0700 (PDT) Message-ID: <00641d5b-86a3-f5d1-02ee-13b4f815df75@bytedance.com> Date: Sun, 25 Jun 2023 11:15:01 +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 Content-Language: en-US From: Qi Zheng 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, RCU References: <20230622085335.77010-1-zhengqi.arch@bytedance.com> <20230622085335.77010-25-zhengqi.arch@bytedance.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 1B70340004 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: c9zgf48yacp7g5w3f5xgk9mmxbasorrf X-HE-Tag: 1687662911-208632 X-HE-Meta: U2FsdGVkX186LD+5RGRddrpgJrCt7pjWcDukMn28m+np2D1KBDf+7zQaJPxvbkSYxE7HGSLesvFj5OgtdW90B53XiEwrR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xHSaKz2xXhwIoqAy462oiSjvwjqbGjZ/jbqPtQ0sYqvA09LkulqsZCsumZbP8XX8UvEylCqqOVeHNGr+wX1ovmjYg77KtAysWNXHYfhFfll+mIrSvFMua8XUIsGOohJAkMQtCR9N6/7HS4CGTQlLKA6AGYkS0nMBPkKsGeZPAUEdIfxFOPfC0mpKLT+WYzw5Vh+s/M8EP2RA== 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: On 2023/6/24 19:08, Qi Zheng wrote: > 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. But most of the system is 'sb-xxx' shrinker instances, they all have the SHRINKER_MEMCG_AWARE flag, so it should have little impact on the speed of traversing info->map. ;) > >> >>> 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. :) Also + RCU mailing list. > > Thanks, > Qi > >> >> -Dave