Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sched/numa, mm: make numa migrate functions to take a folio

The cpupid (or access time) is stored in the head page for THP, so it is
safely to make should_numa_migrate_memory() and numa_hint_fault_latency()
to take a folio. This is in preparation for large folio numa balancing.

Link: https://lkml.kernel.org/r/20230921074417.24004-7-wangkefeng.wang@huawei.com
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: "Huang, Ying" <ying.huang@intel.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Kefeng Wang and committed by
Andrew Morton
8c9ae56d 75c70128

+10 -10
+3 -3
include/linux/sched/numa_balancing.h
··· 20 20 extern pid_t task_numa_group_id(struct task_struct *p); 21 21 extern void set_numabalancing_state(bool enabled); 22 22 extern void task_numa_free(struct task_struct *p, bool final); 23 - extern bool should_numa_migrate_memory(struct task_struct *p, struct page *page, 24 - int src_nid, int dst_cpu); 23 + bool should_numa_migrate_memory(struct task_struct *p, struct folio *folio, 24 + int src_nid, int dst_cpu); 25 25 #else 26 26 static inline void task_numa_fault(int last_node, int node, int pages, 27 27 int flags) ··· 38 38 { 39 39 } 40 40 static inline bool should_numa_migrate_memory(struct task_struct *p, 41 - struct page *page, int src_nid, int dst_cpu) 41 + struct folio *folio, int src_nid, int dst_cpu) 42 42 { 43 43 return true; 44 44 }
+6 -6
kernel/sched/fair.c
··· 1722 1722 * The smaller the hint page fault latency, the higher the possibility 1723 1723 * for the page to be hot. 1724 1724 */ 1725 - static int numa_hint_fault_latency(struct page *page) 1725 + static int numa_hint_fault_latency(struct folio *folio) 1726 1726 { 1727 1727 int last_time, time; 1728 1728 1729 1729 time = jiffies_to_msecs(jiffies); 1730 - last_time = xchg_page_access_time(page, time); 1730 + last_time = xchg_page_access_time(&folio->page, time); 1731 1731 1732 1732 return (time - last_time) & PAGE_ACCESS_TIME_MASK; 1733 1733 } ··· 1784 1784 } 1785 1785 } 1786 1786 1787 - bool should_numa_migrate_memory(struct task_struct *p, struct page * page, 1787 + bool should_numa_migrate_memory(struct task_struct *p, struct folio *folio, 1788 1788 int src_nid, int dst_cpu) 1789 1789 { 1790 1790 struct numa_group *ng = deref_curr_numa_group(p); ··· 1814 1814 numa_promotion_adjust_threshold(pgdat, rate_limit, def_th); 1815 1815 1816 1816 th = pgdat->nbp_threshold ? : def_th; 1817 - latency = numa_hint_fault_latency(page); 1817 + latency = numa_hint_fault_latency(folio); 1818 1818 if (latency >= th) 1819 1819 return false; 1820 1820 1821 1821 return !numa_promotion_rate_limit(pgdat, rate_limit, 1822 - thp_nr_pages(page)); 1822 + folio_nr_pages(folio)); 1823 1823 } 1824 1824 1825 1825 this_cpupid = cpu_pid_to_cpupid(dst_cpu, current->pid); 1826 - last_cpupid = page_cpupid_xchg_last(page, this_cpupid); 1826 + last_cpupid = page_cpupid_xchg_last(&folio->page, this_cpupid); 1827 1827 1828 1828 if (!(sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING) && 1829 1829 !node_is_toptier(src_nid) && !cpupid_valid(last_cpupid))
+1 -1
mm/mempolicy.c
··· 2642 2642 if (pol->flags & MPOL_F_MORON) { 2643 2643 polnid = thisnid; 2644 2644 2645 - if (!should_numa_migrate_memory(current, &folio->page, curnid, 2645 + if (!should_numa_migrate_memory(current, folio, curnid, 2646 2646 thiscpu)) 2647 2647 goto out; 2648 2648 }