From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) (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 B11F23DA7F9 for ; Wed, 25 Feb 2026 16:34:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772037288; cv=none; b=jrei2JZyWRupV6ZDDWv07hEfrTm4+5xttpCZuyreN+O3cYsRAQYzfsuiiAfSsliL3djkZZJvyLlTfKodh/5as+lralROfb1sl5sf1GWj4ndNXxpVsvtKVrZEE26T5EZzFs4Vx233K4N/da1FWJ1KZlSVLI2+6sBLgejohShvflc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772037288; c=relaxed/simple; bh=sx3H3IOQ89Ikw+o22X/xCeXvyaUAPvxEmXbm7LaeCmE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PkcEwMhF5U40a4+Aq64Tn3iA+bIV6dO7tr/h3LDfW+1wVt6zR3+vCT81Po5j1HE6mDd0oyURN80JuV2fn3sA9trwjAUSXyA2YUWnhI0/ZeqK45FjYqqSIip9YMfL4L7GHsLKQL6Ezo7gBMKZqzJN96MAsKSyKJ4KS4IF8RImy4Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ugivcgfm; arc=none smtp.client-ip=209.85.221.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ugivcgfm" Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-4376e25bb4dso4752824f8f.0 for ; Wed, 25 Feb 2026 08:34:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1772037285; x=1772642085; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Zn/sQ5//FH47xWrBpYa+2czdly0Dx/d99/N8Hn2JIac=; b=ugivcgfmcIr7FnvCRUGPj3X6PXCyUk5Kpnel2/Y+9zKShQUb80NvbAo4iwmTvMZgp/ nmL2t+Z16jAqF1yxaoFnFf9FYVtSvGK5PrsqwfB2Hw2Y7Z3P/P5uEMi8VdUkHc3XzNPs jf1A96nWANXhMBqT75KNgZOKBU3LH3rCM01RFNWr5sAmmZs4tNjqIK24mhhBHGLu3eMv 1iE74OvGq3lAX7597kXcRStYuB7p71ZgHyvI6FMsvXXyfUz5UdDaiv539FwPVRqwSIx9 ZneIsbvH1cMCLCEZqZMF8mJT5OZgW3Bo5xjqKHAS/elBHOGfSt+BdeuL3Z0/5UlNckm6 m13A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772037285; x=1772642085; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Zn/sQ5//FH47xWrBpYa+2czdly0Dx/d99/N8Hn2JIac=; b=MBU1Afs9rgfBhD9BYbCJMrwAFpKT6ID609n4dLny1OdzS2u7Akxy8IwHe/h2ZMMeBm 9/AvKhmgkwoT/jl0fw7ozTSSC9JhydSSU094tfLGPsAWxthXMkJm4SObsc0gEijWk40Z NbWGV7qYx1eN5ekhofx8zImiMt4sz+nA2GpgB1Q9BFq4NxKykF3GVQgpT1i2mPfJuDM3 K+GCUknDs5BGAmEXhiUuTPb7Y+jyfe9fFdxv3OZefOJW5uZbYxepij6juxjqjUiA0dM0 agK7Z6RnT88vwO/cJb7OTSmozCBpVlcYYFrM3rOf/D2rQZ72Kgj3ZYRgeJ2ON0Jt2Dpu DZMA== X-Forwarded-Encrypted: i=1; AJvYcCWJvqYXGj4qM0iAn6B+vRV1vGC7YIOGAwyxfDSt//p/MXUBHHxdsrUxqfXYN1NBV/pCyOiP/PLXogAcgKQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwockQnBf2sn4/KU3JCX9efbFbAf6lV1ddiENmEv+buaIVv5bC9 YCvW1VjWJePPUuivZSsrl2h5G2ljDzD51rVMJU5gBWxeDG2iBWfhTKm8sLHmYdg5r11Mv5Qh5FW ppDNF8ENiMV9LDQ== X-Received: from wrbbn22.prod.google.com ([2002:a05:6000:616:b0:436:30bc:37dd]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:2c08:b0:439:94a7:715a with SMTP id ffacd0b85a97d-43994a771a8mr1769317f8f.17.1772037284432; Wed, 25 Feb 2026 08:34:44 -0800 (PST) Date: Wed, 25 Feb 2026 16:34:32 +0000 In-Reply-To: <20260225-page_alloc-unmapped-v1-0-e8808a03cd66@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260225-page_alloc-unmapped-v1-0-e8808a03cd66@google.com> X-Mailer: b4 0.14.3 Message-ID: <20260225-page_alloc-unmapped-v1-7-e8808a03cd66@google.com> Subject: [PATCH RFC 07/19] mm/page_alloc: don't overload migratetype in find_suitable_fallback() From: Brendan Jackman To: Borislav Petkov , Dave Hansen , Peter Zijlstra , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Vlastimil Babka , Wei Xu , Johannes Weiner , Zi Yan Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, x86@kernel.org, rppt@kernel.org, Sumit Garg , derkling@google.com, reijiw@google.com, Will Deacon , rientjes@google.com, "Kalyazin, Nikita" , patrick.roy@linux.dev, "Itazuri, Takahiro" , Andy Lutomirski , David Kaplan , Thomas Gleixner , Brendan Jackman , Yosry Ahmed Content-Type: text/plain; charset="utf-8" This function currently returns a signed integer that encodes status in-band, as negative numbers, along with a migratetype. This function is about to be updated to a mode where this in-band signaling no longer makes sense. Therefore, switch to a more explicit/verbose style that encodes the status and migratetype separately. In the spirit of making things more explicit, also create an enum to avoid using magic integer literals with special meanings. This enables documenting the values at their definition instead of in one of the callers. Signed-off-by: Brendan Jackman --- mm/compaction.c | 3 ++- mm/internal.h | 14 +++++++++++--- mm/page_alloc.c | 40 +++++++++++++++++++++++----------------- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 1e8f8eca318c6..cf65a3425500c 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -2323,7 +2323,8 @@ static enum compact_result __compact_finished(struct compact_control *cc) * Job done if allocation would steal freepages from * other migratetype buddy lists. */ - if (find_suitable_fallback(area, order, migratetype, true) >= 0) + if (find_suitable_fallback(area, order, migratetype, true, NULL) + == FALLBACK_FOUND) /* * Movable pages are OK in any pageblock. If we are * stealing for a non-movable allocation, make sure diff --git a/mm/internal.h b/mm/internal.h index cb0af847d7d99..1d88e56a9dee0 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1028,9 +1028,17 @@ static inline void init_cma_pageblock(struct page *page) } #endif - -int find_suitable_fallback(struct free_area *area, unsigned int order, - int migratetype, bool claimable); +enum fallback_result { + /* Found suitable migratetype, *mt_out is valid. */ + FALLBACK_FOUND, + /* No fallback found in requested order. */ + FALLBACK_EMPTY, + /* Passed @claimable, but claiming whole block is a bad idea. */ + FALLBACK_NOCLAIM, +}; +enum fallback_result +find_suitable_fallback(struct free_area *area, unsigned int order, + int migratetype, bool claimable, unsigned int *mt_out); static inline bool free_area_empty(struct free_area *area, int migratetype) { diff --git a/mm/page_alloc.c b/mm/page_alloc.c index fcc32737f451e..1cd74a5901ded 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2280,25 +2280,29 @@ static bool should_try_claim_block(unsigned int order, int start_mt) * we would do this whole-block claiming. This would help to reduce * fragmentation due to mixed migratetype pages in one pageblock. */ -int find_suitable_fallback(struct free_area *area, unsigned int order, - int migratetype, bool claimable) +enum fallback_result +find_suitable_fallback(struct free_area *area, unsigned int order, + int migratetype, bool claimable, unsigned int *mt_out) { int i; if (claimable && !should_try_claim_block(order, migratetype)) - return -2; + return FALLBACK_NOCLAIM; if (area->nr_free == 0) - return -1; + return FALLBACK_EMPTY; for (i = 0; i < MIGRATE_PCPTYPES - 1 ; i++) { int fallback_mt = fallbacks[migratetype][i]; - if (!free_area_empty(area, fallback_mt)) - return fallback_mt; + if (!free_area_empty(area, fallback_mt)) { + if (mt_out) + *mt_out = fallback_mt; + return FALLBACK_FOUND; + } } - return -1; + return FALLBACK_EMPTY; } /* @@ -2408,16 +2412,16 @@ __rmqueue_claim(struct zone *zone, int order, int start_migratetype, */ for (current_order = MAX_PAGE_ORDER; current_order >= min_order; --current_order) { - area = &(zone->free_area[current_order]); - fallback_mt = find_suitable_fallback(area, current_order, - start_migratetype, true); + enum fallback_result result; - /* No block in that order */ - if (fallback_mt == -1) + area = &(zone->free_area[current_order]); + result = find_suitable_fallback(area, current_order, + start_migratetype, true, &fallback_mt); + + if (result == FALLBACK_EMPTY) continue; - /* Advanced into orders too low to claim, abort */ - if (fallback_mt == -2) + if (result == FALLBACK_NOCLAIM) break; page = get_page_from_free_area(area, fallback_mt); @@ -2447,10 +2451,12 @@ __rmqueue_steal(struct zone *zone, int order, int start_migratetype) int fallback_mt; for (current_order = order; current_order < NR_PAGE_ORDERS; current_order++) { + enum fallback_result result; + area = &(zone->free_area[current_order]); - fallback_mt = find_suitable_fallback(area, current_order, - start_migratetype, false); - if (fallback_mt == -1) + result = find_suitable_fallback(area, current_order, start_migratetype, + false, &fallback_mt); + if (result == FALLBACK_EMPTY) continue; page = get_page_from_free_area(area, fallback_mt); -- 2.51.2