From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 36BEE30B533 for ; Wed, 6 May 2026 06:46:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778050011; cv=none; b=DtIsfdk8rTWXjZhLu3adoZsbL437Do96sXvHBHD3mQLbFXOzuOaZ/nGPZ23XCUC6g4q+T2P+ifEECmhi9MJpOV7CHRYlOEkmv3dOSZc/VpVZyB/JQeDCd64un87k+SG4+MK85GseoslZXxkd70HLduLrGf9axvEP49cefRdLHtw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778050011; c=relaxed/simple; bh=HFZLpvkdsNmTj63qRZ7hFn86ZsvIp71KRJEco/ZEoww=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=WIwtZBoo/hfZpYCQLM8Y5twpIaMuja09TDwvlrupZw5R4RGMBcP01Vp7J0v2MigDUKtt8pm8pu7WNNzXmHwf2EJbui08jxJfL5JoJgTplTDsxE1G5UtwqpZ8gjK+pGTB0G3GuIdUXOGpLj4Z09zI6KVN9+dTxZ0yT2xvqeSBkX0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=iZSjygop; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="iZSjygop" 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 164071A25; Tue, 5 May 2026 23:46:44 -0700 (PDT) Received: from [10.164.148.46] (MacBook-Pro.blr.arm.com [10.164.148.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0139E3F763; Tue, 5 May 2026 23:46:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1778050009; bh=HFZLpvkdsNmTj63qRZ7hFn86ZsvIp71KRJEco/ZEoww=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=iZSjygopO7FKtdzR7WuyKQRo4UxpS+t/O4U4GQ4lSfoaQtPS/qNgUJKQAO0o5JqEO XhZxOFlIBLwPAN1Cmf6hP+b6FbHcGABYauA6SLw62LqPzySqOIM4mQ4aMWLek12rxk rGiRJXuxCEbQc3MFkLnNvPba33PW5CQK0YQKnOok= Message-ID: <3fb8c00d-d60d-4fec-81b1-e7633384a52d@arm.com> Date: Wed, 6 May 2026 12:16:35 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] mm/khugepaged: clear MMF_VM_HUGEPAGE on mm_slot_alloc() failure To: Ye Liu , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Xin Hao Cc: Ye Liu , Zi Yan , Baolin Wang , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Barry Song , Lance Yang , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20260506012130.9306-1-ye.liu@linux.dev> Content-Language: en-US From: Dev Jain In-Reply-To: <20260506012130.9306-1-ye.liu@linux.dev> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 06/05/26 6:51 am, Ye Liu wrote: > From: Ye Liu > > __khugepaged_enter() sets MMF_VM_HUGEPAGE before allocating the > corresponding mm_slot. If mm_slot_alloc() fails, the function > returns with the flag set but without inserting the mm into the > khugepaged tracking structures. > > This leaves the mm in an inconsistent state: it is marked as > registered (MMF_VM_HUGEPAGE set), but will never be scanned by > khugepaged. Future attempts to register the mm are skipped since > khugepaged_enter_vma() checks the flag and returns early. > > Fix this by clearing MMF_VM_HUGEPAGE when mm_slot_alloc() fails, > restoring the ability to retry registration later. > > Fixes: 16618670276a ("mm: khugepaged: avoid pointless allocation for struct mm_slot") > Signed-off-by: Ye Liu > --- > Changes since v1: > - Add Fixes tag as suggested by Dev Jain and Lance Yang > > mm/khugepaged.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index 7d48d4fbd5f3..60ab7c1b61dd 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -559,8 +559,10 @@ void __khugepaged_enter(struct mm_struct *mm) > return; > > slot = mm_slot_alloc(mm_slot_cache); > - if (!slot) > + if (!slot) { > + mm_flags_clear(MMF_VM_HUGEPAGE, mm); > return; > + } Note that, a racing khugepaged_enter_vma() may back off when it sees that MMF_VM_HUGEPAGE is set, but then the above clears the flag after slot alloc failure. So we end up not registering the mm with khugepaged. But I am sure no one cares, we are in much big trouble if slot alloc is failing. Although one could argue the same about this patch, I will still say it is important to fix "flag is set but not registered with khugepaged" because that just feels wrong. Reviewed-by: Dev Jain > > spin_lock(&khugepaged_mm_lock); > mm_slot_insert(mm_slots_hash, mm, slot);