Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1396991pxb; Sun, 17 Jan 2021 07:25:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJzkjCBTr6KuF298zELsjYGvZ3M931er2+OBiRnOY6Xp3eK3KAdAO4Ssv4dCHnxSD7D86P/o X-Received: by 2002:a17:906:4143:: with SMTP id l3mr3396700ejk.306.1610897111052; Sun, 17 Jan 2021 07:25:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610897111; cv=none; d=google.com; s=arc-20160816; b=XBHgeLpK27fLOAh0Els2FmtC35jS6MVVf6+pYPtau33OwH+xlCyq0yH4ofcc78Jrqi jWIqnd4uiZq6E46biY3/K70cFsFgC5Qz9icER7CGa3KPqLS4bmHl/IoFdJeLl+ji7VI1 2uRj6XzarwmR4tcR4KKpfd0soy+B1XspHvGlrq7jRgVobjIW5Xk1xqlELGsflgn8BRm4 90G3UChi9tn8o139FP6lcCsNyKHAaZmfVlkkATtNdlD1JQrk0roECfvQtkc9nRsjxiLE 9A0Dq+wjC7fHblo3O8J0nYx4ZW5Cnfm17+ZvRCdBsth67nB+439phuzq4x/yaBPp+OhV hdow== 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=leMCwiJUMOALRI5sultiZwFK5v4LdPgwOBvUXqzpH+M=; b=FlqQb+r68iDFytsN6gswnq/PAurjQWjHBKa1tdRByka0XwIbnN5EgaGo1h/yprYcJa 5ghzlygm9PYZrNcOhR3AL586MkKmBZhwh8og/QlcOPzo3cE1eqA8oc3Vi2u/PDiup6EH BNCOZTxMxLX7TbwIRMx6vMQ+DZYyqkx4z6M+tbOkmIySToN2amzD7BhvKwuBgfFlf1Im n5SwBgyNPkBH43QDU0ZqZS9B0JhxlWfqKi2NQUcp8tJK7YZTW6EvguXRsKCS5vrOBKm0 OuDNNn2wJ0D2UkVMapYEUb+yHRi2j5XNt2bhWhRLXhjgOQKuVSw7J0X73hr03I77l+js K9ZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=nU947GUB; 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 dp16si6185542ejc.564.2021.01.17.07.24.48; Sun, 17 Jan 2021 07:25:11 -0800 (PST) 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=nU947GUB; 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 S1729575AbhAQPUI (ORCPT + 99 others); Sun, 17 Jan 2021 10:20:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729552AbhAQPP2 (ORCPT ); Sun, 17 Jan 2021 10:15:28 -0500 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F287BC061573 for ; Sun, 17 Jan 2021 07:15:08 -0800 (PST) Received: by mail-pf1-x42f.google.com with SMTP id 11so8665239pfu.4 for ; Sun, 17 Jan 2021 07:15:08 -0800 (PST) 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=leMCwiJUMOALRI5sultiZwFK5v4LdPgwOBvUXqzpH+M=; b=nU947GUBl5gNEwin/Dh5khj/oNK7YocifknATbfcT2PQvf7wzkSL2i6ac0RWNMcswJ Qx9QJkfu5r/pQ7szUy775TQPy5EYJmymzC4qqeBhixQbfrtgPUktVp0kRD17Ri4XG+4J rFJZmd9tnAuk3hx+ll4HmwdZo6uF07W1TaOuGWE4131eUzOEOT/wPOHoTn9/3BgFsoBD NCvpEwEJMtD/6JLkB8zj6uSHx5rbDo6arnxQMWYoygDiNYrii79NFNrRhjzxLaOJoiZB EmB3Sqvobb4k/AvAem+aG5Crop1DkzAosxPSsCTPLN8ffvz62UC2MmSITreWPt793E89 z9mA== 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=leMCwiJUMOALRI5sultiZwFK5v4LdPgwOBvUXqzpH+M=; b=RfNiOzLfNG1ndcnCkINxBw0Yrnwmo8JFB/iPOkhr9e7JRuSs53/5zN8ea8gcLGRvkJ 6JPh9cZMQB3JIWiJoNtJ515nk2+D3oRYtYTtle4OYF+lEJTzHCdW3rJgo/7rfpUs1H3X lJ0zEnWuNjaC52V5uv8AsZpytFLWaKzNRyGwrZ2YKQQUQ79Im67gZxn3+yE+FMVRA3sO d6AA+0d9F06at2To7zWzdcjEeceipSraQyJ8uwxtW/i68mN7PUyWvPMjAx+JlgjUyNFj hTLJcXbohzfjHpSmW/kIfwkYe+m5e7OY3yhveCQmEUsn8NN8/texhWutcnumx4xjAw6q 1i/A== X-Gm-Message-State: AOAM530ZQbIfsbYFy+NPNImSBY5ycKShNIDGz9ru8ulPeBXSAuLR8XQo s4NCo7LdVWMeqqIOISJN1c79Iw== X-Received: by 2002:aa7:83cd:0:b029:1a5:fb23:ad7f with SMTP id j13-20020aa783cd0000b02901a5fb23ad7fmr22184733pfn.46.1610896508537; Sun, 17 Jan 2021 07:15:08 -0800 (PST) Received: from localhost.bytedance.net ([139.177.225.247]) by smtp.gmail.com with ESMTPSA id i22sm9247915pjv.35.2021.01.17.07.14.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 17 Jan 2021 07:15:08 -0800 (PST) From: Muchun Song To: corbet@lwn.net, mike.kravetz@oracle.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, viro@zeniv.linux.org.uk, akpm@linux-foundation.org, paulmck@kernel.org, mchehab+huawei@kernel.org, pawan.kumar.gupta@linux.intel.com, rdunlap@infradead.org, oneukum@suse.com, anshuman.khandual@arm.com, jroedel@suse.de, almasrymina@google.com, rientjes@google.com, willy@infradead.org, osalvador@suse.de, mhocko@suse.com, song.bao.hua@hisilicon.com, david@redhat.com, naoya.horiguchi@nec.com Cc: duanxiongchun@bytedance.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Muchun Song Subject: [PATCH v13 08/12] mm: hugetlb: introduce PageHugeInflight Date: Sun, 17 Jan 2021 23:10:49 +0800 Message-Id: <20210117151053.24600-9-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210117151053.24600-1-songmuchun@bytedance.com> References: <20210117151053.24600-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When we free a HugeTLB page whose vmemmap pages can be optimized, it is freed to the buddy allocator through a kworker. And the ref count of page is zero, so if we dissolve it before it is freed to the buddy allocator. It can be freed again. In order to avoid this, we introduce PageHugeInflight to indicate that the HugeTLB page is already freed from hugepage pool but not freed to buddy allocator yet. When we hit the inflight page, we just need to flush the work. Signed-off-by: Muchun Song --- mm/hugetlb.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 3222bad8b112..14549204ddcb 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1343,6 +1343,36 @@ static inline void flush_hpage_update_work(struct hstate *h) flush_work(&hpage_update_work); } +#ifdef CONFIG_HUGETLB_PAGE_FREE_VMEMMAP +static inline bool PageHugeInflight(struct page *head) +{ + return page_private(head + 5) == -1UL; +} + +static inline void SetPageHugeInflight(struct page *head) +{ + set_page_private(head + 5, -1UL); +} + +static inline void ClearPageHugeInflight(struct page *head) +{ + set_page_private(head + 5, 0); +} +#else +static inline bool PageHugeInflight(struct page *head) +{ + return false; +} + +static inline void SetPageHugeInflight(struct page *head) +{ +} + +static inline void ClearPageHugeInflight(struct page *head) +{ +} +#endif + static inline void __update_and_free_page(struct hstate *h, struct page *page) { /* No need to allocate vmemmap pages */ @@ -1351,6 +1381,8 @@ static inline void __update_and_free_page(struct hstate *h, struct page *page) return; } + SetPageHugeInflight(page); + /* * Defer freeing to avoid using GFP_ATOMIC to allocate vmemmap * pages. @@ -1637,6 +1669,7 @@ static void prep_new_huge_page(struct hstate *h, struct page *page, int nid) { free_huge_page_vmemmap(h, page); + ClearPageHugeInflight(page); INIT_LIST_HEAD(&page->lru); set_compound_page_dtor(page, HUGETLB_PAGE_DTOR); set_hugetlb_cgroup(page, NULL); @@ -1913,13 +1946,16 @@ int dissolve_free_huge_page(struct page *page) if (h->free_huge_pages - h->resv_huge_pages == 0) goto out; + rc = 0; hwpoison_subpage_set(h, head, page); + if (PageHugeInflight(head)) + goto out; + list_del(&head->lru); h->free_huge_pages--; h->free_huge_pages_node[nid]--; h->max_huge_pages--; update_and_free_page(h, head); - rc = 0; } out: spin_unlock(&hugetlb_lock); -- 2.11.0