From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F051E606A322 for ; Thu, 3 Dec 2026 12:29:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=m77tYW2v Received: by kanga.kvack.org (Postfix) id CA6096B05B6; Thu, 3 Dec 2026 07:29:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C56D66B05B7; Thu, 3 Dec 2026 07:29:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD11D6B05B8; Thu, 3 Dec 2026 07:29:29 -0500 (EST) 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 218846B05B6 for ; Thu, 3 Dec 2026 07:29:28 -0500 (EST) Received: from smtpin05.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 775E51A0620 for ; Thu, 3 Dec 2026 12:29:28 +0000 (UTC) X-FDA: 85502602416.05.344042E Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf04.hostedemail.com (Postfix) with ESMTP id DD40840009 for ; Thu, 3 Dec 2026 12:29:26 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=m77tYW2v; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf04.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796300967; b=MYzFNpbdFaqxkEOUNapcYBpuxsnmJM1TAnes8/IkQ3uEytav3ZdgyOS99pzq6Wdyv6BVwx SR0j0Jb0RsakDK4j6NvIwWyqeMqVUu2Cnm2oyc5JSpUMzfcfikiLXHDR4IQTOTOLY//RhJ uJGmkkl9bVcbzazPOIGQp4fsca/YCSI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796300967; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=PJnG5tfq1AlxGdVTqHw+qvs7VNmVcNG0FyQc/oAG/co=; b=W7pTsXZuTZ9JPc0gss+3cR7kSwACObzX9DaR37BFvlIka7VtbhucpzePhFhxHqQpRFXGfG D1DlRLGlGx9uPuuPCyjfbvEQ1119Ek1wDOxQzI37HoGpG2Arj/P/S+EMwCnHEzprPsAZ75 i3ik1CQNKiG4zS90O9Do4asdABxoxdw= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=m77tYW2v; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf04.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 4D5A360E36; Thu, 3 Dec 2026 12:29:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8B591F000C1; Thu, 3 Dec 2026 12:29:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796300966; bh=PJnG5tfq1AlxGdVTqHw+qvs7VNmVcNG0FyQc/oAG/co=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=m77tYW2v3Mkjt5fuHoI9XJ8J4crG4tejIqXa/PKyE4PUCHYpq2z1W9N+jiHUZdzL1 Vjj8ixEbbX9Do1rCb5xMO2mMZbQp+uTjtvZ+MgDM1KOjXk5H4Wh/ciLzTN1hXC+D5G Vt4ynyAwlbWaAMt+MZUhXAUCeMWBFOsYVQL1E3Yg6Y8fvqYUOutWRMtObnj9wTRQQU M9D3GuRGhIdbx8ERDp2tkoU2Y8+0qN4+fGUdsp0dKctCTDCCHnFJoICN+yWntihhTe 9P5Kx+qi1Wj9j8CwhLM8l6s84G0iHL97lLfg/HNuf3gz85xNBRVnUwJYa39D2FMH80 vfiq3Oo7qV5rg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 10/35] mm/hugetlb: wait for deferred frees before failing an allocation Reply-To: sashiko-reviews@lists.linux.dev To: =?utf-8?b?RGF2aWQgSGlsZGVuYnJhbmQgKEFybSk=?= , "Muchun Song" , "Oscar Salvador" , "Andrew Morton" , "Hongfu Li" , "Jinmeng Zhou" , "Mina Almasry" , "Davidlohr Bueso" , "Naoya Horiguchi" , "Liam R. Howlett" , "Vlastimil Babka" , "Mike Rapoport" , "Michal Hocko" , "Jonathan Corbet" , "Shuah Khan" , "Randy Dunlap" , "Vivek Kasireddy" , "Mel Gorman" , "Hugh Dickins" , "Baolin Wang" , "Dave Airlie" , "Jason Gunthorpe" , "Andy Whitcroft" , "Roman Gushchin" , "Barry Song" , "Andrea Arcangeli" , "Lorenzo Stoakes" , "Suren Baghdasaryan" , "Shakeel Butt" , "Pedro Falcato" , "Jann Horn" , "Guillaume Morin" , "Yang Shi" , "James Houghton" , "Rik van Riel" , "Harry Yoo" , "Lance Yang" , "Axel Rasmussen" , "Peter Xu" , "Sasha Levin" , "Kiryl Shutsemau" , "Christian Brauner" , =?utf-8?b?U3RldmVuIFJvc3RlZHQgKEdvb2ds?= =?utf-8?b?ZSk=?= , "Hongbo Li" , "Gregory Price" , "Zi Yan" , "Joshua Hahn" , "Rakie Kim" , "Ying Huang" , "Matthew Brost" , "Byungchul Park" , "Alistair Popple" , "Andi Kleen" , "David Rientjes" , "Joern Engel" , "Aneesh Kumar K.V" Cc: linux-mm@kvack.org, "Gerd Hoffmann" , "Johannes Weiner" , "Chris Mason" , "Jiaqi Yan" In-Reply-To: <20261203-hugetlb_fixes_2-v2-10-9bbeabb555d2@kernel.org> References: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> <20261203-hugetlb_fixes_2-v2-10-9bbeabb555d2@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 12:29:22 +0000 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: DD40840009 X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Stat-Signature: 76wfdixrx4zayf36an6bixz5ds6yr1nx X-Rspam-User: X-HE-Tag: 1796300966-615048 X-HE-Meta: U2FsdGVkX18K2qk+3AruWchlkoB5yhK/nj03R2N/S4YkAUaGih6xL5fHC0rG5o24HGW8Hz58DwJAKsOtF8sQ2JW+qBIND9Hg7au8OFwgP8AqVEgXj5z4BIciEerif2rdNUTSGQpbSQpt5fHTFPDBS2r8dXtBRRFKXXCYZgMJe6T/od8KfXoqgmoJpLtygZ+n438/9bNiPnGIUHYfGL+3agCWszP5ZPErNCOdzMG+83Crhya9EV/lMP1WpDs8BtfjvkApN7hJuljdXS76wV00PkDNm7URqmL9VZpiUxBJQDiISioO8C9GgZxA9jWgiwRionPjyB+QPXLQ9C3WIACOvDXRPDiWxb/l7gnTCzGmC7V7BgE355RulE1kTyA0r+/llZorbXxBqk7ESFE88kM8Bm12D0luNahCa43XI8+g4wcYPwGy6cVJ7k9OuJk9ic2Hms9opTXEtdU7iy8U1VwLurEDgHZ71rdlBfcgwc4oqmIxuD6SRA5eBWv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ea9D08sn/7lKtp5k+RMsoFwY/7Q7c9lThyt85Ex6KQaoCSlUvrPPrnyTnMEoJzKXzMWLjABsfxNJRIB9i7tVDMlZm4/hpFfYRmoCdff6ihFT51KWAY9LxepG9WmErPBpi3gbzjzrooIbydp/hV3KFzrEXxOhdX7MkgyBZjAbrpXo6ngZMDOoNTQ8hP0YxduwkhR/KmTaqnIE1s8hybrAW2V8ODH8rXVumvlLPdbY5rjE7daVSuvrMeS3ERx/fZOexA3D6MwAFmYrrdWiiTYFZ75XZYK+9UMBtimM4yCZVwH2CO9YlLA3xchBIOdQ8qT09bOGGsC/zRca/zEZp04R8G00= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Medium] mm/hugetlb: missed retry when free_hpage_work finishes before flush_work() - [Medium] mm/hugetlb: futile retry and double reclaim on cgroup charge failure - [Medium] mm/hugetlb: unconditional flush_work() stalls unrelated allocation failures - [Medium] mm/hugetlb: flush_work() on !WQ_MEM_RECLAIM wq in __alloc_hugetlb_folio() -- commit 43bf56053c89d72ce19fd9c0b36b6e5378a398ed Author: David Hildenbrand (Arm) mm/hugetlb: wait for deferred frees before failing an allocation This commit flushes free_hpage_work in __alloc_hugetlb_folio() and retries hugetlb_alloc_folio() once when the initial allocation returns an error. > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 5984377160d37..d7ced61b4d2d4 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -3218,6 +3218,9 @@ static struct folio *__alloc_hugetlb_folio(struct v= m_area_struct *vma, > }; > =20 > folio =3D hugetlb_alloc_folio(h, &mpoli, memcg_mm, alloc_flags); > + /* Wait for deferred freeing and retry once before giving up. */ > + if (IS_ERR(folio) && flush_work(&free_hpage_work)) > + folio =3D hugetlb_alloc_folio(h, &mpoli, memcg_mm, alloc_flags); > =20 > mpol_cond_put(mpol); [Severity: Medium] Can gating the retry on flush_work(&free_hpage_work) miss folios freed while the first hugetlb_alloc_folio() attempt was in progress? hugetlb_alloc_folio() checks h->hugepage_freelists via dequeue_hugetlb_folio() before dropping hugetlb_lock and entering alloc_buddy_hugetlb_folio(), and never rechecks the pool on failure: CPU0 kworker (free_hpage_workfn) __alloc_hugetlb_folio() hugetlb_alloc_folio() dequeue_hugetlb_folio() -> NULL alloc_buddy_hugetlb_folio() (direct reclaim/compaction) __update_and_free_hugetlb_folio() hugetlb_vmemmap_restore_folio() fails add_hugetlb_folio() (back to pool) work completes (now idle) returns ERR_PTR(-ENOSPC) flush_work(&free_hpage_work) -> false <-- retry skipped Because flush_work() returns false once the work item is idle, the retry is skipped and the task still gets SIGBUS even though a folio is free in h->hugepage_freelists. [Severity: Medium] Should the flush and retry happen only when pool and buddy allocation fail, rather than on every ERR_PTR from hugetlb_alloc_folio()? free_huge_folio() uncharges hugetlb_cgroup and mem_cgroup synchronously before deferring freeing, so flushing free_hpage_work cannot resolve a cgroup charge failure. Worse, when a newly allocated surplus folio with optimized vmemmap fails mem_cgroup_charge_hugetlb(), hugetlb_alloc_folio() calls folio_put() before returning ERR_PTR(-ENOSPC). That folio_put() schedules free_hpage_work itself, causing flush_work() to return true and trigger a futile second allocation, memcg reclaim pass, and vmemmap TLB flush. Moving the wait and retry inside hugetlb_alloc_folio() when alloc_buddy_hugetlb_folio() fails would avoid this and also cover direct callers of hugetlb_alloc_folio(). [Severity: Medium] Does calling flush_work(&free_hpage_work) unconditionally stall unrelated allocation failures while holding fault and VMA locks? Expected non-fatal paths such as hugetlb_wp() owner CoW fallback (which falls back to unmap_ref_private() when no spare pages exist) hold hugetlb_fault_mutex_table, hugetlb_vma_lock_read(), and the mmap/VMA lock across __alloc_hugetlb_folio(). With this change, even hstates without vmemmap optimization or overcommit block for the full sequential drain of hpage_freelist in free_hpage_workfn(), and still acquire raw_spin_lock_irq(&pool->lock) in start_flush_work() on every failure once free_hpage_work has run once. [Severity: Medium] Could flush_work(&free_hpage_work) here flush a !WQ_MEM_RECLAIM workqueue from a WQ_MEM_RECLAIM worker? update_and_free_hugetlb_folio() queues free_hpage_work via schedule_work() onto system_percpu_wq, which lacks WQ_MEM_RECLAIM. Meanwhile, mlx5 ODP faults on HugeTLB VMAs run on the WQ_MEM_RECLAIM mlx5_ib_page_fault workqueue: mlx5_ib_eqe_pf_action() -> ... -> ib_umem_odp_map_dma_and_lock() -> hmm_range_fault_unlocked_timeout() -> hmm_do_fault() -> handle_mm_fault() -> hugetlb_fault() -> __alloc_hugetlb_folio() If hugetlb_alloc_folio() fails while free_hpage_work is pending, check_flush_dependency() triggers WARN_ONCE and risks a forward-progress deadlock under memory pressure if system_percpu_wq has no idle worker. Moving free_hpage_work to a WQ_MEM_RECLAIM workqueue, or skipping the flush when current_is_workqueue_mem_reclaim() or PF_MEMALLOC is set, would avoid this. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203-hugetlb_fi= xes_2-v2-0-9bbeabb555d2@kernel.org?part=3D10