From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F45823BF91 for ; Sun, 21 Dec 2025 12:38:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766320714; cv=none; b=d4yskSps+tfVlnfIjE4UyrF47UeRpJkI91W257NLxEi5cj9sM6hh5Qa/x4N291buOvGWsDzGH2XKsTUi6L14mBEOqLwjsNG74BxB76dfKWQEZ8SyBCgy3Y7CMFJkABXnAfwvpzZUb8zLkDsic81uFp7BFt9aCczPQRqa6bgxA38= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766320714; c=relaxed/simple; bh=yQI3MoHPbO28EHvbqMqjjiZJaErEVPOr0JMQxo7trIM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=EqXXtGTcACNbySC5n/+lztrBQHS1uTYI5cj279PQeU7uELLbY0MKxy3Y7eQn+b1uoIOyJiQCXonYQIsljFZH7oLsNxttsFgIG2vzEF196BcyyCM2b5XcVwFcMQT4c0qGVLFxN7ggUkiYLlit6QffWeoT345j+aeV5tmIgnIxI28= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mlv2rjd0; arc=none smtp.client-ip=209.85.218.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mlv2rjd0" Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-b7ffbf4284dso354537466b.3 for ; Sun, 21 Dec 2025 04:38:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766320711; x=1766925511; darn=vger.kernel.org; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=vKd1omiKDIcMLE2GVnEeEbOL7CbBL2uJXl9dtv3whtc=; b=mlv2rjd0GORSk3TGrzyfp5vml8YGUuO6HgQSsWGhQk5p6bIH9Asz4vJL3+7cNODaLd Nie8rtSD0UdfYp5wrv4syhEqPNhz22Xdrr78NzSzj7E1avKCdUPiiZ+Tka9SxoQbQT88 QGBydHGa2YDGYjHaiqS7aZt0VaQ7WxqfcSw288pQ/qluygx7RtPT+LmbjimkWE6pI9bC H0KzmUoQw4bc7prc0KMAoh3TLB7wrEVHDBkMLJ/fBuV611hchQ6hdSLmy6RZY1oLSRY/ D1XZyg+rdWIBqHbf4g5WSJwaUbyy2yoYTjOrXZVfAsJ5Ny58EBBLQ5uG7wxQyyVYX8q0 J9Ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766320711; x=1766925511; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vKd1omiKDIcMLE2GVnEeEbOL7CbBL2uJXl9dtv3whtc=; b=celnPapCbU0/dN2d4iJFN/NBgmlI9apBUHE/Jffq9gG8DcvZqn5OlNENjyhNsjX/eo yJzvnRjLwY28dcnLQxrGrWrvKLwgAK7goIppQYkFFMrmh9P8CKCW3G1qkAbYXhlItFNJ 8bfesc36DWHjDmHcOExANq63hu/ckMR2r7pq7II4F9GPu8F3nbfN093dbFTgK1uFxTNH JoXwX1epaRSi9Y7Xt3WDsweixWmwYs4V5cKQKrYXVuZ/kKB/mh43mxl65BNaEqw32Atv An4RYjQkxQkQEFa2bBiEoNufW/c5flCv45l8QVkQPn3V8IDib1JIaz6YZOCT6wPOCxFp iJiQ== X-Forwarded-Encrypted: i=1; AJvYcCUQsQkrzAd75+SmuCvQjhlgxGbb//EEh2QV2dprMB+Z0dFayMuIaQbQVNghinbiY2X5mX3374eTLlp7s/I=@vger.kernel.org X-Gm-Message-State: AOJu0YzurBBEGC/AhBrNS2+rfJ/dyXdBhHXLDctQ3Blfz942VcRQ3VFY Crq74Qw1CHocWvr+g0IdKJLZaOuqxxafBKv9rw4N+ZRsaAQ74retfOg/ X-Gm-Gg: AY/fxX4SNThm33HDuTDAYNO0uKnfg5DutgKDsVQ1I1qBsVC0vm4LFElhyOQnq3exYz+ nKgdMER1ILc1H2RMowdMpWM9ElcOMKy+Kbl93YkKHoScvJVzw0y4WmbwE1QM48WCLSDoMrX9QxK V+IIyYzb5lb6pxO0QG3a6BYgi+uepHYUMTEM1dkA7OqI5TQay8tvR4HkN040APf2GW6RQGtyYZA eOWdoKuIV8HIhO/MLjNpYfq4dQgWcHmNAMcOV6UJlAzOmKSHA+VXH4FLzhHqqM6QNgxTEnK8vaI XU+xL3I07odtvxkzXBHsfxNrj+yyXO6QUGcDReNwCBuxeOVWSHnvUZ8xoBBaxvRN3qcJn4FOmQ3 jQRGwNooKBPi7dQPGen/yk7MqEubr8oh5MAhRaO+/rzQCIfaspsJwhkzT4JWqzO2X91FK+oYuwQ 3B3hxER9CTDQ== X-Google-Smtp-Source: AGHT+IEPkBYxKxvMO8vTyzymRyaWpcIIPKSU5dbBhuwDl9GbH/oMHllfQOWCXa+XEUq44H92noLtRA== X-Received: by 2002:a17:907:3da8:b0:b7a:1be1:983 with SMTP id a640c23a62f3a-b80372699eemr943322866b.63.1766320711106; Sun, 21 Dec 2025 04:38:31 -0800 (PST) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8037ad8577sm762477466b.24.2025.12.21.04.38.30 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 21 Dec 2025 04:38:30 -0800 (PST) Date: Sun, 21 Dec 2025 12:38:30 +0000 From: Wei Yang To: Vernon Yang Cc: Wei Yang , "David Hildenbrand (Red Hat)" , 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 Subject: Re: [PATCH 3/4] mm: khugepaged: move mm to list tail when MADV_COLD/MADV_FREE Message-ID: <20251221123830.zr2szhudd6pdq7h5@master> Reply-To: Wei Yang References: <20251215090419.174418-1-yanglincheng@kylinos.cn> <20251215090419.174418-4-yanglincheng@kylinos.cn> <3c75d915-5d7f-4e80-975f-4479393e7139@kernel.org> <6e8684a5-1f71-4be6-8805-9b047a2bcb78@kernel.org> <20251221021044.2r5fhepiyyhvuo7h@master> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) On Sun, Dec 21, 2025 at 12:25:44PM +0800, Vernon Yang wrote: >On Sun, Dec 21, 2025 at 02:10:44AM +0000, Wei Yang wrote: >> On Fri, Dec 19, 2025 at 09:58:17AM +0100, David Hildenbrand (Red Hat) wrote: >> >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. >> > >> >> I think we should, but seems we didn't do this for anonymous memory during >> khugepaged. >> >> We check the vma with thp_vma_allowable_order() during scan. >> >> * For anonymous memory during khugepaged, if we always enable 2M collapse, >> we will scan this vma. Even VM_NOHUGEPAGE is set. >> >> * For other cases, it looks good since __thp_vma_allowable_order() will skip >> this vma with vma_thp_disabled(). > >Hi David, Wei, > >The khugepaged has already checked the VM_NOHUGEPAGE flag for anonymous >memory during scan, as below: > >khugepaged_scan_mm_slot() > thp_vma_allowable_order() > thp_vma_allowable_orders() Oops, you are right. It only bypass __thp_vma_allowable_order() if orders is 0. > __thp_vma_allowable_orders() > vma_thp_disabled() { > if (vm_flags & VM_NOHUGEPAGE) > return true; > } > >REAL ISSUE: when madvise(MADV_COLD),not set VM_NOHUGEPAGE flag to vma, >so the khugepaged will continue scan this vma. > >I set VM_NOHUGEPAGE flag to vma when madvise(MADV_COLD), the test has >been successful. I will send it in the next version. > >-- >Thanks, >Vernon -- Wei Yang Help you, Help me