From patchwork Tue Aug 2 10:07:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: luofei X-Patchwork-Id: 12934461 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71A4CC19F2C for ; Tue, 2 Aug 2022 10:07:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 117848E0003; Tue, 2 Aug 2022 06:07:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0A0776B0072; Tue, 2 Aug 2022 06:07:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E5C2C8E0003; Tue, 2 Aug 2022 06:07:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id D4DFA6B0071 for ; Tue, 2 Aug 2022 06:07:48 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 98ECBAA192 for ; Tue, 2 Aug 2022 10:07:48 +0000 (UTC) X-FDA: 79754226216.22.1839D0F Received: from spam.unicloud.com (mx.gosinoic.com [220.194.70.58]) by imf29.hostedemail.com (Postfix) with ESMTP id 14E301200F1 for ; Tue, 2 Aug 2022 10:07:45 +0000 (UTC) Received: from eage.unicloud.com ([220.194.70.35]) by spam.unicloud.com with ESMTP id 272A7VV3097087; Tue, 2 Aug 2022 18:07:31 +0800 (GMT-8) (envelope-from luofei@unicloud.com) Received: from localhost.localdomain (10.10.1.7) by zgys-ex-mb09.Unicloud.com (10.10.0.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2375.17; Tue, 2 Aug 2022 18:07:30 +0800 From: luofei To: , , CC: , , luofei Subject: [PATCH] mm, hwpoison, hugetlb: Free hwpoison huge page to list tail and dissolve hwpoison huge page first Date: Tue, 2 Aug 2022 06:07:11 -0400 Message-ID: <20220802100711.2425644-1-luofei@unicloud.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Originating-IP: [10.10.1.7] X-ClientProxiedBy: zgys-ex-mb09.Unicloud.com (10.10.0.24) To zgys-ex-mb09.Unicloud.com (10.10.0.24) X-DNSRBL: X-MAIL: spam.unicloud.com 272A7VV3097087 ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf29.hostedemail.com: domain of luofei@unicloud.com designates 220.194.70.58 as permitted sender) smtp.mailfrom=luofei@unicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659434867; a=rsa-sha256; cv=none; b=HX/arEeHaw8ghwqtMFVg81xbsfbBihq2VCfXNjG6BZKLSLyGmBNyDW873OIT6DdxPUnM74 w7vqaVC82XJFbGphJanSFGwu27E4jupxLikalEpFIkx9DxGWHI9+xm+NsDLcddzmUZGfny SOeWKklUSwjSlXqZWnJEk6MoAJgwGJ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659434867; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=QIPGMgEz3i66cNliR5lVrlPJjpAJ04mKVOQ17UnqePc=; b=pcZ6NfMrgfqY6f3fHg0eLaUgrbKAZ6gCUdUzZQc+NWmaVtUljpy3oYNAB8OOzPQP4Lcqok qEG+lLAaq4IV0KrTWacNy8x7MSc3e5LHJL3eTOqfivA2FVi5+sZmAT0SsPPVwjjoYJF98m XdAvAGIw4OcblFINY1iBK3No3ria9w8= X-Stat-Signature: 8pi3o3z79hnpz7wt1xfycmk6cbhjrgt9 X-Rspamd-Queue-Id: 14E301200F1 X-Rspam-User: Authentication-Results: imf29.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf29.hostedemail.com: domain of luofei@unicloud.com designates 220.194.70.58 as permitted sender) smtp.mailfrom=luofei@unicloud.com X-Rspamd-Server: rspam04 X-HE-Tag: 1659434865-189185 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000532, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: If free hwpoison huge page to the end of hugepage_freelists, the loop can exit directly when the hwpoison huge page is traversed, which can effectively reduce the repeated traversal of the hwpoison huge page. Meanwhile, when free the free huge pages to lower level allocators, if hwpoison ones are released first, this can improve the effecvive utilization rate of huge page. Signed-off-by: luofei --- mm/hugetlb.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 28516881a1b2..ca72220eedd9 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1116,7 +1116,10 @@ static void enqueue_huge_page(struct hstate *h, struct page *page) lockdep_assert_held(&hugetlb_lock); VM_BUG_ON_PAGE(page_count(page), page); - list_move(&page->lru, &h->hugepage_freelists[nid]); + if (unlikely(PageHWPoison(page))) + list_move_tail(&page->lru, &h->hugepage_freelists[nid]); + else + list_move(&page->lru, &h->hugepage_freelists[nid]); h->free_huge_pages++; h->free_huge_pages_node[nid]++; SetHPageFreed(page); @@ -1133,7 +1136,7 @@ static struct page *dequeue_huge_page_node_exact(struct hstate *h, int nid) continue; if (PageHWPoison(page)) - continue; + break; list_move(&page->lru, &h->hugepage_activelist); set_page_refcounted(page); @@ -2045,7 +2048,7 @@ static struct page *remove_pool_huge_page(struct hstate *h, */ if ((!acct_surplus || h->surplus_huge_pages_node[node]) && !list_empty(&h->hugepage_freelists[node])) { - page = list_entry(h->hugepage_freelists[node].next, + page = list_entry(h->hugepage_freelists[node].prev, struct page, lru); remove_hugetlb_page(h, page, acct_surplus); break; @@ -3210,7 +3213,7 @@ static void try_to_free_low(struct hstate *h, unsigned long count, for_each_node_mask(i, *nodes_allowed) { struct page *page, *next; struct list_head *freel = &h->hugepage_freelists[i]; - list_for_each_entry_safe(page, next, freel, lru) { + list_for_each_entry_safe_reverse(page, next, freel, lru) { if (count >= h->nr_huge_pages) goto out; if (PageHighMem(page)) @@ -3494,7 +3497,7 @@ static int demote_pool_huge_page(struct hstate *h, nodemask_t *nodes_allowed) for_each_node_mask_to_free(h, nr_nodes, node, nodes_allowed) { list_for_each_entry(page, &h->hugepage_freelists[node], lru) { if (PageHWPoison(page)) - continue; + break; return demote_free_huge_page(h, page); }