From mboxrd@z Thu Jan 1 00:00:00 1970 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 28D3FC3ABAC for ; Fri, 2 May 2025 08:27:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A950B6B008A; Fri, 2 May 2025 04:27:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A43956B008C; Fri, 2 May 2025 04:27:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9584A6B0092; Fri, 2 May 2025 04:27:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 771896B008A for ; Fri, 2 May 2025 04:27:32 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8D4DB1CEA31 for ; Fri, 2 May 2025 08:27:33 +0000 (UTC) X-FDA: 83397288786.14.C3D7D4B Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf04.hostedemail.com (Postfix) with ESMTP id 5882E4000D for ; Fri, 2 May 2025 08:27:31 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf04.hostedemail.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1746174452; a=rsa-sha256; cv=none; b=606Q5eCkr2zXPRJO9E3iJI8UQU8VlkUJogCh/+GnLmSdXrGJB9qnWh/wqr69rAZV3s2V25 22iEqIDALCwXxgRF0Ld0eivwNxyVGeBhuKxkwcXc1bxncHtUNPOaHGxn0BCK5tgKByO9QX 0ho9cvBNZCXUH9XxXT+cw3Zz9TJCYek= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf04.hostedemail.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1746174452; 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:in-reply-to:references:references; bh=GSYuwzmTE7W2Bk3tlKPZA+uJVtT6cFv0laRPjOD+R7w=; b=IvZ0TJqfYwW+XBPc+Evaa8uPhoWUqYYHfuqlPEAOR5cNFopcKDUgrF7T8UH2uyRb2xScC6 heRAdqvezlbJ/8ojlzI3G/XK9yg7Xm9ESB2yxCB3fJqZwxjB0cmSfi/BnoV8nJ2RCEpEPg fQMIE8gp+/Tyvpzr0pMt+C/0zhbkAWw= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 95CFB106F; Fri, 2 May 2025 01:27:22 -0700 (PDT) Received: from [10.163.80.122] (unknown [10.163.80.122]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 88BF23F66E; Fri, 2 May 2025 01:27:28 -0700 (PDT) Message-ID: Date: Fri, 2 May 2025 13:57:25 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm/hugetlb: copy the CMA flag when demoting To: Frank van der Linden , akpm@linux-foundation.org, muchun.song@linux.dev, linux-mm@kvack.org Cc: osalvador@suse.de References: <20250501044325.20365-1-fvdl@google.com> Content-Language: en-US From: Anshuman Khandual In-Reply-To: <20250501044325.20365-1-fvdl@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 5882E4000D X-Stat-Signature: qp6ccinfzmmy46idghkbi819dujam1sb X-HE-Tag: 1746174451-602388 X-HE-Meta: U2FsdGVkX18t1S16mueuWQGl/AGPCMKm9BgrU5ODht/dGt4kiMckCEID1Yr3JV1PE77UssH9beVIiOEGgBkxp2LHaleoohTb98UNtg1jbt/w2AaoHT1CmK6zpHW1pNAjiX9Tyl2BabCvRFsC3HzqlYK280GeJquTrr5M5YOiOFeE6vsLPPg+8Dcgo0fOouIDXUAnwNRP0rVv0sZVf6B6Q327xurSBVK3EemthrbbRcmtuQgol87fKuZUBxC+iuujZY5R31KSskRtYy7ygH3RcuF2q8Dh4ZiCstbjgPDFCkzvKCZpzjlu/35M9TVn4r3pjHRqB2ju7wb530ELsheAWcDykmA+VWCMhUztHYhLmudVha9lS4wvlJxobOCFNwIkk84nlCpY0WGuXzFvji4/YcfGMoQ6U/iJ7yodkUZ6DHaPiR4/9H0qn2LH4ZHbuQYd8shaMaub4H0gXYzeG1ppJiHaJfBasH2hfQJ4YCH0pQPj18qki26DqBSVPhPPxSCwzB5pVd4Spsw+2w3sM2o6ING8j9fbdo0Hcf9sxIThSGLsnx//HYAZQXHdS9ErO6uVs0xYK2mB64hABqVT+JMj6H9gfR0upeSkJ6Sd26f6Zrp0iusZMxx8tDahTlFSGh3bt0Gwbe2KKPtN5UhnKXYBh5pjSNpyIJACL8hmRCcmVS1RLB7ti/gbARp1HxA1pahyq02o04Hz843i0owGZ/H5U92RBYXmtA/wyFeFMjBfuA1273FjUAHTZTwTg/1AoWdYNdmSeOvmhd/KGExOnC8guNVmp53+bdJK5sjLAv6fKERELuclCiEFLB+Tm4iqc3PTIx0DZ4flN7rAhogcDMjBfP7sgWkV1cJX2Jl0Kmbvi9fg+4r58mHa/otnv3WnVUbRhctOrYAgfCQiDk7Y37i68s42NqtfWjmRLi2U1TbVS9bO7ZSQfTkFyv/tjTwGAjq8bL2KTsSiZbDUEb9KH+1 jteQSITd ZQXPOUrsnR2LHvP62DgaQ+sVngHNSwlN0PLEIkjT9l8rvBWP9FcRjkuIaqTZZMZ1J1TwsG7YbRfghjGXn7ciDEjC5AVR2VTsj1WMnpOYWIetHs7hSq0p4MxVXx0Emu2nEAa2RcNptG0Pt1qeyJrAffnNchTNVShNTUyEFLowD0fnyqwUz9qwBjBAZAIL3i89Rzwh3KpOzHnlorwWtojtAu6vswvKqY7HVDvnW 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: List-Subscribe: List-Unsubscribe: On 5/1/25 10:13, Frank van der Linden wrote: > Since commit d2d786714080 ("mm/hugetlb: enable bootmem allocation > from CMA areas"), a flag is used to mark hugetlb folios as allocated > from CMA. This flag is also used to decide if it should be freed > to CMA. > > However, the flag isn't copied to the smaller folios when a hugetlb > folio is broken up for demotion, which would cause it to be freed > incorrectly. > > Fix this by copying the flag to the smaller order hugetlb pages > created from the original one. > > Fixes: d2d786714080 ("mm/hugetlb: enable bootmem allocation from CMA areas") > Signed-off-by: Frank van der Linden > --- > mm/hugetlb.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index e3e6ac991b9c..6ea1be71aa42 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -4034,10 +4034,13 @@ static long demote_free_hugetlb_folios(struct hstate *src, struct hstate *dst, > > list_for_each_entry_safe(folio, next, src_list, lru) { > int i; > + bool cma; > > if (folio_test_hugetlb_vmemmap_optimized(folio)) > continue; > > + cma = folio_test_hugetlb_cma(folio); > + > list_del(&folio->lru); > > split_page_owner(&folio->page, huge_page_order(src), huge_page_order(dst)); > @@ -4053,6 +4056,9 @@ static long demote_free_hugetlb_folios(struct hstate *src, struct hstate *dst, > > new_folio->mapping = NULL; > init_new_hugetlb_folio(dst, new_folio); > + /* Copy the CMA flag so that it is freed correctly */ > + if (cma) > + folio_set_hugetlb_cma(new_folio); > list_add(&new_folio->lru, &dst_list); > } > } Agree with Oscar that HPG_cma need documentation like other flags. Reviewed-by: Anshuman Khandual