From patchwork Thu Sep 16 13:47:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12499131 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D8DEC433EF for ; Thu, 16 Sep 2021 13:52:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4081A60EB4 for ; Thu, 16 Sep 2021 13:52:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4081A60EB4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id D64016B007D; Thu, 16 Sep 2021 09:52:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D13AE6B007E; Thu, 16 Sep 2021 09:52:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BDCCD6B0080; Thu, 16 Sep 2021 09:52:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0095.hostedemail.com [216.40.44.95]) by kanga.kvack.org (Postfix) with ESMTP id AEFB36B007D for ; Thu, 16 Sep 2021 09:52:51 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 72157182811CA for ; Thu, 16 Sep 2021 13:52:51 +0000 (UTC) X-FDA: 78593577342.17.D6FC6CE Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf03.hostedemail.com (Postfix) with ESMTP id 30CEC30000AC for ; Thu, 16 Sep 2021 13:52:51 +0000 (UTC) Received: by mail-pf1-f172.google.com with SMTP id y8so5929558pfa.7 for ; Thu, 16 Sep 2021 06:52:50 -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=xqRNOri396qVGI8Drv9BL2167qBW7PZton2b/SSrCrU=; b=2kJaAcBoYzi6fqMoyRdw1+AjsWMsTyGBQy7Hm71Due/Dq+2fhnE+Tsm9dpkwmuKRBh JMxcMEQmjWJfV81NQNe0RR++yf/2ED9Ng8Oqo1vcyLxobv0UXI+/ERUtF3d1VaJH772L AskxBx0CSNYzk5s6qYuFljJL9swhxrugGy/xPy4u0UgTxcbq9nXOedVcgWkFdnT84TGu RFK68oGYvbh0QAM/b/DrhgDqBIwwfI5nOtihvToD8ikCGQmmksCkIFkXrdNRQjQeSROT HCWR/m2E/xZQ8J91hVD+v9R8MXiusoDjrI1zfCPzqb/XCzmzYBgHWzAjwJgrocJKwrtD muJQ== 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=xqRNOri396qVGI8Drv9BL2167qBW7PZton2b/SSrCrU=; b=KsQJQU9UgRCnvMaDwrFWbjtWhsoxSR2YhQw/X5mGwpJHCjfKsl7L74KtB5qZi7FEwA MGQmgWcwMxNaOtQIT0BMtfnEkBgQPlSRmqEFBmBv+sI5g4v5xiF2u2k2w1UYQEcnJpLp PnHbO7xzhiykaAleqTeIKkcwTLbgrHfUqZNiVzMEQwiEdnLnxsK5yTSjDpuyI+fgDA9Q 3EYNYLl6d1xa0w8XHwRBkdosZG9VISiKNRAtBPNHyiKtXZEJlmnjCaAl8n53fNsLd9pz urb1P1+++jgHHM8Gy6ek3wwd/0e+8cvT3yv6zE1IukTFF7DnJ8ag85zXWQZ2YBcjqsW1 O2fw== X-Gm-Message-State: AOAM530JaSW9+CRgNp3ReNsSX0myzPq36+DSdqWePVJMCG+av3aK2X2E OV1aA9Gwzy38DihSvBuaZ77Ozw== X-Google-Smtp-Source: ABdhPJzAK19Z2U3CeVnflfe4LQQJJPRoJrF0z9YnW5hMuY00wkZvM9UnIjFhxbQu5cpipON9b6hLTw== X-Received: by 2002:a62:dd94:0:b0:442:bb03:9663 with SMTP id w142-20020a62dd94000000b00442bb039663mr2523613pff.0.1631800370277; Thu, 16 Sep 2021 06:52:50 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.226]) by smtp.gmail.com with ESMTPSA id o9sm3617443pfh.217.2021.09.16.06.52.44 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Sep 2021 06:52:49 -0700 (PDT) From: Muchun Song To: guro@fb.com, hannes@cmpxchg.org, mhocko@kernel.org, akpm@linux-foundation.org, shakeelb@google.com, vdavydov.dev@gmail.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, duanxiongchun@bytedance.com, fam.zheng@bytedance.com, bsingharora@gmail.com, shy828301@gmail.com, alexs@kernel.org, smuchun@gmail.com, zhengqi.arch@bytedance.com, Muchun Song Subject: [PATCH v2 07/13] mm: thp: make split queue lock safe when LRU pages reparented Date: Thu, 16 Sep 2021 21:47:42 +0800 Message-Id: <20210916134748.67712-8-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210916134748.67712-1-songmuchun@bytedance.com> References: <20210916134748.67712-1-songmuchun@bytedance.com> MIME-Version: 1.0 Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=2kJaAcBo; spf=pass (imf03.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.210.172 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 30CEC30000AC X-Stat-Signature: 4dcyaeeksxkyjpp8f4k6uz4snqmoask8 X-HE-Tag: 1631800371-92220 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: Similar to lruvec lock, we use the same approach to make the split queue lock safe when LRU pages reparented. Signed-off-by: Muchun Song Reported-by: kernel test robot --- mm/huge_memory.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 9d8dfa82991a..12950d4988e6 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -535,9 +535,22 @@ static struct deferred_split *split_queue_lock(struct page *head) { struct deferred_split *queue; + rcu_read_lock(); +retry: queue = page_split_queue(head); spin_lock(&queue->split_queue_lock); + if (unlikely(split_queue_memcg(queue) != page_memcg(head))) { + 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; } @@ -546,9 +559,19 @@ split_queue_lock_irqsave(struct page *head, unsigned long *flags) { struct deferred_split *queue; + rcu_read_lock(); +retry: queue = page_split_queue(head); spin_lock_irqsave(&queue->split_queue_lock, *flags); + if (unlikely(split_queue_memcg(queue) != page_memcg(head))) { + spin_unlock_irqrestore(&queue->split_queue_lock, *flags); + goto retry; + } + + /* See the comments in split_queue_lock(). */ + rcu_read_unlock(); + return queue; }