Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2858904ioo; Tue, 24 May 2022 07:32:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlR0QcWg9ANjHB2ZoecmJ+UmVZKGbRbllM6PMk73++mD8UVqjbKteSDtNZwZ+ykQCxD6bQ X-Received: by 2002:a05:6a00:724:b0:4fa:a35f:8e0f with SMTP id 4-20020a056a00072400b004faa35f8e0fmr28669490pfm.25.1653402731204; Tue, 24 May 2022 07:32:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653402731; cv=none; d=google.com; s=arc-20160816; b=Ko+y3myfpzOMknjwpjyMZiKsNNlDC/9Z1GJn5EE5nWmAkoc37eQ+t6rWFNk2lwQWK1 KiTF8x4K6LhwsUke6iVid69rITl3akSol6Ah/BIIzum5tHTxvoCrmLRBxMZAusUEEH5/ ht/5/8zzdEOvtkSkW6FgutTUCjg8fVCTsxTN5Revotb2kJUhPseBaX2iGiBRjTGzczTc Ks6pWuaXArG5N0Q4SAH5vFK2zfQ3YdwQX5c3fEYxDcM5VRmNixOgL4xDADbvSBRKQqXI qiMbOxoTuENc7F+7jKxMzUL4u3DT/gzdRBHqENs9wd/nVKfNqjft/XpQdpRSEr60XRE0 UQUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2mx9bPTY7AEcp+j24lhXXPGVls/yhivZ1agLRVxoLiw=; b=fhqg3Mj96SWH2gv3sX1XNO98UsIjJO2B3pWsD6CUv+Fg3j0TISzjJGp0pUB1umg5qQ GUPeOZ45QBtV94NDhdYmn+7fVltyG0D4YZ1jHo2Fqjy6ua7klfyMq0r/+mZ/H6S0TEcX u2CwJqxwLg3ghqPMOaCaErxmAsoDb5WE2tONyOHDijNu2ZJo/HuNWpbGoUMgN9lmLKUj QyPs/js0balyCOzzD/FHWI0rE7h3npt7O9iKN3Wfzrzn7lnNZAJVmXAkh4mKazjTU8ry zGzxl8qgPbNRgFPNfE9msJ7lg3Zfv1HgxSkHSM+zVq/rfhh760teNsyIA8+qGBJ+Dj42 twyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=v+S3AKD3; 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 o11-20020a62cd0b000000b00505b770f007si17083230pfg.249.2022.05.24.07.31.57; Tue, 24 May 2022 07:32:11 -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=v+S3AKD3; 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 S235009AbiEXG2H (ORCPT + 99 others); Tue, 24 May 2022 02:28:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234985AbiEXG17 (ORCPT ); Tue, 24 May 2022 02:27:59 -0400 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 813F172E1F for ; Mon, 23 May 2022 23:27:57 -0700 (PDT) Received: by mail-pg1-x52f.google.com with SMTP id a9so13513213pgv.12 for ; Mon, 23 May 2022 23:27:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2mx9bPTY7AEcp+j24lhXXPGVls/yhivZ1agLRVxoLiw=; b=v+S3AKD3IZY1715alsr8yTzbsVUYEJKe+49LFvD+HdqE9G/w+5EjzEN0EwaEDyGrgn i9Ya3PVga4iPV58AJIeN1oTrMCpdjatANgHWEgSW8H8UHrlDSX4k0sGGqWcV7AXdFW13 EAk3nLfKEjQm6om5mFrDB7o4f02o242GQEXT/WIFEL4yR/3PpF7M5gtnBfzi+dSVbTxu StmM8BZkmo2YtgyD2u3N/KxcgJyaZoQ5QI6XjNdjDbH/gX13NzTb6mqHMmzWnw0wjnjt 6G2U6k80RGyCUtx5VNIlrbZZrmZIkm6UOOp3C70ojMsYgXdvqPAfokDNwMjQRVy8THGC Q/Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2mx9bPTY7AEcp+j24lhXXPGVls/yhivZ1agLRVxoLiw=; b=AFCkqLzTMjh69gAuhKv01elZcabg6YuuvBgKYM+X3BgrlExUoER5jgI2GZyat4EYx+ XBgQ7hIXkZZUhoZKMt56Pj0C77SEjpqQzVHZJaI6s1VKFrjY78UwjX7TtdTxi7jh+nNW LVK11KAB2F7d7KtclClldRbBP3sDFPUC8+9QnLNXuBqARnsja8olnv4uU8q05VMefwML rvjtsykQdQqLMGfcqPqbHO6yFZuodWZfj6ZEOb6TtUvuUpNuAXKjgmy4TWFptPwkaz8R u0FChzD5fc7kHaDySRzm0l5/1OdlmWYLPXGJhAc5ZMirdd2yWt99TxAQ4yYeuz9IWEtP 58/g== X-Gm-Message-State: AOAM530LzaPpFPyUTerh8MzsQyRRglUf/9v/FoCGCGEegf2DaFgJHA4j ND8mH/dazOsJSyZDIu3zKf6KJg== X-Received: by 2002:a62:f901:0:b0:518:307a:b392 with SMTP id o1-20020a62f901000000b00518307ab392mr27007106pfh.44.1653373677075; Mon, 23 May 2022 23:27:57 -0700 (PDT) Received: from FVFYT0MHHV2J.bytedance.net ([2408:8207:18da:2310:f940:af17:c2f5:8656]) by smtp.gmail.com with ESMTPSA id h5-20020a170902f54500b0016168e90f2dsm6254455plf.219.2022.05.23.23.27.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 23:27:56 -0700 (PDT) From: Muchun Song To: hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeelb@google.com Cc: cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, duanxiongchun@bytedance.com, longman@redhat.com, Muchun Song Subject: [PATCH v4 06/11] mm: thp: make split queue lock safe when LRU pages are reparented Date: Tue, 24 May 2022 14:05:46 +0800 Message-Id: <20220524060551.80037-7-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.1 (Apple Git-133) In-Reply-To: <20220524060551.80037-1-songmuchun@bytedance.com> References: <20220524060551.80037-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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-kernel@vger.kernel.org Similar to the lruvec lock, we use the same approach to make the split queue lock safe when LRU pages are reparented. Signed-off-by: Muchun Song --- mm/huge_memory.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index ea152bde441e..cc596034c487 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -543,9 +543,22 @@ static struct deferred_split *folio_split_queue_lock(struct folio *folio) { struct deferred_split *queue; + rcu_read_lock(); +retry: queue = folio_split_queue(folio); spin_lock(&queue->split_queue_lock); + if (unlikely(folio_split_queue_memcg(folio, queue) != folio_memcg(folio))) { + spin_unlock(&queue->split_queue_lock); + goto retry; + } + + /* + * Preemption is disabled in the internal of spin_lock, which can serve + * as RCU read-side critical sections. + */ + rcu_read_unlock(); + return queue; } @@ -554,9 +567,19 @@ folio_split_queue_lock_irqsave(struct folio *folio, unsigned long *flags) { struct deferred_split *queue; + rcu_read_lock(); +retry: queue = folio_split_queue(folio); spin_lock_irqsave(&queue->split_queue_lock, *flags); + if (unlikely(folio_split_queue_memcg(folio, queue) != folio_memcg(folio))) { + spin_unlock_irqrestore(&queue->split_queue_lock, *flags); + goto retry; + } + + /* See the comments in folio_split_queue_lock(). */ + rcu_read_unlock(); + return queue; } -- 2.11.0