From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 7B37D1E9B12 for ; Thu, 18 Dec 2025 09:29:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766050162; cv=none; b=Z2IsE+iQThnbJbuudGIQ/YM1L+71kaFJeIkvjpmXZcyQCsJOolYoh3Mn83Ao67mlZOwM5+fkO6GIQwXlFgJNf663g9eSI3ghekiotdp4qy8LBGNyMSqJc7Y9pFaOV/4jsf4wXmt3jztJeFYFdgZYftfd5FGf0vLhTfWYCLVEyWE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766050162; c=relaxed/simple; bh=PwfhwNBp4OTVlzrnBYQt+m4yQcf5Ez56MmgeevhN+yQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=LXXWh2Vb4k/N+ahm4/kB1mAMcnWqxiCanpYIOcKDP2l3f2BK8k4qJ/yiZG8sfNs9nhfqIT5mI6cfg3Ek3q4Jo1Jjl9BZORc3cVKZ/c6QoChs1JAy+CTlEHZFmpEYHT3WWbMyfFVTY9XAHA5BtRe0MKrIpaRKToemj3s0FnHqtL0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NzYkT75b; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NzYkT75b" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6AECC4CEFB; Thu, 18 Dec 2025 09:29:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1766050162; bh=PwfhwNBp4OTVlzrnBYQt+m4yQcf5Ez56MmgeevhN+yQ=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=NzYkT75bJMXUIzr1h1EQdvkNi+7yiwjbuzRLg7JIonZ4kq7iN2GkaOPOarRVTV8Vz A6wqun+XI0Xa+GJdF0SIvRxl3zNPUgbu0AWh96UN/6X7ti/AKtRSIrmQUPk0UBbM43 aZhkFIuXQMNjORk/9Ag+soufMSU+0P6Odgap6egDcTtws/1vaNsEmPG+o8Ow+O9ODc D5KZVSmef0biiV5olr6UzsY5dfTz+r52zBFSUcK9mm5R9ZiLvcUWJKHLlC7mFmQNM+ dOg6mxI2rZkIsSn+ez3I+7D+ZRmTup+c+kQGQBvM6Lb1yFJKVFg3BWBdAPe3TkcU0F Aq7AnUrU4W0Tg== Message-ID: <26e65878-f214-4890-8bcb-24a45122bfd6@kernel.org> Date: Thu, 18 Dec 2025 10:29:18 +0100 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 2/4] mm: khugepaged: remove mm when all memory has been collapsed To: Vernon Yang , akpm@linux-foundation.org, lorenzo.stoakes@oracle.com Cc: ziy@nvidia.com, npache@redhat.com, baohua@kernel.org, lance.yang@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Vernon Yang References: <20251215090419.174418-1-yanglincheng@kylinos.cn> <20251215090419.174418-3-yanglincheng@kylinos.cn> From: "David Hildenbrand (Red Hat)" Content-Language: en-US In-Reply-To: <20251215090419.174418-3-yanglincheng@kylinos.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 12/15/25 10:04, Vernon Yang wrote: > The following data is traced by bpftrace on a desktop system. After > the system has been left idle for 10 minutes upon booting, a lot of > SCAN_PMD_MAPPED or SCAN_PMD_NONE are observed during a full scan by > khugepaged. > > @scan_pmd_status[1]: 1 ## SCAN_SUCCEED > @scan_pmd_status[4]: 158 ## SCAN_PMD_MAPPED > @scan_pmd_status[3]: 174 ## SCAN_PMD_NONE > total progress size: 701 MB > Total time : 440 seconds ## include khugepaged_scan_sleep_millisecs > > The khugepaged_scan list save all task that support collapse into hugepage, > as long as the take is not destroyed, khugepaged will not remove it from > the khugepaged_scan list. This exist a phenomenon where task has already > collapsed all memory regions into hugepage, but khugepaged continues to > scan it, which wastes CPU time and invalid, and due to > khugepaged_scan_sleep_millisecs (default 10s) causes a long wait for > scanning a large number of invalid task, so scanning really valid task > is later. > > After applying this patch, when all memory is either SCAN_PMD_MAPPED or > SCAN_PMD_NONE, the mm is automatically removed from khugepaged's scan > list. If the page fault or MADV_HUGEPAGE again, it is added back to > khugepaged. I don't like that, as it assumes that memory within such a process would be rather static, which is easily not the case (e.g., allocators just doing MADV_DONTNEED to free memory). If most stuff is collapsed to PMDs already, can't we just skip over these regions a bit faster? -- Cheers David