From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-171.mta1.migadu.com (out-171.mta1.migadu.com [95.215.58.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A974238176 for ; Mon, 5 Jan 2026 02:09:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767579001; cv=none; b=JiDdHA36heD6tyEqBmwaqI7IxPqJBGN4WfEYMoOfmLMMQ6NvYxHeR77nt5zAEqHhYOxLA8FAPAvYsXL5v841K6xjZPcBhd3BpHON6FS0PB1lhYlAnJ1p46B0e9dkkoDWLbMAkJ+TnCyrVmPY1IHHvshd92r5qSqmmcaGiOcoN5Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767579001; c=relaxed/simple; bh=wSUBu3i5G8y81HZWFT1Dnj1kTAOh34Ww5vlckbf6vls=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=fSxj6r9IqgLxqiBo9eXz5n4avUNmhRr61yDyuhxo3k+o+MAkAKyLpPRF7Qucq5sEuVMSiOCgsQzdPuek0RgQxdvksIRIfvhdAAprxlBluT3VofIHFFyDTWcksBZadxHXPWgy34uSPf2E8Ja8fXEhWvCsD4rNYkvayN36WeRZU5Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=hc1DzIWl; arc=none smtp.client-ip=95.215.58.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="hc1DzIWl" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1767578996; h=from:from: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=gNRGv23p5K6B6+hbFqyk7acP1QElSBybPClHvzoXsN4=; b=hc1DzIWlNRpdtkcj5GBA2EPwYztubu8pdn+LfsS+7LACW29MMqI+9MgKLvh0mHdjDEQ1X1 Tmkvd35wV+0LIit+Kx56sEI6nr5pQYF7f9VhZSYDAAgVZgI+2p5ESO5F7gj/u4BapZYXY/ IxRBmmxu2jN8SqALKVsvEaDFwIUmb68= Date: Mon, 5 Jan 2026 10:09:43 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH v3 6/6] mm: khugepaged: set to next mm direct when mm has MMF_DISABLE_THP_COMPLETELY Content-Language: en-US To: Wei Yang Cc: Vernon Yang , lorenzo.stoakes@oracle.com, ziy@nvidia.com, dev.jain@arm.com, baohua@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, david@kernel.org, Vernon Yang , akpm@linux-foundation.org References: <20260104054112.4541-1-yanglincheng@kylinos.cn> <20260104054112.4541-7-yanglincheng@kylinos.cn> <20260105003128.7xitfioeno56h7f3@master> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Lance Yang In-Reply-To: <20260105003128.7xitfioeno56h7f3@master> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 2026/1/5 08:31, Wei Yang wrote: > On Sun, Jan 04, 2026 at 08:20:29PM +0800, Lance Yang wrote: >> >> >> On 2026/1/4 13:41, Vernon Yang wrote: >>> When an mm with the MMF_DISABLE_THP_COMPLETELY flag is detected during >>> scanning, directly set khugepaged_scan.mm_slot to the next mm_slot, >>> reduce redundant operation. >>> >>> Signed-off-by: Vernon Yang >>> --- >>> mm/khugepaged.c | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/mm/khugepaged.c b/mm/khugepaged.c >>> index 1ca034a5f653..d4ed0f397335 100644 >>> --- a/mm/khugepaged.c >>> +++ b/mm/khugepaged.c >>> @@ -2541,7 +2541,7 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, int *result, >>> * Release the current mm_slot if this mm is about to die, or >>> * if we scanned all vmas of this mm. >>> */ >>> - if (hpage_collapse_test_exit(mm) || !vma) { >>> + if (hpage_collapse_test_exit_or_disable(mm) || !vma) { >>> /* >>> * Make sure that if mm_users is reaching zero while >>> * khugepaged runs here, khugepaged_exit will find >> >> >> Let's convert hpage_collapse_test_exit() in collect_mm_slot() as well, >> otherwise the mm_slot would not be freed and will be scanned again ... >> >> static void collect_mm_slot(struct mm_slot *slot) >> { >> struct mm_struct *mm = slot->mm; >> >> lockdep_assert_held(&khugepaged_mm_lock); >> >> if (hpage_collapse_test_exit(mm)) { <- >> > > What if user toggle the MMF_DISABLE_THP_COMPLETELY flag again? Maybe it's fine :) If user sets MMF_DISABLE_THP_COMPLETELY, they probaly would not clear it soon. Keeping the slot wastes memory. If they do clear it later, page faults will trigger do_huge_pmd_anonymous_page() -> khugepaged_enter_vma(), which re-adds the mm. Anyway, no strong opinion on that. > >> hash_del(&slot->hash); >> list_del(&slot->mm_node); >> >> mm_slot_free(mm_slot_cache, slot); >> mmdrop(mm); >> } >> } >