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; } From patchwork Mon Sep 18 10:32:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13389374 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 9344FC46CA1 for ; Mon, 18 Sep 2023 10:32:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 80FE46B02D2; Mon, 18 Sep 2023 06:32:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 797216B02D3; Mon, 18 Sep 2023 06:32:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A1106B02D4; Mon, 18 Sep 2023 06:32:54 -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 413536B02D3 for ; Mon, 18 Sep 2023 06:32:54 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 165E21A01F5 for ; Mon, 18 Sep 2023 10:32:54 +0000 (UTC) X-FDA: 81249355068.18.69604B8 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf07.hostedemail.com (Postfix) with ESMTP id 3CB2D4000B for ; Mon, 18 Sep 2023 10:32:50 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf07.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695033172; 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=Q0j2iplv8tIoDxFaHxiXvS50HobKD+ChXL38zg2Jy/Q=; b=rc2VtbweBU1ckGu4jKDKP6S8VHpgACst5W87t+0gy1KITsJz+esfqujkwg7viDniAK97JQ OOrs/wq3nzak3MsSQDvFRfYyYKUxvi1qulhyOxK0YJX+nHFzG7+HfuMsTLe7TdTs/r/a8g 5ogogw8ZHxCa1s8wBAX7zGfzX82sBMY= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf07.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695033172; a=rsa-sha256; cv=none; b=vS8wOP4ZW6cHundnbtupBdbxSw4ihXSHrHheXWBZpFNFV4PYwAfZL0bsqLOSDFOE8DT5hq uKwRoTrcIToVyxahmwdvg0E1xYTjUWxiIpcH8kK9bwYTGWyjAKAF533GkIyPiBGwH+A86Q L4wHyq4v+QGAAaiTyW0N45MVAy2ptQY= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Rq1JJ308ZzVky6; Mon, 18 Sep 2023 18:29:52 +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:47 +0800 From: Kefeng Wang To: Andrew Morton CC: , , , , , Zi Yan , Mike Kravetz , , Kefeng Wang Subject: [PATCH 2/6] mm: mempolicy: make mpol_misplaced() to take a folio Date: Mon, 18 Sep 2023 18:32:09 +0800 Message-ID: <20230918103213.4166210-3-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-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 3CB2D4000B X-Stat-Signature: 8ym6hw83mewz9fptof6ier6iuq8wzk8y X-HE-Tag: 1695033170-814029 X-HE-Meta: U2FsdGVkX189+L4RcPhr1t8T9tHsS0j/QOAih7ol9m8xBT/IKsXi/B0PPTuvEYM3UigHOMjM+ySTvvfLOFDgJVBvwQhAvNtHjhEcFRqrNEVYvcHh+FSzlvFYF8stxWP3+Hu/e145UlkTjTOZIXSwINlRQh54RjONk8+3OZL92RMVc3ndpCPHQN6U1+MLVNzd+2G3LvPYtWjn4mvzBZI8SDPmuhzcF07ZPf6gny89POZzgreQYW2bQvIAU6MMBhUrkWpRl+ZmxFkYMxEm+Qqd5Ym/xNokavfCS4wvTAJ6Awh1cDF5ASXycRHmBYiDqKYG0RprSXP7WmC3fNSGd3rkqhHWq4awDDqTBstwch9LP8rbiARJjI/Bl9qrM4DVv5wMj4PY2+9Dn4/9yWQ0KMuXodtZUA3PDgilBJT3IlTGOxgO9wsS67gRF1kK18NSulRUwMIoUllxG92gWfMOFB+cGYNBiB5yMpo4F8MJ51tkyVFzCco6QBhBODgrx+7xyzCLC++h2g2uAfW+Zi3p4cdOlcRXDsD1eAHEdHvwK7lZwgQp1noNlXIafxUeVU/X95KaP6PgQhcbB6Qp3pruzTZqsFk7xLopfOeJz+7i1aBCN2z/FS7XmvJ5V6eBWNbwXRlN1PzNPnGJInpbPLatNbzGfEw+nVxGt+99TbOoo/4i11jjSxs0xwCr3YGTddJYIN1xLyc0YLBQxKKjbmEGrHytElcQPHxWZH04OLUWITxxTZMUxpAcnFgpNClm6y7q/M+fY3qchO4aP6tbJTsMkU132e6RTRIqN95P5RkbagfHYrgMTWOqfyVt9ssetP24T5+q0s0qlak5GMILZUbydFVEDQVP1YRXzEYwHrRES45rYzUgW9lIUZJ4neG0TMAiwm99mSVkXwNqtoqkLeaUAfXDWX6vsA62xPWDCJcaU+0PQoc5aSDSSbDmfteFKo9bNALbtLMAT2TNki/sXpAiVZJ OV21qtiv Gr3nMPdsFUkmkSE87URBSBTFAwDagMkgq12juRyyWaQTuBSaB0uq542JgWZBUham7ytS78kmLTdqtuRHQbA/nv6ncBYZBeRkD6vzMRFe+TduQHTHsGDn4Xshv32eA7MVeo9WVEVTmUSwpbCnYEJgB0NlW2bRTGDTKWEBWhkbNXjkdukRlUBJQqRJ0TlfONmHZnll5 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: In preparation for large folio numa balancing, make mpol_misplaced() to take a folio, no functional change intended. Signed-off-by: Kefeng Wang --- include/linux/mempolicy.h | 4 ++-- mm/memory.c | 2 +- mm/mempolicy.c | 21 ++++++++++----------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h index d232de7cdc56..4a82eee20073 100644 --- a/include/linux/mempolicy.h +++ b/include/linux/mempolicy.h @@ -174,7 +174,7 @@ extern void mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol); /* Check if a vma is migratable */ extern bool vma_migratable(struct vm_area_struct *vma); -extern int mpol_misplaced(struct page *, struct vm_area_struct *, unsigned long); +extern int mpol_misplaced(struct folio *, struct vm_area_struct *, unsigned long); extern void mpol_put_task_policy(struct task_struct *); static inline bool mpol_is_preferred_many(struct mempolicy *pol) @@ -278,7 +278,7 @@ static inline int mpol_parse_str(char *str, struct mempolicy **mpol) } #endif -static inline int mpol_misplaced(struct page *page, struct vm_area_struct *vma, +static inline int mpol_misplaced(struct folio *folio, struct vm_area_struct *vma, unsigned long address) { return -1; /* no node preference */ diff --git a/mm/memory.c b/mm/memory.c index 983a40f8ee62..a04c90604c73 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4731,7 +4731,7 @@ int numa_migrate_prep(struct page *page, struct vm_area_struct *vma, *flags |= TNF_FAULT_LOCAL; } - return mpol_misplaced(page, vma, addr); + return mpol_misplaced(page_folio(page), vma, addr); } static vm_fault_t do_numa_page(struct vm_fault *vmf) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 39584dc25c84..14a223b68180 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -2565,24 +2565,24 @@ static void sp_free(struct sp_node *n) } /** - * mpol_misplaced - check whether current page node is valid in policy + * mpol_misplaced - check whether current folio node is valid in policy * - * @page: page to be checked - * @vma: vm area where page mapped - * @addr: virtual address where page mapped + * @folio: folio to be checked + * @vma: vm area where folio mapped + * @addr: virtual address in @vma for shared policy lookup and interleave policy * - * Lookup current policy node id for vma,addr and "compare to" page's + * Lookup current policy node id for vma,addr and "compare to" folio's * node id. Policy determination "mimics" alloc_page_vma(). * Called from fault path where we know the vma and faulting address. * * Return: NUMA_NO_NODE if the page is in a node that is valid for this - * policy, or a suitable node ID to allocate a replacement page from. + * policy, or a suitable node ID to allocate a replacement folio from. */ -int mpol_misplaced(struct page *page, struct vm_area_struct *vma, unsigned long addr) +int mpol_misplaced(struct folio *folio, struct vm_area_struct *vma, unsigned long addr) { struct mempolicy *pol; struct zoneref *z; - int curnid = page_to_nid(page); + int curnid = folio_nid(folio); unsigned long pgoff; int thiscpu = raw_smp_processor_id(); int thisnid = cpu_to_node(thiscpu); @@ -2638,12 +2638,11 @@ int mpol_misplaced(struct page *page, struct vm_area_struct *vma, unsigned long BUG(); } - /* Migrate the page towards the node whose CPU is referencing it */ + /* Migrate the folio towards the node whose CPU is referencing it */ if (pol->flags & MPOL_F_MORON) { polnid = thisnid; - if (!should_numa_migrate_memory(current, page_folio(page), - curnid, thiscpu)) + if (!should_numa_migrate_memory(current, folio, curnid, thiscpu)) goto out; } From patchwork Mon Sep 18 10:32:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13389377 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 ED960CD37B0 for ; Mon, 18 Sep 2023 10:33:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8FA9D6B02D8; Mon, 18 Sep 2023 06:33:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8823D6B02D9; Mon, 18 Sep 2023 06:33:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 74A086B02DA; Mon, 18 Sep 2023 06:33:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 636FF6B02D8 for ; Mon, 18 Sep 2023 06:33:11 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 39285C0D0F for ; Mon, 18 Sep 2023 10:33:11 +0000 (UTC) X-FDA: 81249355782.14.32961AC Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf28.hostedemail.com (Postfix) with ESMTP id 4F639C000C for ; Mon, 18 Sep 2023 10:33:07 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 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=1695033189; 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=xzBNWzs4QslYgQE6UPXgY6Lc++vpLEbqpWbKW/jYig0=; b=yvI/gLov59my576d8oHHt+XPexM3Ox2iTYvXKjtAzvnQWSFes26cMW+btQcEbyVxUDJFt4 /TDbWyy3R1dYSjC3DE2TW+oob2bX0L39cFK/VfAsF97MmjjMlA6mRY1+GFQ6UCbYEaZG55 C1bxMci3bidL+KnQcYEYZqpVM+EAPO0= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695033189; a=rsa-sha256; cv=none; b=N6Ca+GaD7y9jFfZ9688iouR8nLS2YJ2gALfH0WrazswpalKNYSjnckRMPEmnnpR1V6CW5u Y0sg7bFurnbHEJyTRePU7zlDFSeVdzA21X/V6nfZYRx5tVzKJiluTAa02CFO/NR++o2Xol egjYBYZ3OVyse/pG9uUt0H4nLs4BZAY= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Rq1KJ5QCjz15NQJ; Mon, 18 Sep 2023 18:30:44 +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:47 +0800 From: Kefeng Wang To: Andrew Morton CC: , , , , , Zi Yan , Mike Kravetz , , Kefeng Wang Subject: [PATCH 3/6] mm: memory: make numa_migrate_prep() to take a folio Date: Mon, 18 Sep 2023 18:32:10 +0800 Message-ID: <20230918103213.4166210-4-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-Rspamd-Queue-Id: 4F639C000C X-Rspam-User: X-Stat-Signature: usk3et1x1utc4j1tfy3mizxjodtcpsp9 X-Rspamd-Server: rspam01 X-HE-Tag: 1695033187-965351 X-HE-Meta: U2FsdGVkX19cMBSk70Lpsm6Fbco3DYbD9oFNw4SmqzxU8TascCOgfrjW5JdyZ/Ldd04KuTl9IzC135tP5lPidbwkW8/spyStWEtaL2khra9TlGN7e4yu/Y7wCl1VHUHU2T8Invd/4+rvjtbSBwVNZVEXZncgREIo65zkSWSNAtCTiMkGfIAd4w6LssjLuV9kQBGVagWf5Upppy68zYdsfSOj3AxbYb1BQCWz9pk3QnPfMbaO1UT2KZQtL3aztO+dZAABDVaSdvYOuxq5TbTU8hsNyvAWslatP/EDS+BWSp1voKGMLq7p1Q7C2y5LVM6YkwnarU1p/9MKd6jbfBvV2ftLDDLlTFp+UhR1FPKsyGd1UsopQV5KRVEIEmvXF3YQZthPnE5ryrVI9/XL3eZGhq7sdSLQAzVPS8tN5ZRdiEnxK0KYCd2A5mMEYt4hQ5bFe4r9t25MRqCxGWdNo2wv6Bf0q4uKYIj+cKua4Oq1lOOdc+CRIKXhjiZa4WbEw6iGPsHHTTAj7Bu60ZRW+N2zgqXFjA2dWhRpbnGPIHQjE0py5kS6SrhHdfxDOx2JqYGXgfJJ3I8vDwjvXqNXXaxwzqWWRZ2D+su/lFhzBHddXVjok1yAYw+atfWJp4Ik8FarcIrsX03458lqFkWIcpL5sAYnmJys1LwjP5azJsHFgU7Gv05zbHUKAjIz4Cq8JYIBvVZ7l8+eVx6hs5iL8g+r31iP6WiK6fS15BaGpId+ndz1mFMjsq8IS7SFcwT75jgSnMBBVEExDCWv19ClLKE5z7ZETl2tpU/gmNbUgVAoeSwVOaqUhEE3FSiCtVemMRfEfXpvPutPRMxmFcjZe2U9Ic+9yiXHRDyvbPPKVXbbOPs5d0076tPqWCUmjz/8P6dbkF45StGdJ+u3AnbfTI2thbv63HRI/wiT7vVMJTkKkuBauT8aYjmnANqcWF/OzO5xvUTHv9gBbxz+nMFIOVd Zjr3GHiZ qgxxUejm/FdTS4sI8T5u+PHr7N0EY2YfG/bOJ+QKJaAVn6SW0Lpm4CIwnqztDIo264uPxlOXLFWiPksSQWpBRWcMDIVAxUmO5o5weAmSm3E+RUoz//RFyHh6bhAsRAd0aanY74kc+uo8EJyTI46mRaGm+9MlJWtI74lspaNws81F+ovwaXUw3TrD7Wp+gPp4cRdPI 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: In preparation for large folio numa balancing, make numa_migrate_prep() to take a folio, no functional change intended. Signed-off-by: Kefeng Wang --- mm/huge_memory.c | 2 +- mm/internal.h | 2 +- mm/memory.c | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 0da653080d8c..3e34a48fbdd8 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1556,7 +1556,7 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf) */ if (node_is_toptier(page_nid)) last_cpupid = page_cpupid_last(page); - target_nid = numa_migrate_prep(page, vma, haddr, page_nid, + target_nid = numa_migrate_prep(page_folio(page), vma, haddr, page_nid, &flags); if (target_nid == NUMA_NO_NODE) { diff --git a/mm/internal.h b/mm/internal.h index 8c90e966e9f8..f30b81f365c1 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -926,7 +926,7 @@ void vunmap_range_noflush(unsigned long start, unsigned long end); void __vunmap_range_noflush(unsigned long start, unsigned long end); -int numa_migrate_prep(struct page *page, struct vm_area_struct *vma, +int numa_migrate_prep(struct folio *folio, struct vm_area_struct *vma, unsigned long addr, int page_nid, int *flags); void free_zone_device_page(struct page *page); diff --git a/mm/memory.c b/mm/memory.c index a04c90604c73..ce7d9d9eddc4 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4717,10 +4717,10 @@ static vm_fault_t do_fault(struct vm_fault *vmf) return ret; } -int numa_migrate_prep(struct page *page, struct vm_area_struct *vma, +int numa_migrate_prep(struct folio *folio, struct vm_area_struct *vma, unsigned long addr, int page_nid, int *flags) { - get_page(page); + folio_get(folio); /* Record the current PID acceesing VMA */ vma_set_access_pid_bit(vma); @@ -4731,7 +4731,7 @@ int numa_migrate_prep(struct page *page, struct vm_area_struct *vma, *flags |= TNF_FAULT_LOCAL; } - return mpol_misplaced(page_folio(page), vma, addr); + return mpol_misplaced(folio, vma, addr); } static vm_fault_t do_numa_page(struct vm_fault *vmf) @@ -4805,8 +4805,8 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) last_cpupid = (-1 & LAST_CPUPID_MASK); else last_cpupid = page_cpupid_last(page); - target_nid = numa_migrate_prep(page, vma, vmf->address, page_nid, - &flags); + target_nid = numa_migrate_prep(page_folio(page), vma, vmf->address, + page_nid, &flags); if (target_nid == NUMA_NO_NODE) { put_page(page); goto out_map; From patchwork Mon Sep 18 10:32:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13389425 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 5320CCD37B0 for ; Mon, 18 Sep 2023 10:51:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD8036B02E1; Mon, 18 Sep 2023 06:51:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C88486B02E2; Mon, 18 Sep 2023 06:51:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B4FDB6B02E4; Mon, 18 Sep 2023 06:51:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A4F116B02E1 for ; Mon, 18 Sep 2023 06:51:37 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6D2B3120CCC for ; Mon, 18 Sep 2023 10:51:37 +0000 (UTC) X-FDA: 81249402234.08.4642CF4 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf25.hostedemail.com (Postfix) with ESMTP id 8CCB4A001B for ; Mon, 18 Sep 2023 10:51:34 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; spf=pass (imf25.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695034295; a=rsa-sha256; cv=none; b=jjIg7QsF+YsEIHmYs9kRKv0OUGZhyprY3tn41drECvAPFC+A/Xxptqm9YxseBI8OccZXJs 3VZCme4Dnq/YajAGEj489HmrdCPtAAMORy3pO/PBpXYvNRS6y9jLT/X4Alvw0nBJd32y7Z Mghye7vp8xTcnm9+fK35Tcx13lQCOB0= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; spf=pass (imf25.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=1695034295; 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=CMSHTaHrk6mPrRaj+nNWbQVpdzwUiaPbO4b5ojYmYnI=; b=dNFKZfIYmEeUxBB1utMkiexcUWc4wKwsSlh5ljSOa4imgjyisZfjPkILwzKY8m5+k4lH9i Cz3tArc3x/QvOHNkqcEKIk2fLqp4Tugjnxf02S0vWbGJeKgj2+vXluT/Qa00zzcb2rjjag Pom6vzshKFv3okLel1mdm8lXdGLoQko= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Rq1HL6T1FzNnfq; Mon, 18 Sep 2023 18:29:02 +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:48 +0800 From: Kefeng Wang To: Andrew Morton CC: , , , , , Zi Yan , Mike Kravetz , , Kefeng Wang Subject: [PATCH 4/6] mm: memory: use a folio in do_numa_page() Date: Mon, 18 Sep 2023 18:32:11 +0800 Message-ID: <20230918103213.4166210-5-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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 8CCB4A001B X-Stat-Signature: kg9sxokhu65adtwyk7uzmpauhnak3sf6 X-HE-Tag: 1695034294-87368 X-HE-Meta: U2FsdGVkX18FWYIadcoEgaps8TY6HwtBclKqqR85pvWBwo9Mwig9dI4BJhTv1tChI+mEG8azZt5EHQ3XnSKp3O0HDO7IlhIYTQ1VJDqVY3DoWCeRGFlC9XRm+JcKR+fTFW+CLXz08BchlPxkxz0QIduYmaKlbzc4zrLIYuX4GVdNh50ybRWLFT8rNwVNaUOoWayEpakZLmhxMGj4ysQHwyD34z46JB2lvyVzP2TyC94at354EgZ9K2Iql675Qz+ug8s789fLmqrPypD9UX4uDJaCzXHy7VQgUmk3VsZX6oLWgDZmp2suT5Xscmj2C7zNnTHzFawWyLoNv7KCwb9y5tA82dW1zrplbFvlIxk5SH2dFEV2U3+128qO4+mORbAeSz6hnGzo/rHWOoLFgGXwiwInu0lnxffVNWKiXU3eaCuwIyzObkS7mVizraZcTHRdQFJVXA4HfKyqHuHQaWOOikoUijrgDuZ/Jau2WyJc2Hzm25FSDngBxjx9mu1bDD7/U0e+gYipjdOf/s+7T+SkwkO4oT3xSIQ++mtITQOpyPri0uA0Cq/k2GrnZe9wPKOmd4PDuUDqpGP7A9JlIKiikkQiV6uHXex0qOHWQ2ylN1cFhDkvw8z5FfiyUniDO0YBnfKyBG1F/0JkskXxiC6yFYrN5o6A5vJkr0dJIbKz61zHm1Y7dgq3kpfhVKsbxovU8T8CmZ7J9tQSvOv8qJJpkWhGraxR8GD9cu6fvo+35xzOOSEswf5vbVLA/rPLpRzqowMwGWM7RHMlM/NZmI/fGZzoNiWy+1fVRqEdt8eWyqeUSmpuHZcVjeS9EnhE0eMWJwhSuEuKQsYd0+R7Wo40IYCIqID/3sQMpPqxi7VSHzjaQ56k3kSjcGN/C0ZbUR4/yeKZ3/a4qJjjHNDeps0am6/vEyt/HzvWILdkJOosJB4PFi6t5j4De4sPf+TIU6ImwLKNAqn9LZQ403QFNBa dDZXlzs7 /C4bPnPT3D4s+9NXRe/Do3gGVn0SaiZR9Y3vm5HwPj6LhWYw/HoTKOCsXUA5zYWLwhsYvpNE1hM4p50VWLvOtEVOS1VH1kdVbOOy5Imcgia0uznpsIdwY3S7QP2h8SCufkT+Se3CIvGlIUBwj5mrdKXP/T6m6HwLEVLKfFGer/3JNOBkVhKU9gXelocdE18+zGADy 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: Numa balancing only try to migrate non-compound page in do_numa_page(), use a folio in it to save several compound_head calls, note we use folio_estimated_sharers(), it is enough to check the folio sharers since only normal page is handled, if large folio numa balancing is supported, a precise folio sharers check would be used, no functional change intended. Signed-off-by: Kefeng Wang --- mm/memory.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index ce7d9d9eddc4..ce3efe7255d2 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4737,8 +4737,8 @@ int numa_migrate_prep(struct folio *folio, struct vm_area_struct *vma, static vm_fault_t do_numa_page(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; - struct page *page = NULL; - int page_nid = NUMA_NO_NODE; + struct folio *folio = NULL; + int nid = NUMA_NO_NODE; bool writable = false; int last_cpupid; int target_nid; @@ -4769,12 +4769,12 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) can_change_pte_writable(vma, vmf->address, pte)) writable = true; - page = vm_normal_page(vma, vmf->address, pte); - if (!page || is_zone_device_page(page)) + folio = vm_normal_folio(vma, vmf->address, pte); + if (!folio || folio_is_zone_device(folio)) goto out_map; /* TODO: handle PTE-mapped THP */ - if (PageCompound(page)) + if (folio_test_large(folio)) goto out_map; /* @@ -4789,34 +4789,33 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) flags |= TNF_NO_GROUP; /* - * Flag if the page is shared between multiple address spaces. This + * Flag if the folio is shared between multiple address spaces. This * is later used when determining whether to group tasks together */ - if (page_mapcount(page) > 1 && (vma->vm_flags & VM_SHARED)) + if (folio_estimated_sharers(folio) > 1 && (vma->vm_flags & VM_SHARED)) flags |= TNF_SHARED; - page_nid = page_to_nid(page); + nid = folio_nid(folio); /* * For memory tiering mode, cpupid of slow memory page is used * to record page access time. So use default value. */ if ((sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING) && - !node_is_toptier(page_nid)) + !node_is_toptier(nid)) last_cpupid = (-1 & LAST_CPUPID_MASK); else - last_cpupid = page_cpupid_last(page); - target_nid = numa_migrate_prep(page_folio(page), vma, vmf->address, - page_nid, &flags); + last_cpupid = page_cpupid_last(&folio->page); + target_nid = numa_migrate_prep(folio, vma, vmf->address, nid, &flags); if (target_nid == NUMA_NO_NODE) { - put_page(page); + folio_put(folio); goto out_map; } pte_unmap_unlock(vmf->pte, vmf->ptl); writable = false; /* Migrate to the requested node */ - if (migrate_misplaced_folio(page_folio(page), vma, target_nid)) { - page_nid = target_nid; + if (migrate_misplaced_folio(folio, vma, target_nid)) { + nid = target_nid; flags |= TNF_MIGRATED; } else { flags |= TNF_MIGRATE_FAIL; @@ -4832,8 +4831,8 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) } out: - if (page_nid != NUMA_NO_NODE) - task_numa_fault(last_cpupid, page_nid, 1, flags); + if (nid != NUMA_NO_NODE) + task_numa_fault(last_cpupid, nid, 1, flags); return 0; out_map: /* From patchwork Mon Sep 18 10:32:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13389376 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 530B3CD37B0 for ; Mon, 18 Sep 2023 10:32:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CCBC86B02D4; Mon, 18 Sep 2023 06:32:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C78136B02D9; 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 A092B6B02DA; Mon, 18 Sep 2023 06:32:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 81AF26B02D4 for ; Mon, 18 Sep 2023 06:32:55 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4E722140364 for ; Mon, 18 Sep 2023 10:32:55 +0000 (UTC) X-FDA: 81249355110.04.CA6A4C8 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf27.hostedemail.com (Postfix) with ESMTP id 88A2B40029 for ; Mon, 18 Sep 2023 10:32:51 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf27.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@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=Wep4XMTReQIGX+QGef6xN/N0d87XNkh3obqJUoMPMNU=; b=awNCRWX7rUi45MyP7a/cieRMrPbDwkXOikfP8mTCZDHLnCMr7HhpdHDzowDS6HekfhioyP EO8K0OXhizI48B9o9oqe2DiGnfF+4WtGhRNdtn7MDIW746X3neIF4E4fQer8MyipGs1Xzo 2W9DuFEy/ryoCMLKEJduBUk0h17Qtsc= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf27.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695033173; a=rsa-sha256; cv=none; b=od3tFkGQ1J34g8cN87doKpeBuHdUtsxmcK8DcD5JV7xeWnTdHM/JHQFU17g+kJAJlApYQp MNVjr92OPId5VrLZgC6HvN9KsCcaiupJ7+8vse3hs+ThVyryJc8bm7r4sjwP09cB3GxyyS Gb31hL8z9U+sj848yAHcf1GhHtVMXos= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Rq1JK6Y0RzVky5; Mon, 18 Sep 2023 18:29:53 +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:48 +0800 From: Kefeng Wang To: Andrew Morton CC: , , , , , Zi Yan , Mike Kravetz , , Kefeng Wang Subject: [PATCH 5/6] mm: memory: add vm_normal_pmd_folio() Date: Mon, 18 Sep 2023 18:32:12 +0800 Message-ID: <20230918103213.4166210-6-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-Rspamd-Queue-Id: 88A2B40029 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: bb648wqo885rgujmji8krkiz77j5fkw8 X-HE-Tag: 1695033171-599830 X-HE-Meta: U2FsdGVkX1+aXBFj6BFPW5QHNnXnu2ok1/c+TJoaje9NkSBrhHPHRnZ6jX55xiVLqL2MHUnbjdkBQ8wNTYrmdXIXn8E9coWdrfmiw19AmJnrLSPRnGaRyM0G1kbXlmSqxUkVqQ6lJagP5ksDmhxqYtxYu+CAaKk/QMcj9AsHzPPqsIFIOtHv2S3QAJHKE6gH8riFsQjS/wtcVXjDbDfo4Wx67LQKfLw8wss7Y9u2O8W1LauLB86z1a59vohfsI4jeKV/wY5yBm0VMPLgPkC+B0gV4wOb/FHUGemOH6/0UnC8eKKAPue+n2e/w+B5zXm1KGuy5aVkCa+nPtLInO54d0d1p8XBUJFurLVD3sFGX3/8lH3fXQRXCQdUtXx0XTluZKGPil79+ZiPXkCjhlTZx83ZUrDuc0M7cRSTtmz5a0B7YGvToauQx4lsPBmavAzgtRi74x5ze6b4n4mJP1C2ldumuee6wwYH6jlFKCGhpG4DkVo1gdav2jyWdiTkAnpCm86eebYSHnOkHGppm15sTwuHrchY3ZAMowxyqvlsakI+RYkM8x5cS50eRYeHnz9/SG4lFompvUAXx/zL4r54GSx1DfBkPhy4YxLkER6ai65O/mIJZNdt+l2e4tUzPUu+PGUlJ6jgzbxnqrlJzDcxe4/Y44DNgrWet1dcB+98T8OU2Copm7Ek+vulG7+ZhmkbrOh4qwQw6eDRpU8wAxeKWw1T1kex6WEpLSQD1j8uB1n04APjd3DW3I5c/YSB3n3zF13+kYVTcp3Kbb/GamrKE2NqCmS/NBSsipaWJo/1a6ExesPp1vhFfR92xAyaIprjbESiuV/75dqY4a9AdX5R5qEi4S7GwFJUf2j53Vy9gF2GKWiAgnWNKTdIAMuMEQl2hcUH8DOqXqmsLbcbCCPYHEnkpe891mk/NvG8eNN8pqz6gHZExc5MLPIY0fPhlihP+9Cn5znbqwLWfBpxEP9 hx7GaLa7 JslX+u0Ld5ku+TTc60kTkgRiAWUySrkJU30sna0+FYgqJRnQ1KTuHDlKuzU6MfZX85g+MPohNkpzVtrireXtGFLynNqU1Hd/pFpP8krh45IQccBfRQ5OJXH6W8LHGc/QCqXWE40AtTpkJPzJxdiBlV89jjEAE8vVZdZYsaY5iEVC5fYiPbtxvlSVbyTwstjy1wfEC 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 new vm_normal_pmd_folio() wrapper is similar to vm_normal_folio(), which allow them to completely replace the struct page variables with struct folio variables. Signed-off-by: Kefeng Wang --- include/linux/mm.h | 2 ++ mm/memory.c | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 12335de50140..7d05ec047186 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2327,6 +2327,8 @@ struct folio *vm_normal_folio(struct vm_area_struct *vma, unsigned long addr, pte_t pte); struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr, pte_t pte); +struct folio *vm_normal_pmd_folio(struct vm_area_struct *vma, unsigned long addr, + pmd_t pmd); struct page *vm_normal_page_pmd(struct vm_area_struct *vma, unsigned long addr, pmd_t pmd); diff --git a/mm/memory.c b/mm/memory.c index ce3efe7255d2..d4296ee72730 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -689,6 +689,16 @@ struct page *vm_normal_page_pmd(struct vm_area_struct *vma, unsigned long addr, out: return pfn_to_page(pfn); } + +struct folio *vm_normal_pmd_folio(struct vm_area_struct *vma, unsigned long addr, + pmd_t pmd) +{ + struct page *page = vm_normal_page_pmd(vma, addr, pmd); + + if (page) + return page_folio(page); + return NULL; +} #endif static void restore_exclusive_pte(struct vm_area_struct *vma, From patchwork Mon Sep 18 10:32:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13389378 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 158B4C46CA1 for ; Mon, 18 Sep 2023 10:33:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E39C6B02D9; Mon, 18 Sep 2023 06:33:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 96DBE6B02DA; Mon, 18 Sep 2023 06:33:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7E6A16B02DB; Mon, 18 Sep 2023 06:33:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 6FCDA6B02D9 for ; Mon, 18 Sep 2023 06:33:13 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 46AA31CA9BD for ; Mon, 18 Sep 2023 10:33:13 +0000 (UTC) X-FDA: 81249355866.26.CE0AEAC Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf04.hostedemail.com (Postfix) with ESMTP id 164C64000C for ; Mon, 18 Sep 2023 10:33:10 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 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=1695033191; 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=o3O6hmLLoJvLAdN2vXw7QU0xANFE3e9WK0chunZ4xxk=; b=KC83zIADjLUIxGrV+vDG2eX0xTSAk1K1ReCiyb4PHs0SRkB7QWwfoFByMA6fiiQm1p0liG VyS65YotlmQdbbZExlXw5lI03AsnDcPH6EbkhBmR6oEHdhuQXiNcPttnydglExPinC6Ele U/178tF1M05sha7pMUO9WZ9ywlAWhhw= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695033191; a=rsa-sha256; cv=none; b=VZHVm6f8hfDCWXCXM29rg8KZw1hgjcr8teqc3dcWAJR/DYYovMIsGnZi8xDdtyQBr9D65W 0FiA+IzfYShMJK4hdIb8IHb3jBAETzj4lZoUR03FgRd3WLI1JCMVKLWhwwAUYEE79RjFnu HSiKMJ6C0TcdTNf0br2//ZxtVs9/CsE= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Rq1KL21nhz15NQY; Mon, 18 Sep 2023 18:30:46 +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:49 +0800 From: Kefeng Wang To: Andrew Morton CC: , , , , , Zi Yan , Mike Kravetz , , Kefeng Wang Subject: [PATCH 6/6] mm: huge_memory: use a folio in do_huge_pmd_numa_page() Date: Mon, 18 Sep 2023 18:32:13 +0800 Message-ID: <20230918103213.4166210-7-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-Rspamd-Queue-Id: 164C64000C X-Rspam-User: X-Stat-Signature: qsrjragb6nafpsg9tkp389ynije3ket8 X-Rspamd-Server: rspam01 X-HE-Tag: 1695033190-398841 X-HE-Meta: U2FsdGVkX18jIvzKlMF+35tPixCQ0PBmo6+vo2YpGa4WsV6TeAMePGc6NtmDbRy9vfnjzzcKxFYtT/P0dpm49+9DJTwsdBcjsSRZB4GkDt9DiM4wwYDH2V0UzvnaYJoY2Vtm59fwiIzaDPq10uvIL40tLxyrwVqo8pfg2CFew/+UbiSxCfOvZf6uYmOwRs/lbw8AZJzzqVVpY3Ed7MpOy39eP25atekkMWV8j3LXdMvDhldl8JoNgS+aB7SGfxOKYLWqjz6J8mJEnSdGW301cJlpzgaY6MpJjEHlo0LcfYTQLbg5w0MsnohlDVXUr0ni8hmNy0GG4fSOL19m6pnisaAPpUdsGhNbUD2ZMWoz9DcpAyJ+qdl5bNvfkMAumoAsg9t31oTHK0X6OsxeBA6Y/8oEZFtw19dtrhuiQkkLR2ryOY7SSvZtwsEsgqPipDVLyzMVBXiXv9ldupWgfzi55hj53wY2Q4dELWJuyKpJ1q7YQjprB3VAibqq1JCwzXG5nRUmPNiV9c+2RYPcWNQ1rcasG1wX9X69RwKWSTzfM8j1pzvTiSW5oIOl/9wVdgoRaAGDNtXsOPAaw12CcRG6SHlgubpxKLdchpgWhYfTzV1RT/3cWOnyYxinlZpzHRvSi+x0WDWPyB8NFtQD/uvqGOcCBP/Hkz3/jKLdv/tHNJ894YECAV96BMwTVNCo1xypQfvlKSTP5eZ/hUtWTAhu1/mTvXsJpzO8MDjNtPrVVN7YC38RD9l4TJQgEMlPTRcztFSgvtD4oP5ufnlkFE0bzXwJqhdu489ugEyOQTr0ZbPogWOAr53JWOiwzrVl0dIzGQUtoMk7eOi4qLYC41oNBlfBuN6szAofwW11YalUPcTp+Y+qs24Ay/LZG3VU7h1Cvgptnz8XWuJHIVjfWr4Bo1mrWKGx1innvuivW0HnBdTKXoNB95dFiIpUuYOFHduo2ttrz1JuE/vylf4kYGq NQckrgY3 TkNsck+A2YQ/969OFGzygItVWtNs9CJymyzJIoQb+KVB6Yk6+MMG7QukH9cz64AiMRiUxL/27u2naX22nK2ScHUgA5LwwixoNhPmHb4z6h9GSkl9OMl6aIaLnynmn9eWEZUpxe3z34VH6C3CGXCN4JT/9Srn5HJhIyzKXaWDBzKt2wouWhap+xCoMc+x8L293zhR/ 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: Use a folio in do_huge_pmd_numa_page(), reduce three page_folio() calls to one, no functional change intended. Signed-off-by: Kefeng Wang --- mm/huge_memory.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 3e34a48fbdd8..5c015ca40fea 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1517,9 +1517,9 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf) struct vm_area_struct *vma = vmf->vma; pmd_t oldpmd = vmf->orig_pmd; pmd_t pmd; - struct page *page; + struct folio *folio; unsigned long haddr = vmf->address & HPAGE_PMD_MASK; - int page_nid = NUMA_NO_NODE; + int nid = NUMA_NO_NODE; int target_nid, last_cpupid = (-1 & LAST_CPUPID_MASK); bool migrated = false, writable = false; int flags = 0; @@ -1541,36 +1541,35 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf) can_change_pmd_writable(vma, vmf->address, pmd)) writable = true; - page = vm_normal_page_pmd(vma, haddr, pmd); - if (!page) + folio = vm_normal_pmd_folio(vma, haddr, pmd); + if (!folio) goto out_map; /* See similar comment in do_numa_page for explanation */ if (!writable) flags |= TNF_NO_GROUP; - page_nid = page_to_nid(page); + nid = folio_nid(folio); /* * For memory tiering mode, cpupid of slow memory page is used * to record page access time. So use default value. */ - if (node_is_toptier(page_nid)) - last_cpupid = page_cpupid_last(page); - target_nid = numa_migrate_prep(page_folio(page), vma, haddr, page_nid, - &flags); + if (node_is_toptier(nid)) + last_cpupid = page_cpupid_last(&folio->page); + target_nid = numa_migrate_prep(folio, vma, haddr, nid, &flags); if (target_nid == NUMA_NO_NODE) { - put_page(page); + folio_put(folio); goto out_map; } spin_unlock(vmf->ptl); writable = false; - migrated = migrate_misplaced_folio(page_folio(page), vma, target_nid); + migrated = migrate_misplaced_folio(folio, vma, target_nid); if (migrated) { flags |= TNF_MIGRATED; - page_nid = target_nid; + nid = target_nid; } else { flags |= TNF_MIGRATE_FAIL; vmf->ptl = pmd_lock(vma->vm_mm, vmf->pmd); @@ -1582,9 +1581,8 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf) } out: - if (page_nid != NUMA_NO_NODE) - task_numa_fault(last_cpupid, page_nid, HPAGE_PMD_NR, - flags); + if (nid != NUMA_NO_NODE) + task_numa_fault(last_cpupid, nid, HPAGE_PMD_NR, flags); return 0;