Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp843079lqs; Tue, 5 Mar 2024 20:17:57 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUyJkM/Ci4WwTC72ZhlUEhZKxF4EdEFePeQX71QpDnDGNL7KDvR55XDYsBD+3y4AQujAww66MrWCJs88zS/Ti2E5tMUpnlBvTfQhXhxLw== X-Google-Smtp-Source: AGHT+IHps4wZKrh7HEBaq0K95vLC0fWuf4A0PQuY4ykr8cCw0U4d1UVEpKcgQcCybrnz19n+Fx5S X-Received: by 2002:a17:906:eb4d:b0:a45:b36c:55c8 with SMTP id mc13-20020a170906eb4d00b00a45b36c55c8mr1007855ejb.38.1709698677160; Tue, 05 Mar 2024 20:17:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709698677; cv=pass; d=google.com; s=arc-20160816; b=hgxG9LIoSO6nslJlx8tTozS/KeQApDqWRauqKn+Y8v3Rp8vJ9uLq7x0orPB4QYpg1C 6D+Elus3SoVzJOR9Kf2nnt4QJXHqJIuXLojfjfxjlCWSVdVoZHreLoE2lbevUBJe8LRY /ZhvLZvR6y4NG3FiBUyLaK9HQcBNMyJkewrHO6oBGLGsfK8bx6wkrtUHt3Q1CV7GCWX2 +QTvEJFpvfF1Lg9Zlh1IvFiwAiDMZ9BsBwkdmFEmtC7hI6taaT/swDp11jhl1aeYn37O 26SDIrfpM82mry3zrT+4f7hFbi6r1cnLSOlH7wHDTMrA7eudnzqWCvbC6uZbeV4sgm05 /Uxg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=m/ZzL/TH/R4lBA3ZDd+dHH0WpYTGgWIE5ifE2nwqWl8=; fh=8a61ag+AH6Dk5sT/aqoJrunZiG9FHRO1gmBYA3q/vbI=; b=rgHxtiiTF0ylMDDMW8UiT6hcAE1TLBahASNH+ZExDEA+SXFrgXGbeDNfc7M/LqJfHM k+AD9np7XA8uIiARwE9AXIX+z/To1iQB4E+G+JgkuPYq2XIX6QiUS6FGZDM6BFr+Cc0e kJ8ghoM0odvJd4CiwLf/6TSTS6ppQV79WEAijYWkxhbiXpdv5B1y1OSLRvdWyyC4aeYS Z5C/iomSMKRoUtOf2ZIyienai5hpKHynKgJPB6Qew549zO3z/ME9Cndm70Xp1o5bMxE+ Ig2IbWKNGGJ01IfcxQdxN1cWQL8PUrqgwkAiRQg+ytoGSPHZPxST78wNyCl0hYP6elsS 5leQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=Z7qztWbb; arc=pass (i=1 spf=pass spfdomain=cmpxchg.org dkim=pass dkdomain=cmpxchg-org.20230601.gappssmtp.com dmarc=pass fromdomain=cmpxchg.org); spf=pass (google.com: domain of linux-kernel+bounces-93320-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-93320-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id ds15-20020a170907724f00b00a44df2a3297si3830380ejc.589.2024.03.05.20.17.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 20:17:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-93320-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=Z7qztWbb; arc=pass (i=1 spf=pass spfdomain=cmpxchg.org dkim=pass dkdomain=cmpxchg-org.20230601.gappssmtp.com dmarc=pass fromdomain=cmpxchg.org); spf=pass (google.com: domain of linux-kernel+bounces-93320-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-93320-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id DFB441F22613 for ; Wed, 6 Mar 2024 04:17:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7B15D1C69E; Wed, 6 Mar 2024 04:16:36 +0000 (UTC) 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="Z7qztWbb" Received: from mail-qv1-f45.google.com (mail-qv1-f45.google.com [209.85.219.45]) (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 6A3A81C287 for ; Wed, 6 Mar 2024 04:16:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709698595; cv=none; b=f2Jt0niHTx1RLItuostzO2/b2MoDvtK34EoqxEs+GJ5CJR0UD8AdVpiyABArqMWLGOtnmnREOJw6/er5R8OpLTv1kkgsXtjCj8KOkbmqsJxWCb8S2TI+aqq1uf9KWjNLZdKAsQIHkakGjlTMT0MRKa8rQf1XZL+AU0Q/q81fyVM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709698595; c=relaxed/simple; bh=e6YdF+uo8QOiGW71azSWYV45mVoP1WOMRJ0W3MkhvWI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dkm755/UXZ3rsfCawCApe5ErJ+rU4X0yOhupT5qE4Zv+d+Kh+W2x65g1y+YlibEvd1jFCRzD4vX3o2+J0HShSjkJkhaZcLJN33y/zkp/EuRCd03Cpvssp8KqyD23GkOewUUqP7Y0VjZqzry0nV2qEZ3daFy8ODc1SiJGrDCcFeA= 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=Z7qztWbb; arc=none smtp.client-ip=209.85.219.45 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 Received: by mail-qv1-f45.google.com with SMTP id 6a1803df08f44-6900f479e3cso13728006d6.0 for ; Tue, 05 Mar 2024 20:16:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1709698592; x=1710303392; 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=m/ZzL/TH/R4lBA3ZDd+dHH0WpYTGgWIE5ifE2nwqWl8=; b=Z7qztWbb9VYRRchmyVsC0/7xKPbcgEcpHu3DcypSMDG4Xla3qYEKenFc2AIjg73zjh rs7cfdIHdG7I3orYyv9upY/KNyAP8VCJN1mLlZWdnyaDi3DLcimiQNfpfgDafftCVRjt 8ET58MT9Tnh5YyfNFeGVvjySLeCx5Vlh2XuA5I94UQK/Ymk3XIJNR10g1HlhKfJKhlrN 3pCXUoUZfIlhUGYVqgVJEdwGuD1AnzsKgkjtaUrOHfYVoP7nmjWL/j6Xd6ZS8axz7Ztd Rm0l2wl+Q/O2Vo2xAdY5EjiCRj3Pdc3Y+XEVrCwxBcJs99vlkwjAgY0VoCj9sisN4/m+ IP1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709698592; x=1710303392; 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=m/ZzL/TH/R4lBA3ZDd+dHH0WpYTGgWIE5ifE2nwqWl8=; b=fnLJ5ZH3kOllJONwZJEcamKHrEp+qAKMag4LPGBaB0jbf6ygsPgIvtntCCFdwoMBA5 4UT0FgULw6j8wvq5HCiE2bj0MxVCK9lilbLJligvwoxMU8BuECYgHa5/PS7UIkA6LLPb zxwM1D+Qu5Zv48qTBHNPDZ/p65kaBKiaZ5hLfXZcEAZk4ogantPN53vLO0Dq5K0Teklj rmtJ1qmS+PdAhpknz/89ShGLHR33/uy+b9S/6FC3iYrkgOkv3kl98a0CVmS4OIkYzXLU CLNEMv8MTGqOpDXSAv9TEUs2RVwjNnx/zTAe1p/6veAFq6rory169fcBCVFys7dZGzze iYgA== X-Forwarded-Encrypted: i=1; AJvYcCVYyf+eOvJQnzu3kni6P/iwxP7+/CAecdKhaAoL99FrBSh4grXw+e+Qs7zA5nBX3DfpsgazVXgnuxKm4i0LVSudPTfMT4xBN79eTBly X-Gm-Message-State: AOJu0YxuZe9xfJPHXjpdZvJxGHrSx+oFgyD03B4GYxSvcW7+41qeYId7 Byq3JrMLGjPyWdu3MeVuR7k7ll5vWwUIphdsSh3/lZIS7VHO/h5j4S+FrysvBBj1Rpc897Xb7U6 N X-Received: by 2002:ad4:4d06:0:b0:690:6ce7:432e with SMTP id l6-20020ad44d06000000b006906ce7432emr4033712qvl.9.1709698591864; Tue, 05 Mar 2024 20:16:31 -0800 (PST) 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 pd6-20020a056214490600b006907801a000sm2714835qvb.26.2024.03.05.20.16.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 20:16:31 -0800 (PST) From: Johannes Weiner To: Andrew Morton Cc: Vlastimil Babka , Mel Gorman , Zi Yan , Mike Kravetz , "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: Tue, 5 Mar 2024 23:08:39 -0500 Message-ID: <20240306041526.892167-9-hannes@cmpxchg.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240306041526.892167-1-hannes@cmpxchg.org> References: <20240306041526.892167-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: 8bit 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 --- 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 82e6c4068647..a057b82c4f1d 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1581,9 +1581,8 @@ static inline struct page *__rmqueue_cma_fallback(struct zone *zone, #endif /* - * Move the free pages in a range to the freelist tail of the requested type. - * 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 = 0; + VM_WARN_ON(start_pfn & (pageblock_nr_pages - 1)); + VM_WARN_ON(start_pfn + pageblock_nr_pages - 1 != end_pfn); + for (pfn = start_pfn; pfn <= end_pfn;) { page = pfn_to_page(pfn); if (!PageBuddy(page)) { @@ -1610,6 +1612,8 @@ static int move_freepages(struct zone *zone, unsigned long start_pfn, pages_moved += 1 << order; } + set_pageblock_migratetype(pfn_to_page(start_pfn), migratetype); + return pages_moved; } @@ -1837,7 +1841,6 @@ steal_suitable_fallback(struct zone *zone, struct page *page, if (free_pages + alike_pages >= (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); } @@ -1911,12 +1914,10 @@ static void reserve_highatomic_pageblock(struct page *page, struct zone *zone) /* Yoink! */ mt = 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) != -1) { - set_pageblock_migratetype(page, MIGRATE_HIGHATOMIC); + if (migratetype_is_mergeable(mt)) + if (move_freepages_block(zone, page, + MIGRATE_HIGHATOMIC) != -1) zone->nr_reserved_highatomic += pageblock_nr_pages; - } - } out_unlock: spin_unlock_irqrestore(&zone->lock, flags); @@ -1995,7 +1996,6 @@ static bool unreserve_highatomic_pageblock(const struct alloc_context *ac, * not fail on zone boundaries. */ WARN_ON_ONCE(ret == -1); - set_pageblock_migratetype(page, ac->migratetype); if (ret > 0) { spin_unlock_irqrestore(&zone->lock, flags); return ret; @@ -2698,10 +2698,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) != -1) - set_pageblock_migratetype(page, MIGRATE_MOVABLE); + if (migratetype_is_mergeable(mt)) + move_freepages_block(zone, page, + MIGRATE_MOVABLE); } } 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, int 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 *page, int migratetype) */ WARN_ON_ONCE(nr_pages == -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); -- 2.44.0