From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.107 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796557169; b=aZ8uV5ryKTAzMT+xUbo9Tcn9Y14fhpbhrqY6G3fsNTbx1bPR0nRK+FTceOT4bAAUFGQN 05jk9FnhILlOVfkSa/Bv47qav3jJ2+AntVd8Jn0mjhmasVcapm93blSVKq20LYKxuwNOb ar0kIdb7H/AY2RcmDVrGe/v5ql62kwWe+G0E9sBRIcCFOIeqnAiOZA7WiQvVcuyArVcg7 kXClR/QwC3z4PiVMpFVWBS7bDFmcc+5jeoCsLC0wUOQLau9vP3eBhVTrXFV0w5UHUrsK7 v4xWJK7HrqYqN5RcUlgjABwc9vrH9wswlcqSNp/4xkKp9hLYjdg/fnJcUgUeelUiHag== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796557169; 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=wg5+CT2o4OPwLq1vmxFdgNYedGSBYO5keqjG87PqPUg=; b=Zsihwg0OO/ZtrSieDWyp9zme44CBZzNDCOhcEeJ+nykqWzIK9LGUIaIUwWGP7qmndFuz w5stQ7+sT6nbhOPpIO60SNyILXddht4MbWqIRHATGmCpzv8bK4VyLKClUgrWQG3Rs/21T RNzgq602Vkg4iuTJ22/hyO2FsYdXT6LQAvDxNWTREE2AebB6wanBtBWs+7XL8qX/jeztf aJrsUJgVlMdpoQeucUvPbwJqP61+L8eUovAc7U/wiMRkB39aVDl9wIimGiedpkE5HBA29 CLKidRU7SwRMHXqX8fUzoIflA6ORmCXF4Rl0Xj6HfxtmqxnShV/EEuwYI3tZZd8rC8w== 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=tmIBFjDk; arc=none smtp.remote-ip=95.215.58.107 Received: from mta1.migadu.com (out-107.mta1.migadu.com [95.215.58.107]) (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 1A57D606A33F for ; Sun, 6 Dec 2026 11:39:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1A57D606A33F 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=tmIBFjDk X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=LwA0ZkLvwytrNYSoUF6/CVY2KXw/EaRoYT0JsoniCXc=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796557158; v=1; x=1797161958; b=tmIBFjDkswHcUmHEuGynvzvvaUcA1xMLUTgrClRdgSJzyWVtT8CacI/1nXQ4J4nW62TWhcHx J5ovWT8B9l6A4jeZkmjgq7UCb76R5k+AhplwqDIOgfOd1hqc2iM/YiW9HbiBGbRV4m4xhM+bz1B BPr0SPMJPamnqKuiIupM9JlE= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id cc9e04e99b7c4b69; Sun, 06 Dec 2026 11:39:18 +0000 X-Mizu-Trace-ID: cc9e04e99b7c4b69 X-Migadu-Flow: FLOW_OUT From: Qiliang Yuan Date: Sun, 06 Dec 2026 06:38:40 -0500 Subject: [PATCH 3/8] sched/numa: Extend accessed-bit sampling to DAX mappings 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-3-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 DAX mappings point straight at persistent memory or other device memory. Their pages are not on the LRU and are never migrated, and vma_migratable() makes task_numa_work() skip such VMAs. Where that memory sits still matters to the task using it. A task working on a DAX file whose device is attached to one node gets no placement signal from it and may run on the other package for good. Treat DAX VMAs like hugetlb ones: sample every folio in the range rather than only pinned ones, and account the pages found accessed as faults on the node of the device memory, without changing the protection. A task copying within a 3 GiB file on ext4 mounted with dax=always on emulated pmem (memmap=4G!8G) of node 0 in 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 4, 3 rounds of 2 runs of 40 s alternating with the kernel without this patch; time of the last copy. With the patch every run settled on node 0, within 1.4 to 1.8 s: before after change runs settled on node 0 0/6 6/6 runs ending off package 6/6 0/6 slowest run (ms) 362 189 -48% median run (ms) 298 (292-362) 186 (183-189) -38% Signed-off-by: Qiliang Yuan --- include/linux/mm.h | 3 ++- kernel/sched/fair.c | 11 ++++++++--- mm/mempolicy.c | 16 ++++++++++++---- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index d887d74d54975..df33d4519fae0 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -5030,7 +5030,8 @@ void vma_set_file(struct vm_area_struct *vma, struct file *file); unsigned long change_prot_numa(struct vm_area_struct *vma, unsigned long start, unsigned long end); unsigned long numa_sample_range(struct vm_area_struct *vma, unsigned long start, - unsigned long end, unsigned long *node_pages); + unsigned long end, unsigned long *node_pages, + bool all); #endif struct vm_area_struct *find_extend_vma_locked(struct mm_struct *, diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index eaf8b77ecb6ac..520728ada00fb 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -4378,8 +4378,12 @@ static void task_numa_work(struct callback_head *work) } for (; vma; vma = vma_next(&vmi)) { - /* Hugetlb pages are not migrated but their accesses are sampled. */ - sample_only = node_pages && vma_is_hugetlb(vma); + /* + * Hugetlb and DAX pages are not migrated but their accesses are + * sampled. + */ + sample_only = node_pages && + (vma_is_hugetlb(vma) || vma_is_dax(vma)); if (!sample_only && (!vma_migratable(vma) || !vma_policy_mof(vma) || vma_is_hugetlb(vma) || !vma_is_mm_managed(vma))) { @@ -4485,7 +4489,8 @@ static void task_numa_work(struct callback_head *work) if (sample_only || (node_pages && mm_flags_test(MMF_HAS_PINNED, mm))) nr_sampled = numa_sample_range(vma, start, end, - node_pages); + node_pages, + sample_only); if (nr_sampled) vma_set_access_pid_bit(vma); diff --git a/mm/mempolicy.c b/mm/mempolicy.c index fcdcf69f8e6c7..e69a4b38b136e 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -935,8 +935,14 @@ unsigned long change_prot_numa(struct vm_area_struct *vma, struct numa_sample_walk { unsigned long *node_pages; unsigned long nr_young; + bool all; }; +static bool numa_sample_folio(struct numa_sample_walk *sw, struct folio *folio) +{ + return folio && (sw->all || folio_maybe_dma_pinned(folio)); +} + static int numa_sample_pud_entry(pud_t *pud, unsigned long addr, unsigned long next, struct mm_walk *walk) { @@ -962,7 +968,7 @@ static int numa_sample_pmd_entry(pmd_t *pmd, unsigned long addr, folio = pmd_present(pmdval) ? vm_normal_folio_pmd(vma, addr, pmdval) : NULL; - if (folio && folio_maybe_dma_pinned(folio) && + if (numa_sample_folio(sw, folio) && pmdp_test_and_clear_young(vma, addr, pmd)) { sw->node_pages[folio_nid(folio)] += HPAGE_PMD_NR; sw->nr_young += HPAGE_PMD_NR; @@ -982,7 +988,7 @@ static int numa_sample_pmd_entry(pmd_t *pmd, unsigned long addr, continue; folio = vm_normal_folio(vma, addr, ptent); - if (!folio || !folio_maybe_dma_pinned(folio)) + if (!numa_sample_folio(sw, folio)) continue; if (ptep_test_and_clear_young(vma, addr, pte)) { @@ -1038,6 +1044,7 @@ static const struct mm_walk_ops numa_sample_ops = { * @start: Start of the range. * @end: End of the range. * @node_pages: Per-node counters, indexed by node id. + * @all: Sample every folio instead of pinned folios only. * * 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. @@ -1045,9 +1052,10 @@ static const struct mm_walk_ops numa_sample_ops = { * Return: The number of pages found accessed. */ unsigned long numa_sample_range(struct vm_area_struct *vma, unsigned long start, - unsigned long end, unsigned long *node_pages) + unsigned long end, unsigned long *node_pages, + bool all) { - struct numa_sample_walk sw = { .node_pages = node_pages }; + struct numa_sample_walk sw = { .node_pages = node_pages, .all = all }; /* * Like the MGLRU page table walk, clear the accessed bits without flushing -- 2.43.0