From patchwork Tue Aug 22 00:53:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13360021 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 1DBB1EE49AB for ; Tue, 22 Aug 2023 00:54:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2515B940016; Mon, 21 Aug 2023 20:54:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 201A728000B; Mon, 21 Aug 2023 20:54:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 02CAE94001C; Mon, 21 Aug 2023 20:54:16 -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 E7E6B940016 for ; Mon, 21 Aug 2023 20:54:16 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id BE39F1C84BE for ; Tue, 22 Aug 2023 00:54:16 +0000 (UTC) X-FDA: 81149919312.07.9EE5069 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) by imf22.hostedemail.com (Postfix) with ESMTP id 9566AC0005 for ; Tue, 22 Aug 2023 00:54:14 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf22.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.99 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692665655; 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=DlJp3/3E7Xb8ya6yRKzSEIygAUPOQPvI4nkRhXzfxUw=; b=q9M2Gj0JT8akI9CXJrV+SkmfLugRd5PWLwlvO998FIMblH2+BuunqfsywzvkLnf10aaQFl caTPrWkVKaiwGNt0PzqZYrq3uF1dVBfLpuxVoZ8LHuNS+eFfJ0OBpB2pM244s+2br7EnHa rSj2i42GX70kOJrnGi5q3UPEmpWhyvE= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf22.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.99 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692665655; a=rsa-sha256; cv=none; b=f7+l2FbvimsdM6RGAe38MEBRIc1I/4PekQaQo0lYvo3N9MUCfapk6AFh4up652a+1aYuJu 0bMrqMTvIvGX0Sm5QFMLk+5jxRJ8tBi4TvYIx1yhhr64Cky3Z8hN4zxEdzId7atUj3rS2n rF5KbVmyYeqQ7RZSl787G5IJ6rB+IDc= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0VqK0DQ6_1692665650; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VqK0DQ6_1692665650) by smtp.aliyun-inc.com; Tue, 22 Aug 2023 08:54:11 +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 v2 3/4] mm: migrate: change migrate_misplaced_page() to support multiple pages migration Date: Tue, 22 Aug 2023 08:53:51 +0800 Message-Id: <02c3d36270705f0dfec1ea583e252464cb48d802.1692665449.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 9566AC0005 X-Stat-Signature: 11zcn7tkcrerjotntq9deyyrp4cofn6t X-Rspam-User: X-HE-Tag: 1692665654-200034 X-HE-Meta: U2FsdGVkX19tFDHS/o0MMVlpKsvjlFC/hLtnEIj/yZ4D8s3RVYbtwYy/b2wqQlC2BizHCEvWKTmheRtjicto+dCZlZBub2GxJqGK7Na8nf8f2GnEtmNkF1pANt8lgjuzWd5kfw2TEjmT6fcs3wuvXhdbstsFifz1rSij5YqQWIMWAhRTGQ8jW3pKrNTytR3T8rcBtiILvYP9ujh4ZStWQaoTgnDxRI4qnUzMDwEwGC/+ReoHdP09VJ1//msFXyJrsMNWrBD5ljN/bkgnjcaBjbXyD0leU1Mk4xb7sdgP3+VDm1ZPGBS4TQLStxur7hAeTg9reTvOxtcRtPumXCs5ODMhNwgLmPDgvJmHKiv7QwJNswdCzjnI19ryihJzrcJKps5y56UZj+K78r5Z4tNzoah2IxgYa329PxE3yUlgcTToIX2A06LE5duJ3e2qPSBRt9Q3xkUoIcVUdpweboPnfwnnhe7Ao61icPUUpXwayEwL1s+DJTngLREQ8/hlHnljd/1uBCYxcLsY254gxtuKbLcg+a5nw77FCpr6oeby0h6BkdrjJqyIl+xsCdPt9eYxFWR1piIMbtyp0gmZCkgSRoqsTFNSrYCId6+WtnE7vwgbFprG7k4f7maNddmpxIoIf1vPZ6ArQZv7O9KE/Gp8of9bVNALAmVlayH83IAarGPdqokOatXz5J2k60d030P+sERlD29IFeFS2kmHmkXXUES3IxIMMsE78JjdkzGY5B02tE4ymgy3FGfYR6s0JzLchgdTu5TnOOZ3tEfDFwZny+/Icu+gQP6QO7sJVADx+6nqMSYKwZaGHcrqb6bP2MOgVfadc2Xlf5VG25EXaV1p9Sfe0ch8r6TWyqOBzFsJTTTZXI23QN0nu5h4tiId9Bh/s34mqIDbvLAxWhd1s187vmEL0hrX/n49acrF+2JbhoiJU+bPpkWNdqFPNO4t7oD5pWPNw/GcSrADcNlsiqS 9781KMIW zU+r4lQVELKwtSlxjR2vAso5WC3Jfl9zHe57TspJ5Jl+Ou0xVQB/rYfxWnywZ65dsemGgy/fV5/S6qtb6lb3G+7IDpL01DVqLrID3t7NaA31K52a03+Tc/KFk6FEj0Sz4qGlN4R4bBEUs7Fs= 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: Expanding the migrate_misplaced_page() function to allow passing in a list to support multiple pages migration as a preparation to support batch migration for NUMA balancing as well as compound page NUMA balancing in future. Signed-off-by: Baolin Wang --- include/linux/migrate.h | 9 +++++---- mm/huge_memory.c | 5 ++++- mm/memory.c | 4 +++- mm/migrate.c | 26 ++++++++++---------------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/include/linux/migrate.h b/include/linux/migrate.h index ddcd62ec2c12..87edce8e939d 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -142,12 +142,13 @@ 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 migrate_misplaced_page(struct list_head *migratepages, struct vm_area_struct *vma, + int source_nid, int target_nid); bool 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) +static inline int migrate_misplaced_page(struct list_head *migratepages, + struct vm_area_struct *vma, + int source_nid, int target_nid) { return -EAGAIN; /* can't migrate now */ } diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 07149ead11e4..4401a3493544 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1497,6 +1497,7 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf) bool migrated = false, writable = false; int flags = 0; pg_data_t *pgdat; + LIST_HEAD(migratepages); vmf->ptl = pmd_lock(vma->vm_mm, vmf->pmd); if (unlikely(!pmd_same(oldpmd, *vmf->pmd))) { @@ -1552,7 +1553,9 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf) goto migrate_fail; } - migrated = migrate_misplaced_page(page, vma, target_nid); + list_add(&page->lru, &migratepages); + migrated = migrate_misplaced_page(&migratepages, vma, + page_nid, target_nid); if (migrated) { flags |= TNF_MIGRATED; page_nid = target_nid; diff --git a/mm/memory.c b/mm/memory.c index 4e451b041488..9e417e8dd5d5 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4770,6 +4770,7 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) pte_t pte, old_pte; int flags = 0; pg_data_t *pgdat; + LIST_HEAD(migratepages); /* * The "pte" at this point cannot be used safely without @@ -4851,8 +4852,9 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) goto migrate_fail; } + list_add(&page->lru, &migratepages); /* Migrate to the requested node */ - if (migrate_misplaced_page(page, vma, target_nid)) { + if (migrate_misplaced_page(&migratepages, vma, page_nid, target_nid)) { page_nid = target_nid; flags |= TNF_MIGRATED; } else { diff --git a/mm/migrate.c b/mm/migrate.c index 0b2b69a2a7ab..fae7224b8e64 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2519,36 +2519,30 @@ bool numamigrate_isolate_page(pg_data_t *pgdat, struct page *page) * node. Caller is expected to have an elevated reference count on * the page that will be dropped by this function before returning. */ -int migrate_misplaced_page(struct page *page, struct vm_area_struct *vma, - int node) +int migrate_misplaced_page(struct list_head *migratepages, struct vm_area_struct *vma, + int source_nid, int target_nid) { - pg_data_t *pgdat = NODE_DATA(node); + pg_data_t *pgdat = NODE_DATA(target_nid); int migrated = 1; int nr_remaining; unsigned int nr_succeeded; - LIST_HEAD(migratepages); - int nr_pages = thp_nr_pages(page); - list_add(&page->lru, &migratepages); - nr_remaining = migrate_pages(&migratepages, alloc_misplaced_dst_folio, - NULL, node, MIGRATE_ASYNC, + nr_remaining = migrate_pages(migratepages, alloc_misplaced_dst_folio, + NULL, target_nid, MIGRATE_ASYNC, MR_NUMA_MISPLACED, &nr_succeeded); if (nr_remaining) { - if (!list_empty(&migratepages)) { - list_del(&page->lru); - mod_node_page_state(page_pgdat(page), NR_ISOLATED_ANON + - page_is_file_lru(page), -nr_pages); - putback_lru_page(page); - } + if (!list_empty(migratepages)) + putback_movable_pages(migratepages); + migrated = 0; } if (nr_succeeded) { count_vm_numa_events(NUMA_PAGE_MIGRATE, nr_succeeded); - if (!node_is_toptier(page_to_nid(page)) && node_is_toptier(node)) + if (!node_is_toptier(source_nid) && node_is_toptier(target_nid)) mod_node_page_state(pgdat, PGPROMOTE_SUCCESS, nr_succeeded); } - BUG_ON(!list_empty(&migratepages)); + BUG_ON(!list_empty(migratepages)); return migrated; } #endif /* CONFIG_NUMA_BALANCING */