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 BA46E72634 for ; Wed, 31 Dec 2025 12:20:04 +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=1767183606; cv=none; b=dVy5zFvHP62QBwQTe/SNFcgGiy4OedlAxgv2ZZdy/FNBMZxFqws0U3LWTvIo7vJBInALGW/LxKo7C1Q2FUs4Yo0Sfj2T7RPphRHLBWluUHcDxw9jkNR51g9RYqzd+I3sdyk4U/tZdgouZiZhR0FSTJ1W0Jkzuc0gOKiOgIprVtc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767183606; c=relaxed/simple; bh=6JsT0Go9bhDpDyQcmpzezbZhJaAg0PltAhVOKwaVUD4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ohH44ci3WdqGeaoz9U8uBL4yqXESYYvuehBFXwjgXyLOypwx8vsqJDUVjt91yhVPlaJ0pO2aN7csj1vW5a3aAKQxPqlUiGbQL7TdLlA0FZQ9UUIh87cNBKp8RQy+Hhhv0TCZtiCixADwv+OuhwwsItNWnPbSkrfwPXRmWoFuNsg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sKkssGvx; 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="sKkssGvx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84223C113D0; Wed, 31 Dec 2025 12:20:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767183604; bh=6JsT0Go9bhDpDyQcmpzezbZhJaAg0PltAhVOKwaVUD4=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=sKkssGvxd294VQSOv9dbIgBsZ5gnNDW8sQAHO87WrhIzCaGWNzPJjebTtgBldRiha 3xbMVE3RaZgZN8FKgIA/sLKQ7qHjuWdjsVeS/DcxhSMS1xnKtB8HS/XUVZlHUIrgik FHrlvEghIcrbJ4NiiOwQYS5WaAhLc6Gl/vh4Y1+n/vGZyKvQxEu+SvfOIcBp18R04Q gzAE9QWCZk8VzhHdyUcs0pyeyIq+klYl5RM7Oor8hexeUq9P3T/XqV7eU3YGZkP4mE xORreMXlABl5lkG6iVumdxpWLTTJU08WixEzahmpcGjlhYGYU3Hi0UhFBa2YSgwyll vQJc+fKCHOirg== Message-ID: Date: Wed, 31 Dec 2025 13:19:59 +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 v2 3/4] mm: khugepaged: set VM_NOHUGEPAGE flag when MADV_COLD/MADV_FREE To: Vernon Yang Cc: akpm@linux-foundation.org, lorenzo.stoakes@oracle.com, ziy@nvidia.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, richard.weiyang@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Vernon Yang References: <20251229055151.54887-1-yanglincheng@kylinos.cn> <20251229055151.54887-4-yanglincheng@kylinos.cn> <084eee6b-6c9e-454b-a563-b2babb76b099@kernel.org> <4y4aht35lkswkaorr36m6276aktp65bywdtnj6sxo7koscj3qp@qpdjv47lc75v> From: "David Hildenbrand (Red Hat)" Content-Language: en-US In-Reply-To: <4y4aht35lkswkaorr36m6276aktp65bywdtnj6sxo7koscj3qp@qpdjv47lc75v> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 12/31/25 13:13, Vernon Yang wrote: > On Tue, Dec 30, 2025 at 08:54:33PM +0100, David Hildenbrand (Red Hat) wrote: >> On 12/29/25 06:51, Vernon Yang wrote: >>> For example, create three task: hot1 -> cold -> hot2. After all three >>> task are created, each allocate memory 128MB. the hot1/hot2 task >>> continuously access 128 MB memory, while the cold task only accesses >>> its memory briefly andthen call madvise(MADV_COLD). However, khugepaged >>> still prioritizes scanning the cold task and only scans the hot2 task >>> after completing the scan of the cold task. >>> >>> So if the user has explicitly informed us via MADV_COLD/FREE that this >>> memory is cold or will be freed, it is appropriate for khugepaged to >>> skip it only, thereby avoiding unnecessary scan and collapse operations >>> to reducing CPU wastage. >>> >>> Here are the performance test results: >>> (Throughput bigger is better, other smaller is better) >>> >>> Testing on x86_64 machine: >>> >>> | task hot2 | without patch | with patch | delta | >>> |---------------------|---------------|---------------|---------| >>> | total accesses time | 3.14 sec | 2.93 sec | -6.69% | >>> | cycles per access | 4.96 | 2.21 | -55.44% | >>> | Throughput | 104.38 M/sec | 111.89 M/sec | +7.19% | >>> | dTLB-load-misses | 284814532 | 69597236 | -75.56% | >>> >>> Testing on qemu-system-x86_64 -enable-kvm: >>> >>> | task hot2 | without patch | with patch | delta | >>> |---------------------|---------------|---------------|---------| >>> | total accesses time | 3.35 sec | 2.96 sec | -11.64% | >>> | cycles per access | 7.29 | 2.07 | -71.60% | >>> | Throughput | 97.67 M/sec | 110.77 M/sec | +13.41% | >>> | dTLB-load-misses | 241600871 | 3216108 | -98.67% | >>> >>> Signed-off-by: Vernon Yang >>> --- >> >> As raised in v1, this is not the way to go. Just because something was once >> indicated to be cold does not meant that it will stay like that forever. >> >> Also, >> >> (1) You are turning this into an operation that will perform VMA >> modifications and require the mmap lock in write mode, bad. >> >> (2) You might now create many VMAs, possibly breaking user space, bad. >> >> If user space knows that memory will stay cold, it can use madvise() to >> indicate that these regions are not a good fit for THPs. >> >> But are they really not a good fit? What about smaller-order THPs? >> >> Nobody knows, but changing the behavior like you suggest is definetly bad. >> :) >> > > Thank you for review and explanation. I got it. > > For MADV_FREE, we will skip the lazy-free folios instead. > For MADV_COLD, it will be removed in the next version. Just to be clear, setting VM_NOHUGEPAGE should not be done from any of these operations. Treating lazyfree folios differently in khugepaged code could indeed make sense. -- Cheers David