Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1408161pxb; Sun, 17 Jan 2021 07:50:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJzz63LdhK6dyxkQh6aMk/oqQuZI3XTvuy4vJYhkZHkcg3oD7eGKbZopbwWHq9FqxTW0H5rT X-Received: by 2002:a17:906:3b97:: with SMTP id u23mr531340ejf.147.1610898641920; Sun, 17 Jan 2021 07:50:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610898641; cv=none; d=google.com; s=arc-20160816; b=cmc3ZDgmLSq+hi953AVOSIXev75dzMIepi6XwbGx20fyD7wsEEUSbDkrObNYJE5fWw JUzUYtYeOTmT3PjbrUKy98z6tOIezqIMGeAJEXtB68iQkS6yQRukiEaRem7Log4ayP84 BHKVUj9e0vEil31T1DakhHIjj57WKfJO3k8Qr2KujgbzfHiPW1XJntHoGsooa8f3sowG 9blO2QPYHr62BouowtVGdixT3LT30R5nogefQbXPAbk/j68hd6ZYRAE/GwZcsGSTb5Rr 6kPu7/c80lEa4QyGF5wAf7+JpiiJRokcqXfjmCf5FJ3CaZ89C1KYdzubqYzzPfr+8nTh ajKQ== 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=dASYKFPFHjiUnTmEMcq8ifWiWDwHax4a4AuznfbkXhg=; b=gCJxhLE7N4gouYohiJXbTLbg60vx1l3RR9GWjveqGKh0tGOVC4+22KYhe57mWN+f4v SvjQg8J7mF1KHPI0hgz4snYKuQfwD52aQBmqwxJqQYL8JWCdy188ZiY/KuRFlCt5B/og Jkkqc2ghY8rw7nuotWWGr1zY6Ma/Esa0BgJ59RzFaQCB3k2+JGH1jM7I46Y6RNPeMRP3 nOdXE6LcF4Wt7+1E3XQcekhA1U4TsA2R1QemPTgNMnZO40vzoNz3RxA215pk85/FLFUw kDVVp6ZyQzJbeoiFVSkmBZtYSxxR7g7Q0i+/1ZWtRGW1sKiUD/eRCY5fG8iBDmYaxiw+ kDVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=fWMqIgVi; 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 d13si5900440ejz.583.2021.01.17.07.50.18; Sun, 17 Jan 2021 07:50:41 -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=fWMqIgVi; 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 S1729557AbhAQPTi (ORCPT + 99 others); Sun, 17 Jan 2021 10:19:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729451AbhAQPPX (ORCPT ); Sun, 17 Jan 2021 10:15:23 -0500 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEAE8C061798 for ; Sun, 17 Jan 2021 07:14:54 -0800 (PST) Received: by mail-pl1-x633.google.com with SMTP id q4so7222449plr.7 for ; Sun, 17 Jan 2021 07:14:54 -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=dASYKFPFHjiUnTmEMcq8ifWiWDwHax4a4AuznfbkXhg=; b=fWMqIgVimAbohcSo2EpgXsd0ZyJcaZzla1+P95eOMhnyBL67qm5KAucfNimJ/Y8PPb 6lF03rRUJiEGIKgB/d1AF+BsYCsr8ZT/Pkx2QnCiOzg30HL6dN6laFtm47lJUIMes242 fLMU5PBdfikWpoU3XtBfxGbxS21r+dNKUIs0erFDXDnITMS6DorxcHLayrDhExX+u1kd LKu1pnMupUMbBV/W81fmIsxl2VIip0Rjx4irqQjbsT4/3aLaB+AP+zMyGWoJlzg4xCTQ XUmjXCkW9w6/ar5htk+JxAIb65JCm2a9ZELvCKmKVdv+ntoLKXK7+b4P7Ny7qpDyk5jR /pZg== 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=dASYKFPFHjiUnTmEMcq8ifWiWDwHax4a4AuznfbkXhg=; b=FRRkZu7Ee8WKGeT3U2F5OUty9fZxJCmLGAYQAbUfSa/dvvtPnKBZyyBpe9XGXxtn1q Q+8YRzenEqQycYH/8CBLS+ue5eMwP6GwWrSBgf+qyEde9cG2UlSkevlPGB3zVkvJ4+We kiMchOLZsA5394P15dn+JY/lFK93pL/rC7j2EStD9iDYVeMPp99mYd71PQ20n5d3Ec4U R0e7V2L7m5YBEy04SKaByEBoyqX2se8FXtFxMdDum2AuDdzyQQm2G2VLDCDEk+b9SKcF tP0xxWTMELdzLXv93gUt7MJC/MCTYudYQTnJW1Fw/PmG6HO34aru9QmN4sBQfTmfu4wH OXnA== X-Gm-Message-State: AOAM530dYgDlP1QFztf+/iawSaCFqiIvZPW+FiOg63+ngPvNZDSEe/MI nsM56VmpDpMrL+suljSIsxTZVw== X-Received: by 2002:a17:90a:df84:: with SMTP id p4mr21024876pjv.81.1610896494542; Sun, 17 Jan 2021 07:14:54 -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.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 17 Jan 2021 07:14:54 -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 07/12] mm: hugetlb: flush work when dissolving a HugeTLB page Date: Sun, 17 Jan 2021 23:10:48 +0800 Message-Id: <20210117151053.24600-8-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 We should flush work when dissolving a HugeTLB page to make sure that the HugeTLB page is freed to the buddy allocator. Because the caller of dissolve_free_huge_pages() relies on this guarantee. Signed-off-by: Muchun Song Reviewed-by: Oscar Salvador --- mm/hugetlb.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 6caaa7e5dd2a..3222bad8b112 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1337,6 +1337,12 @@ static void update_hpage_vmemmap_workfn(struct work_struct *work) } static DECLARE_WORK(hpage_update_work, update_hpage_vmemmap_workfn); +static inline void flush_hpage_update_work(struct hstate *h) +{ + if (free_vmemmap_pages_per_hpage(h)) + flush_work(&hpage_update_work); +} + static inline void __update_and_free_page(struct hstate *h, struct page *page) { /* No need to allocate vmemmap pages */ @@ -1887,6 +1893,7 @@ static int free_pool_huge_page(struct hstate *h, nodemask_t *nodes_allowed, int dissolve_free_huge_page(struct page *page) { int rc = -EBUSY; + struct hstate *h = NULL; /* Not to disrupt normal path by vainly holding hugetlb_lock */ if (!PageHuge(page)) @@ -1900,8 +1907,9 @@ int dissolve_free_huge_page(struct page *page) if (!page_count(page)) { struct page *head = compound_head(page); - struct hstate *h = page_hstate(head); int nid = page_to_nid(head); + + h = page_hstate(head); if (h->free_huge_pages - h->resv_huge_pages == 0) goto out; @@ -1915,6 +1923,14 @@ int dissolve_free_huge_page(struct page *page) } out: spin_unlock(&hugetlb_lock); + + /* + * We should flush work before return to make sure that + * the HugeTLB page is freed to the buddy. + */ + if (!rc && h) + flush_hpage_update_work(h); + return rc; } -- 2.11.0