From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.100 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796557151; b=0blMPePv4c9wH0VjfZFB2n0F02G29rvIGzVaCKmfgDiTmenj/0kompzy6ijLrm6tn/dr Z8vCWXojfbSq4DV15Y++I6tcXfpuMG0RExHfWrLR0HtPW2Nzo2RO8iTydPdVa4T1E+bvm UmuRJUxZoqnVPuDwRiNDatQT8j/ZleLFGHOUv2kSAUGuKnQbNymQYp1/gNkhgUUA0s4Wp j8RbdK898BYCLkTQQ6C+rEY2coq4ooDSJs6xv4jHGCHKKrbRvmfQtIRFDXT928kvv/c/h snS4RwNGDa6KzBK8KyyD1BNJ4RMepP/VUL42pSn9pbBS/3ewAydtJRVEEfic7f+Pxww== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796557151; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:Date:Subject:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer; bh=kUgmMz96VsXVNt+5+J1GD/gDMCoW9hj/n7I714eG0cU=; b=IY1PTpjdd2urdkqQvht2/b2XRpAzkmLIcJn3XElKUQ5giew9rzkDyZFyPlp8Oo708ReZ OOrXO9pQDTPmba6XLqFdrS2NUnsMr7R+wICHA93g3jVCg6pdIDlAH9S6nG/IWzNH5zsVh T2ycyVJJpdmeCkLcOOYfk1DgUTEPEQzSa52DnCeYB0KinjvPtD5DpKyX8ajWcMSi8Go3e ujLgpK8/uzURLedBazBToW7ALTcmgT9XY9ITIAahNB4gjLeUwYZ6/65ZXtVus7y92M0+v uyyUm6vcnbFS2kI6+kbVejXOF4hGNtNgLcIeAeNW/IS7E7WY5rOJwaf4xT2qHdbuhFg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=O6Nt5QXY; arc=none smtp.remote-ip=95.215.58.100 Received: from mta1.migadu.com (out-100.mta1.migadu.com [95.215.58.100]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A21B6606A33A for ; Sun, 6 Dec 2026 11:39:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A21B6606A33A 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, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=O6Nt5QXY X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=kEMYR9dmHrwUlDiOoWFmk9+PIsFFbGqICszv//ArM1g=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796557147; v=1; x=1797161947; b=O6Nt5QXYRvTfL95wiHtMgM+73SvQhFbIf/z6GOaTe0YxVJhP8GNg4law3P0QZ1JoOprfcDQi KBqWB2STxAadtlvfxWfR8cR8CqHZyHSgwGA7ug8mCvojh7Pxb5b7r06hP0jIxAnwiq6rU828boZ kYBfxJaVjauu3I3OhGDj90f8= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 930f9f0d9be15e11; Sun, 06 Dec 2026 11:39:06 +0000 X-Mizu-Trace-ID: 930f9f0d9be15e11 X-Migadu-Flow: FLOW_OUT From: Qiliang Yuan Date: Sun, 06 Dec 2026 06:38:39 -0500 Subject: [PATCH 2/8] sched/numa: Cover hugetlb mappings with accessed-bit sampling X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261206-feat-numab-series-v1-2-2af21ad24718@linux.dev> References: <20261206-feat-numab-series-v1-0-2af21ad24718@linux.dev> In-Reply-To: <20261206-feat-numab-series-v1-0-2af21ad24718@linux.dev> To: Peter Zijlstra , Ingo Molnar , Juri Lelli , Vincent Guittot , Mel Gorman , K Prateek Nayak , David Hildenbrand , Andrew Morton Cc: Dietmar Eggemann , Steven Rostedt , Ben Segall , Valentin Schneider , Zi Yan , Gregory Price , Ying Huang , Kefeng Wang , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Qiliang Yuan X-Mailer: b4 0.13.0 task_numa_work() skips hugetlb VMAs entirely: hugetlb pages are not migrated by NUMA balancing, so there is no point in making them fault. Guest memory of virtual machines is commonly backed by hugetlb pages. As with pinned memory, skipping them leaves the scheduler blind to where that memory lives. A vCPU or any other task working on hugetlb memory gets no preferred node from it and can stay on the far side of the machine indefinitely. Sample hugetlb VMAs instead: test and clear the accessed bit of each present huge page in the scanned range and account the accessed pages as faults on their node, without changing the protection. Such sample-only ranges are charged to the virtual scan budget only, like ranges where no PTE was updated, so they do not slow down the scanning of migratable memory. A task copying within 4 GiB of 2 MiB hugetlb pages on node 0 of an 8-node VM (2 packages of 4 nodes, 8 vCPUs and 4 LLCs per node, SLIT 10/15/25/27, guest memory on host huge pages), started on node 1, 4 or 5, 3 runs of 40 s per start node, alternating with the kernel without this patch; time of the last copy. A copy takes 244 to 248 ms anywhere in the package of the memory and 394 to 520 ms on the other one. With the patch every run settled on node 0, within 3.4 to 5.6 s: before after change runs settled on node 0 0/9 9/9 runs ending off package 5/9 0/9 slowest run (ms) 520 248 -52% median run (ms) 394 (245-520) 246 (244-248) -38% Signed-off-by: Qiliang Yuan --- kernel/sched/fair.c | 20 +++++++++++++------- mm/mempolicy.c | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 14a4a15ac2747..eaf8b77ecb6ac 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -4292,6 +4292,7 @@ static void task_numa_work(struct callback_head *work) bool vma_pids_forced = false; unsigned long *node_pages = NULL; unsigned long nr_sampled; + bool sample_only; int nid; WARN_ON_ONCE(p != container_of(work, struct task_struct, numa_work)); @@ -4350,9 +4351,8 @@ static void task_numa_work(struct callback_head *work) if (!pages) return; - if (mm_flags_test(MMF_HAS_PINNED, mm)) - node_pages = kcalloc(nr_node_ids, sizeof(*node_pages), - GFP_KERNEL | __GFP_NOWARN); + node_pages = kcalloc(nr_node_ids, sizeof(*node_pages), + GFP_KERNEL | __GFP_NOWARN); if (!mmap_read_trylock(mm)) { kfree(node_pages); @@ -4378,8 +4378,11 @@ static void task_numa_work(struct callback_head *work) } for (; vma; vma = vma_next(&vmi)) { - if (!vma_migratable(vma) || !vma_policy_mof(vma) || - vma_is_hugetlb(vma) || !vma_is_mm_managed(vma)) { + /* Hugetlb pages are not migrated but their accesses are sampled. */ + sample_only = node_pages && vma_is_hugetlb(vma); + if (!sample_only && + (!vma_migratable(vma) || !vma_policy_mof(vma) || + vma_is_hugetlb(vma) || !vma_is_mm_managed(vma))) { trace_sched_skip_vma_numa(mm, vma, NUMAB_SKIP_UNSUITABLE); continue; } @@ -4475,9 +4478,12 @@ static void task_numa_work(struct callback_head *work) start = max(start, vma->vm_start); end = ALIGN(start + (pages << PAGE_SHIFT), HPAGE_SIZE); end = min(end, vma->vm_end); - nr_pte_updates = change_prot_numa(vma, start, end); + nr_pte_updates = 0; nr_sampled = 0; - if (node_pages) + if (!sample_only) + nr_pte_updates = change_prot_numa(vma, start, end); + if (sample_only || (node_pages && + mm_flags_test(MMF_HAS_PINNED, mm))) nr_sampled = numa_sample_range(vma, start, end, node_pages); if (nr_sampled) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index d11c38828ee87..fcdcf69f8e6c7 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -996,9 +996,39 @@ static int numa_sample_pmd_entry(pmd_t *pmd, unsigned long addr, return 0; } +#ifdef CONFIG_HUGETLB_PAGE +static int numa_sample_hugetlb_entry(pte_t *pte, unsigned long hmask, + unsigned long addr, unsigned long end, + struct mm_walk *walk) +{ + struct hstate *h = hstate_vma(walk->vma); + struct numa_sample_walk *sw = walk->private; + unsigned long psize = huge_page_size(h); + spinlock_t *ptl; + pte_t entry; + int nid; + + ptl = huge_pte_lock(h, walk->mm, pte); + entry = huge_ptep_get(walk->mm, addr, pte); + if (pte_present(entry) && pte_young(entry)) { + nid = folio_nid(pfn_folio(pte_pfn(entry))); + entry = huge_ptep_get_and_clear(walk->mm, addr, pte, psize); + set_huge_pte_at(walk->mm, addr, pte, pte_mkold(entry), psize); + sw->node_pages[nid] += pages_per_huge_page(h); + sw->nr_young += pages_per_huge_page(h); + } + spin_unlock(ptl); + + return 0; +} +#else +#define numa_sample_hugetlb_entry NULL +#endif + static const struct mm_walk_ops numa_sample_ops = { .pud_entry = numa_sample_pud_entry, .pmd_entry = numa_sample_pmd_entry, + .hugetlb_entry = numa_sample_hugetlb_entry, .walk_lock = PGWALK_RDLOCK, }; @@ -1009,8 +1039,8 @@ static const struct mm_walk_ops numa_sample_ops = { * @end: End of the range. * @node_pages: Per-node counters, indexed by node id. * - * Test and clear the accessed bit of pinned folios and add the pages found - * accessed to @node_pages for the node they reside on. + * Test and clear the accessed bit of hugetlb pages and of pinned folios and + * add the pages found accessed to @node_pages for the node they reside on. * * Return: The number of pages found accessed. */ -- 2.43.0