From nobody Fri Dec 19 16:07:32 2025 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2051.outbound.protection.outlook.com [40.107.243.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F11629B8C5 for ; Fri, 23 May 2025 19:13:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748027603; cv=fail; b=pucMzwxBQ3k/cdFkiOwFZS4yItJsLhKjvMIEhdnwOY4u6Wuu1FLkqpw2IEo2MspN1yNahdMpeXTKQXLEGPuPgGPmnVYmz5FJ3TvvualCxZkq7NwBmCypwLloiUBv1FiwEPzSclRbNVzabmQtI33OwWztNI6hYb4QDzq4UzAsvtY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748027603; c=relaxed/simple; bh=4+y1hL26rPRbIFpXfD5Nfrtu2w7iIyPC/XeENr+cCcM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=rUnvSRA4wXuKlQ9Hj1BXDNEDStXC6WomWUgD4CgjbptDficcFL8jRr+H80dWxpE/AY+gTJaObkqlRQM2BfETGeZQ3DQfJlhW8jVGOfRkRkDcy71D68qx/5CoVzitAIMYXW4JFe3vTpgQv0Zbj3eDisDNhzwkT+24zKMM3cYxatI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=XJje5FvX; arc=fail smtp.client-ip=40.107.243.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="XJje5FvX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=x3FFPU+JXnCZ9o9F2mFbSG2f+se/+7gzJgqoSQZYxvBQE3SN/tCCu3uwbTMnyIy3Qu3mOujQG5xcjXLgMUxQvXmzqBkF3u9HDl9cvomXGQwSlG5ywQEOFx/m24eN4W57RTy0UomB6v7Y4TcHcnjHEXxOO0V0ZLZOs6I3f8EPp0w6KPNJwHFHakFZCkOuWmvOq1OuofkWJKDlTZJbk8Q5conhc/XxlEsZg03HEEN/XonCw8adrTHbXpmZ310ywd5kqOhpmuhdTqeSIpM8nFvAS1cQy18ApaJqGHQI/Vr43B8gbvt/JdN1Md0h4TrEyUab9bQwojmad4HDH6a0CICw8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Esh/l8wkLWPiw2U5i8LYI8cpIn30pibYhoot+1uC7Uo=; b=YY5jUtwbZ+vJby13l1EjDHPKHAOa/7ye0cjyvFFVO4SOF1/v7eLJXMhWoMge5HnpxuuKPKps7xB8I84FljPSFCbWb0fHWn4Z2X2+HOgbsY7dypUsnH1OK0WKyAbCBW4M8JGnqQICsM7RyfYbXjTj4fP1vF7CcTAB02PKJ5FmrVIkzt0Xu/nwVqMSyDvVfi9NwGKCvETSv58ZZNVTl2vyOR9bm48D1DBjfj89rJ/SD01ZvIcz8sWvuvGqg70lIQc5Q3rfU9+OV6EVP4Bd3B4JFr4CldY/Ya3ytLrlFqIT/uU55sWQ86leAZ6BFtCW7T4DfUm25+r2V5IykVGtOI0l3A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Esh/l8wkLWPiw2U5i8LYI8cpIn30pibYhoot+1uC7Uo=; b=XJje5FvX0mXFiYOWqrT25oH1Uh4tSDZfNbaB53tCyhzqaLp+DBc6Qh8k526h2r2jh4d7QlQjVVtBYDfRwn0R2S9SmXXP/ToF0DKIymh2tcEUZn1ABQUZa0rbUKTuUVQ1HyWb08Bx9JzYb82D7q03XdtWBkFsfCpAqZbxouzGYAqlIamsLbj9AwBDO7LwZi3sL/Q1r+kmSAy6eH4QXtEl5pa2fTKr9z+jxj59sdejlx75Wmk6l4XSYLAHAGdal2+Abb2aaTlGtXyTKNyRBAZBf44DfNYEFnzCn/iLddTsF2Jn2uQ/473abBtsV0vF36zZPAm+iD+buTdD2p57Tct8uw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by SJ2PR12MB8737.namprd12.prod.outlook.com (2603:10b6:a03:545::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8769.21; Fri, 23 May 2025 19:13:16 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%5]) with mapi id 15.20.8746.030; Fri, 23 May 2025 19:13:16 +0000 From: Zi Yan To: David Hildenbrand , Johannes Weiner , linux-mm@kvack.org Cc: Andrew Morton , Oscar Salvador , Vlastimil Babka , Baolin Wang , "Kirill A . Shutemov" , Mel Gorman , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Richard Chang , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v5 1/6] mm/page_alloc: pageblock flags functions clean up. Date: Fri, 23 May 2025 15:12:53 -0400 Message-ID: <20250523191258.339826-2-ziy@nvidia.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250523191258.339826-1-ziy@nvidia.com> References: <20250523191258.339826-1-ziy@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BL1PR13CA0002.namprd13.prod.outlook.com (2603:10b6:208:256::7) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|SJ2PR12MB8737:EE_ X-MS-Office365-Filtering-Correlation-Id: b5a4b21f-6c47-4261-93c7-08dd9a2ddecc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?p3RrgbZREf6omdcK1jra8qRJgFPstB3WiDMrB2qZlgGAoMbzpjlg5qAbOfhH?= =?us-ascii?Q?QLzQ1T96GUgZcJEdzGACyY/MS+x+H/Gd15YOADbxRX8cUtFXx1lbecSw8KWH?= =?us-ascii?Q?G4SVD3312BVcNII3qtogHqUfqIuabm2xJ4Sp79AeBS0Ipy6jOKhryuRDzbhN?= =?us-ascii?Q?ilAEFGaGUw/RNFKYQTwgC0RxW6bq1K+bTt9IqobnYQ0bBmvooJaW2Rp4iuqS?= =?us-ascii?Q?tjc33ezKdDmYb8z16OODzBV3ozP3Iv8RZP0yJ9DwTbjzYx7TCYH2la9dy4yE?= =?us-ascii?Q?qEDxNkc1avGhpQdd0Hcq/WhFHxAiH2tt5kIML1dr7KKAqUF71aH70IZ8UWve?= =?us-ascii?Q?9UouGMbVeO+Vtp6k3ThvV7jv4nYXYL+M65cFBjxBokbk0GT13+GRiIroXAm9?= =?us-ascii?Q?zDFpo0lu4G0tw70xST38xgptwvFJS0YmdNlrqXHOmc6UTlZzFGXogLeM92mG?= =?us-ascii?Q?ZUeZfZo+/FlopEXhuSrNnTX0+HBpkbezDeNnAX+bqQyB6lMSFCOs/LbPcwLq?= =?us-ascii?Q?yTFdedQvrDsmx80i8utbx8g/qZt2Wm+MOs9G2tb3MIiNUmYbiiaEjFdrkSnU?= =?us-ascii?Q?l28YX4GdSMJX1FJvzIrxiNtdJlC9utukQGBjVxD80PKN+t+WitDEwXFUnw88?= =?us-ascii?Q?XFUk9XcFAmzdtifY3dpQrLi0NnX1lttUjPrZoS+fVy59qk5njDzeJ9f4/oUf?= =?us-ascii?Q?ilyFVOvm95ONFHwied4Y2BR41k4o5Q4OwBseVHM/IspsEut7yk42m07mWEJM?= =?us-ascii?Q?8bNZE4yxh/UNHETG2albuvh89doAOVJhaXV30sU6fm4N379HrlCXEOAHQf5T?= =?us-ascii?Q?aOdSpnzptyCsl9lHy5AakyG07SRKv53MGTgNUn9UayG1S03Ml1mIt2TMayIq?= =?us-ascii?Q?d90EX+iuv4xyIL51UFUSDlasszTwpCQ+iwvzBSmbn3WgSJG6BylMB7SU1/Z0?= =?us-ascii?Q?pVpTS09hqLJbRHeY2NgyKcFEDi4a2rAtllaJg/wmkbLoAZPokr34LmmPQeRw?= =?us-ascii?Q?WhnPKo4AVoXs9j1mrFyejeUZd82ln92uZkts6YvBYns6YVambT75aibQI8p/?= =?us-ascii?Q?wVZoCBj6+WzSMY5I59YNZ1JFVJ8RqDj14BPdODfApQ8KiXFQytcPpQA5HwI1?= =?us-ascii?Q?ewxZikqmtmYtmXOxBoIo/hNMs4IAktNy+UimSbsg4mWgGpgVUi1DN52RlEim?= =?us-ascii?Q?rbIuuWEoRBGymxEY9tOtnRgmPUufpFDqVJkq49iAC8V4TXk9FdFcUABfFX6Y?= =?us-ascii?Q?Pvy6Ms1jci0CcBZO6HpMVOu7fgOKCfsbBXXujLWIkCwMMamELzSP3+9YwjOS?= =?us-ascii?Q?n6kWhoHajTpDq4aTn0EkbdEIcKz/9OqZ7dDtGYqO59qywpDsY8XKXS7HisEh?= =?us-ascii?Q?tyTo0lVwsIRhf8SJAsQOdn535WVY7HP3OEJBDpStBBT1xuCKLXgT1trlpixN?= =?us-ascii?Q?x6mf9/ODlIE=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB9473.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(7416014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?VzzNIz488xiTyc9nEPa7c9JXjC+0VMZi/0w/n3QxOmXaHdHTLJL2LIbWqZ3e?= =?us-ascii?Q?9lAOs8QKSNfZFFilbxxKREZ0blGHikl+74WZpQcOrcp/tiCghtZTT+fQI8kl?= =?us-ascii?Q?5QMp9IJZ1DvcNyWXP/1A6lOhMqqO2y3uAcKa4ysZhvDEXZkQictiK3iBE0v1?= =?us-ascii?Q?9xAb+F3tDWzdNAQuXYnBTkXWTpV7CPYmbUqlEuG83amGEq4wssgRWVZBhuIQ?= =?us-ascii?Q?8GUzKJ2ieKdKumTqcjF8ksKN3U5uiXY6CgGBr5UUWOwFAZ8HRp3UAFH/Qe3T?= =?us-ascii?Q?1wmJbB8nFnPOwsZdvIyvJKb+szAv1TmDRWGE8Yg1fqOPodSaFWbH7TquHUvn?= =?us-ascii?Q?hAnWo0KQjiu3J2xDcjFMjZd+aOMTWQFXLmOSVcFACqKjFPaiCEqQAmvl9lIG?= =?us-ascii?Q?y3N6yJHkxbcXWMukiPxK3sLPq/vQm+/nqWqgSq0njKE1S14n7WO5RAWjwQTI?= =?us-ascii?Q?l12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5T0tdMHH/wWYVVr074a9?= =?us-ascii?Q?6/3SvzGB99G+/N32KIH4YNDNWTPuEdE83rKNgtljmcctmWLW9lY0qzeAzder?= =?us-ascii?Q?OKrWrb/aZiLJGX6C37eIBoCp6/BOmq4qMrddE9Ti/0YhqdauCfndvYheuWVw?= =?us-ascii?Q?8fRhv2V6rYARdBO1BQK2ZgP8LCMMl8guRUSzbOLHRjZGL/D8Nqd+B/Em4SY2?= =?us-ascii?Q?0IjL+CZOco8RCFS/nbSuxyXEv9eBFN5+MOTpSTyr?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b5a4b21f-6c47-4261-93c7-08dd9a2ddecc X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2025 19:13:15.9695 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 3ea06b4MSCP4v6to520vaeelTsgmPvRSIxeV0D9JENDI8NfCU1eOm22ialI65z6a X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8737 Content-Type: text/plain; charset="utf-8" No functional change is intended. 1. Add __NR_PAGEBLOCK_BITS for the number of pageblock flag bits and use roundup_pow_of_two(__NR_PAGEBLOCK_BITS) as NR_PAGEBLOCK_BITS to take right amount of bits for pageblock flags. 2. Add {get,set,clear}_pfnblock_bit() to operate one a standalone bit, like PB_migrate_skip. 3. Make {get,set}_pfnblock_flags_mask() internal functions and use {get,set}_pfnblock_migratetype() for pageblock migratetype operations. 4. Move pageblock flags common code to get_pfnblock_bitmap_bitidx(). 3. Use MIGRATETYPE_MASK to get the migratetype of a pageblock from its flags. 4. Use PB_migrate_end in the definition of MIGRATETYPE_MASK instead of PB_migrate_bits. 5. Add a comment on is_migrate_cma_folio() to prevent one from changing it to use get_pageblock_migratetype() and causing issues. Signed-off-by: Zi Yan --- include/linux/mmzone.h | 18 ++-- include/linux/page-isolation.h | 2 +- include/linux/pageblock-flags.h | 32 +++--- mm/memory_hotplug.c | 2 +- mm/page_alloc.c | 169 ++++++++++++++++++++++++-------- 5 files changed, 158 insertions(+), 65 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index b19a98c20de8..39540213d5b9 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -76,8 +76,12 @@ extern const char * const migratetype_names[MIGRATE_TYPE= S]; #ifdef CONFIG_CMA # define is_migrate_cma(migratetype) unlikely((migratetype) =3D=3D MIGRAT= E_CMA) # define is_migrate_cma_page(_page) (get_pageblock_migratetype(_page) =3D= =3D MIGRATE_CMA) -# define is_migrate_cma_folio(folio, pfn) (MIGRATE_CMA =3D=3D \ - get_pfnblock_flags_mask(&folio->page, pfn, MIGRATETYPE_MASK)) +/* + * __dump_folio() in mm/debug.c passes a folio pointer to on-stack struct = folio, + * so folio_pfn() cannot be used and pfn is needed. + */ +# define is_migrate_cma_folio(folio, pfn) \ + (get_pfnblock_migratetype(&folio->page, pfn) =3D=3D MIGRATE_CMA) #else # define is_migrate_cma(migratetype) false # define is_migrate_cma_page(_page) false @@ -106,14 +110,12 @@ static inline bool migratetype_is_mergeable(int mt) =20 extern int page_group_by_mobility_disabled; =20 -#define MIGRATETYPE_MASK ((1UL << PB_migratetype_bits) - 1) +#define get_pageblock_migratetype(page) \ + get_pfnblock_migratetype(page, page_to_pfn(page)) =20 -#define get_pageblock_migratetype(page) \ - get_pfnblock_flags_mask(page, page_to_pfn(page), MIGRATETYPE_MASK) +#define folio_migratetype(folio) \ + get_pageblock_migratetype(&folio->page) =20 -#define folio_migratetype(folio) \ - get_pfnblock_flags_mask(&folio->page, folio_pfn(folio), \ - MIGRATETYPE_MASK) struct free_area { struct list_head free_list[MIGRATE_TYPES]; unsigned long nr_free; diff --git a/include/linux/page-isolation.h b/include/linux/page-isolation.h index 898bb788243b..277d8d92980c 100644 --- a/include/linux/page-isolation.h +++ b/include/linux/page-isolation.h @@ -25,7 +25,7 @@ static inline bool is_migrate_isolate(int migratetype) #define MEMORY_OFFLINE 0x1 #define REPORT_FAILURE 0x2 =20 -void set_pageblock_migratetype(struct page *page, int migratetype); +void set_pageblock_migratetype(struct page *page, enum migratetype migrate= type); =20 bool move_freepages_block_isolate(struct zone *zone, struct page *page, int migratetype); diff --git a/include/linux/pageblock-flags.h b/include/linux/pageblock-flag= s.h index fc6b9c87cb0a..3acbb271a29a 100644 --- a/include/linux/pageblock-flags.h +++ b/include/linux/pageblock-flags.h @@ -25,9 +25,13 @@ enum pageblock_bits { * Assume the bits will always align on a word. If this assumption * changes then get/set pageblock needs updating. */ - NR_PAGEBLOCK_BITS + __NR_PAGEBLOCK_BITS }; =20 +#define NR_PAGEBLOCK_BITS (roundup_pow_of_two(__NR_PAGEBLOCK_BITS)) + +#define MIGRATETYPE_MASK ((1UL << (PB_migrate_end + 1)) - 1) + #if defined(CONFIG_HUGETLB_PAGE) =20 #ifdef CONFIG_HUGETLB_PAGE_SIZE_VARIABLE @@ -65,27 +69,23 @@ extern unsigned int pageblock_order; /* Forward declaration */ struct page; =20 -unsigned long get_pfnblock_flags_mask(const struct page *page, - unsigned long pfn, - unsigned long mask); - -void set_pfnblock_flags_mask(struct page *page, - unsigned long flags, - unsigned long pfn, - unsigned long mask); +enum migratetype get_pfnblock_migratetype(const struct page *page, + unsigned long pfn); +bool get_pfnblock_bit(const struct page *page, unsigned long pfn, + enum pageblock_bits pb_bit); +void set_pfnblock_bit(const struct page *page, unsigned long pfn, + enum pageblock_bits pb_bit); +void clear_pfnblock_bit(const struct page *page, unsigned long pfn, + enum pageblock_bits pb_bit); =20 /* Declarations for getting and setting flags. See mm/page_alloc.c */ #ifdef CONFIG_COMPACTION #define get_pageblock_skip(page) \ - get_pfnblock_flags_mask(page, page_to_pfn(page), \ - (1 << (PB_migrate_skip))) + get_pfnblock_bit(page, page_to_pfn(page), PB_migrate_skip) #define clear_pageblock_skip(page) \ - set_pfnblock_flags_mask(page, 0, page_to_pfn(page), \ - (1 << PB_migrate_skip)) + clear_pfnblock_bit(page, page_to_pfn(page), PB_migrate_skip) #define set_pageblock_skip(page) \ - set_pfnblock_flags_mask(page, (1 << PB_migrate_skip), \ - page_to_pfn(page), \ - (1 << PB_migrate_skip)) + set_pfnblock_bit(page, page_to_pfn(page), PB_migrate_skip) #else static inline bool get_pageblock_skip(struct page *page) { diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index b1caedbade5b..4ce5210ea56e 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -797,7 +797,7 @@ void move_pfn_range_to_zone(struct zone *zone, unsigned= long start_pfn, =20 /* * TODO now we have a visible range of pages which are not associated - * with their zone properly. Not nice but set_pfnblock_flags_mask + * with their zone properly. Not nice but set_pfnblock_migratetype() * expects the zone spans the pfn range. All the pages in the range * are reserved so nobody should be touching them so we should be safe */ diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 90b06f3d004c..0207164fcaf6 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -353,81 +353,172 @@ static inline int pfn_to_bitidx(const struct page *p= age, unsigned long pfn) return (pfn >> pageblock_order) * NR_PAGEBLOCK_BITS; } =20 +static __always_inline void +get_pfnblock_bitmap_bitidx(const struct page *page, unsigned long pfn, + unsigned long **bitmap_word, unsigned long *bitidx) +{ + unsigned long *bitmap; + unsigned long word_bitidx; + + BUILD_BUG_ON(NR_PAGEBLOCK_BITS !=3D 4); + BUILD_BUG_ON(MIGRATE_TYPES > (1 << PB_migratetype_bits)); + VM_BUG_ON_PAGE(!zone_spans_pfn(page_zone(page), pfn), page); + + bitmap =3D get_pageblock_bitmap(page, pfn); + *bitidx =3D pfn_to_bitidx(page, pfn); + word_bitidx =3D *bitidx / BITS_PER_LONG; + *bitidx &=3D (BITS_PER_LONG - 1); + *bitmap_word =3D &bitmap[word_bitidx]; +} + + /** - * get_pfnblock_flags_mask - Return the requested group of flags for the p= ageblock_nr_pages block of pages + * __get_pfnblock_flags_mask - Return the requested group of flags for + * a pageblock_nr_pages block of pages * @page: The page within the block of interest * @pfn: The target page frame number * @mask: mask of bits that the caller is interested in * * Return: pageblock_bits flags */ -unsigned long get_pfnblock_flags_mask(const struct page *page, - unsigned long pfn, unsigned long mask) +static unsigned long __get_pfnblock_flags_mask(const struct page *page, + unsigned long pfn, + unsigned long mask) { - unsigned long *bitmap; - unsigned long bitidx, word_bitidx; + unsigned long *bitmap_word; + unsigned long bitidx; unsigned long word; =20 - bitmap =3D get_pageblock_bitmap(page, pfn); - bitidx =3D pfn_to_bitidx(page, pfn); - word_bitidx =3D bitidx / BITS_PER_LONG; - bitidx &=3D (BITS_PER_LONG-1); + get_pfnblock_bitmap_bitidx(page, pfn, &bitmap_word, &bitidx); /* - * This races, without locks, with set_pfnblock_flags_mask(). Ensure + * This races, without locks, with set_pfnblock_migratetype(). Ensure * a consistent read of the memory array, so that results, even though * racy, are not corrupted. */ - word =3D READ_ONCE(bitmap[word_bitidx]); + word =3D READ_ONCE(*bitmap_word); return (word >> bitidx) & mask; } =20 -static __always_inline int get_pfnblock_migratetype(const struct page *pag= e, - unsigned long pfn) +/** + * get_pfnblock_bit - Check if a standalone bit of a pageblock is set + * @page: The page within the block of interest + * @pfn: The target page frame number + * @pb_bit: pageblock bit to check + * + * Return: true if the bit is set, otherwise false + */ +bool get_pfnblock_bit(const struct page *page, unsigned long pfn, + enum pageblock_bits pb_bit) { - return get_pfnblock_flags_mask(page, pfn, MIGRATETYPE_MASK); + unsigned long *bitmap_word; + unsigned long bitidx; + + if (WARN_ON_ONCE(pb_bit <=3D PB_migrate_end || + pb_bit >=3D __NR_PAGEBLOCK_BITS)) + return false; + + get_pfnblock_bitmap_bitidx(page, pfn, &bitmap_word, &bitidx); + + return test_bit(bitidx + pb_bit, bitmap_word); } =20 /** - * set_pfnblock_flags_mask - Set the requested group of flags for a pagebl= ock_nr_pages block of pages + * get_pfnblock_migratetype - Return the migratetype of a pageblock + * @page: The page within the block of interest + * @pfn: The target page frame number + * + * Return: The migratetype of the pageblock + * + * Use get_pfnblock_migratetype() if caller already has both @page and @pfn + * to save a call to page_to_pfn(). + */ +__always_inline enum migratetype +get_pfnblock_migratetype(const struct page *page, unsigned long pfn) +{ + return __get_pfnblock_flags_mask(page, pfn, MIGRATETYPE_MASK); +} + +/** + * __set_pfnblock_flags_mask - Set the requested group of flags for + * a pageblock_nr_pages block of pages * @page: The page within the block of interest - * @flags: The flags to set * @pfn: The target page frame number + * @flags: The flags to set * @mask: mask of bits that the caller is interested in */ -void set_pfnblock_flags_mask(struct page *page, unsigned long flags, - unsigned long pfn, - unsigned long mask) +static void __set_pfnblock_flags_mask(struct page *page, unsigned long pfn, + unsigned long flags, unsigned long mask) { - unsigned long *bitmap; - unsigned long bitidx, word_bitidx; + unsigned long *bitmap_word; + unsigned long bitidx; unsigned long word; =20 - BUILD_BUG_ON(NR_PAGEBLOCK_BITS !=3D 4); - BUILD_BUG_ON(MIGRATE_TYPES > (1 << PB_migratetype_bits)); - - bitmap =3D get_pageblock_bitmap(page, pfn); - bitidx =3D pfn_to_bitidx(page, pfn); - word_bitidx =3D bitidx / BITS_PER_LONG; - bitidx &=3D (BITS_PER_LONG-1); - - VM_BUG_ON_PAGE(!zone_spans_pfn(page_zone(page), pfn), page); + get_pfnblock_bitmap_bitidx(page, pfn, &bitmap_word, &bitidx); =20 mask <<=3D bitidx; flags <<=3D bitidx; =20 - word =3D READ_ONCE(bitmap[word_bitidx]); + word =3D READ_ONCE(*bitmap_word); do { - } while (!try_cmpxchg(&bitmap[word_bitidx], &word, (word & ~mask) | flags= )); + } while (!try_cmpxchg(bitmap_word, &word, (word & ~mask) | flags)); +} + +/** + * set_pfnblock_bit - Set a standalone bit of a pageblock + * @page: The page within the block of interest + * @pfn: The target page frame number + * @pb_bit: pageblock bit to set + */ +void set_pfnblock_bit(const struct page *page, unsigned long pfn, + enum pageblock_bits pb_bit) +{ + unsigned long *bitmap_word; + unsigned long bitidx; + + if (WARN_ON_ONCE(pb_bit <=3D PB_migrate_end || + pb_bit >=3D __NR_PAGEBLOCK_BITS)) + return; + + get_pfnblock_bitmap_bitidx(page, pfn, &bitmap_word, &bitidx); + + __set_bit(bitidx + pb_bit, bitmap_word); +} + +/** + * clear_pfnblock_bit - Clear a standalone bit of a pageblock + * @page: The page within the block of interest + * @pfn: The target page frame number + * @pb_bit: pageblock bit to clear + */ +void clear_pfnblock_bit(const struct page *page, unsigned long pfn, + enum pageblock_bits pb_bit) +{ + unsigned long *bitmap_word; + unsigned long bitidx; + + if (WARN_ON_ONCE(pb_bit <=3D PB_migrate_end || + pb_bit >=3D __NR_PAGEBLOCK_BITS)) + return; + + get_pfnblock_bitmap_bitidx(page, pfn, &bitmap_word, &bitidx); + + __clear_bit(bitidx + pb_bit, bitmap_word); } =20 -void set_pageblock_migratetype(struct page *page, int migratetype) +/** + * set_pageblock_migratetype - Set the migratetype of a pageblock + * @page: The page within the block of interest + * @migratetype: migratetype to set + */ +__always_inline void set_pageblock_migratetype(struct page *page, + enum migratetype migratetype) { if (unlikely(page_group_by_mobility_disabled && migratetype < MIGRATE_PCPTYPES)) migratetype =3D MIGRATE_UNMOVABLE; =20 - set_pfnblock_flags_mask(page, (unsigned long)migratetype, - page_to_pfn(page), MIGRATETYPE_MASK); + __set_pfnblock_flags_mask(page, page_to_pfn(page), + (unsigned long)migratetype, MIGRATETYPE_MASK); } =20 #ifdef CONFIG_DEBUG_VM @@ -667,7 +758,7 @@ static inline void __add_to_free_list(struct page *page= , struct zone *zone, int nr_pages =3D 1 << order; =20 VM_WARN_ONCE(get_pageblock_migratetype(page) !=3D migratetype, - "page type is %lu, passed migratetype is %d (nr=3D%d)\n", + "page type is %d, passed migratetype is %d (nr=3D%d)\n", get_pageblock_migratetype(page), migratetype, nr_pages); =20 if (tail) @@ -693,7 +784,7 @@ static inline void move_to_free_list(struct page *page,= struct zone *zone, =20 /* Free page moving can fail, so it happens before the type update */ VM_WARN_ONCE(get_pageblock_migratetype(page) !=3D old_mt, - "page type is %lu, passed migratetype is %d (nr=3D%d)\n", + "page type is %d, passed migratetype is %d (nr=3D%d)\n", get_pageblock_migratetype(page), old_mt, nr_pages); =20 list_move_tail(&page->buddy_list, &area->free_list[new_mt]); @@ -715,7 +806,7 @@ static inline void __del_page_from_free_list(struct pag= e *page, struct zone *zon int nr_pages =3D 1 << order; =20 VM_WARN_ONCE(get_pageblock_migratetype(page) !=3D migratetype, - "page type is %lu, passed migratetype is %d (nr=3D%d)\n", + "page type is %d, passed migratetype is %d (nr=3D%d)\n", get_pageblock_migratetype(page), migratetype, nr_pages); =20 /* clear reported state and update reported page count */ @@ -3127,7 +3218,7 @@ static struct page *rmqueue_pcplist(struct zone *pref= erred_zone, =20 /* * Do not instrument rmqueue() with KMSAN. This function may call - * __msan_poison_alloca() through a call to set_pfnblock_flags_mask(). + * __msan_poison_alloca() through a call to set_pfnblock_migratetype(). * If __msan_poison_alloca() attempts to allocate pages for the stack depo= t, it * may call rmqueue() again, which will result in a deadlock. */ --=20 2.47.2 From nobody Fri Dec 19 16:07:32 2025 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2051.outbound.protection.outlook.com [40.107.243.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63C2129B8DA for ; Fri, 23 May 2025 19:13:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748027605; cv=fail; b=DPXR2RmYNEr4YVWKAbeCYIkohyjsZQxmuhz4Qt5f4/TFNWETZqNylddVGYfaXeqPbQDEZbq2QBxhEwJ/vnNuJAQst6NnrSkxLug1kKLfLrcuzQi7e53eQE5zMQdnu/4PTJhSJdgoQ5sTaWynDOHP1eLPK7vJIxpmthY5noS0sY0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748027605; c=relaxed/simple; bh=pdgIhT0lY9uxl9vKUMQPK64fBZNL5RtVup3exWNBRQY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=ZTPjN/kWEV/TukUMYCeL49b8ZK/f7PJ2GKHhiLagEhxaHHdWq5cOOpoljrWracwcKvDaihMzrYA0244ZHl9d7ondAo3qioh3cwt/Pb2ycKqvB5aeeNe0Dfvg5LTpKcOOtIQ43JRJN7RUgID914Q2FojMFfBevBSXm6mWRRXITBY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=cVBm7SZ8; arc=fail smtp.client-ip=40.107.243.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="cVBm7SZ8" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=R8rzANGDg1iRacT+dnbVsAkCtewVtKheThcClVOkI8ULNXvIxCGx5qunN0Hon613kJBiqpowpVTFoJmz4+UtIoa36Ef8mGeKVRkvrBAlv5qovs+Q9vAw8Z4yktgxyyCcnXa+Ye2MGK+wJL/aIwsYJygIwqLuZ6SA7He4sYTL0UK02eXpzzcZxOGPiDLgEkIjqeW1UHy8daukWUeoXgHqJtUYySQ959PuoPkKkhhJl4RlCAA+VggSw9mWuNgZwD9dUk16HKD2ZskNY9HetR59Xjj1cOCxmSHwHsK4MzFmYL6QeVGlA9B/xZU23Whkw56eZdcXHwmjzhjY+PaE26RVNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=E594aYiquQwC5VWHr8AS7at5/I01hy0lXAtazGW4ZUo=; b=KXE+1/EECokTMVSCONk+WGScZISCi6xC06FFuqxqKgleGF6ZltT0xYL2PAAJAViPW+GCN3tydhn+y2Lc3/a83kgXyU6YF/4VTVMYmyEt5IvcgzTCvj9A6UWrOU3pIIcM1Sknvx2wYPpvkXqc4dQqrh5US8Kptnw5xwl+kBktIQqz+i4/Q97G7yfg8+w/zsn7PbXlcVWzaL1ToEXKJZrKcqlVkutwVQOV/IxIZys5AkutXc0mtmKbBmZftPsjDhErCCXmCOHzCkouon5vxJdQ910Pqnf2f/AEirYGuW6Bw6IlzNC/j9pAHNCMChMwG+OoGTbg0MM27ZO2bblC6rMM/w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=E594aYiquQwC5VWHr8AS7at5/I01hy0lXAtazGW4ZUo=; b=cVBm7SZ8Eis6AjynGI6vl4PLp0P/ehimJdZidfwMbBUUrclqurQQTpV6TY3QcGHSE66b4mYS+nThZ5Co8sw34gzqceeP9fhSucs08bminM0A34UDWddsOY3G1JzlRrAEGbkH6u9b5myNSN6kbrhwzcIwJhycKsDMWXt1BGqEnT6NieHQ7cAmy9I6t7l1T9b/L4YLGYi/0D2I6t9AEaGtqzhaEMWw+5ecgw03fcQ81izpTQG2B4EYQgLef2lQqntO1uWT9gdacPELrFXqzlJeQxOO0LExI0Rf2IEGuJkixwVQ5/hZKAWpUsJJndlSjfFn8bM8RntLaUm0UDOiXa6ZyQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by SJ2PR12MB8737.namprd12.prod.outlook.com (2603:10b6:a03:545::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8769.21; Fri, 23 May 2025 19:13:17 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%5]) with mapi id 15.20.8746.030; Fri, 23 May 2025 19:13:17 +0000 From: Zi Yan To: David Hildenbrand , Johannes Weiner , linux-mm@kvack.org Cc: Andrew Morton , Oscar Salvador , Vlastimil Babka , Baolin Wang , "Kirill A . Shutemov" , Mel Gorman , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Richard Chang , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v5 2/6] mm/page_isolation: make page isolation a standalone bit. Date: Fri, 23 May 2025 15:12:54 -0400 Message-ID: <20250523191258.339826-3-ziy@nvidia.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250523191258.339826-1-ziy@nvidia.com> References: <20250523191258.339826-1-ziy@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BL1PR13CA0023.namprd13.prod.outlook.com (2603:10b6:208:256::28) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|SJ2PR12MB8737:EE_ X-MS-Office365-Filtering-Correlation-Id: d69cb1b1-3f25-473a-fbaf-08dd9a2ddfaa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?eZbpwLdEoCMAFwpne26/+s6F74gBaiEZkY4h7qZZlJ15D8Dv5f9oEQRnlFZh?= =?us-ascii?Q?YhcCBsBp9QvvbyHqyLeP/l68ou2IUrPXKikahjrZaAr6Xqshvsca5SXVmLB/?= =?us-ascii?Q?CXqaCSSJZhXpS+WUgNd8xT+FPd5KzFWgUAdOWgMQlaGvyYreqsnKJ52Zqwbx?= =?us-ascii?Q?xA+oeMgkGN/vubfcrqDWi+Jcl65os7bd6mmxyd1UFuBbsl0ZbSSYfokIv8tX?= =?us-ascii?Q?DVnGC1ISIy6ZUeJ4TimKrK8vM/spyWMKwTbgsi6/7H69iKTk8v7YxMYKO0aC?= =?us-ascii?Q?YkNwQqDiTrfm3aEOOA24TY7dsHaiQkwB732JxyQYzhgRlGTKd07hUUV6dvz0?= =?us-ascii?Q?wefdRPKHjEK4Tsj/UswF7Zw1J3kcgRRyN7bQcN+Welmhkzt/Ir5mX4DnsPct?= =?us-ascii?Q?LTw4eYz+ord9v1eDkUaTPrsVMIA8gj0LurqF1dG7WEfSNqwZSzjOawlMA6WZ?= =?us-ascii?Q?XKDFLxIke+73mXRBmk0KPtP3rH67y7IJrrtQjFrVLXJ39ADkt0EZNCsnGncu?= =?us-ascii?Q?QLqjddFMpZBUInzj+74czdjbW0V+Sct8UTOQnO9Rb5+Fg5EVgqM0z15hplIH?= =?us-ascii?Q?SQ2iPxaQ/S3d85Dmlz3DwVHKYYx8KYRaZrPDmqOyXPANM5aSgEo34eeebq/o?= =?us-ascii?Q?i8RgtuJmBgrZUaEEBhGZj2mey4aasa7GhHlzDe/UabI7vIKzssRhluAu5R1R?= =?us-ascii?Q?4/DcMyLFDQaicQAZ201NqB32GCOWijGd9mLE8x4V+BXn+OxidOW002qtQTjv?= =?us-ascii?Q?2hxTeVXEJkbAD3IRNSqGi3rkUj78u8EiRJ911FvddrISvhSgzWa++ibbtGF2?= =?us-ascii?Q?VHttynHNL8qeGuc3+ufUP+vZApxDfXO2MZQl5oJOv6TXvajFO0iRgHDgMijU?= =?us-ascii?Q?X/U7gHgMrlmHb08X3GPtIrWe6KMSaXikgB6q3jMoqIviO4O3LDdjNVSCFwhs?= =?us-ascii?Q?nI5Sp1hV0KWSR6XNaaYAxIC/mPZYQx3c26ST64PhoUL1JjnIDzpoz/euaz8p?= =?us-ascii?Q?+h3D2lU4dGoTfshFtZaZ5aUS7RJnXLAIjXRxM68OrW7llMNZti9N/6NGBuF7?= =?us-ascii?Q?6r5Y0NfV22W8UH0xHvlO2Wp8WRYLGfCaWjk0buvzob+udlFce+CjD9Qvu1qE?= =?us-ascii?Q?zEnpnEAjU7uj29eLXSoVgo2LVB9jANCewPp1PMIsTgrDssyAjJuago0eUQfd?= =?us-ascii?Q?oh+/jbfWrMu5o5ruoyAGFeQ+pl+W3A9lynTp3DYk3hCMG3Ba7GxR3sW+HOqn?= =?us-ascii?Q?sbiwRMxTVGnDRVT8IzYLpTzUgeBU812A0V074wpcjRxMkaMPk9KH6Dwlu3m3?= =?us-ascii?Q?TlW1zQwxrC2trAY+URH1lzF0S9biC8IgaOMVGxx7bQIsrl8iU3dsntv0x/M5?= =?us-ascii?Q?xCxvf0YjftQnOor2BsQ08/+WUXw9e0Wai0zfv8K3naHziTVEs4DZ7o8zxp1Y?= =?us-ascii?Q?wRzvZqz4O60=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB9473.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(7416014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?egnSgJlrOHvYp51b/uMXBnR+nZ5tkxt2lD4HYGpwXYoGLZIzq00OdxWm1e4M?= =?us-ascii?Q?DJcmth9FOezOlavi3beuuR43I76hwaRR1TqsX3I94haXEMAA+rfjpE5IKfS7?= =?us-ascii?Q?iyyJB+nbQ1XNvzTCCi43p5xr/+Z59glwrpAZixiNJvYbmDOmiIw5lIjfvP/J?= =?us-ascii?Q?gVwRsMaTycj1RuJiC1TZuhvOTyrPXuCuxmTBEE0zoWuXjtpRDkkCTs3q7ou/?= =?us-ascii?Q?2qVTGaW3zTM1/8x20YPVIWGIZVmEekm+7yUYTJcF3AjKIyOSHkwP88WNmpeD?= =?us-ascii?Q?jq1iC9h610SxLK704xgN1nm7O9xhldcw5MxTzvHreleli//Lm7WAn9PBmOCZ?= =?us-ascii?Q?kbnQsSUj98mGk5wopic+6jDpWtPERfMfickLZFh4PFErIU0mwcInC+lS3Z8Z?= =?us-ascii?Q?5qv8Okhog8Y6bnWuQUxno/VM7g8bvQwVnOEamgHd0DO9Z8pzxBMmoKEBAYU6?= =?us-ascii?Q?fr351UUDGqyzqfgZY+Sxwi/pI4MTzxsZ8tA42G/YMv2CRBE+TIUZPBM1VkxD?= =?us-ascii?Q?yNTsbL/vXiwqwfddPNepgDOSORD4oOUPQnd+1goq0sHgLrELBBRKCG+v/26l?= =?us-ascii?Q?Ril3XYSAE75FYPUXBVLHIX+CSMLlRlOHxNt3RzDDOonxLARAZ1HgLGGNqBLe?= =?us-ascii?Q?QjEKACYf+tSMJ/MFRLfp9JKjqpL6IDyee9C0414CXpjXOMAK1vmNKlPfMGr/?= =?us-ascii?Q?BpB7LF0vXveZWLj7utqQsgihcQIa+POKU1d+QS4k9M+3ydna6LrphHId+ifH?= =?us-ascii?Q?EphgtdvxChBOFRjUXrQVTu/NFgjj4HEgbQc4wLaE+S5I6oqqLhqgFZrOUDGD?= =?us-ascii?Q?bP7y1W26iTnYnYPxBIx9WXXenGn2Y9klu764JBKmW5dgoroMUDD2SHr9WDTb?= =?us-ascii?Q?rM8aNv3521Tn8eo/Yi7PclGoXR/qCTXqHsWuSi9ICmWWdUfZZPiUPuaPl4sl?= =?us-ascii?Q?uuS9GUqbxwKUTXvB+bRHVPqdWn5FezJ6Zcv/K/YAz1lvzzL0tDc/Qibamnqi?= =?us-ascii?Q?XpGL8XoGkUkuNVjIEg7V4Eakm0FT/rNnv6L1eAP4gZQVEgrIU9YdPyCHrOf9?= =?us-ascii?Q?3a9rNjk/wspzaF1XX9m56wOd3sWxB9PPO6+KafWh6ILxmopqHk1XGHcyVXrR?= =?us-ascii?Q?yNe6BZcEguQ4WqS9aAHHrTIgC/bC7bu7iQEnSFj3M03rhqUL0A/+9BLUcX2L?= =?us-ascii?Q?kpNgGWLAJWnD25GyJPUA52G2UWHK6Y0eqzeSldYg6lDCvJ4p4MHLD05H/EYH?= =?us-ascii?Q?dL54qy34W+wUPR/VYA+sWp1vkUkWyvIpE3nuuUNJuDq/psDjyyjS6W2bEjyF?= =?us-ascii?Q?XL7jbxiqR93fc7Ew5oREHkg1Hq/Xp8Fic7iOK9b0iIdT0LWa8RU03GVibqiw?= =?us-ascii?Q?F0GDxyApLW1by7voE4A4u7LJ05Kb/E7O7hQw1pZgiZDjt0j8F7WQLNXkPI+B?= =?us-ascii?Q?hN1F0zTyomuY22edO+p85NOcrUjTIcU/piGD2siN6s2zGNSyjjMaXkpu0ptG?= =?us-ascii?Q?idISqUEi9ZKhVUr0wHclv1s0qYWjhX1ncnfXQovG2WVJgPQOaHANvBjFh7LS?= =?us-ascii?Q?cvkeky3UILK4xyuPBX3HYUSOU+gPpPuVJhY+VuEi?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: d69cb1b1-3f25-473a-fbaf-08dd9a2ddfaa X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2025 19:13:17.4362 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Y04CTDLMS1fkieUcWyV2fvqIxIfcnFgbUq8eZ8B+/F4pW3qz+Zh6f/7ifwbt9wou X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8737 Content-Type: text/plain; charset="utf-8" During page isolation, the original migratetype is overwritten, since MIGRATE_* are enums and stored in pageblock bitmaps. Change MIGRATE_ISOLATE to be stored a standalone bit, PB_migrate_isolate, like PB_migrate_skip, so that migratetype is not lost during pageblock isolation. Signed-off-by: Zi Yan --- include/linux/page-isolation.h | 16 ++++++++++++++++ include/linux/pageblock-flags.h | 13 ++++++++++++- mm/page_alloc.c | 33 +++++++++++++++++++++++++++++++-- 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/include/linux/page-isolation.h b/include/linux/page-isolation.h index 277d8d92980c..fc021d3f95ca 100644 --- a/include/linux/page-isolation.h +++ b/include/linux/page-isolation.h @@ -11,6 +11,12 @@ static inline bool is_migrate_isolate(int migratetype) { return migratetype =3D=3D MIGRATE_ISOLATE; } +#define get_pageblock_isolate(page) \ + get_pfnblock_bit(page, page_to_pfn(page), PB_migrate_isolate) +#define clear_pageblock_isolate(page) \ + clear_pfnblock_bit(page, page_to_pfn(page), PB_migrate_isolate) +#define set_pageblock_isolate(page) \ + set_pfnblock_bit(page, page_to_pfn(page), PB_migrate_isolate) #else static inline bool is_migrate_isolate_page(struct page *page) { @@ -20,6 +26,16 @@ static inline bool is_migrate_isolate(int migratetype) { return false; } +static inline bool get_pageblock_isolate(struct page *page) +{ + return false; +} +static inline void clear_pageblock_isolate(struct page *page) +{ +} +static inline void set_pageblock_isolate(struct page *page) +{ +} #endif =20 #define MEMORY_OFFLINE 0x1 diff --git a/include/linux/pageblock-flags.h b/include/linux/pageblock-flag= s.h index 3acbb271a29a..f2f8540b95ca 100644 --- a/include/linux/pageblock-flags.h +++ b/include/linux/pageblock-flags.h @@ -20,7 +20,13 @@ enum pageblock_bits { PB_migrate_end =3D PB_migrate + PB_migratetype_bits - 1, /* 3 bits required for migrate types */ PB_migrate_skip,/* If set the block is skipped by compaction */ - +#ifdef CONFIG_MEMORY_ISOLATION + /* + * Pageblock isolation is represented with a separate bit, so that + * the migratetype of a block is not overwritten by isolation. + */ + PB_migrate_isolate, /* If set the block is isolated */ +#endif /* * Assume the bits will always align on a word. If this assumption * changes then get/set pageblock needs updating. @@ -32,6 +38,11 @@ enum pageblock_bits { =20 #define MIGRATETYPE_MASK ((1UL << (PB_migrate_end + 1)) - 1) =20 +#ifdef CONFIG_MEMORY_ISOLATION +#define MIGRATETYPE_AND_ISO_MASK \ + (((1UL << (PB_migrate_end + 1)) - 1) | BIT(PB_migrate_isolate)) +#endif + #if defined(CONFIG_HUGETLB_PAGE) =20 #ifdef CONFIG_HUGETLB_PAGE_SIZE_VARIABLE diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 0207164fcaf6..b2c623699461 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -360,8 +360,14 @@ get_pfnblock_bitmap_bitidx(const struct page *page, un= signed long pfn, unsigned long *bitmap; unsigned long word_bitidx; =20 +#ifdef CONFIG_MEMORY_ISOLATION + BUILD_BUG_ON(NR_PAGEBLOCK_BITS !=3D 8); + /* extra one for MIGRATE_ISOLATE */ + BUILD_BUG_ON(MIGRATE_TYPES > (1 << PB_migratetype_bits) + 1); +#else BUILD_BUG_ON(NR_PAGEBLOCK_BITS !=3D 4); BUILD_BUG_ON(MIGRATE_TYPES > (1 << PB_migratetype_bits)); +#endif VM_BUG_ON_PAGE(!zone_spans_pfn(page_zone(page), pfn), page); =20 bitmap =3D get_pageblock_bitmap(page, pfn); @@ -435,7 +441,20 @@ bool get_pfnblock_bit(const struct page *page, unsigne= d long pfn, __always_inline enum migratetype get_pfnblock_migratetype(const struct page *page, unsigned long pfn) { - return __get_pfnblock_flags_mask(page, pfn, MIGRATETYPE_MASK); + unsigned long mask =3D MIGRATETYPE_MASK; + unsigned long flags; + +#ifdef CONFIG_MEMORY_ISOLATION + mask =3D MIGRATETYPE_AND_ISO_MASK; +#endif + + flags =3D __get_pfnblock_flags_mask(page, pfn, mask); + +#ifdef CONFIG_MEMORY_ISOLATION + if (flags & BIT(PB_migrate_isolate)) + return MIGRATE_ISOLATE; +#endif + return flags & MIGRATETYPE_MASK; } =20 /** @@ -513,12 +532,22 @@ void clear_pfnblock_bit(const struct page *page, unsi= gned long pfn, __always_inline void set_pageblock_migratetype(struct page *page, enum migratetype migratetype) { + unsigned long mask =3D MIGRATETYPE_MASK; + if (unlikely(page_group_by_mobility_disabled && migratetype < MIGRATE_PCPTYPES)) migratetype =3D MIGRATE_UNMOVABLE; =20 +#ifdef CONFIG_MEMORY_ISOLATION + if (migratetype =3D=3D MIGRATE_ISOLATE) { + set_pfnblock_bit(page, page_to_pfn(page), PB_migrate_isolate); + return; + } + /* change mask to clear PB_migrate_isolate if it is set */ + mask =3D MIGRATETYPE_AND_ISO_MASK; +#endif __set_pfnblock_flags_mask(page, page_to_pfn(page), - (unsigned long)migratetype, MIGRATETYPE_MASK); + (unsigned long)migratetype, mask); } =20 #ifdef CONFIG_DEBUG_VM --=20 2.47.2 From nobody Fri Dec 19 16:07:32 2025 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2051.outbound.protection.outlook.com [40.107.243.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A9F329B8F7 for ; Fri, 23 May 2025 19:13:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748027607; cv=fail; b=uF48l7LAHVEbP1QCfzG4xt6wfpz+uPc34tS78+/Gmbaczqryy0vfqcANezT8tVQaI9oApXKvagazOAU9q72qgkOEwmdN/+W5wR6Iu0OyW5U2MGIQMXCOiOFRhprhfZBDbclGN8GgK7fet24+voUl7Le+JnaAov9w1Hlaxou77Dk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748027607; c=relaxed/simple; bh=6EWWL7W9ceh4iOFdwK+4zl5iblwWh90pF7L6+PUiux8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=mEcoru7AldCx+bfFcfiUG2kwKbb2GWwSu/IM0SskGzwpdYNQmYDjrArtChqKaOw/Tin+5GSIC1n/BCU623REXTi562TvtMnplEC8TSAnVwJPMwBJmjJ6UYYkMA3WwZTLmLguZabZ07kfQRRbSeWAQBn9iOH0+6cQspWQ5U4yR6E= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=RcaBvYYU; arc=fail smtp.client-ip=40.107.243.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="RcaBvYYU" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hyl1A+DoK9trSyXgkB/ApTTTFhtbrQ3y6hFXZvwhB9pN363jdgBbHnJyEDG2uRVlZZQ4SB4vsgYQyYOAK5d2zU7vx3dNfSri4zlBri5RgHBf9uTJE15rV+0bw7VhpzBIXh8+qaXDSdRH7HByRSFUwnBm9W8MAgcidUv6WFNvjGYYmciXolXRCm4sr5AfmVK7ZWuEc8BGVuLeGkvw+CB86cEh4q6BTj5wRZ+BQSQnzbgJjkQGccLGtuvSKTyw3mepGTaV2CSBmNXkLvvxxc8h87Mvg9iCwqpoTQR3NdIZVF4EyLgyO8fSqIze5Ldkn23e4yhYsROHzHYc2BBB6/GxPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Nq6BItPI7CaktlEy3uoEPSTvMgNx147oHoj3GeZ2Mgg=; b=WIq9JpvGbLPDvoWN+aDiSLV5LfSBDUxT8IFp1F6fBoplRTdEsnGqr20UxoZdD2USVP4gpYedzcu2tFoceF486RTWIBgTwdi3FzaogvnWCKaCMWIWG3tQZVpBvP32A+yZxES0mVed+6XoO3ocj8bLvm/VyJhi/gnIs/hI+E7xhS/7ESqz6ON+q0vHpgLTK4OHaE4xbnYqYnIwPfkpbFISRhlIU4hNny/k5IXHraGr1RPMYvSjcMR8eot0VgkxLChndcpzG95aSF0UMW3DtWafjC5+qt6PjfOMtaVwnYSlzegreQ6avjuAPV7C1hdpSKwedBJ9ndSDDb6cjMdWxtlbbQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Nq6BItPI7CaktlEy3uoEPSTvMgNx147oHoj3GeZ2Mgg=; b=RcaBvYYUK7cxl+ab991uenX9tkozmYsJ2brh9RKY5xnroJaau1iVpmAqpi5flodIa0yjLYPUhljMFwGt8QdUh5kV11gnGnAPo604ReTYKL6uNIJevSaqFXbQUUAUN+E6xgu/8OzbJFnzuQwd7g/+J1t1r+FrxF2JsAu0DOOXJbEehbkF4Rs5GGK1koEhgNqSng2KSZ7qIDJEL2ha9t4OpYXmnHRzDoquW2A7kVqLQ+IQU7atVnuLNgvN7NThdvGj6PEworLEXLJ+FwPF27dcy4LEVHWkKxeV/TkkfBFI/TFi0eLHyP/yxmCs/noQoo2J2HWekmIi+Zc+riXHCNzrLg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by SJ2PR12MB8737.namprd12.prod.outlook.com (2603:10b6:a03:545::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8769.21; Fri, 23 May 2025 19:13:19 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%5]) with mapi id 15.20.8746.030; Fri, 23 May 2025 19:13:19 +0000 From: Zi Yan To: David Hildenbrand , Johannes Weiner , linux-mm@kvack.org Cc: Andrew Morton , Oscar Salvador , Vlastimil Babka , Baolin Wang , "Kirill A . Shutemov" , Mel Gorman , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Richard Chang , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v5 3/6] mm/page_alloc: add support for initializing pageblock as isolated. Date: Fri, 23 May 2025 15:12:55 -0400 Message-ID: <20250523191258.339826-4-ziy@nvidia.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250523191258.339826-1-ziy@nvidia.com> References: <20250523191258.339826-1-ziy@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BL1PR13CA0029.namprd13.prod.outlook.com (2603:10b6:208:256::34) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|SJ2PR12MB8737:EE_ X-MS-Office365-Filtering-Correlation-Id: 179ccae7-60e5-407a-242f-08dd9a2de0a8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?F1oTAJ0smVHD7s7dd7VNNhKpPzl7jkzHbMDAQs40d0GJms2jZx4ul2SFOkWE?= =?us-ascii?Q?91UwzrgmWdi59qDnjo/aFreIa5LqOsj4goGoce5c9N98xyBGn34MBtdfM6iM?= =?us-ascii?Q?wt/UyUZ+7Tlz0jRGXq05M5HURQhGRFCSBpZkoBG3rF1QaMd/eswVqjKzaJQw?= =?us-ascii?Q?E5SJZqfenPt5G81cU+OPG/s8kh/lsrb5egNBxMttokeHsQkySV2OjUH86v6A?= =?us-ascii?Q?o7IztiKPC+Sk0ggL9Q2Mu1HVZvWYk3fRoXMmppBT3GXtNRAjaEqIYZ0NFUKw?= =?us-ascii?Q?DISXLhfB3MwTF/Hs/1igoKJY06F1gTeP1rPcXnV7nTyC/4Kgu8hpV9LAR5Da?= =?us-ascii?Q?9Z0/gtw5/32Hupp8Z3v1wSyySLdbusnV8g6pmLWnCMv1ZLJ4lDiqdB6900Tj?= =?us-ascii?Q?MTyGaVVGExLFB1TzXoyjpiHNAO+upGr/r00Y+6GsQZwggZlN2YxLlTBADtbw?= =?us-ascii?Q?+FRmeNB6BRWtaj8gm0uilEsheqU+cNtEWfaTRC4L4CJ246+OWfsvHTI/eoQk?= =?us-ascii?Q?1xXw1iuLKTjSYigpa++oa7EN1HaIhcZAYRYuuiWX7M39X4LBjUYnSaxpbM8C?= =?us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P:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB9473.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(7416014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?vHJIbvlXi8mblhg+A7aXVfb/Xz5Ga5zTfTqzlD5xio7R9hwMrXY3Qi+vL6hR?= =?us-ascii?Q?ZuD/lzZSEMglg3KXxP0nu5Aa4S045NmYBPTsKue+Uo5ooZNNE5vqELvSa2q1?= =?us-ascii?Q?szSHGVAVoAsHgQzYSNNDZk7NeJP5+/9nnGcsJgeN3IXsm/xhySfbtyCCkAZc?= =?us-ascii?Q?LmaZDhEVzd5jPArCL1pnfOAGTf9AKe470yGDnLad4jcKKPPRtQRHyh+DQKS+?= =?us-ascii?Q?9/fLBRB2CQ2FkLRb0hFUUOdpiFm/ST9ghe0IZCctP4Z0i/UqYbfNgPwan3ZQ?= =?us-ascii?Q?G85voAPt0v2nR4RKBz7u1rtDFDe2Az/dKtfM6+cu9xacTGs6cHD7UERy+Tre?= =?us-ascii?Q?ii8B4urFQ/nAwSPO8sqkNHALyJnDXePIteBsSN0eKO2V5S4C1IBKVhROOvNt?= =?us-ascii?Q?n8vQNKsrwcChtlhH+09BS0W/mRogsJkP/cO7d+cGLTbklOWcQoQ+vwSHIAOg?= =?us-ascii?Q?RXBzcdq+EMhvWcu2rz4jcVuJ0ybuBtVAVhlgcj+y9F8IylTYlTbGpULA/oaT?= =?us-ascii?Q?rqlXpB2om+f1La9LJ0zrHj/OsLp0fAbxkKmxKnDUynSL9tIayxQpKlkuBonr?= =?us-ascii?Q?lHMUG457xvapUPAKPLkeW/kDpB68CcnzUOvJ0doKe577wlhl5XeSRooTD+nb?= =?us-ascii?Q?re4U+B46UlF02fdQCUsaXlV3LAzR3R5CV4ljjKs7T3748lfQS0+s4V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1sJYd/+zYfBiR+ue?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 179ccae7-60e5-407a-242f-08dd9a2de0a8 X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2025 19:13:19.0838 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: C7k9tTiEGGq2WFhU/VXTDR6QHAc0X8FXSvNDo+d0oxUa5W+rq07Y3uH5IawaJ21F X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8737 Content-Type: text/plain; charset="utf-8" MIGRATE_ISOLATE is a standalone bit, so a pageblock cannot be initialized to just MIGRATE_ISOLATE. Add init_pageblock_migratetype() to enable initialize a pageblock with a migratetype and isolated. Signed-off-by: Zi Yan Reviewed-by: Vlastimil Babka --- include/linux/memory_hotplug.h | 3 ++- include/linux/page-isolation.h | 3 +++ mm/hugetlb.c | 4 ++-- mm/internal.h | 3 ++- mm/memory_hotplug.c | 12 ++++++++---- mm/memremap.c | 2 +- mm/mm_init.c | 24 +++++++++++++++--------- mm/page_alloc.c | 26 ++++++++++++++++++++++++++ 8 files changed, 59 insertions(+), 18 deletions(-) diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index eaac5ae8c05c..23f038a16231 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -314,7 +314,8 @@ extern int add_memory_driver_managed(int nid, u64 start= , u64 size, mhp_t mhp_flags); extern void move_pfn_range_to_zone(struct zone *zone, unsigned long start_= pfn, unsigned long nr_pages, - struct vmem_altmap *altmap, int migratetype); + struct vmem_altmap *altmap, int migratetype, + bool isolate_pageblock); extern void remove_pfn_range_from_zone(struct zone *zone, unsigned long start_pfn, unsigned long nr_pages); diff --git a/include/linux/page-isolation.h b/include/linux/page-isolation.h index fc021d3f95ca..14c6a5f691c2 100644 --- a/include/linux/page-isolation.h +++ b/include/linux/page-isolation.h @@ -41,6 +41,9 @@ static inline void set_pageblock_isolate(struct page *pag= e) #define MEMORY_OFFLINE 0x1 #define REPORT_FAILURE 0x2 =20 +void __meminit init_pageblock_migratetype(struct page *page, + enum migratetype migratetype, + bool isolate); void set_pageblock_migratetype(struct page *page, enum migratetype migrate= type); =20 bool move_freepages_block_isolate(struct zone *zone, struct page *page, diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 5a0bf1ea48f9..001c8ad48819 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3311,8 +3311,8 @@ static void __init hugetlb_bootmem_init_migratetype(s= truct folio *folio, if (folio_test_hugetlb_cma(folio)) init_cma_pageblock(folio_page(folio, i)); else - set_pageblock_migratetype(folio_page(folio, i), - MIGRATE_MOVABLE); + init_pageblock_migratetype(folio_page(folio, i), + MIGRATE_MOVABLE, false); } } =20 diff --git a/mm/internal.h b/mm/internal.h index 6b8ed2017743..c43180bea6b4 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -821,7 +821,8 @@ extern void *memmap_alloc(phys_addr_t size, phys_addr_t= align, int nid, bool exact_nid); =20 void memmap_init_range(unsigned long, int, unsigned long, unsigned long, - unsigned long, enum meminit_context, struct vmem_altmap *, int); + unsigned long, enum meminit_context, struct vmem_altmap *, int, + bool); =20 #if defined CONFIG_COMPACTION || defined CONFIG_CMA =20 diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 4ce5210ea56e..43ac34ee8d2e 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -770,7 +770,8 @@ static inline void section_taint_zone_device(unsigned l= ong pfn) */ void move_pfn_range_to_zone(struct zone *zone, unsigned long start_pfn, unsigned long nr_pages, - struct vmem_altmap *altmap, int migratetype) + struct vmem_altmap *altmap, int migratetype, + bool isolate_pageblock) { struct pglist_data *pgdat =3D zone->zone_pgdat; int nid =3D pgdat->node_id; @@ -802,7 +803,8 @@ void move_pfn_range_to_zone(struct zone *zone, unsigned= long start_pfn, * are reserved so nobody should be touching them so we should be safe */ memmap_init_range(nr_pages, nid, zone_idx(zone), start_pfn, 0, - MEMINIT_HOTPLUG, altmap, migratetype); + MEMINIT_HOTPLUG, altmap, migratetype, + isolate_pageblock); =20 set_zone_contiguous(zone); } @@ -1127,7 +1129,8 @@ int mhp_init_memmap_on_memory(unsigned long pfn, unsi= gned long nr_pages, if (mhp_off_inaccessible) page_init_poison(pfn_to_page(pfn), sizeof(struct page) * nr_pages); =20 - move_pfn_range_to_zone(zone, pfn, nr_pages, NULL, MIGRATE_UNMOVABLE); + move_pfn_range_to_zone(zone, pfn, nr_pages, NULL, MIGRATE_UNMOVABLE, + false); =20 for (i =3D 0; i < nr_pages; i++) { struct page *page =3D pfn_to_page(pfn + i); @@ -1192,7 +1195,8 @@ int online_pages(unsigned long pfn, unsigned long nr_= pages, =20 =20 /* associate pfn range with the zone */ - move_pfn_range_to_zone(zone, pfn, nr_pages, NULL, MIGRATE_ISOLATE); + move_pfn_range_to_zone(zone, pfn, nr_pages, NULL, MIGRATE_MOVABLE, + true); =20 arg.start_pfn =3D pfn; arg.nr_pages =3D nr_pages; diff --git a/mm/memremap.c b/mm/memremap.c index c417c843e9b1..3319e7cc2898 100644 --- a/mm/memremap.c +++ b/mm/memremap.c @@ -254,7 +254,7 @@ static int pagemap_range(struct dev_pagemap *pgmap, str= uct mhp_params *params, zone =3D &NODE_DATA(nid)->node_zones[ZONE_DEVICE]; move_pfn_range_to_zone(zone, PHYS_PFN(range->start), PHYS_PFN(range_len(range)), params->altmap, - MIGRATE_MOVABLE); + MIGRATE_MOVABLE, false); } =20 mem_hotplug_done(); diff --git a/mm/mm_init.c b/mm/mm_init.c index 1c5444e188f8..a3d9ea02e07b 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -685,7 +685,8 @@ void __meminit __init_page_from_nid(unsigned long pfn, = int nid) __init_single_page(pfn_to_page(pfn), pfn, zid, nid); =20 if (pageblock_aligned(pfn)) - set_pageblock_migratetype(pfn_to_page(pfn), MIGRATE_MOVABLE); + init_pageblock_migratetype(pfn_to_page(pfn), MIGRATE_MOVABLE, + false); } =20 #ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT @@ -874,7 +875,8 @@ static void __init init_unavailable_range(unsigned long= spfn, void __meminit memmap_init_range(unsigned long size, int nid, unsigned lon= g zone, unsigned long start_pfn, unsigned long zone_end_pfn, enum meminit_context context, - struct vmem_altmap *altmap, int migratetype) + struct vmem_altmap *altmap, int migratetype, + bool isolate_pageblock) { unsigned long pfn, end_pfn =3D start_pfn + size; struct page *page; @@ -931,7 +933,8 @@ void __meminit memmap_init_range(unsigned long size, in= t nid, unsigned long zone * over the place during system boot. */ if (pageblock_aligned(pfn)) { - set_pageblock_migratetype(page, migratetype); + init_pageblock_migratetype(page, migratetype, + isolate_pageblock); cond_resched(); } pfn++; @@ -954,7 +957,8 @@ static void __init memmap_init_zone_range(struct zone *= zone, return; =20 memmap_init_range(end_pfn - start_pfn, nid, zone_id, start_pfn, - zone_end_pfn, MEMINIT_EARLY, NULL, MIGRATE_MOVABLE); + zone_end_pfn, MEMINIT_EARLY, NULL, MIGRATE_MOVABLE, + false); =20 if (*hole_pfn < start_pfn) init_unavailable_range(*hole_pfn, start_pfn, zone_id, nid); @@ -1035,7 +1039,7 @@ static void __ref __init_zone_device_page(struct page= *page, unsigned long pfn, * because this is done early in section_activate() */ if (pageblock_aligned(pfn)) { - set_pageblock_migratetype(page, MIGRATE_MOVABLE); + init_pageblock_migratetype(page, MIGRATE_MOVABLE, false); cond_resched(); } =20 @@ -1996,7 +2000,8 @@ static void __init deferred_free_pages(unsigned long = pfn, /* Free a large naturally-aligned chunk if possible */ if (nr_pages =3D=3D MAX_ORDER_NR_PAGES && IS_MAX_ORDER_ALIGNED(pfn)) { for (i =3D 0; i < nr_pages; i +=3D pageblock_nr_pages) - set_pageblock_migratetype(page + i, MIGRATE_MOVABLE); + init_pageblock_migratetype(page + i, MIGRATE_MOVABLE, + false); __free_pages_core(page, MAX_PAGE_ORDER, MEMINIT_EARLY); return; } @@ -2006,7 +2011,8 @@ static void __init deferred_free_pages(unsigned long = pfn, =20 for (i =3D 0; i < nr_pages; i++, page++, pfn++) { if (pageblock_aligned(pfn)) - set_pageblock_migratetype(page, MIGRATE_MOVABLE); + init_pageblock_migratetype(page, MIGRATE_MOVABLE, + false); __free_pages_core(page, 0, MEMINIT_EARLY); } } @@ -2305,7 +2311,7 @@ void __init init_cma_reserved_pageblock(struct page *= page) set_page_count(p, 0); } while (++p, --i); =20 - set_pageblock_migratetype(page, MIGRATE_CMA); + init_pageblock_migratetype(page, MIGRATE_CMA, false); set_page_refcounted(page); /* pages were reserved and not allocated */ clear_page_tag_ref(page); @@ -2319,7 +2325,7 @@ void __init init_cma_reserved_pageblock(struct page *= page) */ void __init init_cma_pageblock(struct page *page) { - set_pageblock_migratetype(page, MIGRATE_CMA); + init_pageblock_migratetype(page, MIGRATE_CMA, false); adjust_managed_page_count(page, pageblock_nr_pages); page_zone(page)->cma_pages +=3D pageblock_nr_pages; } diff --git a/mm/page_alloc.c b/mm/page_alloc.c index b2c623699461..8fcbd7fa13c2 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -550,6 +550,32 @@ __always_inline void set_pageblock_migratetype(struct = page *page, (unsigned long)migratetype, mask); } =20 +void __meminit init_pageblock_migratetype(struct page *page, + enum migratetype migratetype, + bool isolate) +{ + unsigned long mask =3D MIGRATETYPE_MASK; + unsigned long flags =3D migratetype; + + if (unlikely(page_group_by_mobility_disabled && + migratetype < MIGRATE_PCPTYPES)) + migratetype =3D MIGRATE_UNMOVABLE; + +#ifdef CONFIG_MEMORY_ISOLATION + if (migratetype =3D=3D MIGRATE_ISOLATE) { + VM_WARN_ONCE( + 1, + "Set isolate=3Dtrue to isolate pageblock with a migratetype"); + return; + } + if (isolate) { + mask =3D MIGRATETYPE_AND_ISO_MASK; + flags |=3D BIT(PB_migrate_isolate); + } +#endif + __set_pfnblock_flags_mask(page, page_to_pfn(page), flags, mask); +} + #ifdef CONFIG_DEBUG_VM static int page_outside_zone_boundaries(struct zone *zone, struct page *pa= ge) { --=20 2.47.2 From nobody Fri Dec 19 16:07:32 2025 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2051.outbound.protection.outlook.com [40.107.243.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2EC8B29C339 for ; Fri, 23 May 2025 19:13:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748027609; cv=fail; b=mSBSx3gUQ3qAvb8qPDbvlGZO6LIlNbjt0ehICiBeJcNbnfYQiHmgSqVu6xL4EwedTLe3GZnqIdMbNBQACjFn08LblhWc3VerzTnIP/uzhpOwZID30SzUdVcKF2D+fgSj2ZXggsuojhH5eRU6uNSGMEhQI2mu8lthusppg6XU7Bs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748027609; c=relaxed/simple; bh=OUdGfhRwiIyvvyeknpF6ODQg+aXrcpgxdAMOuwAKwz8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=K3HxjYMMHg5Ip5d7Xvfi2epVtWRIpdubgzngdt17zNvuQREmXtEuqUL5uu/DKix9VUAMwsSY4b/mNiQxsKcWd+n4lkHGyz3a+RUgQkpxberXNKwZV7FrG07E0EFK6beoHc9+3foikjlrY3HksYBzWYlyAaI1TWXs/G8canwcERU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=Pqn1CXOX; arc=fail smtp.client-ip=40.107.243.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="Pqn1CXOX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jlgfJFtsj6e6vKoPrFT5khpRLFk4PWhNuGDUr0gB7YTMCtgNCJK25AIxaicfngnCxDjKYjkGzpL0R0Hc1GMlPUdLI1CTMyD+u11K2XVXuHfHVvX9xS+dc1ML4HfT7DflQAJXQMJGYMpUoLFY8Hoi9Ugbd2lboHx/eJz7g6tczVxQnIXnysxQZy1BoM6OBc44XLfVG1Qm0pTYz4VSMbl3aA5sji7CLHv1DG84ievMv9HWZ0UAeNk42EHf+lUb7Qpyhz1VhRDoZ7wLd6dFScyiKVyAkoqY3txxswW9cJ2sOU2+ro+cZ1MZlbDFAe6B7sbXnldo/8hxyOwZi/2fbrYmmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UTdTDcqx9F40HQdpZ8OgJjE0444u38OVVyqU1iKegxA=; b=vyisrwsZgQat8qnn0q2TWEnU4Gba+zvzb/wCWwRg01fRK8R6zfLia8p3IPodW6Y9ZFSrzst3vp7ttplY5COkRxevd8C1Cj/o+ScA02EtrRwGgpA3ES6m4PYr6OJ5yPKQHYkUnzBtu42bE01jFyX4gwM1RTyRyIimlFN2fjTKfkFPIw+jgDaArcRb6waXaPBSutOg79ECuE0+ZZYEln8+XZOcdQjqEzkZoEf+1jbG9Q1bL5ueOfMVL5eMXWuFCCTM0N4m+txzrO/A3yj17u/N8CMTOp5o2rxHreXVpB1FvXyoRYM9TetXjehLCDEASxTPmzPW/ZdMj9wYrUESLK/U2w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UTdTDcqx9F40HQdpZ8OgJjE0444u38OVVyqU1iKegxA=; b=Pqn1CXOXZzqTlf0BSruSHhyT7WlzW9TokYIawAMVkB2SGuACveKQVybP1gaEyWd2vo8ifq7GUw8yoKmDG71YegVrL3PrNp1141FFOAxVnP1gmygCeYSPKdt8TYAPU8d0cikJ7BeEnswzLIZa4iYT6HjOGP2mDViDQjNZ6Ws3upDXLbXiBQhL7G40QEqm/UiKBJeMVB4tPlU+oBbExUSsqwC0wdjk7g2IGnZ8j2Jt7ioh9gxcSKNBTRYpIbr5OEB3FBz/sKjDRJ+ha/2R5pjbI9fJ0o0TIeIIOoHp31negY3f/Phih8bdjkeM3ygdmxL1QNIM9B1NshPSKf9SE++pBA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by SJ2PR12MB8737.namprd12.prod.outlook.com (2603:10b6:a03:545::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8769.21; Fri, 23 May 2025 19:13:20 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%5]) with mapi id 15.20.8746.030; Fri, 23 May 2025 19:13:20 +0000 From: Zi Yan To: David Hildenbrand , Johannes Weiner , linux-mm@kvack.org Cc: Andrew Morton , Oscar Salvador , Vlastimil Babka , Baolin Wang , "Kirill A . Shutemov" , Mel Gorman , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Richard Chang , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v5 4/6] mm/page_isolation: remove migratetype from move_freepages_block_isolate() Date: Fri, 23 May 2025 15:12:56 -0400 Message-ID: <20250523191258.339826-5-ziy@nvidia.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250523191258.339826-1-ziy@nvidia.com> References: <20250523191258.339826-1-ziy@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BL1PR13CA0020.namprd13.prod.outlook.com (2603:10b6:208:256::25) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|SJ2PR12MB8737:EE_ X-MS-Office365-Filtering-Correlation-Id: da989298-337d-4e89-b766-08dd9a2de168 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?uK5iok49NbCqPt67K+ndUSinvOXHA0aQ66+SZsGr7UUwzmUkXYxfQT6a7wx4?= =?us-ascii?Q?jsGXOD5VhknNUdePwOVmPjBpgQHZ72dqYHhUSJeJXMZUzubE96oTUFiFZbJW?= =?us-ascii?Q?sdLbhV8v8+4UaAUHOcvq3GA3NybfifWSVFekmJbqqNUAQ1NYbvt//OeSqplU?= =?us-ascii?Q?1tCH/i3CAO8YJp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gpmY2Ky?= =?us-ascii?Q?pLFJmVMAtj5D3M49z7O0RA++iO1uKofuYuIRrw2pMXDwX5gLgEwmv/qw3wlZ?= =?us-ascii?Q?erRtK2AfGA37u/wGZyRPLiqLIKvx45V2ryE4SS9fVwiU0NrfaF61KJgRgNPT?= =?us-ascii?Q?XFJuZe+qEDXLs7hfPFTUCU1/jcsTafan/DUICOL9txhByf+K2mG3g1ziL/BJ?= =?us-ascii?Q?JaJTnOXJTG6jvu+nOroa6b6eSxqsTDCVjVWhoATQVqgeLG6leoQ6EvHo8uEg?= =?us-ascii?Q?3zS7EIq2ZdOgn+/DOprAO0/LeSbz14J3gAePlK2bpXrnwFlYDC7q/EPCHzLr?= =?us-ascii?Q?cqUrtxRQA87bFGNcIB6m0+FFHfSJWZQ/dv+xSPHuFyDU6oAFvXVPu87UyyOU?= =?us-ascii?Q?A7qZ4S4FNwU=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB9473.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(7416014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?CZnlsABu1+p87v5ckQfqt8fvub40tMXxqYSyeGA4JkUUz9uI5Hyj+oNGDs4a?= =?us-ascii?Q?sGK9NwT0mCQrqr0hPqo6meWrpstoA7Yg5TWC7mUAYQl4r3OX5vP7r++tFAuc?= =?us-ascii?Q?hZRXeBAkR/c61NKE8qKnXL7ME5gaUezT6Y85ABK3GC+Aoj6moAKJy1V8MrwY?= =?us-ascii?Q?OR/Thry6zt4SNx5TpOlR+Ef1tyiPRo5mdN1IUCltyZqVeEuO0r60ages520S?= =?us-ascii?Q?HHYQuaTMj9AF88y0DeYyeGO9PGO/r1EaAC60Hux77l8iZT2kCp/1hq4yd71v?= =?us-ascii?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yGJdC0YIeumE?= =?us-ascii?Q?RmOnvWj9S6W/8UJwcPazPxqOUc3sSzd/NlDd6q27QS9d0Hh4q6eBduIkHutI?= =?us-ascii?Q?kBKSpHBteKpiDmId1Na+KkrBaDrPb2yekCOj8mw20a3DIXk9GSaQiF+B58RI?= =?us-ascii?Q?pIyXpNuMHv4nVrMejbUhzf3iNx7s358NGkTBvP9nk7TnSw2vwYxr8qDKEHpL?= =?us-ascii?Q?NDRS4BrEYiCw/N09a3lJnEJQYhYaEf/Vdjr1To4sD5QOVt46EMILxQVT51B4?= =?us-ascii?Q?gu8rdadFgd6okM91OgHzAEVRXMc7YA6k0wa+lxfDJ9kCKNkzNPnuxh0ylytY?= =?us-ascii?Q?4gKXpDOE+reX9oajwQ5XEb2jY6tMiSRcYSisPE0d8zeULYvQfk0SyozrbA6/?= =?us-ascii?Q?9oKktmYMKtj2a1HknIsh0BKnGF3SnJ1BRrv2oXtB?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: da989298-337d-4e89-b766-08dd9a2de168 X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2025 19:13:20.4271 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: J1EivfHWH1RkJs2BRGjR72sjNq/091CerWpkCNjz/YDuUf6RVgbV2WjGyeJMdBfI X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8737 Content-Type: text/plain; charset="utf-8" Since migratetype is no longer overwritten during pageblock isolation, moving a pageblock out of MIGRATE_ISOLATE no longer needs a new migratetype. Add pageblock_isolate_and_move_free_pages() and pageblock_unisolate_and_move_free_pages() to be explicit about the page isolation operations. Both share the common code in __move_freepages_block_isolate(), which is renamed from move_freepages_block_isolate(). Add toggle_pageblock_isolate() to flip pageblock isolation bit in __move_freepages_block_isolate(). Make set_pageblock_migratetype() only accept non MIGRATE_ISOLATE types, so that one should use set_pageblock_isolate() to isolate pageblocks. As a result, move pageblock migratetype code out of __move_freepages_block(). Signed-off-by: Zi Yan --- include/linux/page-isolation.h | 5 +- mm/page_alloc.c | 97 ++++++++++++++++++++++++++++------ mm/page_isolation.c | 21 ++++---- 3 files changed, 92 insertions(+), 31 deletions(-) diff --git a/include/linux/page-isolation.h b/include/linux/page-isolation.h index 14c6a5f691c2..7241a6719618 100644 --- a/include/linux/page-isolation.h +++ b/include/linux/page-isolation.h @@ -44,10 +44,9 @@ static inline void set_pageblock_isolate(struct page *pa= ge) void __meminit init_pageblock_migratetype(struct page *page, enum migratetype migratetype, bool isolate); -void set_pageblock_migratetype(struct page *page, enum migratetype migrate= type); =20 -bool move_freepages_block_isolate(struct zone *zone, struct page *page, - int migratetype); +bool pageblock_isolate_and_move_free_pages(struct zone *zone, struct page = *page); +bool pageblock_unisolate_and_move_free_pages(struct zone *zone, struct pag= e *page); =20 int start_isolate_page_range(unsigned long start_pfn, unsigned long end_pf= n, int migratetype, int flags); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 8fcbd7fa13c2..44a08b1a9de4 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -524,13 +524,36 @@ void clear_pfnblock_bit(const struct page *page, unsi= gned long pfn, __clear_bit(bitidx + pb_bit, bitmap_word); } =20 +#ifdef CONFIG_MEMORY_ISOLATION +/** + * toggle_pfnblock_bit - Toggle a standalone bit of a pageblock + * @page: The page within the block of interest + * @pfn: The target page frame number + * @pb_bit: pageblock bit to toggle + */ +static void toggle_pfnblock_bit(const struct page *page, unsigned long pfn, + enum pageblock_bits pb_bit) +{ + unsigned long *bitmap_word; + unsigned long bitidx; + + if (WARN_ON_ONCE(pb_bit <=3D PB_migrate_end || + pb_bit >=3D __NR_PAGEBLOCK_BITS)) + return; + + get_pfnblock_bitmap_bitidx(page, pfn, &bitmap_word, &bitidx); + + __change_bit(bitidx + pb_bit, bitmap_word); +} +#endif + /** * set_pageblock_migratetype - Set the migratetype of a pageblock * @page: The page within the block of interest * @migratetype: migratetype to set */ -__always_inline void set_pageblock_migratetype(struct page *page, - enum migratetype migratetype) +static void set_pageblock_migratetype(struct page *page, + enum migratetype migratetype) { unsigned long mask =3D MIGRATETYPE_MASK; =20 @@ -540,11 +563,15 @@ __always_inline void set_pageblock_migratetype(struct= page *page, =20 #ifdef CONFIG_MEMORY_ISOLATION if (migratetype =3D=3D MIGRATE_ISOLATE) { - set_pfnblock_bit(page, page_to_pfn(page), PB_migrate_isolate); + VM_WARN_ONCE(1, + "Use set_pageblock_isolate() for pageblock isolation"); return; } /* change mask to clear PB_migrate_isolate if it is set */ mask =3D MIGRATETYPE_AND_ISO_MASK; + VM_WARN_ONCE(get_pfnblock_bit(page, page_to_pfn(page), + PB_migrate_isolate), + "Use clear_pageblock_isolate() to unisolate pageblock"); #endif __set_pfnblock_flags_mask(page, page_to_pfn(page), (unsigned long)migratetype, mask); @@ -1931,8 +1958,8 @@ static inline struct page *__rmqueue_cma_fallback(str= uct zone *zone, #endif =20 /* - * Change the type of a block and move all its free pages to that - * type's freelist. + * Move all free pages of a block to new type's freelist. Caller needs to + * change the block type. */ static int __move_freepages_block(struct zone *zone, unsigned long start_p= fn, int old_mt, int new_mt) @@ -1964,8 +1991,6 @@ static int __move_freepages_block(struct zone *zone, = unsigned long start_pfn, pages_moved +=3D 1 << order; } =20 - set_pageblock_migratetype(pfn_to_page(start_pfn), new_mt); - return pages_moved; } =20 @@ -2023,11 +2048,16 @@ static int move_freepages_block(struct zone *zone, = struct page *page, int old_mt, int new_mt) { unsigned long start_pfn; + int res; =20 if (!prep_move_freepages_block(zone, page, &start_pfn, NULL, NULL)) return -1; =20 - return __move_freepages_block(zone, start_pfn, old_mt, new_mt); + res =3D __move_freepages_block(zone, start_pfn, old_mt, new_mt); + set_pageblock_migratetype(pfn_to_page(start_pfn), new_mt); + + return res; + } =20 #ifdef CONFIG_MEMORY_ISOLATION @@ -2055,11 +2085,16 @@ static unsigned long find_large_buddy(unsigned long= start_pfn) return start_pfn; } =20 +static inline void toggle_pageblock_isolate(struct page *page) +{ + toggle_pfnblock_bit(page, page_to_pfn(page), PB_migrate_isolate); +} + /** - * move_freepages_block_isolate - move free pages in block for page isolat= ion + * __move_freepages_block_isolate - move free pages in block for page isol= ation * @zone: the zone * @page: the pageblock page - * @migratetype: migratetype to set on the pageblock + * @isolate: to isolate the given pageblock or unisolate it * * This is similar to move_freepages_block(), but handles the special * case encountered in page isolation, where the block of interest @@ -2074,10 +2109,15 @@ static unsigned long find_large_buddy(unsigned long= start_pfn) * * Returns %true if pages could be moved, %false otherwise. */ -bool move_freepages_block_isolate(struct zone *zone, struct page *page, - int migratetype) +static bool __move_freepages_block_isolate(struct zone *zone, + struct page *page, bool isolate) { unsigned long start_pfn, pfn; + int from_mt; + int to_mt; + + if (isolate =3D=3D get_pageblock_isolate(page)) + return false; =20 if (!prep_move_freepages_block(zone, page, &start_pfn, NULL, NULL)) return false; @@ -2094,7 +2134,7 @@ bool move_freepages_block_isolate(struct zone *zone, = struct page *page, =20 del_page_from_free_list(buddy, zone, order, get_pfnblock_migratetype(buddy, pfn)); - set_pageblock_migratetype(page, migratetype); + toggle_pageblock_isolate(page); split_large_buddy(zone, buddy, pfn, order, FPI_NONE); return true; } @@ -2105,16 +2145,38 @@ bool move_freepages_block_isolate(struct zone *zone= , struct page *page, =20 del_page_from_free_list(page, zone, order, get_pfnblock_migratetype(page, pfn)); - set_pageblock_migratetype(page, migratetype); + toggle_pageblock_isolate(page); split_large_buddy(zone, page, pfn, order, FPI_NONE); return true; } move: - __move_freepages_block(zone, start_pfn, - get_pfnblock_migratetype(page, start_pfn), - migratetype); + /* Use MIGRATETYPE_MASK to get non-isolate migratetype */ + if (isolate) { + from_mt =3D __get_pfnblock_flags_mask(page, page_to_pfn(page), + MIGRATETYPE_MASK); + to_mt =3D MIGRATE_ISOLATE; + } else { + from_mt =3D MIGRATE_ISOLATE; + to_mt =3D __get_pfnblock_flags_mask(page, page_to_pfn(page), + MIGRATETYPE_MASK); + } + + __move_freepages_block(zone, start_pfn, from_mt, to_mt); + toggle_pageblock_isolate(pfn_to_page(start_pfn)); + return true; } + +bool pageblock_isolate_and_move_free_pages(struct zone *zone, struct page = *page) +{ + return __move_freepages_block_isolate(zone, page, true); +} + +bool pageblock_unisolate_and_move_free_pages(struct zone *zone, struct pag= e *page) +{ + return __move_freepages_block_isolate(zone, page, false); +} + #endif /* CONFIG_MEMORY_ISOLATION */ =20 static void change_pageblock_range(struct page *pageblock_page, @@ -2306,6 +2368,7 @@ try_to_claim_block(struct zone *zone, struct page *pa= ge, if (free_pages + alike_pages >=3D (1 << (pageblock_order-1)) || page_group_by_mobility_disabled) { __move_freepages_block(zone, start_pfn, block_type, start_type); + set_pageblock_migratetype(pfn_to_page(start_pfn), start_type); return __rmqueue_smallest(zone, order, start_type); } =20 diff --git a/mm/page_isolation.c b/mm/page_isolation.c index b2fc5266e3d2..08f627a5032f 100644 --- a/mm/page_isolation.c +++ b/mm/page_isolation.c @@ -188,7 +188,7 @@ static int set_migratetype_isolate(struct page *page, i= nt migratetype, int isol_ unmovable =3D has_unmovable_pages(check_unmovable_start, check_unmovable_= end, migratetype, isol_flags); if (!unmovable) { - if (!move_freepages_block_isolate(zone, page, MIGRATE_ISOLATE)) { + if (!pageblock_isolate_and_move_free_pages(zone, page)) { spin_unlock_irqrestore(&zone->lock, flags); return -EBUSY; } @@ -209,7 +209,7 @@ static int set_migratetype_isolate(struct page *page, i= nt migratetype, int isol_ return -EBUSY; } =20 -static void unset_migratetype_isolate(struct page *page, int migratetype) +static void unset_migratetype_isolate(struct page *page) { struct zone *zone; unsigned long flags; @@ -262,10 +262,10 @@ static void unset_migratetype_isolate(struct page *pa= ge, int migratetype) * Isolating this block already succeeded, so this * should not fail on zone boundaries. */ - WARN_ON_ONCE(!move_freepages_block_isolate(zone, page, migratetype)); + WARN_ON_ONCE(!pageblock_unisolate_and_move_free_pages(zone, page)); } else { - set_pageblock_migratetype(page, migratetype); - __putback_isolated_page(page, order, migratetype); + clear_pageblock_isolate(page); + __putback_isolated_page(page, order, get_pageblock_migratetype(page)); } zone->nr_isolate_pageblock--; out: @@ -383,7 +383,7 @@ static int isolate_single_pageblock(unsigned long bound= ary_pfn, int flags, if (PageBuddy(page)) { int order =3D buddy_order(page); =20 - /* move_freepages_block_isolate() handled this */ + /* pageblock_isolate_and_move_free_pages() handled this */ VM_WARN_ON_ONCE(pfn + (1 << order) > boundary_pfn); =20 pfn +=3D 1UL << order; @@ -433,7 +433,7 @@ static int isolate_single_pageblock(unsigned long bound= ary_pfn, int flags, failed: /* restore the original migratetype */ if (!skip_isolation) - unset_migratetype_isolate(pfn_to_page(isolate_pageblock), migratetype); + unset_migratetype_isolate(pfn_to_page(isolate_pageblock)); return -EBUSY; } =20 @@ -504,7 +504,7 @@ int start_isolate_page_range(unsigned long start_pfn, u= nsigned long end_pfn, ret =3D isolate_single_pageblock(isolate_end, flags, true, skip_isolation, migratetype); if (ret) { - unset_migratetype_isolate(pfn_to_page(isolate_start), migratetype); + unset_migratetype_isolate(pfn_to_page(isolate_start)); return ret; } =20 @@ -517,8 +517,7 @@ int start_isolate_page_range(unsigned long start_pfn, u= nsigned long end_pfn, start_pfn, end_pfn)) { undo_isolate_page_range(isolate_start, pfn, migratetype); unset_migratetype_isolate( - pfn_to_page(isolate_end - pageblock_nr_pages), - migratetype); + pfn_to_page(isolate_end - pageblock_nr_pages)); return -EBUSY; } } @@ -548,7 +547,7 @@ void undo_isolate_page_range(unsigned long start_pfn, u= nsigned long end_pfn, page =3D __first_valid_page(pfn, pageblock_nr_pages); if (!page || !is_migrate_isolate_page(page)) continue; - unset_migratetype_isolate(page, migratetype); + unset_migratetype_isolate(page); } } /* --=20 2.47.2 From nobody Fri Dec 19 16:07:32 2025 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2051.outbound.protection.outlook.com [40.107.243.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4292029CB34 for ; Fri, 23 May 2025 19:13:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748027611; cv=fail; b=QryHw536/6bazVF8vux/0LlFZxz83drMYJhaRIl8uwoS18OfBNWZDP79c2aZFiIuVrrD5D4Pf2QCfJNyESlzNXdzdI5rJGb6BdHWLBdJJ9+euCp4AdN+x7b1UZ4n4ChzC9kpPcE7JDBQeYxJuommo6nI1XFJ6LARvEzeL0b4Azg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748027611; c=relaxed/simple; bh=EgKufcdzvqLXl1nbtDRVT3FNbnz1P70iW24lwKk6Qtc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=OukK0/BSYfeNILU6x9XfEkb7bBVipxWYdWNUOh+phycmx1AODZagl0TNZSw+awlpjk4SUJ2W1zCuvJDx+AYSgrLDCJgAHfCkJBH+8wltOMocdMWi7xPHBxhr6aawdO/1vWi55zK2Wokyt8Tuuc0Bg0GWPYZSuB/hNcOwgmJuKj0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=magZl4Wa; arc=fail smtp.client-ip=40.107.243.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="magZl4Wa" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=UC2iyr1X70UBuVIw7niSUZuRRuuTFJoeeowrMA2u1WHsLuh8F7ksNm0CmyG65WphZbTvze6OfLz3jCV59ZwUvX9tMhhGTNnzTcmqK7vYH6qEt2sr3I0+ojZQ5aE+qjkR6rXnqssIHumwAzSOQIIG7HWspmJT1uRYGf3fyRaQ5my7f61SmtoGU+qYMD1/egI2HxrUAubE7OlE/8vHnFqNkts+WWs03ypUW96z9f6jauC8PEt11HBl9MAL7plIs7CFepsGEW+bUJNgbRuCJCQwmntjKZfsdmzB1yNsY5lTq1EoqAhym3cFIEYPAvOuKzSJRRWs1FdWfdSL7LIIHPAaqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/6z3bocu1Y/MYneunan6jixWCvEdXHtI0cKily/vhHo=; b=Mj0MYehCTDrQAbPXjBUa2NBd5ArRmbh5nzB+kUjSe5ZXR+2SMSWq7qxCm4GNPIXs/Mt5mDKdTSe8joBANsj9WawXNALuIBT1hui/9LN8m/xhxJI9t43kevlWcP4c0w2T2RnqhCyY/qiEMHGeakD7zVxMdymBuTBbDj79W9SYsWmSDShQPcL7bYCJQ7clOm17xB2eK7l7DKnRw2Xup/gRoIaQX+xIR7e5RBqGZbq7SdRrwfGcFCX9R+FLaHtsLZADwZAQXD9p9NiJ4IqrxO2YZPtyRGBcW+gcUoXGkBXFl/2hiIAXRLnxpaj1njJIt9fOxi7sm4iPHtpAhXEoMqGA3A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/6z3bocu1Y/MYneunan6jixWCvEdXHtI0cKily/vhHo=; b=magZl4WaSeUNCpQRrvgrBsbLx9+Jp3k/Pv9D0IZkfKzFaRQbqX38uiQ1qIngt7tym6jdNMFjJsW4z5PU6vO9TQhKXDG25CUBCMyREWSZ6Kp1ORsjodI56/lVFk7cj6YVFdPG63EDMnZZr0DMflC8ui69alSU5PJuGBqIG3QSgTml8zVakz2u2UA3VHxDiZ/1479Dtiar2tAFAq8XsCx8ZYGxY8f+yZv6cCGXIQyfhBP2Oj4/pKfLmA92u9rC2KaXNM2Y3mPybTnFvbda6nBnn3Lkp/2zlHzblIz67XgCUnBplOrJ2osFa94EUeR27/405QQXysiLP1hlUYjEA1oA9w== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by SJ2PR12MB8737.namprd12.prod.outlook.com (2603:10b6:a03:545::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8769.21; Fri, 23 May 2025 19:13:22 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%5]) with mapi id 15.20.8746.030; Fri, 23 May 2025 19:13:22 +0000 From: Zi Yan To: David Hildenbrand , Johannes Weiner , linux-mm@kvack.org Cc: Andrew Morton , Oscar Salvador , Vlastimil Babka , Baolin Wang , "Kirill A . Shutemov" , Mel Gorman , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Richard Chang , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v5 5/6] mm/page_isolation: remove migratetype from undo_isolate_page_range() Date: Fri, 23 May 2025 15:12:57 -0400 Message-ID: <20250523191258.339826-6-ziy@nvidia.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250523191258.339826-1-ziy@nvidia.com> References: <20250523191258.339826-1-ziy@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BLAPR05CA0011.namprd05.prod.outlook.com (2603:10b6:208:36e::26) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|SJ2PR12MB8737:EE_ X-MS-Office365-Filtering-Correlation-Id: 3ab445cb-fde8-47f6-9ce1-08dd9a2de266 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014|7053199007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?I/WieTrdfb5++QhUUrllWLqj7j7DTto9q+NQCQxjIx2SvE/ohXpHVq1jGm8w?= =?us-ascii?Q?3rKQETqyc+cALOIaLbZd4VwX3/HpWdJ9t8LvytYrbwLOommP0VvIbIhNKAHl?= =?us-ascii?Q?Vq78+n63x76WnrBziPgcx5r6mb15IVm53gfDdzd3M8M0gBAL1Y+NxtnIsotZ?= =?us-ascii?Q?qumxLx0Ns+JzORbE+mK+GZlXKVwgLQ2a2/Bz9SiieGNppo/LUm6/W+royfcB?= =?us-ascii?Q?3ucV3l4P0C2gZ+ZDXdR0pP2kbLAbRs7dAmA3R90B8IBtkqsObe4Q7KHwrFl3?= =?us-ascii?Q?DlaeWwDTFC49RGyXhRgm7+Brq7WWYflLPYu2RUtFzdsYp4WivojyBOtX4z8n?= =?us-ascii?Q?WCPSlLEaV3QXG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BqTaEFdzF?= =?us-ascii?Q?V9rXjP0D6F17N+I279yN7lka/mjIwd2fsi9+y54nVNXfChZwiFXck5s8CScU?= =?us-ascii?Q?Z9nANCjfuU+9vR7H/wSeWEEO6S5j09IcCTUQ0LQJAOhUn++xpWzNfB/xZxSQ?= =?us-ascii?Q?vm7bAliduEbLR9vSrofMOKVOltUe21I6oDd64ZW093SahPddnsmGMNoElGJk?= =?us-ascii?Q?NPnNqHAg/Kg=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB9473.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(7416014)(7053199007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?L2lvJSTWP8VKe5xMtOh+AX8iFmMogPn9kxhEEdB1dth4/ozT1Lyh8KcLlSAt?= =?us-ascii?Q?iFlz5VSYzHZ9lOr/foGHOFT5WFxyV/yQHEY6omIdvhUn5LBqmvuJ1rZyUW5n?= =?us-ascii?Q?bP1wYzosxfFv3NrQ1SipOtiNP6He9rRMZRfXLqnsdi2SDt/JGLt4p/vnDh10?= =?us-ascii?Q?Rd/VxVi9oLnU3JkrtfdAOie/cV3C/YRzza/9mCEwLxMkV0u3wU8W3zcfnJyW?= =?us-ascii?Q?w/cj5QanlNiHxxEz/v04em3wp3/Y4M52iyHng+cftbOY+vw8jn3aikioBx0c?= =?us-ascii?Q?nWUEMBMlz4GlfOvr6/dh0hLBBc9XRsn8BWqujHzMqpt3SKiXKytVr23/2pPg?= =?us-ascii?Q?cp8bfTHjciaGWvjzV6uOdXMtxGWvzh8goqRaGWKHm/xVWQL1fmJfcUFE/Lhv?= =?us-ascii?Q?821pU4lP7iU6keVWngfptXcAjenU+AWWqrZM6NoGEcGu3Ho3OgiAPjGDdBsO?= =?us-ascii?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hDBKK?= =?us-ascii?Q?ZwZlqfQ9fBdR8SYdvMmsBsvH5HgrRotMPumE0sCBxlEhiGIsbuKjZyYL9Ozh?= =?us-ascii?Q?QibI14hOR8paHu6ObOzCshjWm75rfR/qg95kIHr4k9kTXEAb+aI14TgX0se2?= =?us-ascii?Q?dJLu64qKMiL6wr/x0KygiCwa1AOoY9UjeDHx1Rq555qTQRPhdccnyqZrnunD?= =?us-ascii?Q?sVDZSHxXU0Wgomo5n/JIu/RB5gWIA+IIemVu+jnA?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3ab445cb-fde8-47f6-9ce1-08dd9a2de266 X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2025 19:13:22.0456 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: SKz9xL9QDmlZAUVi1nDrrn6xOSYTvLDjQQfdagl9/8Lu19tHVNQ14LcvrTfHWEWX X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8737 Content-Type: text/plain; charset="utf-8" Since migratetype is no longer overwritten during pageblock isolation, undoing pageblock isolation no longer needs which migratetype to restore. Signed-off-by: Zi Yan Acked-by: David Hildenbrand Reviewed-by: Vlastimil Babka --- include/linux/page-isolation.h | 3 +-- mm/memory_hotplug.c | 4 ++-- mm/page_alloc.c | 2 +- mm/page_isolation.c | 9 +++------ 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/include/linux/page-isolation.h b/include/linux/page-isolation.h index 7241a6719618..7a681a49e73c 100644 --- a/include/linux/page-isolation.h +++ b/include/linux/page-isolation.h @@ -51,8 +51,7 @@ bool pageblock_unisolate_and_move_free_pages(struct zone = *zone, struct page *pag int start_isolate_page_range(unsigned long start_pfn, unsigned long end_pf= n, int migratetype, int flags); =20 -void undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pf= n, - int migratetype); +void undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pf= n); =20 int test_pages_isolated(unsigned long start_pfn, unsigned long end_pfn, int isol_flags); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 43ac34ee8d2e..ab66acd3e6b3 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1233,7 +1233,7 @@ int online_pages(unsigned long pfn, unsigned long nr_= pages, build_all_zonelists(NULL); =20 /* Basic onlining is complete, allow allocation of onlined pages. */ - undo_isolate_page_range(pfn, pfn + nr_pages, MIGRATE_MOVABLE); + undo_isolate_page_range(pfn, pfn + nr_pages); =20 /* * Freshly onlined pages aren't shuffled (e.g., all pages are placed to @@ -2119,7 +2119,7 @@ int offline_pages(unsigned long start_pfn, unsigned l= ong nr_pages, =20 failed_removal_isolated: /* pushback to free area */ - undo_isolate_page_range(start_pfn, end_pfn, MIGRATE_MOVABLE); + undo_isolate_page_range(start_pfn, end_pfn); memory_notify(MEM_CANCEL_OFFLINE, &arg); failed_removal_pcplists_disabled: lru_cache_enable(); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 44a08b1a9de4..499c3f40851f 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -7027,7 +7027,7 @@ int alloc_contig_range_noprof(unsigned long start, un= signed long end, start, end, outer_start, outer_end); } done: - undo_isolate_page_range(start, end, migratetype); + undo_isolate_page_range(start, end); return ret; } EXPORT_SYMBOL(alloc_contig_range_noprof); diff --git a/mm/page_isolation.c b/mm/page_isolation.c index 08f627a5032f..1edfef408faf 100644 --- a/mm/page_isolation.c +++ b/mm/page_isolation.c @@ -515,7 +515,7 @@ int start_isolate_page_range(unsigned long start_pfn, u= nsigned long end_pfn, page =3D __first_valid_page(pfn, pageblock_nr_pages); if (page && set_migratetype_isolate(page, migratetype, flags, start_pfn, end_pfn)) { - undo_isolate_page_range(isolate_start, pfn, migratetype); + undo_isolate_page_range(isolate_start, pfn); unset_migratetype_isolate( pfn_to_page(isolate_end - pageblock_nr_pages)); return -EBUSY; @@ -528,13 +528,10 @@ int start_isolate_page_range(unsigned long start_pfn,= unsigned long end_pfn, * undo_isolate_page_range - undo effects of start_isolate_page_range() * @start_pfn: The first PFN of the isolated range * @end_pfn: The last PFN of the isolated range - * @migratetype: New migrate type to set on the range * - * This finds every MIGRATE_ISOLATE page block in the given range - * and switches it to @migratetype. + * This finds and unsets every MIGRATE_ISOLATE page block in the given ran= ge */ -void undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pf= n, - int migratetype) +void undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pf= n) { unsigned long pfn; struct page *page; --=20 2.47.2 From nobody Fri Dec 19 16:07:32 2025 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2051.outbound.protection.outlook.com [40.107.243.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3539D29CB4C for ; Fri, 23 May 2025 19:13:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748027613; cv=fail; b=LiLMQBS+U917SsTvRjB3XaBh0LipfEqRq5QXCMsF8175CUG5e3iAlTJMF3nu0OxDYafPQ7Zw0efq6MeVqi/1HNoX1cHHU1cehWk2JoWHcmGHEGUSavlDP+I4tBdWZs0FWLspRy+VClo4Ppux0BdrviHcbeDoG2USuaZ4CmBa1HI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748027613; c=relaxed/simple; bh=hmL18ByaK19MHoAk3edaiIqeQCxM2NTtoxjZESF3GZU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=tkA++f5h/2ZevZdKWHzZBHXxpR3F8WIolLRgKbls8ls8VajO+0MMREF9HuxLYdgymVagHKfK6C8EijoqSJKSVOADtdMIom4vSEGBqkJPECPYohkLHN4aQ/mnzy1dlmF6w/GPQBZeXbkKeUal+nWCye4XYX2MY88Ou76Q3pHGCD0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=YZzA0FJD; arc=fail smtp.client-ip=40.107.243.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="YZzA0FJD" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ipbnUYg8n5N5Y4+Nwl0qKIhEnrhKybKAD8j2yzHy88RThK+TVVwUEJAw1PUB+2ckTlzgWU3ShU7XFAq4bryoilKHzeiOBgbYv5B5/8wgVZxz8rPhO45+BQHH4aE7UldYVavV9T4rh+OV9Pg/KotDGCmHKEx1HQDNgv6c+bzp8AkDZ4jYkDAos19ZthGs8GW+bYieI5FQGEVFmRNRXmdVxVXsElQOSgvE+ayR6aXxv0Ldld7OkHKr9ucZYzrWxUj3NubCmYBXT/EG0Q9K1+TLh+nm/t+dRRQ62J9hWMpm/ktC7TI9Gv0WAv2irkDaBLlpLdG+gbLmG0bkl2qbjkkUAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=NLE6JgsZ/zDAuvUyjHzrhg/A4SphG5j0r5A9tL/U78M=; b=fod/I+3scVYyum/1boOUT6N/CPYg8JCP1qYav2sKxZIIVAHkHsYSVm816UEFO8iFeIkURF8UJmdxfI+fmZnDgWP8UFQe49+CRpeptgwg4QuWWzjX7f/MbGI2dMv/R4TZ5qTETubJSwFWQA6vnpWYPWPTnIi+t+u5vjtVnjV8d4iwl+RptB5N20shvSvvfc6/4BgjMVSDZOFmma9Ji0K3hTKLeXGxHZTAqUURFOM+0NxFMH8oYViGAl3f4lxFiu7B+Zm8hAWBxFGIhJajG5ZxIjX0P5L0SVBEqVqOxsT8kPNEw+9HkXLQ5Hkk60efdF14/8/yzyxjwCvjFRPmQnA/uw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NLE6JgsZ/zDAuvUyjHzrhg/A4SphG5j0r5A9tL/U78M=; b=YZzA0FJD40j4c9sNzw3Q0KwmJ05+bxiA+no4bil0j1lSoPDQj4yOWAugb6miLhEltmcQEzDAsYdAXbasbi1gMYUv5GqFc+OJObIKxo3LNytADclpIHa4LusNZ3wDiRX6rW5B3n4ljchpEIuVLefmtU+BTNzZyOJ35vpndTTYths8m/fHa6s5AUWlfNGn5KldbpgF7lS3+cp9URWPnqDmbgFi0p8tq19cohiBfcA2NZfGwxLkCm0Zj3a2HtSqSL222F6J3rNImWqJ46A3filH5Feo8FdiZN3WAidA9USXx0TwCpcYhzJ4JM8lVf3+G1jDtdt3mRCEwZspCJLE4jzzqw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by SJ2PR12MB8737.namprd12.prod.outlook.com (2603:10b6:a03:545::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8769.21; Fri, 23 May 2025 19:13:23 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%5]) with mapi id 15.20.8746.030; Fri, 23 May 2025 19:13:23 +0000 From: Zi Yan To: David Hildenbrand , Johannes Weiner , linux-mm@kvack.org Cc: Andrew Morton , Oscar Salvador , Vlastimil Babka , Baolin Wang , "Kirill A . Shutemov" , Mel Gorman , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Richard Chang , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v5 6/6] mm/page_isolation: remove migratetype parameter from more functions. Date: Fri, 23 May 2025 15:12:58 -0400 Message-ID: <20250523191258.339826-7-ziy@nvidia.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250523191258.339826-1-ziy@nvidia.com> References: <20250523191258.339826-1-ziy@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BLAPR05CA0001.namprd05.prod.outlook.com (2603:10b6:208:36e::6) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|SJ2PR12MB8737:EE_ X-MS-Office365-Filtering-Correlation-Id: 762740c2-03cb-4929-6d22-08dd9a2de343 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014; X-Microsoft-Antispam-Message-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rE8m/q2PgChKug1Yd2?= =?us-ascii?Q?hiE8hqQ0uM3SNDyxnWFbUSY3Yjw3WaJthCl3jKfX8L8jj8nrW/BY2ZEf2SXh?= =?us-ascii?Q?VQR+qDI2GWdgZ1PWx6J1EVRezPVPb7r6EmpQXed0GexsS+WA5hgnDKl3M4mC?= =?us-ascii?Q?BpuQIjO0EwnMBcVVMTrDkrxiZ9QVQMxZCzofSuBGGAq5WtGY78FPtZKeXfcb?= =?us-ascii?Q?wNKyUSLSlD9ceSWU4T0APwSYduuFkQlyGphR2boCA45deS8pSl3No3G6UhhF?= =?us-ascii?Q?wxwlyiQKdl1AH2fHAkN6ntVoTBBYV6uYzUkurTkU2r+m+ktpUc4E9O1CWYP9?= =?us-ascii?Q?SYCIzp8IwcD8tBgrur+GuJo/bgdKoglaLSLtOoouJWxgs/V9vtW2ia9II4Pn?= =?us-ascii?Q?6DEMyUd/fpJMflcn1l/THSwHbZ8hp3Aq9EuTbQ95QJnTGnHdkMoQu19qKvG3?= =?us-ascii?Q?SXz2X9Fyrxu59N0CJcc2TvhWChxoNXJ+rcr1NuLWY57pdWicQb5hhhprvWjH?= =?us-ascii?Q?c9HJmN7+C11QjOyw7PeSiHDFGCr13Irwbh8iGf1+L9/NXHr//IA+chjk6vPa?= =?us-ascii?Q?LMwIZFb31yM=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB9473.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(7416014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?d5fkUob42+JzkJAdSCSWzzj+DzvtPYUiVqR4maFm33+s0u8edz+Q/fV/spK1?= =?us-ascii?Q?mhY1oDx581mzIoWPRsQVn5vxwFLjxqW62CLDrfoWnavayjj8iQr1JMW4GC2G?=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/MnDWv6eIYjY5p+ahkcWwwAgmsqyUXvy5RpoiKhbEZi?= =?us-ascii?Q?sH7uFxnDYH2UDjmdxAZ8QFfSS7gS4QR4xv3whyM/EEfP8ShiwPEwjRDGCnbL?= =?us-ascii?Q?Bt2wE1I0CQIXxiq3348HaT91KH0jK9aHqsWU+ZH4b+NwDk4GUlx+AC26LhWy?= =?us-ascii?Q?IxkdTf+/tMsv4d6QGDGaMrJrLv0aBjFpc8MiPF6jwFISW07wL8fPxhhxO8Br?= =?us-ascii?Q?MaHsQ6wSH4NFt/lUBi5eKlwPauzMaYVc+weFb0+8syUqL6QSGOY1a+pvQpi9?= =?us-ascii?Q?PvwdwIBA+lmv9i7GI4FlKuoRmLW56a6QR6Wvx4jyHDKB55gOhOkb5f7mm7eS?= =?us-ascii?Q?+YSU1WlIZD3cEL2A1fgXhnc3a/VGQuPcrLD3b41u+ft0F1DebCpyK30VoOwS?= =?us-ascii?Q?WfL4XwpDPMxM+RB1nptKI8kHhU60IxBQ94Bk/Huu16Xfay1mRXrQGsUJIFTB?= =?us-ascii?Q?kOg8/X808c77cmkGjsGMJFLj/SDyBbHsNfy5BiS9QjI8BguMWsAPt67zbhDl?= =?us-ascii?Q?FrFHvSr/NnBFUfiT18Cj4TTiJVVo5JTdtbBn1tO/RBeklcyT2dOudmO3xmjN?= =?us-ascii?Q?EDtPLEJIUv2krWOVQ3v5//U8QEj+0IYdjM6TRzjm?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 762740c2-03cb-4929-6d22-08dd9a2de343 X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2025 19:13:23.4831 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: B/pblZUsXVc2P8D6kwgmfd+F1YI3nZtU7Mu7qgX87Kyd24dBLY3LD8PoMaX/WQDh X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8737 Content-Type: text/plain; charset="utf-8" migratetype is no longer overwritten during pageblock isolation, start_isolate_page_range(), has_unmovable_pages(), and set_migratetype_isolate() no longer need which migratetype to restore during isolation failure. For has_unmoable_pages(), it needs to know if the isolation is for CMA allocation, so adding CMA_ALLOCATION to provide the information. At the same time change isolation flags to enum pb_isolate_mode (MEMORY_OFFLINE, CMA_ALLOCATION, and ISOLATE_MODE_OTHERS). Remove REPORT_FAILURE and check MEMORY_OFFLINE instead, since only MEMORY_OFFLINE reports isolation failures. alloc_contig_range() no longer needs migratetype. Replace it with a newly defined acr_flags_t to tell if an allocation is for CMA. So does __alloc_contig_migrate_range(). Signed-off-by: Zi Yan --- drivers/virtio/virtio_mem.c | 3 +- include/linux/gfp.h | 6 ++- include/linux/page-isolation.h | 19 ++++++++-- include/trace/events/kmem.h | 14 ++++--- mm/cma.c | 2 +- mm/memory_hotplug.c | 4 +- mm/page_alloc.c | 25 ++++++------- mm/page_isolation.c | 67 +++++++++++++++------------------- 8 files changed, 72 insertions(+), 68 deletions(-) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index 56d0dbe62163..8accc0f255a8 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -1243,8 +1243,7 @@ static int virtio_mem_fake_offline(struct virtio_mem = *vm, unsigned long pfn, if (atomic_read(&vm->config_changed)) return -EAGAIN; =20 - rc =3D alloc_contig_range(pfn, pfn + nr_pages, MIGRATE_MOVABLE, - GFP_KERNEL); + rc =3D alloc_contig_range(pfn, pfn + nr_pages, 0, GFP_KERNEL); if (rc =3D=3D -ENOMEM) /* whoops, out of memory */ return rc; diff --git a/include/linux/gfp.h b/include/linux/gfp.h index be160e8d8bcb..dea27ed24f8e 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -423,9 +423,13 @@ static inline bool gfp_compaction_allowed(gfp_t gfp_ma= sk) extern gfp_t vma_thp_gfp_mask(struct vm_area_struct *vma); =20 #ifdef CONFIG_CONTIG_ALLOC + +typedef unsigned int __bitwise acr_flags_t; +#define ACR_CMA ((__force acr_flags_t)BIT(0)) // allocate for CMA + /* The below functions must be run on a range from a single zone. */ extern int alloc_contig_range_noprof(unsigned long start, unsigned long en= d, - unsigned migratetype, gfp_t gfp_mask); + acr_flags_t alloc_flags, gfp_t gfp_mask); #define alloc_contig_range(...) alloc_hooks(alloc_contig_range_noprof(__= VA_ARGS__)) =20 extern struct page *alloc_contig_pages_noprof(unsigned long nr_pages, gfp_= t gfp_mask, diff --git a/include/linux/page-isolation.h b/include/linux/page-isolation.h index 7a681a49e73c..b61bca909ddc 100644 --- a/include/linux/page-isolation.h +++ b/include/linux/page-isolation.h @@ -38,8 +38,19 @@ static inline void set_pageblock_isolate(struct page *pa= ge) } #endif =20 -#define MEMORY_OFFLINE 0x1 -#define REPORT_FAILURE 0x2 +/* + * Pageblock isolation modes: + * MEMORY_OFFLINE - isolate to offline (!allocate) memory e.g., skip = over + * PageHWPoison() pages and PageOffline() pages. + * Unmovable pages will be reported in this mode. + * CMA_ALLOCATION - isolate for CMA allocations + * ISOLATE_MODE_OTHERS - isolate for other purposes + */ +enum pb_isolate_mode { + MEMORY_OFFLINE, + CMA_ALLOCATION, + ISOLATE_MODE_OTHERS, +}; =20 void __meminit init_pageblock_migratetype(struct page *page, enum migratetype migratetype, @@ -49,10 +60,10 @@ bool pageblock_isolate_and_move_free_pages(struct zone = *zone, struct page *page) bool pageblock_unisolate_and_move_free_pages(struct zone *zone, struct pag= e *page); =20 int start_isolate_page_range(unsigned long start_pfn, unsigned long end_pf= n, - int migratetype, int flags); + enum pb_isolate_mode mode); =20 void undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pf= n); =20 int test_pages_isolated(unsigned long start_pfn, unsigned long end_pfn, - int isol_flags); + enum pb_isolate_mode mode); #endif diff --git a/include/trace/events/kmem.h b/include/trace/events/kmem.h index f74925a6cf69..efffcf578217 100644 --- a/include/trace/events/kmem.h +++ b/include/trace/events/kmem.h @@ -304,6 +304,7 @@ TRACE_EVENT(mm_page_alloc_extfrag, __entry->change_ownership) ); =20 +#ifdef CONFIG_CONTIG_ALLOC TRACE_EVENT(mm_alloc_contig_migrate_range_info, =20 TP_PROTO(unsigned long start, @@ -311,9 +312,9 @@ TRACE_EVENT(mm_alloc_contig_migrate_range_info, unsigned long nr_migrated, unsigned long nr_reclaimed, unsigned long nr_mapped, - int migratetype), + acr_flags_t alloc_flags), =20 - TP_ARGS(start, end, nr_migrated, nr_reclaimed, nr_mapped, migratetype), + TP_ARGS(start, end, nr_migrated, nr_reclaimed, nr_mapped, alloc_flags), =20 TP_STRUCT__entry( __field(unsigned long, start) @@ -321,7 +322,7 @@ TRACE_EVENT(mm_alloc_contig_migrate_range_info, __field(unsigned long, nr_migrated) __field(unsigned long, nr_reclaimed) __field(unsigned long, nr_mapped) - __field(int, migratetype) + __field(acr_flags_t, alloc_flags) ), =20 TP_fast_assign( @@ -330,17 +331,18 @@ TRACE_EVENT(mm_alloc_contig_migrate_range_info, __entry->nr_migrated =3D nr_migrated; __entry->nr_reclaimed =3D nr_reclaimed; __entry->nr_mapped =3D nr_mapped; - __entry->migratetype =3D migratetype; + __entry->alloc_flags =3D alloc_flags; ), =20 - TP_printk("start=3D0x%lx end=3D0x%lx migratetype=3D%d nr_migrated=3D%lu n= r_reclaimed=3D%lu nr_mapped=3D%lu", + TP_printk("start=3D0x%lx end=3D0x%lx alloc_flags=3D%d nr_migrated=3D%lu n= r_reclaimed=3D%lu nr_mapped=3D%lu", __entry->start, __entry->end, - __entry->migratetype, + __entry->alloc_flags, __entry->nr_migrated, __entry->nr_reclaimed, __entry->nr_mapped) ); +#endif =20 TRACE_EVENT(mm_setup_per_zone_wmarks, =20 diff --git a/mm/cma.c b/mm/cma.c index 397567883a10..9ee8fad797bc 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -822,7 +822,7 @@ static int cma_range_alloc(struct cma *cma, struct cma_= memrange *cmr, =20 pfn =3D cmr->base_pfn + (bitmap_no << cma->order_per_bit); mutex_lock(&cma->alloc_mutex); - ret =3D alloc_contig_range(pfn, pfn + count, MIGRATE_CMA, gfp); + ret =3D alloc_contig_range(pfn, pfn + count, ACR_CMA, gfp); mutex_unlock(&cma->alloc_mutex); if (ret =3D=3D 0) { page =3D pfn_to_page(pfn); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index ab66acd3e6b3..44f140dee0ce 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -2008,9 +2008,7 @@ int offline_pages(unsigned long start_pfn, unsigned l= ong nr_pages, lru_cache_disable(); =20 /* set above range as isolated */ - ret =3D start_isolate_page_range(start_pfn, end_pfn, - MIGRATE_MOVABLE, - MEMORY_OFFLINE | REPORT_FAILURE); + ret =3D start_isolate_page_range(start_pfn, end_pfn, MEMORY_OFFLINE); if (ret) { reason =3D "failure to isolate range"; goto failed_removal_pcplists_disabled; diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 499c3f40851f..48f458f7143a 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -6720,11 +6720,12 @@ static void alloc_contig_dump_pages(struct list_hea= d *page_list) =20 /* * [start, end) must belong to a single zone. - * @migratetype: using migratetype to filter the type of migration in + * @alloc_flags: using acr_flags_t to filter the type of migration in * trace_mm_alloc_contig_migrate_range_info. */ static int __alloc_contig_migrate_range(struct compact_control *cc, - unsigned long start, unsigned long end, int migratetype) + unsigned long start, unsigned long end, + acr_flags_t alloc_flags) { /* This function is based on compact_zone() from compaction.c. */ unsigned int nr_reclaimed; @@ -6796,7 +6797,7 @@ static int __alloc_contig_migrate_range(struct compac= t_control *cc, putback_movable_pages(&cc->migratepages); } =20 - trace_mm_alloc_contig_migrate_range_info(start, end, migratetype, + trace_mm_alloc_contig_migrate_range_info(start, end, alloc_flags, total_migrated, total_reclaimed, total_mapped); @@ -6867,10 +6868,7 @@ static int __alloc_contig_verify_gfp_mask(gfp_t gfp_= mask, gfp_t *gfp_cc_mask) * alloc_contig_range() -- tries to allocate given range of pages * @start: start PFN to allocate * @end: one-past-the-last PFN to allocate - * @migratetype: migratetype of the underlying pageblocks (either - * #MIGRATE_MOVABLE or #MIGRATE_CMA). All pageblocks - * in range must have the same migratetype and it must - * be either of the two. + * @alloc_flags: allocation information * @gfp_mask: GFP mask. Node/zone/placement hints are ignored; only some * action and reclaim modifiers are supported. Reclaim modifiers * control allocation behavior during compaction/migration/reclaim. @@ -6887,7 +6885,7 @@ static int __alloc_contig_verify_gfp_mask(gfp_t gfp_m= ask, gfp_t *gfp_cc_mask) * need to be freed with free_contig_range(). */ int alloc_contig_range_noprof(unsigned long start, unsigned long end, - unsigned migratetype, gfp_t gfp_mask) + acr_flags_t alloc_flags, gfp_t gfp_mask) { unsigned long outer_start, outer_end; int ret =3D 0; @@ -6903,6 +6901,8 @@ int alloc_contig_range_noprof(unsigned long start, un= signed long end, }; INIT_LIST_HEAD(&cc.migratepages); bool is_range_aligned; + isolate_mode_t mode =3D (alloc_flags & ACR_CMA) ? CMA_ALLOCATION : + ISOLATE_MODE_OTHERS; =20 gfp_mask =3D current_gfp_context(gfp_mask); if (__alloc_contig_verify_gfp_mask(gfp_mask, (gfp_t *)&cc.gfp_mask)) @@ -6929,7 +6929,7 @@ int alloc_contig_range_noprof(unsigned long start, un= signed long end, * put back to page allocator so that buddy can use them. */ =20 - ret =3D start_isolate_page_range(start, end, migratetype, 0); + ret =3D start_isolate_page_range(start, end, mode); if (ret) goto done; =20 @@ -6945,7 +6945,7 @@ int alloc_contig_range_noprof(unsigned long start, un= signed long end, * allocated. So, if we fall through be sure to clear ret so that * -EBUSY is not accidentally used or returned to caller. */ - ret =3D __alloc_contig_migrate_range(&cc, start, end, migratetype); + ret =3D __alloc_contig_migrate_range(&cc, start, end, alloc_flags); if (ret && ret !=3D -EBUSY) goto done; =20 @@ -6979,7 +6979,7 @@ int alloc_contig_range_noprof(unsigned long start, un= signed long end, outer_start =3D find_large_buddy(start); =20 /* Make sure the range is really isolated. */ - if (test_pages_isolated(outer_start, end, 0)) { + if (test_pages_isolated(outer_start, end, mode)) { ret =3D -EBUSY; goto done; } @@ -7037,8 +7037,7 @@ static int __alloc_contig_pages(unsigned long start_p= fn, { unsigned long end_pfn =3D start_pfn + nr_pages; =20 - return alloc_contig_range_noprof(start_pfn, end_pfn, MIGRATE_MOVABLE, - gfp_mask); + return alloc_contig_range_noprof(start_pfn, end_pfn, 0, gfp_mask); } =20 static bool pfn_range_valid_contig(struct zone *z, unsigned long start_pfn, diff --git a/mm/page_isolation.c b/mm/page_isolation.c index 1edfef408faf..bcf6525ea238 100644 --- a/mm/page_isolation.c +++ b/mm/page_isolation.c @@ -31,7 +31,7 @@ * */ static struct page *has_unmovable_pages(unsigned long start_pfn, unsigned = long end_pfn, - int migratetype, int flags) + enum pb_isolate_mode mode) { struct page *page =3D pfn_to_page(start_pfn); struct zone *zone =3D page_zone(page); @@ -46,7 +46,7 @@ static struct page *has_unmovable_pages(unsigned long sta= rt_pfn, unsigned long e * isolate CMA pageblocks even when they are not movable in fact * so consider them movable here. */ - if (is_migrate_cma(migratetype)) + if (mode =3D=3D CMA_ALLOCATION) return NULL; =20 return page; @@ -117,7 +117,7 @@ static struct page *has_unmovable_pages(unsigned long s= tart_pfn, unsigned long e * The HWPoisoned page may be not in buddy system, and * page_count() is not 0. */ - if ((flags & MEMORY_OFFLINE) && PageHWPoison(page)) + if ((mode =3D=3D MEMORY_OFFLINE) && PageHWPoison(page)) continue; =20 /* @@ -130,7 +130,7 @@ static struct page *has_unmovable_pages(unsigned long s= tart_pfn, unsigned long e * move these pages that still have a reference count > 0. * (false negatives in this function only) */ - if ((flags & MEMORY_OFFLINE) && PageOffline(page)) + if ((mode =3D=3D MEMORY_OFFLINE) && PageOffline(page)) continue; =20 if (__PageMovable(page) || PageLRU(page)) @@ -151,7 +151,7 @@ static struct page *has_unmovable_pages(unsigned long s= tart_pfn, unsigned long e * present in [start_pfn, end_pfn). The pageblock must intersect with * [start_pfn, end_pfn). */ -static int set_migratetype_isolate(struct page *page, int migratetype, int= isol_flags, +static int set_migratetype_isolate(struct page *page, enum pb_isolate_mode= mode, unsigned long start_pfn, unsigned long end_pfn) { struct zone *zone =3D page_zone(page); @@ -186,7 +186,7 @@ static int set_migratetype_isolate(struct page *page, i= nt migratetype, int isol_ end_pfn); =20 unmovable =3D has_unmovable_pages(check_unmovable_start, check_unmovable_= end, - migratetype, isol_flags); + mode); if (!unmovable) { if (!pageblock_isolate_and_move_free_pages(zone, page)) { spin_unlock_irqrestore(&zone->lock, flags); @@ -198,7 +198,7 @@ static int set_migratetype_isolate(struct page *page, i= nt migratetype, int isol_ } =20 spin_unlock_irqrestore(&zone->lock, flags); - if (isol_flags & REPORT_FAILURE) { + if (mode =3D=3D MEMORY_OFFLINE) { /* * printk() with zone->lock held will likely trigger a * lockdep splat, so defer it here. @@ -292,11 +292,10 @@ __first_valid_page(unsigned long pfn, unsigned long n= r_pages) * isolate_single_pageblock() -- tries to isolate a pageblock that might be * within a free or in-use page. * @boundary_pfn: pageblock-aligned pfn that a page might cross - * @flags: isolation flags + * @mode: isolation mode * @isolate_before: isolate the pageblock before the boundary_pfn * @skip_isolation: the flag to skip the pageblock isolation in second * isolate_single_pageblock() - * @migratetype: migrate type to set in error recovery. * * Free and in-use pages can be as big as MAX_PAGE_ORDER and contain more = than one * pageblock. When not all pageblocks within a page are isolated at the sa= me @@ -311,8 +310,9 @@ __first_valid_page(unsigned long pfn, unsigned long nr_= pages) * either. The function handles this by splitting the free page or migrati= ng * the in-use page then splitting the free page. */ -static int isolate_single_pageblock(unsigned long boundary_pfn, int flags, - bool isolate_before, bool skip_isolation, int migratetype) +static int isolate_single_pageblock(unsigned long boundary_pfn, + enum pb_isolate_mode mode, bool isolate_before, + bool skip_isolation) { unsigned long start_pfn; unsigned long isolate_pageblock; @@ -338,12 +338,11 @@ static int isolate_single_pageblock(unsigned long bou= ndary_pfn, int flags, zone->zone_start_pfn); =20 if (skip_isolation) { - int mt __maybe_unused =3D get_pageblock_migratetype(pfn_to_page(isolate_= pageblock)); - - VM_BUG_ON(!is_migrate_isolate(mt)); + VM_BUG_ON(!get_pageblock_isolate(pfn_to_page(isolate_pageblock))); } else { - ret =3D set_migratetype_isolate(pfn_to_page(isolate_pageblock), migratet= ype, - flags, isolate_pageblock, isolate_pageblock + pageblock_nr_pages); + ret =3D set_migratetype_isolate(pfn_to_page(isolate_pageblock), + mode, isolate_pageblock, + isolate_pageblock + pageblock_nr_pages); =20 if (ret) return ret; @@ -441,14 +440,7 @@ static int isolate_single_pageblock(unsigned long boun= dary_pfn, int flags, * start_isolate_page_range() - mark page range MIGRATE_ISOLATE * @start_pfn: The first PFN of the range to be isolated. * @end_pfn: The last PFN of the range to be isolated. - * @migratetype: Migrate type to set in error recovery. - * @flags: The following flags are allowed (they can be combined in - * a bit mask) - * MEMORY_OFFLINE - isolate to offline (!allocate) memory - * e.g., skip over PageHWPoison() pages - * and PageOffline() pages. - * REPORT_FAILURE - report details about the failure to - * isolate the range + * @mode: isolation mode * * Making page-allocation-type to be MIGRATE_ISOLATE means free pages in * the range will never be allocated. Any free pages and pages freed in the @@ -481,7 +473,7 @@ static int isolate_single_pageblock(unsigned long bound= ary_pfn, int flags, * Return: 0 on success and -EBUSY if any part of range cannot be isolated. */ int start_isolate_page_range(unsigned long start_pfn, unsigned long end_pf= n, - int migratetype, int flags) + enum pb_isolate_mode mode) { unsigned long pfn; struct page *page; @@ -492,8 +484,8 @@ int start_isolate_page_range(unsigned long start_pfn, u= nsigned long end_pfn, bool skip_isolation =3D false; =20 /* isolate [isolate_start, isolate_start + pageblock_nr_pages) pageblock = */ - ret =3D isolate_single_pageblock(isolate_start, flags, false, - skip_isolation, migratetype); + ret =3D isolate_single_pageblock(isolate_start, mode, false, + skip_isolation); if (ret) return ret; =20 @@ -501,8 +493,7 @@ int start_isolate_page_range(unsigned long start_pfn, u= nsigned long end_pfn, skip_isolation =3D true; =20 /* isolate [isolate_end - pageblock_nr_pages, isolate_end) pageblock */ - ret =3D isolate_single_pageblock(isolate_end, flags, true, - skip_isolation, migratetype); + ret =3D isolate_single_pageblock(isolate_end, mode, true, skip_isolation); if (ret) { unset_migratetype_isolate(pfn_to_page(isolate_start)); return ret; @@ -513,8 +504,8 @@ int start_isolate_page_range(unsigned long start_pfn, u= nsigned long end_pfn, pfn < isolate_end - pageblock_nr_pages; pfn +=3D pageblock_nr_pages) { page =3D __first_valid_page(pfn, pageblock_nr_pages); - if (page && set_migratetype_isolate(page, migratetype, flags, - start_pfn, end_pfn)) { + if (page && set_migratetype_isolate(page, mode, start_pfn, + end_pfn)) { undo_isolate_page_range(isolate_start, pfn); unset_migratetype_isolate( pfn_to_page(isolate_end - pageblock_nr_pages)); @@ -556,7 +547,7 @@ void undo_isolate_page_range(unsigned long start_pfn, u= nsigned long end_pfn) */ static unsigned long __test_page_isolated_in_pageblock(unsigned long pfn, unsigned long end_pfn, - int flags) + enum pb_isolate_mode mode) { struct page *page; =20 @@ -569,10 +560,10 @@ __test_page_isolated_in_pageblock(unsigned long pfn, = unsigned long end_pfn, * simple way to verify that as VM_BUG_ON(), though. */ pfn +=3D 1 << buddy_order(page); - else if ((flags & MEMORY_OFFLINE) && PageHWPoison(page)) + else if ((mode =3D=3D MEMORY_OFFLINE) && PageHWPoison(page)) /* A HWPoisoned page cannot be also PageBuddy */ pfn++; - else if ((flags & MEMORY_OFFLINE) && PageOffline(page) && + else if ((mode =3D=3D MEMORY_OFFLINE) && PageOffline(page) && !page_count(page)) /* * The responsible driver agreed to skip PageOffline() @@ -591,11 +582,11 @@ __test_page_isolated_in_pageblock(unsigned long pfn, = unsigned long end_pfn, * test_pages_isolated - check if pageblocks in range are isolated * @start_pfn: The first PFN of the isolated range * @end_pfn: The first PFN *after* the isolated range - * @isol_flags: Testing mode flags + * @mode: Testing mode * * This tests if all in the specified range are free. * - * If %MEMORY_OFFLINE is specified in @flags, it will consider + * If %MEMORY_OFFLINE is specified in @mode, it will consider * poisoned and offlined pages free as well. * * Caller must ensure the requested range doesn't span zones. @@ -603,7 +594,7 @@ __test_page_isolated_in_pageblock(unsigned long pfn, un= signed long end_pfn, * Returns 0 if true, -EBUSY if one or more pages are in use. */ int test_pages_isolated(unsigned long start_pfn, unsigned long end_pfn, - int isol_flags) + enum pb_isolate_mode mode) { unsigned long pfn, flags; struct page *page; @@ -639,7 +630,7 @@ int test_pages_isolated(unsigned long start_pfn, unsign= ed long end_pfn, /* Check all pages are free or marked as ISOLATED */ zone =3D page_zone(page); spin_lock_irqsave(&zone->lock, flags); - pfn =3D __test_page_isolated_in_pageblock(start_pfn, end_pfn, isol_flags); + pfn =3D __test_page_isolated_in_pageblock(start_pfn, end_pfn, mode); spin_unlock_irqrestore(&zone->lock, flags); =20 ret =3D pfn < end_pfn ? -EBUSY : 0; --=20 2.47.2