Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp1251718ioo; Fri, 27 May 2022 05:03:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxa+U44vN+4MV3yWknsYMNkz7GCkQ9if7rDTuacxJII1MxwuXwA/22B5KG5jhmhIQWe6eTu X-Received: by 2002:a17:90b:3ec7:b0:1dc:b008:3cd3 with SMTP id rm7-20020a17090b3ec700b001dcb0083cd3mr8059441pjb.226.1653653019270; Fri, 27 May 2022 05:03:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653653019; cv=none; d=google.com; s=arc-20160816; b=iK7j4fEyHq9/+KlPkVEE5T5FW5E7feKQ8bZm9yW+avIQyeQGphSjHJQBLK+nc3gkpi Vy941PdYzA4EJwf+vF8Lk2DU/UxtuKFtB0nU1tjbuElv0bXxJ4GD8+rI2+gjGhLt7xHh q64WCK/tLJUt7ZUsJoibOPNyc1awPL5J6JATawv57q1vmPEwolIz3rlXjtuuPqh2PwKj sCuQMd/AEpteUgR7J579HjotHoDQHPpyJtD3RKFy6SbJeWB1gGq3kcCzjw77JL1374Qw LEQWGI8IDw4E8Vb1AAtksF2njt4XCrodIOOvvjeWOo1YKTJYwCbMsXwSEUR37xgY19AW XEqQ== 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 :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=KcZz6yVLgZ62yrFoGOM5DElgQzD6OwyWHQ72tERIC7w=; b=j5KMnExjK/+RXS5Zp4chBWnUqHTp5NOiDlkkyeAHwEdFCneDV5FrTUuJioVXbYnHmG qkRDHzd+FlKbEJhmxhtjnc599OVcZtWxMGOZ6iAhDUYYttsDemyUvdl0vOLm2fG3uaX0 fJFoy80kDN/RhD1ALZWZ/6vYaUlJT/J8XWOk4m/fgrPtpnxhGKmVd+soyFRJ7BiDOKM/ t1SvX/PbarJ/9AiTC9gQdm86B5RXis+MuMMLEOWF99UkUw+EBUGeGHkrIXmMPNfjMq0M wyc5X1fOowC4x4782Q5++RRf4BnrINCR8vqi2YGhpq7e9pHSCT6k2I9GaZkPjbNfkqUX 03FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UVRNItfu; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l15-20020a63ea4f000000b003c5e1870569si5848623pgk.171.2022.05.27.05.03.24; Fri, 27 May 2022 05:03:39 -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=@redhat.com header.s=mimecast20190719 header.b=UVRNItfu; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238226AbiEZURg (ORCPT + 99 others); Thu, 26 May 2022 16:17:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232295AbiEZURe (ORCPT ); Thu, 26 May 2022 16:17:34 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 08B04C964A for ; Thu, 26 May 2022 13:17:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653596252; h=from:from: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; bh=KcZz6yVLgZ62yrFoGOM5DElgQzD6OwyWHQ72tERIC7w=; b=UVRNItfurIuaE/1CqJJ31GnavcHM+FXhc6x9K9qjlj+geHOoRxldxNr/U84hr+NyyJG4UA RYeuGSzBNLLN02Yp6/6Up1P6Trz98DxdBMGjkPXRrnsTQcJ/jwOl4GKGEgeUVean6vlJd7 9e7LlPmxq1jVpOyfRSouGlUo57ldeeE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-511-dYebSbIfM4yLfnBJjQQ3eg-1; Thu, 26 May 2022 16:17:28 -0400 X-MC-Unique: dYebSbIfM4yLfnBJjQQ3eg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B89FF185A7A4; Thu, 26 May 2022 20:17:27 +0000 (UTC) Received: from [10.22.8.143] (unknown [10.22.8.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id 389B12026D64; Thu, 26 May 2022 20:17:27 +0000 (UTC) Message-ID: <9fe57cf7-9d21-3f91-ef27-e046b426c219@redhat.com> Date: Thu, 26 May 2022 16:17:27 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH v4 03/11] mm: memcontrol: make lruvec lock safe when LRU pages are reparented Content-Language: en-US To: Muchun Song , 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 References: <20220524060551.80037-1-songmuchun@bytedance.com> <20220524060551.80037-4-songmuchun@bytedance.com> From: Waiman Long In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE,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-kernel@vger.kernel.org On 5/25/22 11:38, Muchun Song wrote: > 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. Note that there is a similar comment in patch 6 which may have to be removed as well. Cheers, Longman