From nobody Fri Dec 19 17:43:34 2025 Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CECAF6FE37 for ; Wed, 20 Mar 2024 18:05:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710957905; cv=none; b=kdAOViFGeoL/6zx0y4AIM8XemshHGPdWZtppM4ntU8C0MlmWNIlnACC51iBPyhtNff4E8mc3te5S1sTj5YFa5aZIPvDW5H7cachE4Z+5RCnWvZckT8W7YUJskWNcvzlpLkY1A0YGeR8/J40L1tOuCZBg4jyiUdm3jKbbn+Y8kE4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710957905; c=relaxed/simple; bh=a5Hd9QHmzdUL3ZAgZf882mRDeq1mAtAaKRwDN3PrUTU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SULiKmZwHNri71k39kVCMojK5x20tOoEGmDLOWrSzB9LiHoeBL2XW6U1zL+9ES1FLpihWFsJDZ11dp3wz08GqIpT1xgf6C0uMRLHwguzeQ8j4m6EzWYQ/n9nCbMo+PLGxlhWS+RyCOMPBAYb2fneWNPOdnua6daOiPCGtvVO71U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org; spf=pass smtp.mailfrom=cmpxchg.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20230601.gappssmtp.com header.i=@cmpxchg-org.20230601.gappssmtp.com header.b=wp8yL/c4; arc=none smtp.client-ip=209.85.222.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20230601.gappssmtp.com header.i=@cmpxchg-org.20230601.gappssmtp.com header.b="wp8yL/c4" Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-789e6e1d96eso10281485a.3 for ; Wed, 20 Mar 2024 11:05:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1710957903; x=1711562703; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/agc7Iq+rpxvE93VG+YAHYepTCDVe1OJjvDT1Xeceos=; b=wp8yL/c4TdGVoNhDI2CRYI0IP4ibTxyFQEOcJx3ypVX9f/TpNG+sD608mKENz8VRxt lzOe+mck5rZlfhcPXu5gx2HkvyFjMhA5EcwVgZV7hMr3rJz+OkQ/D1MJ1LMAcUpuSdro keQ0UYvs1m/OH11fg39vfy+F5RtXranFRa/+BkMVboaGoKXHvc59xEJgClBUAfufeCoO eKUlZkLAwVWRBZwI30dnib2d5fH0QgbDlaFXGxDDoxm1QAiGRKMG/kJohNsVxh7BZaUL BM8PIMHAU2IlXSTVXRqjv+yArEVPp4eVQby7k5f60mSyQ9hvJUEazgz55vEFBN9S24Rs 0sCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710957903; x=1711562703; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/agc7Iq+rpxvE93VG+YAHYepTCDVe1OJjvDT1Xeceos=; b=HNL4nD2r0mjnBDJqqzcoph4T7cPHh6riG2WhSZQTe2Nk2cS+NBv6nakxjqNodsY5Dv yeeoTUVDSlGAYuvuM5Kz5Rq2N0jiLoEzE1AN8D/0BmNaUhT7uU6PZRVAB5JNXo4DPRGM KmsElbxxDzXd8UtB+yDZgmxtBFaQ9b8QJhv+qWrrIOd+7IEnfaZkw9rQ3kryOEA9h0cp zC+YB1FHEXpDvfMxg7hUg0Uktk4jGzepVGRfQzkw/zrWhuM9wQLriZleiNpVk3sds+0i jm63eJ/wpWLfHYXTgMUWdJVBpwPoWYZ93kzw2xTw3cJsrm0mf/oTrP/txb6TejLTZ/re aCEQ== X-Forwarded-Encrypted: i=1; AJvYcCUtzF700FVTe3QA9v4IigCSCSep2KCE10gyidu7H2XgXnk4kVxXZECrtWb6LpVMle20OYG8t8tSXAoFPKwYRVhhre9J47qWNrKXXmTk X-Gm-Message-State: AOJu0Yyl/rUiFVNZDyImqxQXmbrbIALbKlYrxrt4a5omvBMPI4j9AuzD p0M1dES2ytM50WvSZqHqudq1uDSmcOpn+OO4U0Be3qbRBwWjyzibtBpCqWnlCv4= X-Google-Smtp-Source: AGHT+IHVDZsbT9cqnC3HSTs2AyL3KxvP5tWB415HoSJ1bTxAaB/NmMu1L5tzkR6Fc/n91vn14sa1gw== X-Received: by 2002:a37:db11:0:b0:78a:86:534f with SMTP id e17-20020a37db11000000b0078a0086534fmr2673755qki.76.1710957902810; Wed, 20 Mar 2024 11:05:02 -0700 (PDT) Received: from localhost (2603-7000-0c01-2716-da5e-d3ff-fee7-26e7.res6.spectrum.com. [2603:7000:c01:2716:da5e:d3ff:fee7:26e7]) by smtp.gmail.com with ESMTPSA id w8-20020a05620a094800b0078a210372fasm900228qkw.86.2024.03.20.11.05.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 11:05:02 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: Vlastimil Babka , Mel Gorman , Zi Yan , "Huang, Ying" , David Hildenbrand , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 08/10] mm: page_alloc: set migratetype inside move_freepages() Date: Wed, 20 Mar 2024 14:02:13 -0400 Message-ID: <20240320180429.678181-9-hannes@cmpxchg.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240320180429.678181-1-hannes@cmpxchg.org> References: <20240320180429.678181-1-hannes@cmpxchg.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Zi Yan This avoids changing migratetype after move_freepages() or move_freepages_block(), which is error prone. It also prepares for upcoming changes to fix move_freepages() not moving free pages partially in the range. Signed-off-by: Zi Yan Signed-off-by: Johannes Weiner Reviewed-by: Vlastimil Babka --- mm/page_alloc.c | 27 +++++++++++++-------------- mm/page_isolation.c | 7 +++---- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 3f65b565eaad..d687f27d891f 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1581,9 +1581,8 @@ static inline struct page *__rmqueue_cma_fallback(str= uct zone *zone, #endif =20 /* - * Move the free pages in a range to the freelist tail of the requested ty= pe. - * Note that start_page and end_pages are not aligned on a pageblock - * boundary. If alignment is required, use move_freepages_block() + * Change the type of a block and move all its free pages to that + * type's freelist. */ static int move_freepages(struct zone *zone, unsigned long start_pfn, unsigned long end_pfn, int migratetype) @@ -1593,6 +1592,9 @@ static int move_freepages(struct zone *zone, unsigned= long start_pfn, unsigned int order; int pages_moved =3D 0; =20 + VM_WARN_ON(start_pfn & (pageblock_nr_pages - 1)); + VM_WARN_ON(start_pfn + pageblock_nr_pages - 1 !=3D end_pfn); + for (pfn =3D start_pfn; pfn <=3D end_pfn;) { page =3D pfn_to_page(pfn); if (!PageBuddy(page)) { @@ -1610,6 +1612,8 @@ static int move_freepages(struct zone *zone, unsigned= long start_pfn, pages_moved +=3D 1 << order; } =20 + set_pageblock_migratetype(pfn_to_page(start_pfn), migratetype); + return pages_moved; } =20 @@ -1837,7 +1841,6 @@ steal_suitable_fallback(struct zone *zone, struct pag= e *page, if (free_pages + alike_pages >=3D (1 << (pageblock_order-1)) || page_group_by_mobility_disabled) { move_freepages(zone, start_pfn, end_pfn, start_type); - set_pageblock_migratetype(page, start_type); return __rmqueue_smallest(zone, order, start_type); } =20 @@ -1911,12 +1914,10 @@ static void reserve_highatomic_pageblock(struct pag= e *page, struct zone *zone) /* Yoink! */ mt =3D get_pageblock_migratetype(page); /* Only reserve normal pageblocks (i.e., they can merge with others) */ - if (migratetype_is_mergeable(mt)) { - if (move_freepages_block(zone, page, MIGRATE_HIGHATOMIC) !=3D -1) { - set_pageblock_migratetype(page, MIGRATE_HIGHATOMIC); + if (migratetype_is_mergeable(mt)) + if (move_freepages_block(zone, page, + MIGRATE_HIGHATOMIC) !=3D -1) zone->nr_reserved_highatomic +=3D pageblock_nr_pages; - } - } =20 out_unlock: spin_unlock_irqrestore(&zone->lock, flags); @@ -1995,7 +1996,6 @@ static bool unreserve_highatomic_pageblock(const stru= ct alloc_context *ac, * not fail on zone boundaries. */ WARN_ON_ONCE(ret =3D=3D -1); - set_pageblock_migratetype(page, ac->migratetype); if (ret > 0) { spin_unlock_irqrestore(&zone->lock, flags); return ret; @@ -2711,10 +2711,9 @@ int __isolate_free_page(struct page *page, unsigned = int order) * Only change normal pageblocks (i.e., they can merge * with others) */ - if (migratetype_is_mergeable(mt) && - move_freepages_block(zone, page, - MIGRATE_MOVABLE) !=3D -1) - set_pageblock_migratetype(page, MIGRATE_MOVABLE); + if (migratetype_is_mergeable(mt)) + move_freepages_block(zone, page, + MIGRATE_MOVABLE); } } =20 diff --git a/mm/page_isolation.c b/mm/page_isolation.c index 71539d7b96cf..f84f0981b2df 100644 --- a/mm/page_isolation.c +++ b/mm/page_isolation.c @@ -188,7 +188,6 @@ static int set_migratetype_isolate(struct page *page, i= nt migratetype, int isol_ return -EBUSY; } __mod_zone_freepage_state(zone, -nr_pages, mt); - set_pageblock_migratetype(page, MIGRATE_ISOLATE); zone->nr_isolate_pageblock++; spin_unlock_irqrestore(&zone->lock, flags); return 0; @@ -262,10 +261,10 @@ static void unset_migratetype_isolate(struct page *pa= ge, int migratetype) */ WARN_ON_ONCE(nr_pages =3D=3D -1); __mod_zone_freepage_state(zone, nr_pages, migratetype); - } - set_pageblock_migratetype(page, migratetype); - if (isolated_page) + } else { + set_pageblock_migratetype(page, migratetype); __putback_isolated_page(page, order, migratetype); + } zone->nr_isolate_pageblock--; out: spin_unlock_irqrestore(&zone->lock, flags); --=20 2.44.0