From patchwork Sat Aug 14 05:25:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12436499 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.5 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,URIBL_BLOCKED,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 33C31C4338F for ; Sat, 14 Aug 2021 05:26:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D04A8604D7 for ; Sat, 14 Aug 2021 05:26:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D04A8604D7 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 780798D0008; Sat, 14 Aug 2021 01:26:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 730818D0002; Sat, 14 Aug 2021 01:26:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F8E58D0008; Sat, 14 Aug 2021 01:26:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0027.hostedemail.com [216.40.44.27]) by kanga.kvack.org (Postfix) with ESMTP id 459F78D0002 for ; Sat, 14 Aug 2021 01:26:09 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E2FFC8249980 for ; Sat, 14 Aug 2021 05:26:08 +0000 (UTC) X-FDA: 78472550016.22.F3C8590 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf13.hostedemail.com (Postfix) with ESMTP id AD52A101939C for ; Sat, 14 Aug 2021 05:26:08 +0000 (UTC) Received: by mail-pl1-f182.google.com with SMTP id l11so14697742plk.6 for ; Fri, 13 Aug 2021 22:26:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QGMUDL+X4tm/vJIxNFScO4bfVyq5TxNYHUST0OzJycs=; b=Awt006hzmvp3826E028AW54ZQdcH/iHJCFQh7D9WUYxFSVFbozsLRpX7pQ6JEIbg9W s4SyjyqL9SpQNj5AOBfRol+2Kcok6r9Fmk4sH07/7Rxg6R8djmoy6Rc0pKWV+wPdbKBq QkaIJ9bx9o5fdhBlierm42heq3f4pVeSrmi2XaepkVDKf6KsaxR/iom6ChVarEzFNycO TgxgCEjhQw+v9g3ClTw9De3JOtcS0gkL1Oxwz2orY/wTPDBR3qCjPMc8ZJRo9PYZ+rYA dNi8x/tbixxIlvFIaMh6OyuxbSDVbh/X3m8LKHGD15HXOdaD9NlcclnMEcybsIXFNapR CAGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QGMUDL+X4tm/vJIxNFScO4bfVyq5TxNYHUST0OzJycs=; b=qDXBosT75UV1uxAkPcOcXtaUrglwd7ZEf39p5TuNq4PajGHreZx9cKH74EiePGlbZe axoJoGOIdjAGJNTUnC3ZtiVZ3R7ujrL/oCqdcFfdIutH4K3tMtBtUEYMgAaxw3KjgYoy AtJ4oLNpdBJ8pfiXJPAA24ZcM7sNF5PzFKeaNM4W0ApBn1IDbdRiRYn6BnT9GAhmMA0Q PxnEsHXYs4Fb0Lh95uawNq09aVR8mO6GpNm/5Tv3AzVMx88O45atC59gWyDuy980OnOQ Owp+r3lYhPbfhmhN0DtPwJwVrIU6paNXz3nr1Qks/TeQqyKjOlyFIeLmXjtb4nr/DbUj fmHw== X-Gm-Message-State: AOAM532fZqOzgPj5Q416MLfOQxs0p8RFQL8I+1FwKwTSmr99O4d/iA9m 4R0T3Mzmnsc41VszdpUsjxhfEw== X-Google-Smtp-Source: ABdhPJxAx+pnIIz1Pwn50bFJeyyCUDyRI7YRH37fF9YnbX2dv1IvGhcPf/LkKmZqfJrEz5hhj6s9pg== X-Received: by 2002:a63:5153:: with SMTP id r19mr5516505pgl.56.1628918767822; Fri, 13 Aug 2021 22:26:07 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.237]) by smtp.gmail.com with ESMTPSA id s5sm4783133pgp.81.2021.08.13.22.26.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Aug 2021 22:26:07 -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 v1 06/12] mm: thp: make split queue lock safe when LRU pages are reparented Date: Sat, 14 Aug 2021 13:25:13 +0800 Message-Id: <20210814052519.86679-7-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210814052519.86679-1-songmuchun@bytedance.com> References: <20210814052519.86679-1-songmuchun@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: AD52A101939C Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=Awt006hz; spf=pass (imf13.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-Rspamd-Server: rspam01 X-Stat-Signature: n8ddjwgpujjcnasq8mcpj7d5p66ubfgd X-HE-Tag: 1628918768-346895 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 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 c49ef28e48c1..22fbf2c74d49 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -535,9 +535,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(split_queue_memcg(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; } @@ -546,9 +559,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(split_queue_memcg(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; }