From patchwork Sat Aug 19 10:52:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13358590 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 0BE94EE49A8 for ; Sat, 19 Aug 2023 10:52:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B6F790000A; Sat, 19 Aug 2023 06:52:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4403D900004; Sat, 19 Aug 2023 06:52:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 26BD790000A; Sat, 19 Aug 2023 06:52:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 032EB900004 for ; Sat, 19 Aug 2023 06:52:53 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E472D120843 for ; Sat, 19 Aug 2023 10:52:51 +0000 (UTC) X-FDA: 81140541342.02.EE677F4 Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) by imf22.hostedemail.com (Postfix) with ESMTP id A8D7EC0006 for ; Sat, 19 Aug 2023 10:52:47 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.111 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692442370; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Gno/qmUTlW9t9/wqxr/fxCmzyH/MTCfjhdDmjzbuz2c=; b=ozpzHTr3oBU8EYFDzbshjBAOaAxqMNVY1jeCRT/fmmdRuf96DlfXWg0Jrd28lGO1AkMmCS 22h5zMOq7pzxBGs49QEz9FU4z29oIQV8WVc5X/b4UnaaDFxgao8JyfyS7kptUy6SCEoVbc IXwQAUDAI74nLEmLAQSoyZcSoX78VKg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692442370; a=rsa-sha256; cv=none; b=Tyhh0FtMEDXteOqjbIKzaOfJPQGqnmH3Y/aQrcfjwa1Zzq5NuDyYJ9geVcNWxYBqrTDEvf 8klkhfi5J/t+CrdpwDiA6my9J3jQ8gGTGJOxMjtu4MDRx1b6A2moSf057USV/RzJ2FAl7C uQFpPztkiWMVxE6E+FudKQm1kmDLEwg= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.111 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R831e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045168;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0Vq58.SR_1692442363; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0Vq58.SR_1692442363) by smtp.aliyun-inc.com; Sat, 19 Aug 2023 18:52:44 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: mgorman@techsingularity.net, shy828301@gmail.com, david@redhat.com, ying.huang@intel.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] mm: migrate: move the numamigrate_isolate_page() into do_numa_page() Date: Sat, 19 Aug 2023 18:52:35 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: A8D7EC0006 X-Rspam-User: X-Stat-Signature: 83or8ni966us5bmrihac5k467hjf8ato X-Rspamd-Server: rspam03 X-HE-Tag: 1692442367-434453 X-HE-Meta: U2FsdGVkX1+o0jESX5hmq47Q3sBJNKNGl26Gadk1iX2FoE45VId8Vm+TPXEBsTnduSTZaYQOkR4jLBEhhUwM3nKSmxkSkvA6UQvJPBaUgMtrJ7cMM+2FIQTHIO2SPMjp/m941CZ4E7EaUmxVupFpIPbDZ0AYfE32ngWsO+7uaOY6RkCCjHakzHjQOmYzsLdNpZ/PvN+GE0MS8/IqbMmQdpRzpEc8+l+ScK6qh1CIfAfwUU43HHXrffRDTyF3b06ZrtX1OMspOgZpY+7gGpACPz3ODvJM+Zuvrx7PneMWOj/y/R4LFHBSOj92JHgF7AUpkXF11spx+5mBieKjJrV38yu0o134C01KR3/GiAW/pWgpQsuBGmSnN/Lhq0uUGIgkmKxaTKc/EiFD0V+Od1DvlgJ1upS520RxrdDXz6B6E6FuaGyFNRFKKUoU4Og2zKewerOJZuNqB4DTwP41bN7odVYwsYkGK+10cEgSILko9c/Bsei15ytj5LJMYPNCFzi1vk6S3UueRA05RJMDNyq0vk/tnJn0jXXAEvfxvRoAP5GmG9AtO7+1pfkqoQqTLfxe18Mg1gdLpG4oQgTzowMm9jgrQmqn+vJi9MCw/+ZJK8U0DS5/tPwFYU6vQTJtCTQTa04EsGyF5xoHjSI65+V7VwoNqJpZGBxzvhZwdUOt43thXWKXzeqxHY9l79nFSv3ViTpOe71m/1ZwirVTA3icPb58qc5FbHydduSk54yCvnJWdyvt0jmQwBDWCJIki7tNVSOyWwigjaBCB3bfQ0yrGGV+4lhWHI8ego6UR3XGfYsF/dCZWK1BB8CnTrKCGkpSCBtIsEkp4MBGRXeg/qEOQvGuThgROEfUrlODSQOHZ9Dc4NtfWQuhkdRl/hjGvybfazcTk+Uu0Rclcj79Y+nyYLzVySZZ8DqskHF09sWrUPUE6XGZb6G4L8bufc6WV1J5Wcxk87BKi62hriiY1oz 2YFNx/RV kYr6TvsKRPAv6NdaBrV08pLg8SyiOTcrVPC/gKHEhtv1BD9lVNiYE85G23vlC9G/GL4mkmRcy4p9vAUFigtB/hRZKr8jF+2rHppk+g8oAEOefTnrbmG4MxLc+LfmZgE/fHSjZUL9FgEcgA34= 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: Move the numamigrate_isolate_page() into do_numa_page() to simplify the migrate_misplaced_page(), which now only focuses on page migration, and it also serves as a preparation for supporting batch migration for NUMA balancing. Signed-off-by: Baolin Wang --- include/linux/migrate.h | 6 ++++++ mm/huge_memory.c | 10 ++++++++++ mm/memory.c | 10 ++++++++++ mm/migrate.c | 16 ++++------------ 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/include/linux/migrate.h b/include/linux/migrate.h index 711dd9412561..7c5189043707 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -144,12 +144,18 @@ const struct movable_operations *page_movable_ops(struct page *page) #ifdef CONFIG_NUMA_BALANCING int migrate_misplaced_page(struct page *page, struct vm_area_struct *vma, int node); +int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page); #else static inline int migrate_misplaced_page(struct page *page, struct vm_area_struct *vma, int node) { return -EAGAIN; /* can't migrate now */ } + +static inline int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page) +{ + return -EAGAIN; +} #endif /* CONFIG_NUMA_BALANCING */ #ifdef CONFIG_MIGRATION diff --git a/mm/huge_memory.c b/mm/huge_memory.c index cb4432792b88..b7cc6828ce9e 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1496,6 +1496,8 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf) int target_nid, last_cpupid = (-1 & LAST_CPUPID_MASK); bool migrated = false, writable = false; int flags = 0; + pg_data_t *pgdat; + int isolated; vmf->ptl = pmd_lock(vma->vm_mm, vmf->pmd); if (unlikely(!pmd_same(oldpmd, *vmf->pmd))) { @@ -1540,11 +1542,19 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf) spin_unlock(vmf->ptl); writable = false; + pgdat = NODE_DATA(target_nid); + isolated = numamigrate_isolate_page(pgdat, page); + if (!isolated) { + put_page(page); + goto isolate_fail; + } + migrated = migrate_misplaced_page(page, vma, target_nid); if (migrated) { flags |= TNF_MIGRATED; page_nid = target_nid; } else { +isolate_fail: flags |= TNF_MIGRATE_FAIL; vmf->ptl = pmd_lock(vma->vm_mm, vmf->pmd); if (unlikely(!pmd_same(oldpmd, *vmf->pmd))) { diff --git a/mm/memory.c b/mm/memory.c index bee9b1e86ef0..01b1980d4fb7 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4779,6 +4779,8 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) int target_nid; pte_t pte, old_pte; int flags = 0; + pg_data_t *pgdat; + int isolated; /* * The "pte" at this point cannot be used safely without @@ -4849,11 +4851,19 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) pte_unmap_unlock(vmf->pte, vmf->ptl); writable = false; + pgdat = NODE_DATA(target_nid); + isolated = numamigrate_isolate_page(pgdat, page); + if (!isolated) { + put_page(page); + goto isolate_fail; + } + /* Migrate to the requested node */ if (migrate_misplaced_page(page, vma, target_nid)) { page_nid = target_nid; flags |= TNF_MIGRATED; } else { +isolate_fail: flags |= TNF_MIGRATE_FAIL; vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, vmf->address, &vmf->ptl); diff --git a/mm/migrate.c b/mm/migrate.c index 9cc98fb1d6ec..5eeeb2cda21c 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2478,7 +2478,7 @@ static struct folio *alloc_misplaced_dst_folio(struct folio *src, return __folio_alloc_node(gfp, order, nid); } -static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page) +int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page) { int nr_pages = thp_nr_pages(page); int order = compound_order(page); @@ -2523,16 +2523,12 @@ int migrate_misplaced_page(struct page *page, struct vm_area_struct *vma, int node) { pg_data_t *pgdat = NODE_DATA(node); - int isolated; + int migrated = 1; int nr_remaining; unsigned int nr_succeeded; LIST_HEAD(migratepages); int nr_pages = thp_nr_pages(page); - isolated = numamigrate_isolate_page(pgdat, page); - if (!isolated) - goto out; - list_add(&page->lru, &migratepages); nr_remaining = migrate_pages(&migratepages, alloc_misplaced_dst_folio, NULL, node, MIGRATE_ASYNC, @@ -2544,7 +2540,7 @@ int migrate_misplaced_page(struct page *page, struct vm_area_struct *vma, page_is_file_lru(page), -nr_pages); putback_lru_page(page); } - isolated = 0; + migrated = 0; } if (nr_succeeded) { count_vm_numa_events(NUMA_PAGE_MIGRATE, nr_succeeded); @@ -2553,11 +2549,7 @@ int migrate_misplaced_page(struct page *page, struct vm_area_struct *vma, nr_succeeded); } BUG_ON(!list_empty(&migratepages)); - return isolated; - -out: - put_page(page); - return 0; + return migrated; } #endif /* CONFIG_NUMA_BALANCING */ #endif /* CONFIG_NUMA */