From nobody Thu Oct 9 16:43:22 2025 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2064.outbound.protection.outlook.com [40.107.243.64]) (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 BD3B41FDA7B for ; Tue, 17 Jun 2025 02:12:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.64 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750126346; cv=fail; b=Iebhdk3xvjEQWhxs+X9hE5eaJrJ1h1qrY1VJ8OA0FWyXA5tU2p5N3SrOl+0oBo5aMrj9Dsf4kNw4MQajZrbX7abmL8SxUI8LlJ3svY2uzCp9sQQUL4ABLhiHT6SmteiVbZiq5WM4wk7HsY11PsXIBoJaR4a8sKByZVnaTEbrfCk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750126346; c=relaxed/simple; bh=N7UO7wHQXxuCm5PacS6BHJrNgpM2js1V5V2lHd94PiM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=slP03kfk1sOver/xTWOgTWWyMQTaQyBFSWL8xRvyhGNnT3+4KH/iBbkGT08WXdhHRJ0dzw/PnhQW6sb6Zxjky1wZYqvlkRwNnOBt0B2vGv8FPUef4rm7QGwGUhgiKd1CxFzlBtOqEI+SZEKVz0QpYH2nLag1/Q9xwGdsRDY1ho4= 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=sR23UqxR; arc=fail smtp.client-ip=40.107.243.64 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="sR23UqxR" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Qrqyck0/9JVXU0fJOdQeaEOWY95q0+lt8RjYwOC1g88HXSa5alksB4wBGVAAX8V4xTLRbQ7Nu5TniuWKEOtzg6y5VBVSpg8vJhXJ7pBag7JU8xJ5NRAMMP8lCbIE1zNqcu/7QcAmNzDyyW+0bFPpGjWkjIEGEPDZrlXL0eQrlgA8CXcH4xk9OQPKQ8Furwhhyb3cy2uw2pO31NNgue092Yv9ouNdZoE1TaBPBk9ZBlDmXDP25V06G9wsUJ6dIEb9q5tIJeOKrzcJwTE+63iVPUhlZGdVksrtOaPhSMHcWZLFqln38kvFktIHmA8IZAED7DNnG7y1ZeQd6MHfz7SUWA== 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=wE8sLxzQaz8zGgNGZIBWr6Ap7mgkheIObVmJrbM19qM=; b=aabqOhD+t2UqxWdyNw7eqtg6X2LMGY03GMU8iDYXy1TQCzPc2zfYZgpvuGRE98ObcPJlxNNGlYwo7XJq2SE66eNTFrLeIKtuCmF6zH21aOxKGJk0VrVXdZLUEnjzM3IEh5YxYisWjEdbSJZVQqaGea4p7OyCW45AURwKBiGyTu2bEpESYjuSBM/hkIOxNdPjthEtxqG1Ow/oyqhwmg6SsTn3mI0qN49O2mYKvMtDTHrzzZDZOHCV6BRP3p/gJ3fi/VUlJTcnksPhB9E+ZvkFxGiREE5DlwWm7kjJ80wmeP8l6gwKvWBSb+0N+k1xytMQtvYCv5+bibCYQRQRPz4EUg== 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=wE8sLxzQaz8zGgNGZIBWr6Ap7mgkheIObVmJrbM19qM=; b=sR23UqxRftCauBPfrS9QnKvwhNTxtehvkE3NqKKaQs09eW2nvqJdmbHQT3XHR5oVOkCNuXTJbU15A+bBAhePdf5QqxjcRLqWrBGyYYbu2VQb9pDUDxs4S69TvGO7bYYdlEjWBuKKg4eacGo9LB1NgJFohB/fMHjpin+F4ms/0hEXjHIyKbiFa964das8GKCUCFq0TuCaPj3fGAJbvzNKKWyRScUMKXLnMehEajxOZ8JRPTz6hqoZ9G+L43kxnEpzQqPDvGoFiFTRxN1hhXpr1y42YGciHG1gFmpJWbCMsO5xNTo+X4jLhJz5tIOoEz63iHhuGO+CA/PIGdTAgMCfIA== 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 BL1PR12MB5921.namprd12.prod.outlook.com (2603:10b6:208:398::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.29; Tue, 17 Jun 2025 02:12: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.8835.027; Tue, 17 Jun 2025 02:12:20 +0000 From: Zi Yan To: Andrew Morton , linux-mm@kvack.org Cc: David Hildenbrand , Johannes Weiner , Vlastimil Babka , Oscar Salvador , Baolin Wang , "Kirill A . Shutemov" , Mel Gorman , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Richard Chang , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v10 1/6] mm/page_alloc: pageblock flags functions clean up. Date: Mon, 16 Jun 2025 22:11:09 -0400 Message-ID: <20250617021115.2331563-2-ziy@nvidia.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250617021115.2331563-1-ziy@nvidia.com> References: <20250617021115.2331563-1-ziy@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BN9PR03CA0716.namprd03.prod.outlook.com (2603:10b6:408:ef::31) 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_|BL1PR12MB5921:EE_ X-MS-Office365-Filtering-Correlation-Id: f3c889f8-53f5-409a-4827-08ddad4463e6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|7416014|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?zyxlTrFlxskokZh5VvLCUAExUU82JWyw7WN0lElRaM12GeKjDzHULCQH7nbH?= =?us-ascii?Q?K62DAp/FeQ8HdoS+Y07aM2naQOvF9BQ5aOBazU+r1qCd6uIQQ8OakTIperAz?= =?us-ascii?Q?ikVAGCz2CeNX9rPw8cSupYkLdIhEx0iDWGXkGD4Sae3q7L4q3uwj0z60HSLY?= =?us-ascii?Q?lw0TR5Vp7eEhq6JliPjd4LbtqA6iiN/N1QeitZjDNbmBTGggUzp7h1vlC/yc?= =?us-ascii?Q?uCM6uXxH6BK5SIU1nCu9INQiBE1vOLeHDcUx9v3VVPbcWJtN4g+fWMZc/+K7?= =?us-ascii?Q?rqVFkv36UyL/uD8b6KZ8s2w/LWUcvGXsErOOUoVFuqZJhk6Uxjnl9A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RRhjBKihywNksEfUQJvqBmOxXm1WbW7pO?= =?us-ascii?Q?PC31Rx8SIetNKbjL7jDSP3vB+hBoqgu/TWXQ9l3/HDmzTTow/CStJQJiM75e?= =?us-ascii?Q?m235489GB13z72iMsabXE6T/skimdspCihUlFMf9uaRXYJZGOunua/xBVt2z?= =?us-ascii?Q?XsgytkGRpbTETdnpkfrXUriKJqNZQUrP8MKJr1rcismuzEyVFcl0QRCjWlui?= =?us-ascii?Q?E2fQoVX+wRA=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)(7416014)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?npm7AVQCPTUKC48Nk3PuEHCQfi38uW3v4jFNM+pH6/HS/q0zOzf0qXn2P6yJ?= =?us-ascii?Q?oAsZHpZlIJOt66A6YnEBnCi74hPvJtd38qLRue48zUaxO21JpvVnN5WCrYyC?= =?us-ascii?Q?V5JgO8RwShoFEi9tnGy7mY0P8vpP3r8CAyWoMqMbCjxGik/4AtQKoY7LRJ5a?= =?us-ascii?Q?oR3kLe5AOzIj3K6Nl3W5ba1H4Siy4eJGivcknuKAzR4icobjSmvFy01jPheX?= =?us-ascii?Q?mf4saugEGwrYFEj15sGN3FdRTQYhP6V4x9JBT585XTy/v5pAx8Y8v9ZgRIXv?= =?us-ascii?Q?GHk61M7gV7n2s3su8Uvy0n8m1b9VE5QJjtX/P2kKmjZLA8BfmdPIsGkU7876?= =?us-ascii?Q?vJExqDZ+9JbOIJ4z/TJeLAc97sH23BbCGKNlt+64+NvUKdrasTZ9BzlcC19M?= =?us-ascii?Q?Rcd6jaY1c1P83wYoNzTnwBX3c5xLfEuwL/tjUidK77nALxGG909QyNybF4tG?= =?us-asc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pQrNL5jhORxbLJA8PpCRRaHmGULGn?= =?us-ascii?Q?nziwjwO9R8/lbcLwGQkr32EGnF8bWMMxi/BKfjNJRHvC0SvTKSfFjQv07fPn?= =?us-ascii?Q?9ATtdApCMdDTzJoFyzud26mihGxuNwftnggMsPyUlRLZ4k3RQ7sTp60Yl4Bq?= =?us-ascii?Q?QUK+eqWsF7G6YRYCIuW/c9Du+fDb6VkbTWF2M6/zjW52pVhXUMPo3H9TWmEg?= =?us-ascii?Q?IOWycrrrO9vOa0BlHLIdLT45mneyGnpm1nZPb0B0?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f3c889f8-53f5-409a-4827-08ddad4463e6 X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2025 02:12:20.4709 (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: tepWsWfXvHeBAX+k7k4JgKc7aWDCbvw9WUP/8ubfKfHnYV2erYScBRkh+4faiY3o X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5921 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. Rename PB_migrate_skip to PB_compact_skip. 3. Add {get,set,clear}_pfnblock_bit() to operate one a standalone bit, like PB_compact_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 Reviewed-by: Vlastimil Babka Acked-by: David Hildenbrand --- Documentation/mm/physical_memory.rst | 2 +- include/linux/mmzone.h | 18 +-- include/linux/page-isolation.h | 2 +- include/linux/pageblock-flags.h | 34 +++--- mm/memory_hotplug.c | 2 +- mm/page_alloc.c | 171 +++++++++++++++++++++------ 6 files changed, 162 insertions(+), 67 deletions(-) diff --git a/Documentation/mm/physical_memory.rst b/Documentation/mm/physic= al_memory.rst index d3ac106e6b14..9af11b5bd145 100644 --- a/Documentation/mm/physical_memory.rst +++ b/Documentation/mm/physical_memory.rst @@ -584,7 +584,7 @@ Compaction control =20 ``compact_blockskip_flush`` Set to true when compaction migration scanner and free scanner meet, whi= ch - means the ``PB_migrate_skip`` bits should be cleared. + means the ``PB_compact_skip`` bits should be cleared. =20 ``contiguous`` Set to true when the zone is contiguous (in other words, no hole). diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 5bec8b1d0e66..76d66c07b673 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -92,8 +92,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 @@ -122,14 +126,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 6297c6343c55..c240c7a1fb03 100644 --- a/include/linux/pageblock-flags.h +++ b/include/linux/pageblock-flags.h @@ -19,15 +19,19 @@ enum pageblock_bits { PB_migrate, 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 */ + PB_compact_skip,/* If set the block is skipped by compaction */ =20 /* * 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_compact_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_compact_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_compact_skip) #else static inline bool get_pageblock_skip(struct page *page) { diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index dd1c4332347c..ddc6c6c63a30 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -774,7 +774,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 1d46d0fb1f61..b303f60b6ed1 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -353,81 +353,174 @@ 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 bool is_standalone_pb_bit(enum pageblock_bits pb_bi= t) +{ + return pb_bit > PB_migrate_end && pb_bit < __NR_PAGEBLOCK_BITS; +} + +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(!is_standalone_pb_bit(pb_bit))) + 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(!is_standalone_pb_bit(pb_bit))) + return; + + get_pfnblock_bitmap_bitidx(page, pfn, &bitmap_word, &bitidx); + + set_bit(bitidx + pb_bit, bitmap_word); } =20 -void set_pageblock_migratetype(struct page *page, int migratetype) +/** + * 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(!is_standalone_pb_bit(pb_bit))) + return; + + get_pfnblock_bitmap_bitidx(page, pfn, &bitmap_word, &bitidx); + + clear_bit(bitidx + pb_bit, bitmap_word); +} + +/** + * 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 +760,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 +786,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 +808,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 */ @@ -3123,7 +3216,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 Thu Oct 9 16:43:22 2025 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2064.outbound.protection.outlook.com [40.107.243.64]) (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 EF0472036E9 for ; Tue, 17 Jun 2025 02:12:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.64 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750126348; cv=fail; b=CVGxYYmD7h1opfWA6JfO2NkH2uq1n/61Fp5wfPPgcyz8RRHjgMyjBg1PC+bJ/GMTOGTyx22F/Je37f0MYhAU3YYsbNvCFDXudjLZJuSIRIXeFknfLuVvlY6n77XXSbSfTzaRO0lE6M57au7hNPVlhHNPQi4JJYKg8/IickkBTx0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750126348; c=relaxed/simple; bh=xMNOBFptsatJunn4GVsHm8dUqDAS7dh3Q2xY9FmORKs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=o4bJ5tVTPIsa5MncKB0z4WzTb9I9Gv9XsJj3qHGlQiEcTA1aN53Aw/UBAUfSmJK/r9nRU0a9d4cj8cZxxFKt7Hg9xyWkqhQesHV+/O9fFxQfGzAeTwy9FVvsKeczuGiedsZmdeVe3CTa0Bbz0ntkUlHL0ghhElyzqQIf3r63vVo= 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=krr0c/Nd; arc=fail smtp.client-ip=40.107.243.64 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="krr0c/Nd" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QFBoBvH0+ExsiMNKb0AdPTdGTfJWISZ+5Z6kqgUIyDc5UmDp7N0i/dPGiPWsiN1hkVPSMVFo3DkyPqE5QjSXm2q7bE2LBqQJ6/2XW7pAOUflX3d9ovRxArV5BtvN2YqkdgLovxOe33z5dnlAGNRSiIBJMpRQYeMYeDhn+mOHioxn1yh8nG6Eze9CAjVrOGG9hHYkebcB3N/K13tJTygtAe7iR6qDfwws9SeVj2+NStJmB55fjJAvKsV7DC5fs3CGv/fuiBQQ78LBVl6WV9dvHSwKoye2523KuiyiAyPwPdfM+HWqGuBhLdF0/NyIyvkZHMF53fXolNAar/Vzeh+H4w== 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=3aWlbvxfbraMWybz7/Pfg4gx+wiq3tJBlLsue4a5SvI=; b=Dq2f7zb3WIPFbp9c57AM4GTPYzltPsgIr331U9javMF+6roCdloxreK31lu8vsTg+BSAtQXByeH/HKdHCPfMilrVb2/d1a3k5pI8buE+K701gh0ULoTi1HRUEm+RxdJcY5C48utPpgYXMO6NWSeNBBDPYiNJYRfxxxnr2NkctNExwEFgEWwcErFoIqgmLYJkDbfkEGjmhQlyLMg6Uw94xJ1kcm3Qg8Bnk9URZLzsg1yfMs8iNJlxipxfdgj2BJu6Xz4GYL8SVhxldZ/p2qkH8mqa4EdeqN0WnKh2sKBLvFfCGPaEmGvVPvFRsxZ0yGrazsP9IgBQiJ/JYd80xb1GUA== 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=3aWlbvxfbraMWybz7/Pfg4gx+wiq3tJBlLsue4a5SvI=; b=krr0c/NdzSQZT85DLleVFXQCANMD7NngSwS4R9/NAHG1PB8UpaerLLK5GBeu/4+rOMGpUU2o3MHR5HFvRgETZxJ6AwjBnSMscB/06LmzYdKcen00roRErmUNsr4D0f6TB87oVTcRyOFaA6V9GIKQVYYvwxS2jNyNCOOCnw4s5V1oSCz/UXPuQJm3qaRFRTBHC6V8T2FTdPQ+ohAmJe/lEgvZC60uKL5fG0vNgtZWpPeCx7thBdhVkCjcvHXrgTtlvz6kCKRRgMRy+EdZwZFvwURhfnQhdVBjl18zApfMXBC1jqK/4OBlroqx3djqd9k6V78CNhYDLo9DnsagJxLdPA== 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 BL1PR12MB5921.namprd12.prod.outlook.com (2603:10b6:208:398::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.29; Tue, 17 Jun 2025 02:12: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.8835.027; Tue, 17 Jun 2025 02:12:22 +0000 From: Zi Yan To: Andrew Morton , linux-mm@kvack.org Cc: David Hildenbrand , Johannes Weiner , Vlastimil Babka , Oscar Salvador , Baolin Wang , "Kirill A . Shutemov" , Mel Gorman , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Richard Chang , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v10 2/6] mm/page_isolation: make page isolation a standalone bit. Date: Mon, 16 Jun 2025 22:11:10 -0400 Message-ID: <20250617021115.2331563-3-ziy@nvidia.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250617021115.2331563-1-ziy@nvidia.com> References: <20250617021115.2331563-1-ziy@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: MN2PR19CA0008.namprd19.prod.outlook.com (2603:10b6:208:178::21) 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_|BL1PR12MB5921:EE_ X-MS-Office365-Filtering-Correlation-Id: 946a2a86-626d-4b31-e5c2-08ddad4464e0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|7416014|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?0a5czOCnLfSRAR4ptKu8astLKU5Y7MqwmigochKfiqSEI9LFuBd8XxElQrj+?= =?us-ascii?Q?t9xGwYTsrOOI/Qg+iQlEJdj2Tm72FcRtgcgUZGiKAt64v6D+UE9VTcoed1s8?= =?us-ascii?Q?3XPWgvyDAV8DfGWXwy1YSlNTGLMEGyFpDvOYvFGeVEW6iIPfRozns7IlbjGX?= =?us-ascii?Q?ePnCT8RzDPr5q94j2NZ9pIa6f8JOKyn2/HB1sPmyTBuwDq852px5JDbfR4WC?= =?us-ascii?Q?caNTHn6d0y39XKaxhZwgeeLzhxlJ60lO/KYBCMiOP2UW2W++5QfovUNe9L+Q?= =?us-ascii?Q?WKhTm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Qfukea6msd8eps?= =?us-ascii?Q?V310jN5yQG3fVnJ4avT633PTs69IaeREfZFOTb//xnjeMTRm3VCRZu/0lWuI?= =?us-ascii?Q?woaYQ//5VbwMcI1b0Ng54zeb7ISJ3/M+3p1ItOworMylsrXe4QnHtvsVinlY?= =?us-ascii?Q?mJRAkCKdMHVu/gx5LvcNy24LdV/BB0ukQs+r74/fUHKHEGO6X0AWvY2QOvah?= =?us-ascii?Q?OzDCR8keTtI5WNvFdFk5BXYaYV2gAioVX9MnDs6ie0Kql610ww=3D=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)(7416014)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?P1clOo0elRtxRQHSKLYEW9uPU1xz2+A1kQUKVRhI+0oW+MkFQFb3O7J3OQvO?= =?us-ascii?Q?pJjqxFoONJsGZJnaMi+G6relYgrSQIFSVBfjFxek1nBKUN1wUmP0sGVlKAtB?= =?us-ascii?Q?6jv3jnHtW7Q4aDR2FknQWfZu193u6RHGT69CEl5gdU7eli8Dz0867JglYkSj?= =?us-ascii?Q?uq5eEbZ+CHndP4jstHcsyGWIdLIRD2lFr2NC2zzp5dO/xsAsnM51k/i04VoM?= =?us-ascii?Q?wMo2Ja2zkNz7fvewAX8CIrE5Q6eS+l8D58bZIfM7q0mGrcR5gqNtluqubVoH?= =?us-ascii?Q?rYgtoHZpVe+YJaije7AULdrtdb+vuTne3LH5tbXbnNsgnXBVAJHBlnLuYMxY?= =?us-ascii?Q?OKUyOhMLy345zihcBO0SeMzBYQcdXasJlicbnYvqYrB2MdLO/g7AGgfrjnZ9?= =?us-ascii?Q?2SY0fe7qPYo9hiDcZDNng1H/KrIDSlxrkK4v/v34p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sL185jRYT4TAscrKlVmhEXMAqTVEespIF4Tog/hLyjD3Yme9X?= =?us-ascii?Q?J3+4mT2OXK89AAQmQRrRrOdXgA5E5EZK1/GtiPGMsqzYTLJqefrC58G8omWL?= =?us-ascii?Q?joDebjFqwJ36ZlhDEayXKwhBBT+w0TvOGcjoh6sTvcbCYKkNvTHK2lTHwjpG?= =?us-ascii?Q?kRGn5seeo5vqCm9ql52EmZZAqFJM+sKsHV7jztr+KCDEBaHcjmA40qvRWzeX?= =?us-ascii?Q?EYtSjIJNL0Yt5ddW3hsv+0L7in+eTAJ6orF31Idn?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 946a2a86-626d-4b31-e5c2-08ddad4464e0 X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2025 02:12:22.1008 (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: PXj3c1I8qxCQRGoQpJctIH2O4R4Gzv3e4b1YXe7kD1PfMQ4OIJkVELpg/VRf/Rro X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5921 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_compact_skip, so that migratetype is not lost during pageblock isolation. Signed-off-by: Zi Yan Reviewed-by: Vlastimil Babka Acked-by: David Hildenbrand --- include/linux/mmzone.h | 3 +++ include/linux/page-isolation.h | 16 ++++++++++++++++ include/linux/pageblock-flags.h | 14 ++++++++++++++ mm/page_alloc.c | 27 ++++++++++++++++++++++++--- 4 files changed, 57 insertions(+), 3 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 76d66c07b673..1d1bb2b7f40d 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -79,6 +79,9 @@ enum migratetype { * __free_pageblock_cma() function. */ MIGRATE_CMA, + __MIGRATE_TYPE_END =3D MIGRATE_CMA, +#else + __MIGRATE_TYPE_END =3D MIGRATE_HIGHATOMIC, #endif #ifdef CONFIG_MEMORY_ISOLATION MIGRATE_ISOLATE, /* can't allocate from here */ 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 c240c7a1fb03..6a44be0f39f4 100644 --- a/include/linux/pageblock-flags.h +++ b/include/linux/pageblock-flags.h @@ -21,6 +21,13 @@ enum pageblock_bits { /* 3 bits required for migrate types */ PB_compact_skip,/* If set the block is skipped by compaction */ =20 +#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 +39,13 @@ 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)) +#else +#define MIGRATETYPE_AND_ISO_MASK MIGRATETYPE_MASK +#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 b303f60b6ed1..a6e191f86ea3 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -365,8 +365,12 @@ 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); +#else BUILD_BUG_ON(NR_PAGEBLOCK_BITS !=3D 4); - BUILD_BUG_ON(MIGRATE_TYPES > (1 << PB_migratetype_bits)); +#endif + BUILD_BUG_ON(__MIGRATE_TYPE_END >=3D (1 << PB_migratetype_bits)); VM_BUG_ON_PAGE(!zone_spans_pfn(page_zone(page), pfn), page); =20 bitmap =3D get_pageblock_bitmap(page, pfn); @@ -439,7 +443,16 @@ 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_AND_ISO_MASK; + unsigned long flags; + + 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 /** @@ -519,8 +532,16 @@ __always_inline void set_pageblock_migratetype(struct = page *page, 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; + } + /* MIGRATETYPE_AND_ISO_MASK clears PB_migrate_isolate if it is set */ +#endif __set_pfnblock_flags_mask(page, page_to_pfn(page), - (unsigned long)migratetype, MIGRATETYPE_MASK); + (unsigned long)migratetype, + MIGRATETYPE_AND_ISO_MASK); } =20 #ifdef CONFIG_DEBUG_VM --=20 2.47.2 From nobody Thu Oct 9 16:43:22 2025 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2064.outbound.protection.outlook.com [40.107.243.64]) (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 B221C20AF87 for ; Tue, 17 Jun 2025 02:12:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.64 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750126350; cv=fail; b=Pr3uZ7tYaVdEqBqGWyRHdLRD2c1pwcUBqumKi0K6kAKf8R16CNrVtdT0s202h5sVDzgj1FyQ7dA8GclViLJtRkO1PoFdANR1P5BjJCv1crrRGO5JBBu6pnl1RvFMVIRTec66vOJTOxTJPeqDdrqjG6eeXOA40/m9nLhGFf/BbS0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750126350; c=relaxed/simple; bh=huZa/wTHPFvllAnSp3BlNifPS6ZRxyDvQ0rEGtwbJMs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=DX1C6iP6aFMTSfLd6kqeqNLHYb1zzXlvRJIwP6+nRnWoa6/++0bNowv9Kbwz1sT9aN6W8deRphr5uPjo4Yqk7s+hkFgAOSgcUaTIfm/kk+LeDUAAh+Jr55oAhX4lrRXFhzeBAgmbyvmeTPbvtqWIvmBVsnFh5DSFMSxQCFHb8zE= 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=mHrFJPum; arc=fail smtp.client-ip=40.107.243.64 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="mHrFJPum" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tr69YQRFp1+eydqCEAyvFMnm/uNGx9UvxlgEJ8ZB2ssrIxj3FlstgFJyt4rWkqMNIEyr+d7A2IoFYgLAMutz6uMnYWUgdu4KDP9I6AQSQhapvyCFNjtWpcRhkusy+ZKPdn5RKojxqN4GAmVl0Nv2CyNdL/o1Oxh9pIZkov8s8LJbTt+YsSQPO/Fb+/qdShoJAFcziKxZnev1KopNaZ/VoRRohRUYhOlA/4Npxlhtc8z9jS8EF8QEFgOc+cuKkPWrFVIqYu5g7j/NwP8IBABNAw4X78wkOffSnrPAvIMqCh/FF2vc4Lz7Gdm35UXQDETe/GSM9ITKYLQehB4s/MD7ww== 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=UUrmxqacd0NkGZI9EGgRJ1d2aczUkKGq+xxx9NV0W5E=; b=M6lXBytLt+IL4ijRppCsL4Q4YBxLKmr+vpwcad+FbVJnE17J7WEB9UeJ/ZgpKs6cNM5s/1rBPBqdre+Kcg1IvwIF2to9xVSNO6gkXiKlMMz71xrVtOGMDjNw8xVzDcAPJ+FIzAQ7rXxaGLmuJnHE/eA6ZxFyeFIvM3CFJH2eMDP0Y9PLAFHX/x/4DUCTk7peUkjdefysWbinQ4ZeC7LVsoVuEoGvT+1B01Y4Tw0jWnAxGx1klbRufDmJoG1s6PVLjpvcHdgdnjsFUGXWY1woM1w//N5tmeXcjv687xbTF2+nZ7qK50RbtRdGO/+xPp2EIemmBHmwygBCPYrIbFgmpg== 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=UUrmxqacd0NkGZI9EGgRJ1d2aczUkKGq+xxx9NV0W5E=; b=mHrFJPum54fbo1Wne/fqIGf5YkaYbPXlZpn6UTXvxeFxZiqgtKNgpS62erQJ6VqmAk024+EIVwmmSIuE7IvIRXpjECtKM0mhk3/K/n+cle4nlKeLiAYdeksiUCN6Z2F5WVnGw5XgiyoAnjQVGVkaxgrwXWkp7g+pg1LTfM0VKbykGamwrRZSW9LebByjjddaLBIVPDCmgz+C6R7mf8g51cQ/GuydGfLi/iKthF5DpiFFozWhN8pqJCatrtb28n0SS4bZiW+eDaXwUTqOXji6n8nzqJ7TygZuNhudmSt0WzqOxUeOVVwm0swO/IYovAWA33P7kS48ziJj5v13XoSZUQ== 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 BL1PR12MB5921.namprd12.prod.outlook.com (2603:10b6:208:398::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.29; Tue, 17 Jun 2025 02:12: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.8835.027; Tue, 17 Jun 2025 02:12:23 +0000 From: Zi Yan To: Andrew Morton , linux-mm@kvack.org Cc: David Hildenbrand , Johannes Weiner , Vlastimil Babka , Oscar Salvador , Baolin Wang , "Kirill A . Shutemov" , Mel Gorman , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Richard Chang , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v10 3/6] mm/page_alloc: add support for initializing pageblock as isolated. Date: Mon, 16 Jun 2025 22:11:11 -0400 Message-ID: <20250617021115.2331563-4-ziy@nvidia.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250617021115.2331563-1-ziy@nvidia.com> References: <20250617021115.2331563-1-ziy@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: MN2PR19CA0011.namprd19.prod.outlook.com (2603:10b6:208:178::24) 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_|BL1PR12MB5921:EE_ X-MS-Office365-Filtering-Correlation-Id: 05946fad-7fe7-4738-d8e9-08ddad4465e9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|7416014|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?U1kdoHu/ETHb/FWa+kz9Mrf1kCvFyJ8Rbw7OMj2LCcTHYQTXsNBI4guFaAa0?=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P86vn0odkIzwDiVejjpeFwLWE2BPcz?= =?us-ascii?Q?OM35AiAmdVUUm5Mqn0jyqCw9UmjnC1ii+rFf+b11Vcrk/9nURcbjMwrxdAJ5?= =?us-ascii?Q?FPqEZTFzaBdNcYxjbrk77vvQgIAo0vUDdeDHrqmdkQ0qdCY+DCQrdQZsZ9zZ?= =?us-ascii?Q?RroEmBQerrJ2v4sJKEAFqO7wYG6B7jiRdpIPjAvHNFZGYT3fkG9hCk9ivgxS?= =?us-ascii?Q?DjV2VL0id9l9oTYMuoYaAHJPjYDx5fKnTzWHlzEm9Ezd/H/aGnfkWflzt6Kp?= =?us-ascii?Q?08qzxBjRJZ1u4YUKiGs3XOGY5P6k9VNSzRwN6hwz7Z321co5knUGwDaI7/ZX?= =?us-ascii?Q?rVa3nPOu0MpJXXn0p1JxDDuhv0FjbIvOn0ohigOAYKl1x/JOlOMt7qJ1QqDd?= =?us-ascii?Q?7B0oHxx5G9XlzyCQDAcQfv+KqzDgFKXszCloMbZy/VPLKIUC9etHd5Bst3Kb?= =?us-ascii?Q?B8OvmPUa7OiirHTPcgivuErTI7GE2Y4zBzodjSY01NWYpJwiJb30VhH0bkS/?= =?us-ascii?Q?qLO8fuzmMU0=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)(7416014)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?jD7O44Vng4wK6eFOhSnXmRt5AXObv3JUBrJT2305vND1uOYg0ypT0EQV2/0F?= =?us-ascii?Q?IyaKBi3yAkO4buTr9QqNmlVReugM+ieoC30XMCB7WeOvUJiQvNZBC6O/SrtT?= =?us-ascii?Q?ne+PGrCAQnQ97I63lX42c+Ffq0BGTWb16DZ4n/D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QlKfcau1A2SHylMnvcvxvlvqXKzXJ1Lcyo4l7+F8+QkZ4+X+6JbO7?= =?us-ascii?Q?U0GNj4HJFfSRKzVh0C/8sb1f/BchbHNPv6plcMDP4JpTFr2N3MbqMON05JCl?= =?us-ascii?Q?DkhzfbAJ7UmOt93q8ifPY7MtGNF5iJKEL0WOfEiiDzTcQa8bPLrNTsq1gOtP?= =?us-ascii?Q?FP8TZ/3NHGx5Kf7IkM1mKu1OIBrpEqNPFSTuPBWt8gS5slrERwZKEQZV3Dlv?= =?us-ascii?Q?LuoXvu4Nv/XRnlCnS9pWqjeM/pNcwXspOrXsV4SdcJzorFpPKIkt0E2P7c1F?= =?us-ascii?Q?7eWN9aZtHI2ypN9DglR4R4zv1dJ0ms+DdfREJE9O60d4cd6xHJ7ZjInWKRc0?= =?us-ascii?Q?TMQrGIzxgmlPq41YOF8vPs3bWiLDnczIRWehnCLmvUwF22mp70CaV+FSSWFm?= =?us-ascii?Q?XziUkqqik8ZbZf4eCEF716JbsMHldy0bOypYWZww1KhThUrGke8Ke5L8N5YP?= =?us-ascii?Q?qb7v3DWegzCBa0kSV0cqGrLezIzy8A5oXg3gtLvve+c9gJchHzJkukbAzOCj?= =?us-ascii?Q?OAl7hSihwdvFRBdYLTbAGVYlKQrMfq3Mls+8eqEH?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 05946fad-7fe7-4738-d8e9-08ddad4465e9 X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2025 02:12:23.8456 (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: RY7MtLapmvgKJNqqJ6h3sZ0i3iiImgtU3gTabB7KpmrTZT66LfD+Eom3CBoBc0Pd X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5921 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 Acked-by: David Hildenbrand --- include/linux/memory_hotplug.h | 3 ++- include/linux/page-isolation.h | 3 +++ kernel/kexec_handover.c | 4 ++-- 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 ++++++++++++++++++++++++++ 9 files changed, 61 insertions(+), 20 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/kernel/kexec_handover.c b/kernel/kexec_handover.c index 5a21dbe17950..49634cc3fb43 100644 --- a/kernel/kexec_handover.c +++ b/kernel/kexec_handover.c @@ -1100,8 +1100,8 @@ static void __init kho_release_scratch(void) ulong pfn; =20 for (pfn =3D start_pfn; pfn < end_pfn; pfn +=3D pageblock_nr_pages) - set_pageblock_migratetype(pfn_to_page(pfn), - MIGRATE_CMA); + init_pageblock_migratetype(pfn_to_page(pfn), + MIGRATE_CMA, false); } } =20 diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 7a7df0b2a561..3d61ec17c15a 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3299,8 +3299,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 3823fb356d3b..79955ed9ac0a 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 ddc6c6c63a30..35f008364698 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -747,7 +747,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; @@ -779,7 +780,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); } @@ -1104,7 +1106,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); @@ -1171,7 +1174,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 node_arg.nid =3D NUMA_NO_NODE; if (!node_state(nid, N_MEMORY)) { 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 02f41e2bdf60..5c21b3af216b 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 a6e191f86ea3..3fae0694aaaa 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -544,6 +544,32 @@ __always_inline void set_pageblock_migratetype(struct = page *page, MIGRATETYPE_AND_ISO_MASK); } =20 +void __meminit init_pageblock_migratetype(struct page *page, + enum migratetype migratetype, + bool isolate) +{ + unsigned long flags; + + if (unlikely(page_group_by_mobility_disabled && + migratetype < MIGRATE_PCPTYPES)) + migratetype =3D MIGRATE_UNMOVABLE; + + flags =3D migratetype; + +#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) + flags |=3D BIT(PB_migrate_isolate); +#endif + __set_pfnblock_flags_mask(page, page_to_pfn(page), flags, + MIGRATETYPE_AND_ISO_MASK); +} + #ifdef CONFIG_DEBUG_VM static int page_outside_zone_boundaries(struct zone *zone, struct page *pa= ge) { --=20 2.47.2 From nobody Thu Oct 9 16:43:22 2025 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2064.outbound.protection.outlook.com [40.107.243.64]) (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 B58441FDE09 for ; Tue, 17 Jun 2025 02:12:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.64 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750126353; cv=fail; b=b//yvKNLU2s04shSndD6pUmO5m8q0q3ZizvKciw3ykmo0oOaDku3zov+BTtPxdSkXEwiSDTt2WfrthndE4yhQAJlU2PCrXyAqFtmdrK/IWB3Kkc7qV9FqepAxSk0mq2upJUXVVS6jw1iKDs0hUbuDirlZpGn1aTBI2dq+rDomhk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750126353; c=relaxed/simple; bh=EGWpb/EQeiWMZrEmUAFVy8Ia/PUL5CuUPfNWpAowAFU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=B+VJ6z0YUG1KAIxWBZIKzgJUmxnAb4LT4icyWmXZTb1YRexseupCv7YLc4eGk5SzqPFuWLLcy9+/1TfmWTXjJf9OIVEb0YpfdTNoQYhrfqI5w7InJy3P9IkUfZMh5FBAjcCIiXuqUFEsg2QHy0DdQt9G1UL7SbUd0FjQAfGeIe0= 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=VIzKeI49; arc=fail smtp.client-ip=40.107.243.64 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="VIzKeI49" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=y+F4SISn8Pmr//1oBdMelu3AUXkVrskb8cfH5NjxJ5dvRtIE/QTTCsi1HAAEj+tACjQ9G3mE2orKSKCX+QHIEvKWFzLMUoiSLL5nARol7pN/xnX+XF6ldUX/XyomlKtd33YgVa9LoHJ7xtGfh0BcgDvCqfLNs3K+/3VdxaMzc1aRHpG7QRqmnqZUd1s2rr5p0mxgHOdNy2NsGmE9NngK+4KUwTRpay2y1Ww3lykmajSqMdPMv1b2I7oT2kmNvem8pBt13cS2QpKEEfefuSKSt+tpJXwlfHAB9+Ylegcc/YVb8GdUSCZvoPuJbcp5P6KXi0BTO/QF7G8InmxK8k+vcA== 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=NxI0/1wZBlRnZRVuH9jl4pcmlwXpkQJNlOlcwtgHQek=; b=kuKPWWLPKhrAmovIOBYNHge2MRN1LXjlP0hZ+6qOjDS8PkeVpNlizc0CkZdSP8zjzPReEXSK8mUsW8vKVvw2NH6XU/K7QIpz47FGIClgI4kvf/Wjn7DAbvAU2yOYj2WB4UdYpyzQaxfQ9qChxERKBxU2T8EWPA5rKGbcuAt2mmTkxjmE+EdVazallFpLdsqhA2gImO6Km7uBmw0R98fNs40Fr+bYxByiJGWDNg6YxVsxGjRi4613vWEWyrYF9uh0OZ7Q0QGXNkM1O4TiRsMDGHhFtzOvexY/XprMXKjHtJFtuIeZpVrRaEoS4gPbdB+gOEDOnWdS+DFebCyf2IXvOA== 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=NxI0/1wZBlRnZRVuH9jl4pcmlwXpkQJNlOlcwtgHQek=; b=VIzKeI49Ov5aVtG2RzvbRGK8fTl000vR4gxcYKii1MN/W+D+8Ns4Z8jht4xbh1nx7i/ET3yq/cO3TnerU7mt3B2wQw7xaf11XAl1sdr1vdSuOXRLn3fddk/I/I6p0WA0/zNu6mYbAC+wImKoRjsaQyC/Qyb0BqTku+NDxKPXafqaO9Nq15DfRY07yinH4HklB9g+2+NiXzXCVG22trDSR4ONQ/Q01Q9ueRpZ/1HaSgtICw24f8ulaEow8FykuVdgvA5wDQ52FihdbDlGoBlfCn98vpuVnUJkDOIIAebsoPYGeEa7zX9wxu8Hx28eAzOf3l70QgP4vcwybSRmvKJB1g== 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 BL1PR12MB5921.namprd12.prod.outlook.com (2603:10b6:208:398::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.29; Tue, 17 Jun 2025 02:12:25 +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.8835.027; Tue, 17 Jun 2025 02:12:25 +0000 From: Zi Yan To: Andrew Morton , linux-mm@kvack.org Cc: David Hildenbrand , Johannes Weiner , Vlastimil Babka , Oscar Salvador , Baolin Wang , "Kirill A . Shutemov" , Mel Gorman , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Richard Chang , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v10 4/6] mm/page_isolation: remove migratetype from move_freepages_block_isolate() Date: Mon, 16 Jun 2025 22:11:12 -0400 Message-ID: <20250617021115.2331563-5-ziy@nvidia.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250617021115.2331563-1-ziy@nvidia.com> References: <20250617021115.2331563-1-ziy@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: MN2PR19CA0020.namprd19.prod.outlook.com (2603:10b6:208:178::33) 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_|BL1PR12MB5921:EE_ X-MS-Office365-Filtering-Correlation-Id: 4882e724-71ee-4184-6a21-08ddad4466f5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|7416014|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?alaZdHrStAziLiMpZY/IJZW2M71Ypm3QdJ3YJ2DQyBY8IP4eyHmcZW/mDIHD?= =?us-ascii?Q?qSue337qXC7lu68VWVVaM1TbYYhSNAJbhDebkt8V3oi3S2lRpadu2HAN/QY8?= =?us-ascii?Q?38c78nL67kv4ZPsIiouJdmT35nPDyDJ9APM5j4dP0Stz9ayP4Esf1fd+KfE5?= =?us-ascii?Q?uT0WVfvwgZ3l0sFZWUrdtjSSMD4ZwilSWT8njY1r/21e+V5fgCHvX52xylZi?= =?us-ascii?Q?/MlI2SXhVJ3pUJSjkVI41NaF5Vk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L1Jq3XCrzUcfoTE/wfqrI3Ww/Wsjy50Vd5i02lIloit2P0SPPdMD6TRX+7bq?= =?us-ascii?Q?yHM1AstQEO5u5Q6CjXcOFf9LhB51p0omJQNFYur3BdVu49OwPm6nBb3hMAVU?= =?us-ascii?Q?lFmQZhGRJHwiKCjY/HkvswvwBdmdL0aHhF7erVdM+myIO1wrwCGHL2pOqLco?= =?us-ascii?Q?24kSt9tV6mDpEvY0nni+/uOAu/qFrUd+VQaPcFvT2eDywq6KdI0LWWB8DCiR?= =?us-ascii?Q?joKJWtx74MZMZv+Z96TQJn7/JhNnMBpUsajY0XkvZ+tbPJuvzFVfoQRPZMaM?= =?us-ascii?Q?yVrA/mEGczE=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)(7416014)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?CRdlLT+xaMVspLgtgWSI5kSojNy0wJNCY9+b2Wu2gZDkZojpIxcb2H458MCC?= =?us-ascii?Q?SEECZRXZzSD9wY6ZHCihSVTEZPdkDMO/ORVWLzIcxalzV2wA8RH0Xq65aHkz?= =?us-ascii?Q?Nj1GJTD1i0DekRnl+kbOmWKh22yo4GwpZ1I9hKmCIPI3mS7dj0ijkWqme3Ab?= =?us-ascii?Q?x2cjLt2tJc/LO3oOTMyRLv89AkuBKCBpp9xHr+e2xooAc3AqtCzDX+yA4Rp/?= =?us-ascii?Q?CJBEIsLOMn6ogAOS7cUYzSD9I6AysRdoaaIUMd6VJjHZ0jTEQdo7/iOrQDmt?= =?us-ascii?Q?szi0Xi5lru1zu/PDebbrKvTqnizzTMiQwCSKKuew1NwSlgTU4Ig9anrNWzn6?= =?us-ascii?Q?R5ODbCHB8niK6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GEhTPgo?= =?us-ascii?Q?ZrHXR7g8gNG+c9HqpD1XxJOPYX/25JqpBCrYM23H5NRYDxxcAPASUIM7mmQX?= =?us-ascii?Q?j7n5pWtY2rlnFhkj89HpuEaogwijTJemhqlIljSinTh3szCy1nvWbDiB6L08?= =?us-ascii?Q?dnEinbpgEsa6B2m1+jms0Ojtm02mEu1O1GRybeFXZoP99zpyVl1teDzHHVn3?= =?us-ascii?Q?xqe/EF3gxeA4FxSNcUe5f2rolorLvV6k82S5lso40Lu8LGZhOPjzxIw6Xxfc?= =?us-ascii?Q?FKyOA31UJNgunDCeNqGrlh/IG+KIFiXecjxs0+MGSOB3hQHjhS8I/yKg/3xE?= =?us-ascii?Q?nkiT+xFr0ydAVf576kzNhmQg6rcdpzugZ1soZjfK?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4882e724-71ee-4184-6a21-08ddad4466f5 X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2025 02:12:25.5922 (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: Du6Am5sCG19y5yHoWwoYrk14BeHs4kq2yIKbRXTkghVCEEWUOhAXJ8kHdkUvzmhP X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5921 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 Reviewed-by: Vlastimil Babka Acked-by: David Hildenbrand --- include/linux/page-isolation.h | 5 +-- mm/page_alloc.c | 80 ++++++++++++++++++++++++++-------- mm/page_isolation.c | 21 +++++---- 3 files changed, 75 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 3fae0694aaaa..06cc990e2a62 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -525,8 +525,8 @@ void clear_pfnblock_bit(const struct page *page, unsign= ed long pfn, * @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) { if (unlikely(page_group_by_mobility_disabled && migratetype < MIGRATE_PCPTYPES)) @@ -534,9 +534,13 @@ __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; } + VM_WARN_ONCE(get_pfnblock_bit(page, page_to_pfn(page), + PB_migrate_isolate), + "Use clear_pageblock_isolate() to unisolate pageblock"); /* MIGRATETYPE_AND_ISO_MASK clears PB_migrate_isolate if it is set */ #endif __set_pfnblock_flags_mask(page, page_to_pfn(page), @@ -1921,8 +1925,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) @@ -1954,8 +1958,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 @@ -2013,11 +2015,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 @@ -2045,11 +2052,19 @@ static unsigned long find_large_buddy(unsigned long= start_pfn) return start_pfn; } =20 +static inline void toggle_pageblock_isolate(struct page *page, bool isolat= e) +{ + if (isolate) + set_pfnblock_bit(page, page_to_pfn(page), PB_migrate_isolate); + else + clear_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 @@ -2064,10 +2079,18 @@ 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)) { + VM_WARN_ONCE(1, "%s a pageblock that is already in that state", + isolate ? "Isolate" : "Unisolate"); + return false; + } =20 if (!prep_move_freepages_block(zone, page, &start_pfn, NULL, NULL)) return false; @@ -2084,7 +2107,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, isolate); split_large_buddy(zone, buddy, pfn, order, FPI_NONE); return true; } @@ -2095,16 +2118,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, isolate); 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), isolate); + 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, @@ -2296,6 +2341,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 Thu Oct 9 16:43:22 2025 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2064.outbound.protection.outlook.com [40.107.243.64]) (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 B1A7B21C16D for ; Tue, 17 Jun 2025 02:12:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.64 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750126355; cv=fail; b=UwErIB5urGWmBUQ5fL+Iie49Po3d+es5C5z+puybgEz/9fd3HPzmkPVsDZqJXWAuhPUZ7rGgzJPcVfkRoags+73JtKG5g1+9ToC8jbuMA/0QalkmQIVIsmzc46w3Lv+uiPLbJzPjDUBesAPPdMab+Bbkgn5MqLDViHbFPIKQlHo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750126355; c=relaxed/simple; bh=Vaw4uKXFktsK2QkoVycqkyBrM2YsK1BHmChTsh1BKI0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=b0Mm2BlrX2QEdBoXi0B3btCkJmBwrulFk/2erXxg0dHTw2/6iMHZxIXZLFsA5G5JkgYA/AD/RLHBBPvGniswWwrA6FzyIWj88M3Vcscf4W57jopbbqZJVetOM0ZwL/OSYL7rO5ZCHyLIGkLYvFZYxXe7iZNVf2xgA1luvTZ8EOE= 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=N+LL3fG6; arc=fail smtp.client-ip=40.107.243.64 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="N+LL3fG6" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=w4YSaVLnrscSTbASdsfOYu1RjkV8am5B0OhDVoAIIDpLzpU+0H4JPWvYvy5lUvjKNKi8ihsyj8S+/xCCWxOdq46rZCp6zjIzLTdaeFu8cgD2YojZyO7V5VtLVaorj7lop0FmQWIYpqbqms/zyqUSi2j23J8L+EVqox68cgTSO/7VGhMTYYYy1LTvJrxT4O2ipLBRlmpt9UVj/TARulLV1F9AkPFvTO59mxoarb5ZJX1dLudA37gUYIRUab/yIt6+7a/tvWlWYQWNuZXHQ/QKRcxKDpk5NTNds170ZQxpGbSIGEJnBzf/Wv05mfcFCzfKS91jCYHo361wedXTTf7qsQ== 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=cjP6KZAdN18Ayzcw+VYjsBh+lBRJyJFtgmNXEjUOicY=; b=i0GAQVrWCDPuKGOGr21nxjrRYONkUJmvBkDO2QzETMFrJ3ZRoHaS5NxvgGfTFFn+9M0FY4fQJLqsAYKQXyZHtkzAIa73oKG3raH9u9DbO/OL/4HOtdR8xarovUZ/lXlPkLdfk9x2my2zrhfrg6N2q3YfYjXwaSj8TyLS0FH66vwmGlC70X8pDHU7Xh8d/qEqaXWZNETG/HzNFiXGzX4Hk6uzAgAs9tsJf/DbJPHyDzq9knnKA9tLo7VqRmd2Au4ECYwm520jZSmqI3Q8kHKhvprfpjwHWivV6NGdM3rpw47adtffnpUaMtp1Qc5tKxE5a8rBm8n06zB/jT1qSs9dMQ== 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=cjP6KZAdN18Ayzcw+VYjsBh+lBRJyJFtgmNXEjUOicY=; b=N+LL3fG6lCTuw2D9QoKP7wjeQkMTKwnOx29LpGdrBGP6/hqICJkuvEJTHf3NPl7TkxrN28guOyaxudWlRlVFCvjEDCtZxIN2CEJ/psk+88uA9CBK1AK7reVT81QqnB3w8uIldEOSMD/C01uiSnBkqBtj8z3aM8r+lnm048Wd7uBYyCQ51Ju/ovUDPiey7E57leukmTh/XoOvUU8zEQ77j8W90vFprfBDBrUQ2VvBfR0QsSwVbGsQGUevuujeOY6I0tLXlioT/Yq6P3IesDsFuiQU7EY2lOD+G5b7uKQzUoRm6QZ/Ur7oqG2jje/U+UtK0eJo/B/qmke9hUmX2obYlg== 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 BL1PR12MB5921.namprd12.prod.outlook.com (2603:10b6:208:398::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.29; Tue, 17 Jun 2025 02:12:27 +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.8835.027; Tue, 17 Jun 2025 02:12:27 +0000 From: Zi Yan To: Andrew Morton , linux-mm@kvack.org Cc: David Hildenbrand , Johannes Weiner , Vlastimil Babka , Oscar Salvador , Baolin Wang , "Kirill A . Shutemov" , Mel Gorman , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Richard Chang , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v10 5/6] mm/page_isolation: remove migratetype from undo_isolate_page_range() Date: Mon, 16 Jun 2025 22:11:13 -0400 Message-ID: <20250617021115.2331563-6-ziy@nvidia.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250617021115.2331563-1-ziy@nvidia.com> References: <20250617021115.2331563-1-ziy@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: MN2PR19CA0023.namprd19.prod.outlook.com (2603:10b6:208:178::36) 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_|BL1PR12MB5921:EE_ X-MS-Office365-Filtering-Correlation-Id: 4326986e-daff-4f51-7cdd-08ddad446800 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|7416014|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?a14vd5IVigjaq4iZZR4s7upaRBmSYYCKp5+5kyY1pFxtSrOcK4vHBMNcHT71?= =?us-ascii?Q?eZJnNaCRR6s2yvy7N4HSPS0b3zq0bL1EbrR3iKmVlx3KVAGE/IAkd4YZ0hmB?= =?us-ascii?Q?ha65TLdv9xL0AmIZCJ9ouUqLvV3CTbdZHfgMHLqOKb9NdFXXrUxN8u1+7HYS?= =?us-ascii?Q?yFkWHhHKf0e+wnI2fu0L15sApDzywSFQ4tVw8LlyyBDI1eRiRNG07NT6p52T?= =?us-ascii?Q?QTP9GlQmCO3+ReObl8fYJiG2q86Ba2FgbAQAJnXPoQwaABPa8/i93ooA4kYJ?= =?us-ascii?Q?IIjk85CcZYf2sGpSK3758z0JMg6aOa19eJegGe+reyK7LAG28+JhQCUnMQhe?= =?us-ascii?Q?k9S/xLcoGqPYSx+oJVM0cuK0xln8mA9jiqzll/ZCOaUtKb/evcl87Gfv23mS?= =?us-ascii?Q?d7Dgngi8MpmGt/r1B332nS2B/tUey1GSr8itCnpGP4sI65bBNdIvonUd6xd7?= =?us-ascii?Q?1d7AiiJGqG4/v4UryQPkiwcoS+1yoVFwNbU6HoNfaxgRicGVZ+DDld++IPLP?= =?us-ascii?Q?YM88Bu5tjwYkQqpSvkEBhc5Abv6jjzd6CE3IK6l49CHbI92m0QOsTl2erM04?= =?us-ascii?Q?JhmPHaY0f2mrxu6xUIRZz1etzQt7st3Y/Y6ooTqSQvvgLMUfv1lTy54K/DJA?= =?us-ascii?Q?7C92jXeDi0uIT+9Bb2+Gv5lM/lQ50A9mvwMNdakZWXJK4WdvdgFtkSrsNWWn?= =?us-ascii?Q?YvxJ6I1aaAXamKtyKJgeGz6ZDKekBvEcluGgFF9yhPgublAoWH5poZLQauAs?= =?us-ascii?Q?I2z8cbtcQ264NKWDT4Q40qJouyoSWW8Mu+RqSopjin+9m0HLZx6xINAb70DG?= =?us-ascii?Q?WAvCQ1WTpSHFHw23jIRljkYy2nvOSxaWtHbQ4ImaYbYA8PgxwYTh6oZDEMwy?= =?us-ascii?Q?u5zR6JyyE4RCunm6o48TOaqGcqhQSXAWZAvVM+N8NTaIOOVo5t99czCwcMPP?= =?us-ascii?Q?WgPfl1PVqd9BgRaiXWNQSYCNxGvu9F1OKDoVWInoszp3rWNEekGpw52M8tyT?= =?us-ascii?Q?OHo4/FydHSpHhwFf1VGTA9cu5Ye+C96odISmKnL/xpuByLseUcZgAtJybQWZ?= =?us-ascii?Q?fLpxk2OvSzUrzNNJ2KDVk4T8/EDyeavq5Rv/P6FzEkgP6RMbaIzl+DC3UqZe?= =?us-ascii?Q?W4eChu5evsjF6bB6bbqOjdAHMbQAygRr0ZoTNwjvvL35JWprCbBAmOhbi4ZA?= =?us-ascii?Q?uuxT/+8ZnpR5mpVYxTGWtfWA047QXOHCAioq0ZZLlMviCZiusQT4H6J95DC2?= =?us-ascii?Q?Ur7TA0lFtfSk0hclChlxdOn8Cd5mukhxrN3sGq72g5Kp2IDmpleCYM1pgYP/?= =?us-ascii?Q?JXD7+hVH+sroBG9uawr8uXHdqeDHiS3mKNoAvnnXAjV1LCUTyb3onN8rZXfC?= =?us-ascii?Q?Ee/VaJr+LFx5zfP/ZngY7OGS3dhqZCZJtyPwGHBwR1ho7vaDshrBljwLWJI7?= =?us-ascii?Q?7n4XTLqn+ps=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)(7416014)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?FSqLEJER7ff0BuItlJUGjSNlB144oj14/yt6JuqZF6musZF2idJ3QR/5Gs1i?= =?us-ascii?Q?Emjevl5fCbY8bs5qWqWqH9loK/KfRbhxfFtV+09f17HsQ13n0gITh94WOH1U?= =?us-ascii?Q?v4090iNmdShM4pGyPHxSTf3a8/LNPz03A9tae1TPwB+WqvSbpMVazEsKEML+?= =?us-ascii?Q?ZK5dbI9SjmgrkvF/XRxx2jxIt1ENEIJMt3hg2h4u658NF2/1IhFGkB0TJDbI?= =?us-ascii?Q?f2IxcU0V8KlJjT4lg+9yflXT0tNiGuFTOTJZCjy0T2Cy0dRu6PblgKHORAiT?= =?us-ascii?Q?fmEK2agKX7oKevNiCXk8/KNBkTaCHlOGJ+JfKkKj1DZJ/lz+yZ+baVkcZZHi?= =?us-ascii?Q?mBp10BI3Pm4SbqKDQeQT1orexGRkes2eUQl2L1WLd3U4YFE8wGtAkrS07eZJ?= =?us-ascii?Q?Up2tSwm6c1wZn9h5o52hYZ6Ch1xr/pcbWXuM+urKTe7r/1SoXQq5kVexc9C3?= =?us-ascii?Q?KfuCqsRSF7ZoVdHF5YMNd11H8D7mhZ18XxG9JIvIhydGQmMNOn6EzRaCE/JA?= =?us-ascii?Q?Xn8QcgOh0BeqJXf9zLoy+EBITonOjaIF0sHB7FC38C8wsp80tH5mjOVQ9cSf?= =?us-ascii?Q?1IKwhP/q+10tU4EZZRkfZC9MLAq+MiFzzaGuiXYi43Pd92+BWfRoos0J7p4m?= =?us-ascii?Q?p50R5T3bqpvE2gcxLkAFeaKUy6YygCA9QCY82g+hcQdfgsQlGc3kY7dZBpeI?= =?us-ascii?Q?35N+0OUhNzawkL1ppwDeNx22zTyXii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Exchange-CrossTenant-Network-Message-Id: 4326986e-daff-4f51-7cdd-08ddad446800 X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2025 02:12:27.3485 (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: hUxMaJN1arS0Dw41r3S9/LBzi1M7lBYubUY9zVVjNVKuV3pYn6PMT5Crt4Y+efMW X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5921 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 35f008364698..224987824a84 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1223,7 +1223,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 @@ -2092,7 +2092,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); if (cancel_mem_notifier_on_err) memory_notify(MEM_CANCEL_OFFLINE, &mem_arg); if (cancel_node_notifier_on_err) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 06cc990e2a62..64321f6b714f 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -6984,7 +6984,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 Thu Oct 9 16:43:22 2025 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2064.outbound.protection.outlook.com [40.107.243.64]) (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 85ABE2264B7 for ; Tue, 17 Jun 2025 02:12:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.64 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750126357; cv=fail; b=PEpgXkS7o3QaOWWYsuWzU5yeeTytl9tQe6ZeEISYhW/M5i5yx+vpIp7O5Cp+8/SddXIwAFsiW+Mg9Zh1RjGi5sXGXP8zigAtq7PuRx8HF3qGiPJkG5E5kLVEwk1RamG+o2w6uXQwM0ZB5/YCQ/8iIVUTVurf2ghdG+fDPUrHB9c= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750126357; c=relaxed/simple; bh=xRiDR74Jyib6V6XWSnXHVca7INXgcofXPM/jwUcbX+s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=m2s4uDVX3B2KRu8dwSKQA0HwZHL3MlQB3Dse6TDKQls/riHvEUqjnY2jlFkjaF/FMDZkVFXlPtQB/kLQj2+wv21Uzk2K+Jt4qCNDKb++TSQVOnn6vmiHbUwCUviKDU/2uvcJ9bxEIYcKqsOYlxU+ce61BnkZJYkXPOAZAkIEn6o= 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=HQ9KyR1e; arc=fail smtp.client-ip=40.107.243.64 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="HQ9KyR1e" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ycs/EGsfBZ9SVCzNpGpp/k98KKubYQ4NPeIrVpI2cnKD9V8SfZW+yaIAlUC7ZUOrQqEsCjj5p1pg/r5pUwFaBvCXmz2LEp5mBFkN7zRxhaQyjER9R54plsZaAG2U7fhdf7vQYouCROX09Qh3+/aeHT3zGOPIdTmZNPaEkePuiaLGVMFde1wSCyOanULdnTwZ2oJGRy8Aj/TdHK2KCs1DDyQlaQnq15oDJMuxRALBbWNlxLMKHOoCGokZ93p7/FeisbYA0sxYWeMKkgATh0s9oR4xVRiK1WegE7FByKF2wrtFPVxEuGUf1+gSCe/FJ2oMK9naFdPMDeNXZffjuR69cg== 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=X1eQEkxy8Ur/5LcvNruGIBU9rBmLt7aX6Z0A5AUlrL0=; b=R0IjY9hUxpufMLI1dkJc43gl84dkx6wvWf3j78ByQgn6BiDmfCCe+3YFgof0RjHe3/su0zKWvM+Znj3UUKihvToCT9ZmdWQOFFekNKXdvZhJqUq9QPNyvclJfMV191Sq8b6I/BtR9YvedNTfHmX5y4W3vEVZoWn6gllK9pQVyY2NgSeDn97aFA5nYUhTzy3CuDfAXmutxYgExMQEkYAfyNM7X+9tzTBNDiQ0uQjUH5TGYCXNIHIrKYlgmV+EcJnPufaVV28dnYahTPSkvU0G0zQFE6tvfu/OGPr6cuPcl47WyZ9DrzAoh1V3D0BTpAmqO62Wdyos6X5G9//TFKhpNw== 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=X1eQEkxy8Ur/5LcvNruGIBU9rBmLt7aX6Z0A5AUlrL0=; b=HQ9KyR1elsZ5+qRxuNF2TDCEMW3ThtKl6hH4uCUq8hoCRUeaYF9ltZN1o+ty1TMRDPcM8NW2YNJoOTGrYNDQn2OmQnncZFBmoCAOxqU2apMcTDw0gx2esVVjK/UD86J44XuFSorqeasfthgW8f8e5HyaOZz/SFfjvW+9L0IX0kLhkiJtdmaIQwp7Oqr3GleQLdyMwG0c3oN80kkyJUElPjUY5s9aazNIjDaHfhrFD100PJExmf/J/oNpKWUkOTRqQSMTAixabgnaxkqcskHnUA38NnwkJ6VrSG3gy9rVl6/ndkkVoYUkxwOda9sFzuD1U0ZAmfZHPonqzXZ950fsCg== 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 BL1PR12MB5921.namprd12.prod.outlook.com (2603:10b6:208:398::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.29; Tue, 17 Jun 2025 02:12:29 +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.8835.027; Tue, 17 Jun 2025 02:12:29 +0000 From: Zi Yan To: Andrew Morton , linux-mm@kvack.org Cc: David Hildenbrand , Johannes Weiner , Vlastimil Babka , Oscar Salvador , Baolin Wang , "Kirill A . Shutemov" , Mel Gorman , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Richard Chang , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v10 6/6] mm/page_isolation: remove migratetype parameter from more functions. Date: Mon, 16 Jun 2025 22:11:14 -0400 Message-ID: <20250617021115.2331563-7-ziy@nvidia.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250617021115.2331563-1-ziy@nvidia.com> References: <20250617021115.2331563-1-ziy@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: MN2PR19CA0001.namprd19.prod.outlook.com (2603:10b6:208:178::14) 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_|BL1PR12MB5921:EE_ X-MS-Office365-Filtering-Correlation-Id: 58f29b93-49c6-4888-add1-08ddad44691c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|7416014|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Vwmql2mjKuLLWVjZZ7Ke6AC0KGgMeF4d+9o5GWwt6Vd+hKZbrdTjc5rpyOt4?= =?us-ascii?Q?LSk89matjasjkUzOh+EmkWwL3vTts3vKXiGa80owvzRRC368DBX/xkijsfRU?= =?us-ascii?Q?hK+FNrR+Zlj34lGohqvCg99QfjUtjQF/U/vj4pZKfRds+0wt3RPFVgbIb2b7?= =?us-ascii?Q?voSfJghbhOaqct7eXqAMFy5z87psInbhwYCkDQUKDeJGmn38J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ksWvi0rHJXSPQ3o2xquYuuUFesun15aCRYQrQzL1z?= =?us-ascii?Q?ObgVoAe7k2QC5ODWxv8BsEMB81CyASs7TdfNkasaxYYbzhWDfRQymoIf5sR2?= =?us-ascii?Q?2JE9NuJXA2bP6k+U2XdsBpzSuAYahW7XJRP5hyBA4cWr86/YnF8eYL8G55Bz?= =?us-ascii?Q?DwelJvNT0i/fZtVPDNK7lwdT4ZnzTK5FK6ikShfMrDCZNuYh/bqp2AC/2BiR?= =?us-ascii?Q?BYkK+/9zgw8AI8AeqS435vh8J5wXyFtfM4J4q67yNzIQ4d2bflcwrURAgIy/?= =?us-ascii?Q?UW0sGx85U7uVAROVXW2ue4oalm9TGK4XFYsdlrCgpvTswwmWscjHV36Mk5t8?= =?us-ascii?Q?/Kj5+hcLwoI=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)(7416014)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?pQ+NkSFAExSx0PljfwVB/XR21yZXaeDaggGqxF5RsgHE9ZKuc+h0UF3DJkKD?= =?us-ascii?Q?UfPxnk5UgvUv6NlcEmfvZAwjHN8NaGCwuErxX9oNZu47hHoAsADaTAxrRgdD?= =?us-ascii?Q?m5bG46svbozS2IiRof33IrCfdxWq/t/4g3sTBxO6NyRqvCxsxe5PNDd6iXqA?= =?us-ascii?Q?uPz1SM9ekiuKF75VVB1mrEqp8xHXLkfwjW/Tvbt4LzT3FwZcEWpgCaI/ChxU?= =?us-ascii?Q?qz+Xx31Krnd+q1TNx8qqLR6HbenXNLLRDKBJawMfOkUwec21cq9Jh9iY7521?= =?us-ascii?Q?iMHQP66svKf1BPYqR0beLpGn+VBvTfhio6Tm6YiVyDU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BiSt28qzEl0ARDyaoxZCfGy857tzKMrvKJbrcpMdo6lTA?= =?us-ascii?Q?dw3fHRMqRdE1xqApXUUqJd5hhikv5OyHufxHQQCzbOHvmEu49olmSupiiUL0?= =?us-ascii?Q?Hf1sgCO48GwoyDl6wKr1PP5PxUGR89uiONEkZY9WQMhQaQbnLoyNi/zs3e/k?= =?us-ascii?Q?ThMlwzDZ4jQHXbc9bcUF06d3zt6sz5aXLdmSa8iX0yZECdwYcim/joQDGjWx?= =?us-ascii?Q?pPWVMeQ8zQDoIp3dX7aAatiizNOjEc5C129inIQG7EMHw3YhBrpZLvbAqX06?= =?us-ascii?Q?mwzaKnymq5jKOTMhw8Mpl5sNAaz8HLNSMODP5VNvzvIJG9WLArS9fm1SFHIx?= =?us-ascii?Q?yy0fuErrtFdPT2OFc4ymnyvPeCf+2nJYgeAD0fh1?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 58f29b93-49c6-4888-add1-08ddad44691c X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2025 02:12:29.2228 (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: qdu8uH76QeArZxGs/szdYF6oomJjlbSNCzbuEqePOg/Exn+qIGAUFnpintWF9DmM X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5921 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 PB_ISOLATE_MODE_CMA_ALLOC provide the information. At the same time change isolation flags to enum pb_isolate_mode (PB_ISOLATE_MODE_MEM_OFFLINE, PB_ISOLATE_MODE_CMA_ALLOC, PB_ISOLATE_MODE_OTHER). Remove REPORT_FAILURE and check PB_ISOLATE_MODE_MEM_OFFLINE, since only PB_ISOLATE_MODE_MEM_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(). Add ACR_FLAGS_NONE (set to 0) to indicate ordinary allocations. Signed-off-by: Zi Yan Reviewed-by: Vlastimil Babka Acked-by: David Hildenbrand --- drivers/virtio/virtio_mem.c | 2 +- include/linux/gfp.h | 7 +++- include/linux/page-isolation.h | 20 ++++++++-- include/trace/events/kmem.h | 14 ++++--- mm/cma.c | 2 +- mm/memory_hotplug.c | 6 +-- mm/page_alloc.c | 27 ++++++------- mm/page_isolation.c | 70 +++++++++++++++------------------- 8 files changed, 80 insertions(+), 68 deletions(-) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index 56d0dbe62163..1688ecd69a04 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -1243,7 +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, + rc =3D alloc_contig_range(pfn, pfn + nr_pages, ACR_FLAGS_NONE, GFP_KERNEL); if (rc =3D=3D -ENOMEM) /* whoops, out of memory */ diff --git a/include/linux/gfp.h b/include/linux/gfp.h index be160e8d8bcb..5ebf26fcdcfa 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -423,9 +423,14 @@ 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_FLAGS_NONE ((__force acr_flags_t)0) // ordinary allocation req= uest +#define ACR_FLAGS_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..3e2f960e166c 100644 --- a/include/linux/page-isolation.h +++ b/include/linux/page-isolation.h @@ -38,8 +38,20 @@ static inline void set_pageblock_isolate(struct page *pa= ge) } #endif =20 -#define MEMORY_OFFLINE 0x1 -#define REPORT_FAILURE 0x2 +/* + * Pageblock isolation modes: + * PB_ISOLATE_MODE_MEM_OFFLINE - isolate to offline (!allocate) memory + * e.g., skip over PageHWPoison() pages and + * PageOffline() pages. Unmovable pages will be + * reported in this mode. + * PB_ISOLATE_MODE_CMA_ALLOC - isolate for CMA allocations + * PB_ISOLATE_MODE_OTHER - isolate for other purposes + */ +enum pb_isolate_mode { + PB_ISOLATE_MODE_MEM_OFFLINE, + PB_ISOLATE_MODE_CMA_ALLOC, + PB_ISOLATE_MODE_OTHER, +}; =20 void __meminit init_pageblock_migratetype(struct page *page, enum migratetype migratetype, @@ -49,10 +61,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 bd3772773736..c0b2630a1b81 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_FLAGS_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 224987824a84..b4ac226795f2 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1961,8 +1961,7 @@ int offline_pages(unsigned long start_pfn, unsigned l= ong nr_pages, =20 /* set above range as isolated */ ret =3D start_isolate_page_range(start_pfn, end_pfn, - MIGRATE_MOVABLE, - MEMORY_OFFLINE | REPORT_FAILURE); + PB_ISOLATE_MODE_MEM_OFFLINE); if (ret) { reason =3D "failure to isolate range"; goto failed_removal_pcplists_disabled; @@ -2039,7 +2038,8 @@ int offline_pages(unsigned long start_pfn, unsigned l= ong nr_pages, goto failed_removal_isolated; } =20 - ret =3D test_pages_isolated(start_pfn, end_pfn, MEMORY_OFFLINE); + ret =3D test_pages_isolated(start_pfn, end_pfn, + PB_ISOLATE_MODE_MEM_OFFLINE); =20 } while (ret); =20 diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 64321f6b714f..858bc17653af 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -6693,11 +6693,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; @@ -6769,7 +6770,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); @@ -6840,10 +6841,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. @@ -6860,7 +6858,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; @@ -6875,6 +6873,9 @@ int alloc_contig_range_noprof(unsigned long start, un= signed long end, .alloc_contig =3D true, }; INIT_LIST_HEAD(&cc.migratepages); + enum pb_isolate_mode mode =3D (alloc_flags & ACR_FLAGS_CMA) ? + PB_ISOLATE_MODE_CMA_ALLOC : + PB_ISOLATE_MODE_OTHER; =20 gfp_mask =3D current_gfp_context(gfp_mask); if (__alloc_contig_verify_gfp_mask(gfp_mask, (gfp_t *)&cc.gfp_mask)) @@ -6901,7 +6902,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 @@ -6917,7 +6918,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 @@ -6951,7 +6952,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; } @@ -6994,8 +6995,8 @@ 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, ACR_FLAGS_NONE, + 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..ece3bfc56bcd 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 PB_ISOLATE_MODE_CMA_ALLOC) 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 PB_ISOLATE_MODE_MEM_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 PB_ISOLATE_MODE_MEM_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 PB_ISOLATE_MODE_MEM_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,11 +560,12 @@ __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 PB_ISOLATE_MODE_MEM_OFFLINE) && + PageHWPoison(page)) /* A HWPoisoned page cannot be also PageBuddy */ pfn++; - else if ((flags & MEMORY_OFFLINE) && PageOffline(page) && - !page_count(page)) + else if ((mode =3D=3D PB_ISOLATE_MODE_MEM_OFFLINE) && + PageOffline(page) && !page_count(page)) /* * The responsible driver agreed to skip PageOffline() * pages when offlining memory by dropping its @@ -591,11 +583,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 %PB_ISOLATE_MODE_MEM_OFFLINE 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 +595,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 +631,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