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 C6E5F2C236B for ; Fri, 19 Dec 2025 08:58:23 +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=1766134703; cv=none; b=gY2CTfKjkRnBIw3OvLOQCPxw3tAYJPLsnzoR+uuPS+xHBlqHJ1ZAx7N4nOTdHMoI8kT7TWIRTCpzAlL+iEfMTV60lxDcl9OyXPAShaAATqGp1T1LMqYgIv6aCJBLTLnppNQVy7Xz8TmLJfnqY+ELAgXoaiiyY7ZPLiW8eUJ30mM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766134703; c=relaxed/simple; bh=pLIFeiiq3O2vmMMKsgYLtNo2XOFyucyfeDVncolteFA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=TKB7yPsjA3/uPj7SxMbhkyfvCqrS+TVJIbxDbZalQqDkw56tmM8WZd+YC1MSeudfvetEV/5RSjLj91vLnBCqJc4P+9HUgZ9BkI6AqCH4gNZmSd/gjYyEgzwRHSPYN/WuDXXUN5kDr8VIMnI0Y+ksol2Xg0VVuCbnTjVipfUFzVA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eNysq9Ff; 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="eNysq9Ff" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 209B2C116B1; Fri, 19 Dec 2025 08:58:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1766134703; bh=pLIFeiiq3O2vmMMKsgYLtNo2XOFyucyfeDVncolteFA=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=eNysq9FfSfXM0V9W6ZR2RjuE5IMhesVigSVImNYmRmtSCr+OGgLT+Cr5r+4yWFS9Y Jn5+9ORuFQly326lUkuzC6c/lgfmhbZUx7MRZ/Ua9okgNrmGFiyCmN9b6zvTo7UPVe XoikXmmJjmjmvqk8qBt1t7aJsgK336e4WyaS4YumatetaIs4umAApkwz2NU0RWx5N6 CvGOwq2ogqZoc6ZdM8iYLIFr2TAjFUzAu/39KRFJ17S4G0aoCA/kw7Oskf0b0InKqV fFrK2nNGe8VJlErPKzSCKMl9IxWNqlLsAGWz6iA7wa8Cw+Dp5VTjkIpTuhefy+Kqjk p2g1mG+v20FBw== Message-ID: <6e8684a5-1f71-4be6-8805-9b047a2bcb78@kernel.org> Date: Fri, 19 Dec 2025 09:58:17 +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 3/4] mm: khugepaged: move mm to list tail when MADV_COLD/MADV_FREE To: Vernon Yang Cc: akpm@linux-foundation.org, lorenzo.stoakes@oracle.com, ziy@nvidia.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-4-yanglincheng@kylinos.cn> <3c75d915-5d7f-4e80-975f-4479393e7139@kernel.org> From: "David Hildenbrand (Red Hat)" Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 12/19/25 06:29, Vernon Yang wrote: > On Thu, Dec 18, 2025 at 10:31:58AM +0100, David Hildenbrand (Red Hat) wrote: >> On 12/15/25 10:04, 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 >>> scan it only at the latest possible moment, 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.92 sec | -7.01% | >>> | cycles per access | 4.91 | 2.07 | -57.84% | >>> | Throughput | 104.38 M/sec | 112.12 M/sec | +7.42% | >>> | dTLB-load-misses | 288966432 | 1292908 | -99.55% | >>> >>> 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.23 | 2.12 | -70.68% | >>> | Throughput | 97.88 M/sec | 110.76 M/sec | +13.16% | >>> | dTLB-load-misses | 237406497 | 3189194 | -98.66% | >> >> Again, I also don't like that because you make assumptions on a full process >> based on some part of it's address space. >> >> E.g., if a library issues a MADV_COLD on some part of the memory the library >> manages, why should the remaining part of the process suffer as well? > > Yes, you make a good point, thanks! > >> This seems to be an heuristic focused on some specific workloads, no? > > Right. > > Could we use the VM_NOHUGEPAGE flag to indicate that this region should > not be collapsed, so that khugepaged can simply skip this VMA during > scanning? This way, it won't affect the remaining part of the task's > memory regions. I thought we would skip these regions already properly in khugeapged, or maybe I misunderstood your question. -- Cheers David