From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) (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 BB61B86250 for ; Mon, 5 Jan 2026 02:20:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767579651; cv=none; b=Xvm3qeAqr9k2cyvEKniqYlN8xS8zojhlTLd3TzmRXoC6PETAuUomwyoRqTO8LyjSofzEDiW31NP9AgL/QIRY1IyT0J0ar5UuIv2f+eA8v+SExwOvpOG/1KkWWPBBMRHvHt3PnSCx1ILbIXhTdM7+DBJHzRtgtCntDQ4gjhssZ5E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767579651; c=relaxed/simple; bh=bFrXS8s47INeYe/CYww7UVXT/e8OsZJwoKg6b2yDu4g=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Ily7B0rPcyAnidIuv2uxTAl5w+MBsX+JFoNNZo60yI++BSCraX4DQwhOYSNJqkwzOAGMmPpe9+jucBx3Ipn53JuhH74TE+6+sgr8a3cqanqgRXeLssF37l9vOHOQzYLSmstwuoBgHagBwyOTwre+NWgDQ3HIn8MjGNCCN66sdu8= 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=BKWsNJWH; arc=none smtp.client-ip=95.215.58.177 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="BKWsNJWH" Message-ID: <3a446b85-c0dc-4785-af24-333fa07f56e2@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1767579646; 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=u82STQmxMu1BykQcBxZKNP/Gm77mBfCqJU7RXSI0C64=; b=BKWsNJWH5Ma504h/MWudtuBguImKWgiDNnn6zlgdS3cz5X7QyGqBU+jGhqViuLMdq/4XuM NeyDorNkn79aAXTVYbMnFmFIjAy6Kah5+IbtLDiOF5HCkWc8UatEd3rfoJM2oDBP7Cd6r8 +ehJIiNzOAPwbuLcIcrE6VcE9FTAX6Q= Date: Mon, 5 Jan 2026 10:20:33 +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: Vernon Yang Cc: lorenzo.stoakes@oracle.com, ziy@nvidia.com, dev.jain@arm.com, baohua@kernel.org, richard.weiyang@gmail.com, 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> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Lance Yang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On 2026/1/5 10:06, Vernon Yang wrote: > On Sun, Jan 4, 2026 at 8:20 PM 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)) { <- >> >> hash_del(&slot->hash); >> list_del(&slot->mm_node); >> >> mm_slot_free(mm_slot_cache, slot); >> mmdrop(mm); >> } >> } > > This patch just reduces redundant operation, For a detailed > discussion[1]. > > You already commit 5dad604809c5 ("mm/khugepaged: keep mm in mm_slot > without MMF_DISABLE_THP check"), I assume there is some problem here, > e.g. not can readd? data-race? etc. Can you explain the root cause? Thanks! Ah, I didn't fully recall that ... Maybe I kept the slot because it's hard for khugepaged to re-add the mm later. But looking at the code again, I'm not sure if that was the right call :( > > [1] https://lore.kernel.org/linux-mm/CACZaFFOvDad09MUopairAoAjZG6X5gffMaQbnfy0sCHGz8xSfg@mail.gmail.com > > -- > Thanks, > Vernon