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; }