Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp12010801rwd; Thu, 22 Jun 2023 23:32:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6F6w5QtmL0JIvf23iqmReICbVViCFAweQ7xqD8TDGtvEZ+6hMunqwk+e8VM70smegylHRo X-Received: by 2002:a17:90b:2398:b0:25b:e4ac:98ac with SMTP id mr24-20020a17090b239800b0025be4ac98acmr20037230pjb.17.1687501963045; Thu, 22 Jun 2023 23:32:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687501963; cv=none; d=google.com; s=arc-20160816; b=W2I95XG99MKUaoVQCQTpW7n6blLkX+2cEB/bRK/7UzxUbE7il5moKhtS2FO/4fncna gskJx0+fPPIDalmh4etZOTK2L8RitNzPo5Hv9Azc67FDGYti+aNAVAxMmmavOsK4RN3c 5ZJEMmEFFPxJzvCXGgwRRCLdWy1sG+XNaHJ7wcsP44Lc9qLdRP/lxyVW0JTJrCSNOZKd zQhar8tFP2VbgSxcs3DVYU9AL78N+9SjK3GZSp2U9JlUZlqD1M0MDRYlNEvrlzR41uCL kUrW5JiToxNSkF8k3qedx/Y4pH3OwcBfZe8NGbDGy5wr/CnB7aKpV+FEEiuLjuqZezSp 9Vmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=zCEqJX5mm9cbUE56OVCDucRVQniQh/jh7QjO1tCYRyw=; fh=Ybd0fWYKdi5X0HRVVrKkSK1iwjjuHBaKBsJWRTsJIFY=; b=bS2PX5jizyygi86Bka24hSedfBSDWkH4PB3uwbUZGqTM/lpnMykLq4VtKrZDwtDD+1 TkiBWQ9d/ItyOgIUjkXYfTvcWV2lAGoOolurf6gmzRnV+rJrkZLd69u7aGjeaPwSPoYU cSsJj1aeLVvydZfvttH39u1Ozr+ALz9jowHQAVcGbMem2vJTmJei8h0d2e4yQgPBSzqa 0P/ZVmGZJZhEoLyATxgVAt0LyKzlgTnNtZoif2dOZJx/ybPfNgiKXM96Wo9O58PISoVO qOrerOQ2rkoqbBs48yRHjXSF82LDi4dMMoon9r3GtmL3mmm3Sti1zUiW+25rYzBuM1WP ouRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fromorbit-com.20221208.gappssmtp.com header.s=20221208 header.b=VCN1cKAz; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=fromorbit.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 6-20020a17090a018600b00261351eebdfsi1201469pjc.26.2023.06.22.23.32.29; Thu, 22 Jun 2023 23:32:43 -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=@fromorbit-com.20221208.gappssmtp.com header.s=20221208 header.b=VCN1cKAz; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=fromorbit.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230387AbjFWG3p (ORCPT + 99 others); Fri, 23 Jun 2023 02:29:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229865AbjFWG3p (ORCPT ); Fri, 23 Jun 2023 02:29:45 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D73B21BFA for ; Thu, 22 Jun 2023 23:29:43 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1b50e309602so2203985ad.0 for ; Thu, 22 Jun 2023 23:29:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fromorbit-com.20221208.gappssmtp.com; s=20221208; t=1687501783; x=1690093783; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=zCEqJX5mm9cbUE56OVCDucRVQniQh/jh7QjO1tCYRyw=; b=VCN1cKAzYZWGpOm/hUHuPZp8plVnErZlG9G0OlFzhPpXaNGHYvVufkX79JUDsPqJVj SxdYAM9A9ivCYhtFxc3SyvMZr6s5SlnDngyF1CSlxpEdm/HUuOSGwHgmJomuuYgedrRX aqax0M2Dw9QUTGwitN8bpL0qLseKhs7EVUc6lepS488qyivLAQHSFGtevNE0LyqUhWPi NKkNR95/QZWn2OoaLsjXJllgmMFsp0mHDlbo5o60jR1YeUkdYXlMSdAiD7/jZsXdB48G reDdzoxXO5mM4WdQ8i9rMsSwtC5huiBFlnlMXvIXzYTlsiTrC5P7Z8F16npWgNIfnf8B ShDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687501783; x=1690093783; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=zCEqJX5mm9cbUE56OVCDucRVQniQh/jh7QjO1tCYRyw=; b=MuXCNiz7NsPqhjNvkZ3DnhRs1d80DIjP381AQhiRTKc455QYwG55C7gqdYdG4ir22K MtqEkdTVt5ZITpJtDyr13vk48Qh62J47WHmLScKPT3qGDh6OC83kFj57ZflL4aZ/weLG lHPBLv4iDtT0U5WoahcZtMdP5pYpGcKKL5wjU2w0itnpAiExPWvpPwxRlJhtyKyMtmvw LWTLa5D8t+Ja8aFBaNNokX6JtHzUXPs2tAEM2jWhzJn6n7w9hQUmt5NvRzf2PEZPztj4 YsvmG9xd/ed5KTTdUp4jPA5001ZJTdh5YbU/YUV8Tct9WoTdDocVAjcbUfXMIRiraamT 935A== X-Gm-Message-State: AC+VfDxuhAXWvyFlY54T47GOFAOARZLEAjwYJfBUJd3PYaHPdt5hdYvE DXd5FG3QyCynYj1ZCVqswqQwoA== X-Received: by 2002:a17:902:8214:b0:1aa:d971:4623 with SMTP id x20-20020a170902821400b001aad9714623mr18870991pln.38.1687501783228; Thu, 22 Jun 2023 23:29:43 -0700 (PDT) Received: from dread.disaster.area (pa49-180-13-202.pa.nsw.optusnet.com.au. [49.180.13.202]) by smtp.gmail.com with ESMTPSA id x5-20020a1709027c0500b001b246dcffb7sm6311389pll.300.2023.06.22.23.29.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jun 2023 23:29:42 -0700 (PDT) Received: from dave by dread.disaster.area with local (Exim 4.96) (envelope-from ) id 1qCaId-00F8x8-0s; Fri, 23 Jun 2023 16:29:39 +1000 Date: Fri, 23 Jun 2023 16:29:39 +1000 From: Dave Chinner To: Vlastimil Babka Cc: Qi Zheng , akpm@linux-foundation.org, tkhai@ya.ru, roman.gushchin@linux.dev, djwong@kernel.org, brauner@kernel.org, paulmck@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 Subject: Re: [PATCH 24/29] mm: vmscan: make global slab shrink lockless Message-ID: References: <20230622085335.77010-1-zhengqi.arch@bytedance.com> <20230622085335.77010-25-zhengqi.arch@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 On Thu, Jun 22, 2023 at 05:12:02PM +0200, Vlastimil Babka wrote: > On 6/22/23 10:53, Qi Zheng wrote: > > @@ -1067,33 +1068,27 @@ static unsigned long shrink_slab(gfp_t gfp_mask, int nid, > > if (!mem_cgroup_disabled() && !mem_cgroup_is_root(memcg)) > > return shrink_slab_memcg(gfp_mask, nid, memcg, priority); > > > > - if (!down_read_trylock(&shrinker_rwsem)) > > - goto out; > > - > > - list_for_each_entry(shrinker, &shrinker_list, list) { > > + rcu_read_lock(); > > + list_for_each_entry_rcu(shrinker, &shrinker_list, list) { > > struct shrink_control sc = { > > .gfp_mask = gfp_mask, > > .nid = nid, > > .memcg = memcg, > > }; > > > > + if (!shrinker_try_get(shrinker)) > > + continue; > > + rcu_read_unlock(); > > I don't think you can do this unlock? > > > + > > ret = do_shrink_slab(&sc, shrinker, priority); > > if (ret == SHRINK_EMPTY) > > ret = 0; > > freed += ret; > > - /* > > - * Bail out if someone want to register a new shrinker to > > - * prevent the registration from being stalled for long periods > > - * by parallel ongoing shrinking. > > - */ > > - if (rwsem_is_contended(&shrinker_rwsem)) { > > - freed = freed ? : 1; > > - break; > > - } > > - } > > > > - up_read(&shrinker_rwsem); > > -out: > > + rcu_read_lock(); > > That new rcu_read_lock() won't help AFAIK, the whole > list_for_each_entry_rcu() needs to be under the single rcu_read_lock() to be > safe. Yeah, that's the pattern we've been taught and the one we can look at and immediately say "this is safe". This is a different pattern, as has been explained bi Qi, and I think it *might* be safe. *However.* Right now I don't have time to go through a novel RCU list iteration pattern it one step at to determine the correctness of the algorithm. I'm mostly worried about list manipulations that can occur outside rcu_read_lock() section bleeding into the RCU critical section because rcu_read_lock() by itself is not a memory barrier. Maybe Paul has seen this pattern often enough he could simply tell us what conditions it is safe in. But for me to work that out from first principles? I just don't have the time to do that right now. > IIUC this is why Dave in [4] suggests unifying shrink_slab() with > shrink_slab_memcg(), as the latter doesn't iterate the list but uses IDR. 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... Cheers, Dave. -- Dave Chinner david@fromorbit.com