Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp657164ioo; Thu, 26 May 2022 11:29:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPW0Aors/ou6KLsJx1RjZPg35NglwQV2a1SDeLCyk6L1uXkH/Q3TIoQ7CbBftt+ruJHIXJ X-Received: by 2002:a17:90a:af8a:b0:1df:9f11:dbc7 with SMTP id w10-20020a17090aaf8a00b001df9f11dbc7mr3944352pjq.233.1653589765506; Thu, 26 May 2022 11:29:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653589765; cv=none; d=google.com; s=arc-20160816; b=XukP9Jlu+jL2JtTW7IdWY4h2X/OnAtiMrKDGyAZnaefW9i/wlPyoqPSZLqtthbr50j qZ/ee54uP0txinr8jT2/sT27wVenwn0X3Z4W0qcPjF9/njKMlUl8FjRU1vrIA9+qa0Ed ae3LMBmVsP4fpoWZAsV392np3xURr4edPBusLolzKjJHAdedK5gmycPswx0R3pv1hE/J KWJWs7UFhIWM8n4o/Fw2us9Ul1HG2nDaCg1dP4FfkS2FpMSYuau/aw9cj7Vccc1ZoS41 MyLIi1NK/q+Jk3sO78XeCYEY+IvpgGqw+iZx7KSSuPv7Shpf8qOF4l/BqNXMjoAEaYjr So7Q== 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=XfUA65d3SdbF2oQUu55YnSpsWlaG2pXPKVSvY3AeaaY=; b=IO4GeMGMxCTbdknWhgs2Fb3hov9e0P0weSxLolomdUZvHs5ceYtZldGE+TRekc0XkG eogDD7MdOKI5EdhodinrnCEA72ffE+z1g7GnWWhFbbxN5ScH4pmRAYC8JpnfEFWVsZAs m9vFYYL9/eMO2JzdDrGv7LFSbN+FnH3m18VxWicu5mnaBdCQzQ85XsuHvaInnrJnV5Jo HzJZ6eT6zGMJhcwlxnP9KXsouiYs8zaBJ6PxVNw7nRnRQ0K+ltsGi3rBhw2xmWMRKU4B oSex4N0ac00L5kHZiZv/ZRUcQxQUMuczPCGGGqH27CUidVPTYCbcwHvNAOH7VXO8lB5K 53WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=HdWmnFgh; 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=fail (p=NONE sp=NONE 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 g12-20020a170902934c00b00156b24c4bb6si2324085plp.120.2022.05.26.11.29.13; Thu, 26 May 2022 11:29:25 -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=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=HdWmnFgh; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245068AbiEYPir (ORCPT + 99 others); Wed, 25 May 2022 11:38:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229893AbiEYPij (ORCPT ); Wed, 25 May 2022 11:38:39 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 634891A83A for ; Wed, 25 May 2022 08:38:35 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id y189so4467681pfy.10 for ; Wed, 25 May 2022 08:38:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=XfUA65d3SdbF2oQUu55YnSpsWlaG2pXPKVSvY3AeaaY=; b=HdWmnFghAeH4LB9aqAeQKPfx4YaL1PQAnvmeL63qjEhQAsAKGPbUoWiw805DbWMH7w XoiBlH8sgL6Qd92qTjABYEtmtm8Cg+0qLN6NFvKknvRaO+mJDJqgzHyWB8HEZuWXscrH Xz1wzE6LmtCY4J5IB9STw0NM5YtUlc4+LnGaMH+uaVJ+9hl2W1D75vtJW+gstoCx0AkA d24A8qRFz6/7+LHkWFIXmI8WCtXovRtftQ/wkbSch57kOh30B0HA6YIDAZKaOqrc/HGo AI0GxMStontX+lP5N4q0iFkpJeCCyO1oQ5OEx/TB6KuwVerlzTV7dTM9Yp0K4fMtVoKp 48LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=XfUA65d3SdbF2oQUu55YnSpsWlaG2pXPKVSvY3AeaaY=; b=O+TDfTqFj7OlMc2StfrfP1eO/TaPeu9FCV5oVvARMt5sPkE4R2Veo8OdEFDHHvz7lN AXyyoe01J21OIXAK5Cuv+R4xpktAAZxA50Fmw+5xUkmSaAqzobuqU2J4JG3712WafrqS Rt2+g4uC1+iX6eXm8J5V98vyAg/sk932SmarfDntWgijt3gQ+wmgqczksA7DH1kxeGUU DH6qrChZ7Mc8KPx/IxUogP3m4yEyjGlF5Xmsx8unuSWnsX94ehmmDYMhqQ9qHbcE0UHm rVcfnAyT9hdbODZ5WueGpDc+EcNHTeRuQhDb1UIFsvRh4NlgbsrhRjMChN4ZHWoaP+42 6HAA== X-Gm-Message-State: AOAM533CoFtbQWmJz/4cg556V+1tiGzmAQiXh3neivaHMmObYuGrSAtq Q+wj64RqpxEEW9cCDYyy+GrTpA== X-Received: by 2002:a63:1a17:0:b0:3fa:e901:1c68 with SMTP id a23-20020a631a17000000b003fae9011c68mr2278636pga.243.1653493114887; Wed, 25 May 2022 08:38:34 -0700 (PDT) Received: from localhost ([2408:8207:18da:2310:c40f:7b5:4fa8:df3f]) by smtp.gmail.com with ESMTPSA id t2-20020a170902e84200b001618fee3900sm9707878plg.196.2022.05.25.08.38.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 May 2022 08:38:34 -0700 (PDT) Date: Wed, 25 May 2022 23:38:30 +0800 From: Muchun Song To: Johannes Weiner Cc: mhocko@kernel.org, roman.gushchin@linux.dev, shakeelb@google.com, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, duanxiongchun@bytedance.com, longman@redhat.com Subject: Re: [PATCH v4 03/11] mm: memcontrol: make lruvec lock safe when LRU pages are reparented Message-ID: References: <20220524060551.80037-1-songmuchun@bytedance.com> <20220524060551.80037-4-songmuchun@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=ham 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 On Wed, May 25, 2022 at 10:48:54AM -0400, Johannes Weiner wrote: > On Wed, May 25, 2022 at 09:03:59PM +0800, Muchun Song wrote: > > On Wed, May 25, 2022 at 08:30:15AM -0400, Johannes Weiner wrote: > > > On Wed, May 25, 2022 at 05:53:30PM +0800, Muchun Song wrote: > > > > On Tue, May 24, 2022 at 03:27:20PM -0400, Johannes Weiner wrote: > > > > > On Tue, May 24, 2022 at 02:05:43PM +0800, Muchun Song wrote: > > > > > > @@ -1230,10 +1213,23 @@ void lruvec_memcg_debug(struct lruvec *lruvec, struct folio *folio) > > > > > > */ > > > > > > struct lruvec *folio_lruvec_lock(struct folio *folio) > > > > > > { > > > > > > - struct lruvec *lruvec = folio_lruvec(folio); > > > > > > + struct lruvec *lruvec; > > > > > > > > > > > > + rcu_read_lock(); > > > > > > +retry: > > > > > > + lruvec = folio_lruvec(folio); > > > > > > spin_lock(&lruvec->lru_lock); > > > > > > - lruvec_memcg_debug(lruvec, folio); > > > > > > + > > > > > > + if (unlikely(lruvec_memcg(lruvec) != folio_memcg(folio))) { > > > > > > + spin_unlock(&lruvec->lru_lock); > > > > > > + goto retry; > > > > > > + } > > > > > > + > > > > > > + /* > > > > > > + * Preemption is disabled in the internal of spin_lock, which can serve > > > > > > + * as RCU read-side critical sections. > > > > > > + */ > > > > > > + rcu_read_unlock(); > > > > > > > > > > The code looks right to me, but I don't understand the comment: why do > > > > > we care that the rcu read-side continues? With the lru_lock held, > > > > > reparenting is on hold and the lruvec cannot be rcu-freed anyway, no? > > > > > > > > > > > > > Right. We could hold rcu read lock until end of reparting. So you mean > > > > we do rcu_read_unlock in folio_lruvec_lock()? > > > > > > The comment seems to suggest that disabling preemption is what keeps > > > the lruvec alive. But it's the lru_lock that keeps it alive. The > > > cgroup destruction path tries to take the lru_lock long before it even > > > gets to synchronize_rcu(). Once you hold the lru_lock, having an > > > implied read-side critical section as well doesn't seem to matter. > > > > > > > Well, I thought that spinlocks have implicit read-side critical sections > > because it disables preemption (I learned from the comments above > > synchronize_rcu() that says interrupts, preemption, or softirqs have been > > disabled also serve as RCU read-side critical sections). So I have a > > question: is it still true in a PREEMPT_RT kernel (I am not familiar with > > this)? > > Yes, but you're missing my point. > > > > Should the comment be deleted? > > > > I think we could remove the comments. If the above question is false, seems > > like we should continue holding rcu read lock. > > It's true. > Thanks for your answer. > But assume it's false for a second. Why would you need to continue > holding it? What would it protect? The lruvec would be pinned by the > spinlock even if it DIDN'T imply an RCU lock, right? > > So I don't understand the point of the comment. If the implied RCU > lock is protecting something not covered by the bare spinlock itself, > it should be added to the comment. Otherwise, the comment should go. > Got it. Thanks for your nice explanation. I'll remove the comment here.