From patchwork Mon Sep 18 10:32:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13389375 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F93ACD13D2 for ; Mon, 18 Sep 2023 10:32:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA56B6B02D3; Mon, 18 Sep 2023 06:32:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A80386B02D4; Mon, 18 Sep 2023 06:32:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8AA3B6B02D9; Mon, 18 Sep 2023 06:32:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 774216B02D3 for ; Mon, 18 Sep 2023 06:32:55 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 48431120C83 for ; Mon, 18 Sep 2023 10:32:55 +0000 (UTC) X-FDA: 81249355110.04.75794EF Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf22.hostedemail.com (Postfix) with ESMTP id 55FD3C0026 for ; Mon, 18 Sep 2023 10:32:51 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695033173; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=99gOF8CU+1+YWC2p22srbZVzG8oOU3EApfS5TWFFlmQ=; b=XYqNbnCdS6yNHu+GFhBOZP1yI8CYly3bN0HNMdY5L4I+CF+C3lfTqfFC/EZIDyLD3QpCil Y8SmjECuMCGoMJ+98TN7o5k8zJSZ+1SJJBkIHzJqRWy5gcWBVIZ0wi+N5sb/oYPTP83Gbd nrUUFWm2b+G8qpIEyYqtWz9FSq/nMkQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695033173; a=rsa-sha256; cv=none; b=hO16G60WSlcMyc95iHJrILYny1Q1TLuuXHDQcUSLTLeP9ocgsih4XEVOoXCs7yF3V0A/Cg yvxWoWDQgpz/HRkQU+84Vv7qN2eG9QppGLvKhTyxsVWQ98a6aJQ7gkJs/4pfVfh5yBgv2J pMJ5mIg+xQKSFbSoxWPgXACE/X1DqlU= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Rq1HK2n1xzNnfv; Mon, 18 Sep 2023 18:29:01 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Mon, 18 Sep 2023 18:32:46 +0800 From: Kefeng Wang To: Andrew Morton CC: , , , , , Zi Yan , Mike Kravetz , , Kefeng Wang Subject: [PATCH 1/6] sched/numa, mm: make numa migrate functions to take a folio Date: Mon, 18 Sep 2023 18:32:08 +0800 Message-ID: <20230918103213.4166210-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230918103213.4166210-1-wangkefeng.wang@huawei.com> References: <20230918103213.4166210-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Stat-Signature: z3r5tggz7u5xz74oytdzngtaakogzfaw X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 55FD3C0026 X-Rspam-User: X-HE-Tag: 1695033171-41150 X-HE-Meta: U2FsdGVkX19kU0HMgBxEXtPao8UpC2iioyaUrrkMBNZk4csi+ob/pJu6iLyPc3RLL8wfR6ihi35icQValmnzWJpPWGhN3NJP+dPL2wT0agayBdpodXozR9hs/9TgiIhzGKQEYvfu5RpMYYkuwHosx+ybIzzkItDuu3hoPoqia9klvxzY1uaKujdxZMB1qpMuQX8cD2npwI6p8xD3kxowl1iyoNGU+SP/eCDljch1IoABkqDPknIYvWOUrOJaRW7SoHIpTdcqaNmoRjRLz1MeXJwdVgcQWqlpDj/zAdR5P379dESTqfEtOJOlP+96GfsaJKvFbX47W204Zu29otp1rwAIHXrZkr2xUhzr9GP8nOrbbD2dvRuqwtOTXtiNQ+g4Le9CzhkbG+C5dGELmuvJQGa8k1ZDUGOY59NKMuBXd/ej3j6Kq5rQV3uaASJml+CznFeyI8+Duq6btnu6Ev2mF126qabHkkLGzbLYGMYtyDetCIiAnWAGybswPAK7iiw4un7ry7fNzb+CdKFEOzFyMmfnRNzizxtsfRDNmuw6msQpb2tqTARIwGQM2J2xgc0KTe+5YIbq3BjayE/EIYDP7Un5R5AUtkBS+nFXfCff+mr+flXRdjTsoKytGdlzPN8+VyrOxQDnNBsmteT1/nt+jCiWwHJzTmTamLcW2I8bC4BaoVcLik5yF60pa97bMBM6z2E68TlHgtb7UqUIB6/iOPIZsybl/b7UHjzR7UUljIbLSaGfYozTeHRFKKciwWkhN0MpLoGmAKonahe4JRQugaR+7eyL+delb9x5ng62ncGRNmoSF5J+oF7/2N/EiJ2tTXvr3RzkOiAlEqMqBRGbdlJqXdwGy6N8kPcrEBto3z2hMjwVN90cMMefa4Mi4SOdDWjQBoUhUHsiWsKPIB3kWb3CEAViaEvBA9RP7hW/2GUcwtVLPOSZ7jecIyCADE9o5V2tDF2DyoV6Wf+DI21 ZZoRLOto p1ywRjPG/nrc0mDAfdhH6w7bTaqo8qM5pFYfh906Hxdn9pwwHbYUtWdeRU37IPGyPD+TWLJn7paf4ewe7vbvtZv5JzxTOHCBhH0ORlhGswhxDrcsvyPh5rN9rr/VGUTyFSNXkzce1KyEVO9iuKtqeUfTV+w== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The cpuid(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. Signed-off-by: Kefeng Wang --- include/linux/sched/numa_balancing.h | 4 ++-- kernel/sched/fair.c | 12 ++++++------ mm/mempolicy.c | 3 ++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/linux/sched/numa_balancing.h b/include/linux/sched/numa_balancing.h index 3988762efe15..a38528c28665 100644 --- a/include/linux/sched/numa_balancing.h +++ b/include/linux/sched/numa_balancing.h @@ -20,7 +20,7 @@ extern void task_numa_fault(int last_node, int node, int pages, int flags); extern pid_t task_numa_group_id(struct task_struct *p); extern void set_numabalancing_state(bool enabled); extern void task_numa_free(struct task_struct *p, bool final); -extern bool should_numa_migrate_memory(struct task_struct *p, struct page *page, +extern bool should_numa_migrate_memory(struct task_struct *p, struct folio *folio, int src_nid, int dst_cpu); #else static inline void task_numa_fault(int last_node, int node, int pages, @@ -38,7 +38,7 @@ static inline void task_numa_free(struct task_struct *p, bool final) { } static inline bool should_numa_migrate_memory(struct task_struct *p, - struct page *page, int src_nid, int dst_cpu) + struct folio *folio, int src_nid, int dst_cpu) { return true; } diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index cb225921bbca..683cc1e417d7 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -1722,12 +1722,12 @@ static bool pgdat_free_space_enough(struct pglist_data *pgdat) * The smaller the hint page fault latency, the higher the possibility * for the page to be hot. */ -static int numa_hint_fault_latency(struct page *page) +static int numa_hint_fault_latency(struct folio *folio) { int last_time, time; time = jiffies_to_msecs(jiffies); - last_time = xchg_page_access_time(page, time); + last_time = xchg_page_access_time(&folio->page, time); return (time - last_time) & PAGE_ACCESS_TIME_MASK; } @@ -1784,7 +1784,7 @@ static void numa_promotion_adjust_threshold(struct pglist_data *pgdat, } } -bool should_numa_migrate_memory(struct task_struct *p, struct page * page, +bool should_numa_migrate_memory(struct task_struct *p, struct folio *folio, int src_nid, int dst_cpu) { struct numa_group *ng = deref_curr_numa_group(p); @@ -1814,16 +1814,16 @@ bool should_numa_migrate_memory(struct task_struct *p, struct page * page, numa_promotion_adjust_threshold(pgdat, rate_limit, def_th); th = pgdat->nbp_threshold ? : def_th; - latency = numa_hint_fault_latency(page); + latency = numa_hint_fault_latency(folio); if (latency >= th) return false; return !numa_promotion_rate_limit(pgdat, rate_limit, - thp_nr_pages(page)); + folio_nr_pages(folio)); } this_cpupid = cpu_pid_to_cpupid(dst_cpu, current->pid); - last_cpupid = page_cpupid_xchg_last(page, this_cpupid); + last_cpupid = page_cpupid_xchg_last(&folio->page, this_cpupid); if (!(sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING) && !node_is_toptier(src_nid) && !cpupid_valid(last_cpupid)) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 42b5567e3773..39584dc25c84 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -2642,7 +2642,8 @@ int mpol_misplaced(struct page *page, struct vm_area_struct *vma, unsigned long if (pol->flags & MPOL_F_MORON) { polnid = thisnid; - if (!should_numa_migrate_memory(current, page, curnid, thiscpu)) + if (!should_numa_migrate_memory(current, page_folio(page), + curnid, thiscpu)) goto out; }