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 9104FC021A0 for ; Sat, 15 Feb 2025 05:50:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 73D276B0082; Sat, 15 Feb 2025 00:50:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6C7346B0083; Sat, 15 Feb 2025 00:50:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 567446B0085; Sat, 15 Feb 2025 00:50:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 367C26B0082 for ; Sat, 15 Feb 2025 00:50:30 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id DAEC3141436 for ; Sat, 15 Feb 2025 05:50:29 +0000 (UTC) X-FDA: 83121104178.14.3280093 Received: from m16.mail.126.com (m16.mail.126.com [220.197.31.7]) by imf13.hostedemail.com (Postfix) with ESMTP id E35FE20003 for ; Sat, 15 Feb 2025 05:50:26 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=126.com header.s=s110527 header.b=SPd7L8Xe; spf=pass (imf13.hostedemail.com: domain of yangge1116@126.com designates 220.197.31.7 as permitted sender) smtp.mailfrom=yangge1116@126.com; dmarc=pass (policy=none) header.from=126.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1739598628; 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:dkim-signature; bh=Mc5SW8GnMLeHxZeokKRv9vWvAzpmR3VljH2nIJCFHOA=; b=YgYQbj0tRoKUspO4vHgEPu06svIuitQSbJYw/oW+VrigCUDDQjSeDOM//uCUi+kRNA22vx /Aw82BxhNjF4P41odxqS1a2fF2uKv5GlIpz9LMIHFiDlbL8SpNwINte6joZ09n0JWEk5wt LXCbDKwWIGfamToEbAI0iZZtu71qu+I= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=126.com header.s=s110527 header.b=SPd7L8Xe; spf=pass (imf13.hostedemail.com: domain of yangge1116@126.com designates 220.197.31.7 as permitted sender) smtp.mailfrom=yangge1116@126.com; dmarc=pass (policy=none) header.from=126.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1739598628; a=rsa-sha256; cv=none; b=yOS33uzSVaw7/pleAYSOt0MeWkGsnD64gK3MA2RR+4541HwoTQebOlUpouhUO9Q3cFiYc+ i+og+vX/n5e6A5w31Z8yaObqtsZXQf8666D4IDA6dB9VQvEWxHC4Q/l7H7pgrw22NbbCws rPtWS1Dst+/1bU8mMKlTOV7aBaDB0Mw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=Message-ID:Date:MIME-Version:Subject:From: Content-Type; bh=Mc5SW8GnMLeHxZeokKRv9vWvAzpmR3VljH2nIJCFHOA=; b=SPd7L8XemSiJCFisVB+Ehpquqkrcl41L4/HAE3zLayXWmIwdAjuunZYQOwnV7j yNbfXIyq20Qf0jKLCNJw00DZr5KmgTrNY/WSXAzwJYSHV0bN5HA/+iiPTlMWyydV rzGJgrqKtAdWhmy5dE96SG2b653qGhQu7Bs0pSymHIyQM= Received: from [172.19.20.199] (unknown []) by gzsmtp2 (Coremail) with SMTP id PSkvCgDXf7UXK7Bnf_lLAw--.8703S2; Sat, 15 Feb 2025 13:50:16 +0800 (CST) Message-ID: Date: Sat, 15 Feb 2025 13:50:15 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm/hugetlb: wait for hugepage folios to be freed To: David Hildenbrand , akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, 21cnbao@gmail.com, baolin.wang@linux.alibaba.com, muchun.song@linux.dev, osalvador@suse.de, liuzixing@hygon.cn References: <1739514729-21265-1-git-send-email-yangge1116@126.com> <37363b17-88b0-4ccc-a115-8c9f1d83a1b5@redhat.com> From: Ge Yang In-Reply-To: <37363b17-88b0-4ccc-a115-8c9f1d83a1b5@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID:PSkvCgDXf7UXK7Bnf_lLAw--.8703S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxXF1Dtw4kJw4xJw15AFWDJwb_yoW5WrWDpF WrKr4UKayDJr9ayrnrX39Y9r109rWrXFWxGF1aqry3Can8Xr17KF1Sv3Z0ga98Ar10kr40 qrWjvwnruF1UZa7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jbdbbUUUUU= X-Originating-IP: [112.64.138.194] X-CM-SenderInfo: 51dqwwjhrrila6rslhhfrp/1tbiOhf0G2ewEbrW6AAAsA X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E35FE20003 X-Stat-Signature: 6oqomuzr4xz96k67gprnbxqc64qqosdb X-Rspam-User: X-HE-Tag: 1739598626-899474 X-HE-Meta: U2FsdGVkX19S5l+owwxcZNSlPc+OWz2V9MCgKV630RsuGD69dmcvFJnjLzV3xu95v7rbppttE6lgretdJVX1BjLjYyykVYNfLznHqf57XzQOFcvpCukBXu+1MvFAAnoi6Yj6bmwAhoCmuSRlu0JceO4GAFRbM+zKmebw4WmaahZsZDEhWri/kA7UJ/Ij+OdD/oCiijdj/hdb+tuKnvx3QZDJS0gdM1IZz/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OUrIfGdJIpT+a6a/S30LSMxSG5hn8bL26T9JWzVHSzBhZqR6xl8hWNr9Drk0ZBOkiMUY4E= X-Bogosity: Ham, tests=bogofilter, spamicity=0.112575, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 在 2025/2/14 16:08, David Hildenbrand 写道: > On 14.02.25 07:32, yangge1116@126.com wrote: >> From: Ge Yang >> >> Since the introduction of commit b65d4adbc0f0 ("mm: hugetlb: defer >> freeing >> of HugeTLB pages"), which supports deferring the freeing of HugeTLB >> pages, >> the allocation of contiguous memory through cma_alloc() may fail >> probabilistically. >> >> In the CMA allocation process, if it is found that the CMA area is >> occupied >> by in-use hugepage folios, these in-use hugepage folios need to be >> migrated >> to another location. When there are no available hugepage folios in the >> free HugeTLB pool during the migration of in-use HugeTLB pages, new >> folios >> are allocated from the buddy system. A temporary state is set on the >> newly >> allocated folio. Upon completion of the hugepage folio migration, the >> temporary state is transferred from the new folios to the old folios. >> Normally, when the old folios with the temporary state are freed, it is >> directly released back to the buddy system. However, due to the deferred >> freeing of HugeTLB pages, the PageBuddy() check fails, ultimately leading >> to the failure of cma_alloc(). >> >> Here is a simplified call trace illustrating the process: >> cma_alloc() >>      ->__alloc_contig_migrate_range() // Migrate in-use hugepage >>          ->unmap_and_move_huge_page() >>              ->folio_putback_hugetlb() // Free old folios >>      ->test_pages_isolated() >>          ->__test_page_isolated_in_pageblock() >>               ->PageBuddy(page) // Check if the page is in buddy >> >> To resolve this issue, we have implemented a function named >> wait_for_hugepage_folios_freed(). This function ensures that the hugepage >> folios are properly released back to the buddy system after their >> migration >> is completed. By invoking wait_for_hugepage_folios_freed() following the >> migration process, we guarantee that when test_pages_isolated() is >> executed, it will successfully pass. > > Okay, so after every successful migration -> put of src, we wait for the > src to actually get freed. > > When migrating multiple hugetlb folios, we'd wait once per folio. > > It reminds me a bit about pcp caches, where folios are !buddy until the > pcp was drained. > It seems that we only track unmovable, reclaimable, and movable pages on the pcp lists. For specific details, please refer to the free_frozen_pages() function. > I wonder if that waiting should instead be done exactly once after > migrating multiple folios? For example, at the beginning of > test_pages_isolated(), to "flush" that state from any previous migration? > Yes, this can improve performance. I will make the modification in the next version. Thank you. > Thanks for all your effort around making CMA allocations / migration > more reliable. >