From patchwork Sun Jan 17 15:10:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12025491 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 46AC7C433E0 for ; Sun, 17 Jan 2021 15:15:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D9B6522460 for ; Sun, 17 Jan 2021 15:15:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D9B6522460 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 59BA78D0223; Sun, 17 Jan 2021 10:15:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 549178D01D5; Sun, 17 Jan 2021 10:15:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 411508D0223; Sun, 17 Jan 2021 10:15:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0151.hostedemail.com [216.40.44.151]) by kanga.kvack.org (Postfix) with ESMTP id 24BF88D01D5 for ; Sun, 17 Jan 2021 10:15:10 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id DDB9C8249980 for ; Sun, 17 Jan 2021 15:15:09 +0000 (UTC) X-FDA: 77715615138.09.toes34_1611ecc27541 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id C25F6180AD807 for ; Sun, 17 Jan 2021 15:15:09 +0000 (UTC) X-HE-Tag: toes34_1611ecc27541 X-Filterd-Recvd-Size: 6364 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Sun, 17 Jan 2021 15:15:09 +0000 (UTC) Received: by mail-pf1-f172.google.com with SMTP id c79so8688011pfc.2 for ; Sun, 17 Jan 2021 07:15:09 -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=bzTp2uE9CHoAWFah4yyJxWTUfB+cmyxWvhoTCAKbZ/GbPqIkf6+7gzUKY47RMZHXo/ oVnlHNnyQZRxZUT6MvNDQ3ot3S6114f7l+XlPP5MNvClDVNVgSjndoowr5Q6NnML115r r/7pY4sQV9o6EnGIkq75+9vrE11feDSLj5RtwmbuEGLVexIBZbGn9DDYw+eaNgEaJ8p8 HSi1/902LnP8ntoPCyeAvOonjdAOE6e1NRkdvP5x0zcpu0/7hUzKf3MNbBjSremwL+63 bxn9TwHrYlACYtaaY8Op0d8cjKzmwnqdckV7UFTj4FjPUwzDunow9+nXqYCuVf3INlpW t9yQ== X-Gm-Message-State: AOAM533rkzr0AGYZE/ZDJHulatMuZAH4kClRym52lJPoAY5P8HMytUzS 3vGDqSwSSafDvtthCEXSjvS4pA== X-Google-Smtp-Source: ABdhPJwKE9KZZq+vF8UdJn0d8va2uhh4pytapUNaWVa6FNjoKs5iqgjgPpbCtvxqTymHRujF1jknNg== 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 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: 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);