Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1313588pxf; Fri, 9 Apr 2021 05:36:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5A+xJuBD8s+zVzs8Oj74GUuuJnvZyWZr7bioGUTZVaQgddLYbGnPS4NGvOrrSIxu3oVmg X-Received: by 2002:a17:906:4a89:: with SMTP id x9mr5955042eju.121.1617971805844; Fri, 09 Apr 2021 05:36:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617971805; cv=none; d=google.com; s=arc-20160816; b=a4FiM+6UiL22rMzq/3oQIQfNqZqeyg/qIV0Kpj6Lx8izfTu7fWhnwXcuLfMamKQGEr SHWQVekU++TppEdAmPFENqEn6ZDOqpCkHmOqm0swmyFAQoDjH+6IkMMTQX3CfUpcmBtB 26W0KghlT1nHi00R07RS5jVfv9yUJF3XORaYvreD4mqOTy3PASVy9e1/Ad8M1r7tjZSD frU0ZKF4JjwzSdN1X4lCBRjMwFCpE1RpVT/tGWue0gUt/WZ3eKw5Yzu02JD83ckrAJJC hgykBNctUPmZTV7Nck7jfTg56RApZyt3ZLQA1CnuGNMCxFrDxX7/LziI+HHcEOZJfeQv NKWg== 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=EoY+xVUIMEYkMAOym+tsxa0CiEBJagAGYOcFqP2KHJM=; b=h8/Odu6KT29sKe/BqNUNEqtRrBQHwzvjllzwlwMJPircyQpMinVjbfOhWCqPZmN6E/ 4eJJqTaaa+pbPyvwSQUkgpORSc/wBJ1cH5Sp2d0AgKoNu3suh7vEAf0AxDoRD8NIrh6o sgJZQJgP1OpW/8kSVtCUA+FGXkdSkv9G8qTMBfvugpXIHCbT7WunUj7I6kMTUUf8eL0W YcL+CBzLGlydi8KOSzbTsOVB8tnFa1lJjOBkWZqzLuFHKXOpSoqp5Ud6jjkbTHwFXIJH u4xhNPPRDUTW62Shl2+xxYuUCjc7YqKe69mQ4Wlqg6Em6Fsm8sTodVABemudKdpb4DXU c79A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=DsZMvhHW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g21si1156670edy.78.2021.04.09.05.36.22; Fri, 09 Apr 2021 05:36:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=DsZMvhHW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S233805AbhDIMdW (ORCPT + 99 others); Fri, 9 Apr 2021 08:33:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233808AbhDIMdO (ORCPT ); Fri, 9 Apr 2021 08:33:14 -0400 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74DE3C061762 for ; Fri, 9 Apr 2021 05:33:01 -0700 (PDT) Received: by mail-pg1-x529.google.com with SMTP id b17so3787397pgh.7 for ; Fri, 09 Apr 2021 05:33:01 -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=EoY+xVUIMEYkMAOym+tsxa0CiEBJagAGYOcFqP2KHJM=; b=DsZMvhHWm4mrMrUgLxwe8rmKzWWGxf5n4KDgWVqWnWqFoXsMw/R6RWat4E5ynjciPk NX5/37x4XChb5bZbcKFnhd74XnMGTkmeesqaXJ+BjFZb1cs8nHlEo3NLugIlnUtS6ZqN RdbYWTmfPloA5h6gYb7ly2Ifp6esesBHDsIvYDowG1iBHvQ4hVO49/SnUyuKyxqNvkO/ 7bmPHKo9m7QPwRqWseQOIAxd4MGTZlmLswvyk2BFfbviZMyEFVdeUl6FforiFvqPCaTw Fcp6aBUn08w1ytjHCZGWAmPz6KeBflhR4bSL3oJKjbuBmiurrVlzQ6wjdAxEaE/0722/ OHmQ== 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=EoY+xVUIMEYkMAOym+tsxa0CiEBJagAGYOcFqP2KHJM=; b=J+fwoU0WNihvfQus/YrqxxxwgUtKlDsNyFQVfCyAz/zku60VlDj5dBdKfV9YZipcU8 mCsSCvimF6HZWR9f1SXSGE4P05tN+pqUcFr/KTwv49ffU6VltwTBbPD0Z9RnNzGgtuj2 C3er7bH1Z5KuDvXncpFGY+UI2wPT2PYvZKosIP0u9503BGn0fHfKzFv15ichKl4p6m+5 JIHyT3QuNWpM8S7+NJFN/Plaz7c49R1sSgv8oDkNXcmtOlYOVQqq0gaz1XoBJ1J1X4ns ztcdgBRxT4lA6NkWBWEfjVzGtNsl5RFj+0N5WMqdkLM8ik84vZAU6lYIHLNsO35yckMe JODA== X-Gm-Message-State: AOAM530nSgVL6Luj6L35H44WfAkB7nL1jgSP8T/KphynkmqOJNL3Q/bt jG5PyO2NbEBPzN5TtISPfv1I24umWsAZ7INM X-Received: by 2002:a05:6a00:1e:b029:241:72c2:695e with SMTP id h30-20020a056a00001eb029024172c2695emr12073445pfk.17.1617971581010; Fri, 09 Apr 2021 05:33:01 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.243]) by smtp.gmail.com with ESMTPSA id t3sm2167785pfg.176.2021.04.09.05.32.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Apr 2021 05:33:00 -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, alex.shi@linux.alibaba.com, Muchun Song Subject: [RFC PATCH v2 12/18] mm: thp: make deferred split queue lock safe when the LRU pages reparented Date: Fri, 9 Apr 2021 20:29:53 +0800 Message-Id: <20210409122959.82264-13-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210409122959.82264-1-songmuchun@bytedance.com> References: <20210409122959.82264-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Similar to lruvec lock, we use the same approach to make the lock safe when the LRU pages 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 275dbfc8b2ae..aa5d7b72d5fc 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -497,6 +497,8 @@ static struct deferred_split *lock_split_queue(struct page *page) struct deferred_split *queue; struct mem_cgroup *memcg; + rcu_read_lock(); +retry: memcg = page_memcg(compound_head(page)); if (memcg) queue = &memcg->deferred_split_queue; @@ -504,6 +506,17 @@ static struct deferred_split *lock_split_queue(struct page *page) queue = &NODE_DATA(page_to_nid(page))->deferred_split_queue; spin_lock(&queue->split_queue_lock); + if (unlikely(memcg != page_memcg(page))) { + 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; } @@ -513,6 +526,8 @@ static struct deferred_split *lock_split_queue_irqsave(struct page *page, struct deferred_split *queue; struct mem_cgroup *memcg; + rcu_read_lock(); +retry: memcg = page_memcg(compound_head(page)); if (memcg) queue = &memcg->deferred_split_queue; @@ -520,6 +535,14 @@ static struct deferred_split *lock_split_queue_irqsave(struct page *page, queue = &NODE_DATA(page_to_nid(page))->deferred_split_queue; spin_lock_irqsave(&queue->split_queue_lock, *flags); + if (unlikely(memcg != page_memcg(page))) { + spin_unlock_irqrestore(&queue->split_queue_lock, *flags); + goto retry; + } + + /* See the comments in lock_split_queue(). */ + rcu_read_unlock(); + return queue; } #else -- 2.11.0