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: 141347 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2559708vqi; Mon, 18 Sep 2023 03:43:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFvuse4LB2BQ/0lsi6ZXrvDCh7DRbZwHgUZ+10UcGzEl4s9dU1x8hlLfZI9se7ydHuEK5mv X-Received: by 2002:aca:bcd7:0:b0:3a8:1db8:456b with SMTP id m206-20020acabcd7000000b003a81db8456bmr7313341oif.35.1695033826026; Mon, 18 Sep 2023 03:43:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695033825; cv=none; d=google.com; s=arc-20160816; b=nK6vIgEnP5x/qRycNhhXR31mdHl7GE95ZFEzIjNYq0e2FQR0Memojz6h0ggH5/rDtD 5b/xSBpDiFsr5zJisL64K0Y90KjuCGne+Z0lARNV9ZlLzbMhqQvpAc0vsX3rEyikR3U3 jsmg2cHZh2paFOai+SKAr8GDjvxwjesMfZ5PzLJfMaDeBxH+6yyyVhlav3+eJphB2AMo dX8TFOW4JNKG1avQ4zwZzT1p7zJLCv+AG2wxMDEWPfBkW8kORciOZfNswHasrnYZccOr KzYW5cnWbtZl1yAuNrdTVayiKHz1/262EEobadNfE+GDGIupby0ZPmTni4COBN46zn9B Vc2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=99gOF8CU+1+YWC2p22srbZVzG8oOU3EApfS5TWFFlmQ=; fh=Je6qNyAM729b1goCtB6PkBk+yQrlQCIjJMRY6BFgKTo=; b=v7kAMdBsTdp9RXbFEQs4tQyptXvktj7mBD9EdCN5UBYeJylQtPC/TdLb6JUKq6SNub 7VAdadjNS8x+GQ3zHy8yRbgtT5TmhsvaKu+cgC8sDeRBduQI/cdJfVX1MrMQkyDkCpQY Gxx7f2Ks3f4MwcJQsKYJSSWOCaR5wdkVUtZh+KvqJj94kzT3AyjXnS7WnAaxxOe5JcWp jNKRjAfAWotDM18qNXqQqhdNl/znLqqKJy276fOjnHfqJXkxxzOeCkHRSPNfG+qvfyJS feyb/UJXjnc4qFb4V5+9VGcVD6y33lIICf5Z8HXRiC7Bx5Fc1OaOKh9Uv0kjm2TAd2qf QlXQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id ca20-20020a056a02069400b0056532fbe293si8353339pgb.323.2023.09.18.03.43.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 03:43:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 4DE7E816AF03; Mon, 18 Sep 2023 03:34:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241283AbjIRKdc (ORCPT + 27 others); Mon, 18 Sep 2023 06:33:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241324AbjIRKdN (ORCPT ); Mon, 18 Sep 2023 06:33:13 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D817B122 for ; Mon, 18 Sep 2023 03:32:48 -0700 (PDT) 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-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 18 Sep 2023 03:34:07 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777371789124414075 X-GMAIL-MSGID: 1777371789124414075 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: 141359 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2573817vqi; Mon, 18 Sep 2023 04:14:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEWxbnQygN4+WsBFbpKr+wBRrWzb/EzY4FoBAWp1vsHoZ3N1ecOIUGqIT9xxIC4aqZX8cd/ X-Received: by 2002:a17:90a:6e09:b0:268:13c4:b800 with SMTP id b9-20020a17090a6e0900b0026813c4b800mr7932086pjk.21.1695035642183; Mon, 18 Sep 2023 04:14:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695035642; cv=none; d=google.com; s=arc-20160816; b=TfaVCInuDXKjqiNbz4j36eqGDkMs+jCN4U0TMxrFcjZnpMf4bRhIfvYQIfcr6KK8zW dpmlw1Ee2quui9LLa4viADXQlOA/O5B8ZnAGPqMg6UdGJAdpFn4FIlSPvbLEQd0yyurq iA00EAnF8F+LPwy2Vyj4Ww6TKKNCnAxm4+LcSJv6azEJDe6m3N45WYHngp/q0r7KlWtY rrc+X0n8qK6eCK1XWnEyvIBFt747t4Ex7rXFyKUFNhtnXR+9h2f17oWoz0X/c26XAcvV pQiQ6wn/ItWGuPXilD2CfLQk5pZ7LBAWXhsndjHbpIRbP3FWzsloSYbsJFzi9QQCuNME c9Hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Q0j2iplv8tIoDxFaHxiXvS50HobKD+ChXL38zg2Jy/Q=; fh=Je6qNyAM729b1goCtB6PkBk+yQrlQCIjJMRY6BFgKTo=; b=OjvO3U/OmQV3TIMCHknDASBGooixeIITKJo+xFmTfZP5wlgbde5P63qnqgHLwwh2pa XZz3ERlUnItH1+AqWWKBnIP7lTATZSF3GLKMgRQsIOaZH5RmuzwoI/0eYJxkz2U0RS9G eklhGVgxl1y9WAfSH9GKsnLwKI0fcNm7wvBrYPIVRI1XOEJ8eGgKoh2LZkNMBzWMOIfR jxuaKcF9zHXkoYac2Tcgo2El5Tw6QTo2vuu6G1Vzd7y2pGi7DET1kxzjRaezr70U6WY9 OEOLI+s+m4ySjQwsXJZcFBdqVaTGru58ZUA/Rzu6ba7eAAc+9X+VdbgduhzCv3xVBpqg 7U8w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id d3-20020a17090ac24300b0027474b117f7si7217851pjx.21.2023.09.18.04.14.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 04:14:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 209D6802D3D7; Mon, 18 Sep 2023 03:34:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241311AbjIRKdi (ORCPT + 27 others); Mon, 18 Sep 2023 06:33:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241330AbjIRKdN (ORCPT ); Mon, 18 Sep 2023 06:33:13 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DE8E123 for ; Mon, 18 Sep 2023 03:32:49 -0700 (PDT) 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-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 18 Sep 2023 03:34:01 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777373693408342937 X-GMAIL-MSGID: 1777373693408342937 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: 141348 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2559719vqi; Mon, 18 Sep 2023 03:43:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF9KElQmGU6wFkMqfeMxNwKcHIEpOLk/y+HsP/aM0VEJewXnazeCsXXecwJAYBWKnF0FKKl X-Received: by 2002:a05:6a21:9989:b0:140:253b:b658 with SMTP id ve9-20020a056a21998900b00140253bb658mr8666860pzb.57.1695033828033; Mon, 18 Sep 2023 03:43:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695033828; cv=none; d=google.com; s=arc-20160816; b=qdI+Gbya1N2XeMmcJ5ntPjA68LDojCpfj6HWJ1Ir8f1c5sDw3v2Z/cBvpasqOaMNYr xaqwBgflBx/+j61GKAfKfvKiQe4t07p4Wr9/tMBGMDOqx/oKqLttw/xpVNMdvJ8jirZ8 7bTnD/aWWZHvV14Z/zcdIZ68l6yCcCiWmlFVDC6bbbfbZyv6Lcnxw46PzMa3znfKVmyE gp4LofRriEiAFfdNEMFUS0THvCdUg1LgUoya6zRiEjs5Tft/DVZMqZrtiPSwwHyl1cgu BzQSZTSN9hOoWW33Il0iu3iHCa1WXbMTip+9xBelPbxHPObysKNABk6U0sg/ZB9kSysq GyEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=xzBNWzs4QslYgQE6UPXgY6Lc++vpLEbqpWbKW/jYig0=; fh=Je6qNyAM729b1goCtB6PkBk+yQrlQCIjJMRY6BFgKTo=; b=F9kiMSeCKbjE4UdbLu87SOqDHa0lcQ+5cm6irC0JuNfuTM/rV8fom7yTOAcGUpqFbs oS9Y+g8i2uVLUZeP3584srd+g9gSFMsDqe1RJynP/Y48O6gA9+MGXFwy0k/y+YjzHyR3 lVzt2VuGcS3ja32sSwESNxSlsVo/bU5uBnHXvvfJXQbwodatZiz91HhzVB4GCw0kbkjj l6ftMyhLtwEarD8XZk3cnshStkHfIo6d9yHmElQs9zmizdHv/1YxLhtOqFEHdDQ51xva 94hBNR4aggLHuRJIhz1GAE5aDbzbVoBewjSpA92s6mVKewCrM+91vrnIA/BNVRBPjUPJ uFEA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id bu4-20020a056a00410400b0069024c6a9a8si7827914pfb.389.2023.09.18.03.43.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 03:43:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id D1318816CB93; Mon, 18 Sep 2023 03:34:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241393AbjIRKdq (ORCPT + 27 others); Mon, 18 Sep 2023 06:33:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241337AbjIRKdP (ORCPT ); Mon, 18 Sep 2023 06:33:15 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBC18129 for ; Mon, 18 Sep 2023 03:32:50 -0700 (PDT) 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-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 18 Sep 2023 03:34:14 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777371791590186257 X-GMAIL-MSGID: 1777371791590186257 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: 141350 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2561264vqi; Mon, 18 Sep 2023 03:47:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFJH2IqZZEywST0jdB9abveD5Ft7kA3V5nI+FfDbaRCD37pS2ojXn8S0ZvOenBtNDA7xw0A X-Received: by 2002:a05:6a21:718b:b0:154:a9bc:12ca with SMTP id wq11-20020a056a21718b00b00154a9bc12camr7309060pzb.26.1695034056932; Mon, 18 Sep 2023 03:47:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695034056; cv=none; d=google.com; s=arc-20160816; b=Jt+Yab1CVjmbyLsl+HMQhXPEOseAbwxogC6J5wpDNFDJoCJXMofs4gJs2rI4/OdvyV cXE435IMnRlAwfJFnqTQ6apSjMv60Do7f8NKFoKouVCsMTVQkuJR4qvY3kQsxoemb1VM btV1DnxtfB+wfbogEk/4F1czkP4Y9ceg23g4nAhJ6195+nXOMXJHDGEsNhenb5l7HX4A oDvPuX6GuSgxwwxq3rhX3/jswoszcr1cpFrc8jeGK0RLE9zGoo+Th1i1LpZPoIRUMyc7 8+8uYHNNxBRIJoCcTtMDPvKIPrJUBWWYAPgNmacjPX8SIzh6E8h2rMMixIz1priGh3jW u1uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=CMSHTaHrk6mPrRaj+nNWbQVpdzwUiaPbO4b5ojYmYnI=; fh=Je6qNyAM729b1goCtB6PkBk+yQrlQCIjJMRY6BFgKTo=; b=hoUyPaxlm2fIjR3osPpVjWp1OLcIegvvMd6pqt2yf30tmLboT8owQYKtNW6FqBaY6S pb2nFfZlHK4MZADckBdmuVR9HWZqipETfjhySqlhd1VxOkrcKTTlj/PA3xNfScIzyizF IeBWRpPaK49WUuEgnmmakUAcwnmRV8kyirDQQTm5a+7Q5c/Xdd8YIMJ1GyV96IuRfA/3 pvS2zdYyi6oLZKryhZ6qqHMzzepL8/ZBtGesgdRuZw8Hfn3qQYkRneqNi1e4iV0p+liU rO+XEPW4y+bvzhA7+dGCQYQDdqs/ILYNxjW2Zx03Bmoe7bKlNcWbRg0hLo80hQA5kH+a zwGg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id k2-20020a170902c40200b001b8921fbd87si8572484plk.490.2023.09.18.03.47.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 03:47:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id A073E818ABF9; Mon, 18 Sep 2023 03:34:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241369AbjIRKdn (ORCPT + 27 others); Mon, 18 Sep 2023 06:33:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241338AbjIRKdP (ORCPT ); Mon, 18 Sep 2023 06:33:15 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBA31128 for ; Mon, 18 Sep 2023 03:32:50 -0700 (PDT) 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-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 18 Sep 2023 03:34:07 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777372031304516144 X-GMAIL-MSGID: 1777372031304516144 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: 141344 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2558822vqi; Mon, 18 Sep 2023 03:41:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHTekhLAG8AQs5vjy5AScv2wG4s5ac0suXhh9t7oaq9mVtR0fh1u0gu1hhgY5YgP2fhlNlQ X-Received: by 2002:a17:90a:f991:b0:274:751a:3f3 with SMTP id cq17-20020a17090af99100b00274751a03f3mr15073382pjb.7.1695033691857; Mon, 18 Sep 2023 03:41:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695033691; cv=none; d=google.com; s=arc-20160816; b=VTgR7ufgGXbCpWnZszOOftohaDLTih2n86tgK9WAqkxXpDQlK8d6Bl2T5N1qC3pA70 ge2EreV1xbDJEVBUo+oCSfhaqUOwQwa4rkGct5hTH6xHSxAVgRvES9PeHChTtPV54eNs EQSB2m+1WimyqanOGXRAIbuoVPet2kJNj+Drui/AM5ayu3b24Mb93Gf+rhpih0m/7sKW HjN7FYE2tshWjzL42AG7OLtYGDf3ap4/Y2wSKVlg+eHXGfxxYv0KPDaOzXPyIvXrpKWn +JU5KsBJ64nKW/FxUEHICGukFLrdgTLwJVRFAe70IOF0w3vVnACEzbSgDChnVz1mu17T FVyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Wep4XMTReQIGX+QGef6xN/N0d87XNkh3obqJUoMPMNU=; fh=Je6qNyAM729b1goCtB6PkBk+yQrlQCIjJMRY6BFgKTo=; b=ZR6YozqkRZuOl4ne3LJSl51z7aHyStoeOIHXnPIAPe7bciAr3H8ef7/jhtzS5dEyi0 IapZ/ILMIDO4/+DKjEN17hChlwHbMhJH7WmPjbHV/KQnbqHzRD7zcODbeGCDIH3uDRUP w68ah0oRKhsaLbbnz6ROE7vCDwrPMuTjGjE9uJse2QhtCn37RAw5Q1Grw/DlqL78ZJhM KRSZKZpYQwHykzrj73E/Ml3cAOeJuKlVXq1RG//BEXn0nImf7UcFhLf9AcmOqhkXfaw9 QiSsRg6pFWur6OTdOMEzRVSxG2AhwxN+XVbtIyZUUobpdVulZtH2Y2oh3xHgfq3OZHFz oxJw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id z16-20020a656650000000b0056433b221b9si7627032pgv.477.2023.09.18.03.41.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 03:41:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id EB57880D2E4C; Mon, 18 Sep 2023 03:34:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241407AbjIRKds (ORCPT + 27 others); Mon, 18 Sep 2023 06:33:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241341AbjIRKdP (ORCPT ); Mon, 18 Sep 2023 06:33:15 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEF0512E for ; Mon, 18 Sep 2023 03:32:51 -0700 (PDT) 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-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 18 Sep 2023 03:34:32 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777371648501961383 X-GMAIL-MSGID: 1777371648501961383 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: 141351 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2561313vqi; Mon, 18 Sep 2023 03:47:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE5/vsdx7ejsm4vNzxwf0xjj00UdhcuTL30nBykOC+WdSzE6toLdQ6NcEHhLZC49/bq7uDo X-Received: by 2002:a05:6a20:13cb:b0:140:c838:2b2e with SMTP id ho11-20020a056a2013cb00b00140c8382b2emr6669079pzc.22.1695034065971; Mon, 18 Sep 2023 03:47:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695034065; cv=none; d=google.com; s=arc-20160816; b=ZDskc4ZFrgfGepFl3aJ6iQ15D5U4bSZ1IOoa5szpA6/A2ZwP1OlJEZHtEUfUN3S+Ob eBTqT4ZINjdgE2Il1Co0rbQMUat534c21HHKD/ZquOEivAa9YBgJYTqhPhVFRnj+MsGq vocc677BCPc4896zPKFvL3tbHEW2UfMtDc3WMZoqaqVptWkLaJ7hbabzvZ3YSUP3smVk Zlv+/faQm/d/+DndL9I35jkgc4NsWpqh79L1RjypQu9JvXNy0aZdNTHOnc8ucs+BVXpH NF3F9fk236I1+h1EdQsvb9vlIyEv4FxfWSDmEeiyHsqKRqwSVi36wdVX6ewDxpb1a7IN P/EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=o3O6hmLLoJvLAdN2vXw7QU0xANFE3e9WK0chunZ4xxk=; fh=Je6qNyAM729b1goCtB6PkBk+yQrlQCIjJMRY6BFgKTo=; b=TXB3fiwtPVOPSjaDis/fw11CW8bEs9HRUq5ybRqIN60UQs8SWJoiTYFKTDZdAtdpqv rEfHs1PfI9zKCy8DGchkIdpEu1feaJdJ+3WxN6KQb+m7mgN4bfrK0sj3YRo0CzRjxvKD 5MrzdgA1kKYnadLVUK8VCoO5cXrYhLiSl8/pD6rxeEU3ciWVVuX2SG2FdvUGpLBYWqEw IwPz3+Uknh80nO8glly9sPW387Ao+lPdE8T3Lgyl/2hXrDlTteIMJTWlA/1lgrqJl1Rp SHVJP9abUecGh9gV/9bANooG9rf4i6St77MI3IWxkxqCrwwfCdTvCMmRAfsblDaohBDG Ym8A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id m3-20020a170902db0300b001b8a699d248si5189030plx.389.2023.09.18.03.47.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 03:47:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 4339C818ABE3; Mon, 18 Sep 2023 03:34:03 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241319AbjIRKdk (ORCPT + 27 others); Mon, 18 Sep 2023 06:33:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241340AbjIRKdP (ORCPT ); Mon, 18 Sep 2023 06:33:15 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B970E12F for ; Mon, 18 Sep 2023 03:32:51 -0700 (PDT) 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-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 18 Sep 2023 03:34:03 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777372040963283700 X-GMAIL-MSGID: 1777372040963283700 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;