From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C2D34CA5FFF for ; Wed, 7 Oct 2026 02:14:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6ABE46B0088; Tue, 6 Oct 2026 22:14:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 683236B0092; Tue, 6 Oct 2026 22:14:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 598686B0093; Tue, 6 Oct 2026 22:14:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3606B6B0088 for ; Tue, 6 Oct 2026 22:14:18 -0400 (EDT) Received: from smtpin03.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay04.hostedemail.com (Postfix) with ESMTP id BBC1B1A0304 for ; Wed, 7 Oct 2026 02:14:17 +0000 (UTC) X-FDA: 85294210554.03.0FCB531 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by imf24.hostedemail.com (Postfix) with ESMTP id 3BD70180002 for ; Wed, 7 Oct 2026 02:14:16 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=surriel.com header.s=mail header.b="kd5fSF l"; spf=pass (imf24.hostedemail.com: domain of riel@surriel.com designates 96.67.55.147 as permitted sender) smtp.mailfrom=riel@surriel.com; dmarc=pass (policy=quarantine) header.from=surriel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1791339256; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zf956o7Xb3ZAc7snjXqwGB/wRoNyeXb3dU6QTOPLSKg=; b=CsfOky7rgHvOFYPjRTnCrWUieBYomepTiRfdlemDNpHELUzs+4SWpTcdARyEnDU5sMv5w7 5XjWRjXWqQabcFTlVviJL+ZaL3FNoBd2cNRNgg1/O/XBWqnOfJQ8a1MLRMtg8ESkUI4LcI GZtjhutnIn3Snn8dmU8IdkNqNhG7u6Y= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=surriel.com header.s=mail header.b="kd5fSF l"; spf=pass (imf24.hostedemail.com: domain of riel@surriel.com designates 96.67.55.147 as permitted sender) smtp.mailfrom=riel@surriel.com; dmarc=pass (policy=quarantine) header.from=surriel.com ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1791339256; b=hVNGutsMTEj35eRMmySfTq6AB1LBY9X5oLPGitR4Mol8p9GlLLwM+c1jCSdONK/62ovHpR 6IJj8E0bblinXFoWQH92TMifQSJwzwoKlfcf3f1uGo8Ao57hLiRJF7c3zzX57Lz9TZtclM SIYPHCWUb1WR/uLn7Vrtu4rBNaIZY9I= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=surriel.com ; s=mail; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID; bh=zf956o7Xb3ZAc7snjXqwGB/wRoNyeXb3dU6QTOPLSKg=; b=kd5fSF l1Et4fuw0fA/NTiBHcgmHsADezDrKr41HJkv4gh4mFoTJaNVite5V94t24F00jvCE2bOUCrs7BDMV qvdJt1HTbg58GOIvpC4j+CfpLTCg+uBbAvFYcT/O51TEaV/1UPEqHQ5qYdcTznuTTFAqFe6WYPN1M dyjStLuG1fGrtrULibk6ffePjNy9DSnxdUOsrO9fPvIGyfChZr1HfaThA/+C92rUiiOKeoyovp6lf 9rP1wre5v0LanRQA4zwjyHPueBhS549qRt61dZaw5r7IIODlfa28gmukedY64P80IA2reU008BUbK tVsaTISFiH1kj8CBIUqObIgBEi1A==; Received: from [2601:18c:8100:a0e0:2541:b86e:2586:d219] (helo=fangorn.surriel.com) by shelob.surriel.com with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.99.5) (envelope-from ) id 1xEH9M-0000000B2cT-45iF; Wed, 07 Oct 2026 02:12:56 +0000 From: Rik van Riel To: linux-kernel@vger.kernel.org Cc: Andrew Morton , Vlastimil Babka , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Baolin Wang , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Mike Rapoport , linux-mm@kvack.org, Rik van Riel Subject: [RFC PATCH 2/5] mm/page_alloc: count a merged buddy's pages under the merged type Date: Tue, 6 Oct 2026 22:12:47 -0400 Message-ID: <20261007021250.1665929-3-riel@surriel.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261007021250.1665929-1-riel@surriel.com> References: <20261007021250.1665929-1-riel@surriel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 3BD70180002 X-Rspam-User: X-Stat-Signature: wz97m3eh9k8hkcbr1bf9t65y79jxjygk X-HE-Tag: 1791339256-342952 X-HE-Meta: U2FsdGVkX18dOY3WBJCIteBYgCRIOK58TSJaCJXPcGZf8hA/ST+Lnv9LB2bG113mV7MuGAJSZxed/W6Lf2iEXELhyywdk6iEWM+gxarOCeEgBCTd3LSzJ72XdVboxLRBwnhw5DFZMmUEKl2iGMn1BFbFqd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2fUAYumKV1Z40lUPKj4f9y3HA/JCndhWrM8wz/ygmOfpWzfxuMQIwCHcYlifQBbulsuGuoTiCCB+9MqY6KUR8HQmW7PmeXbbHxvXBzTLpHHwV/MpF+CJA== Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: __free_one_page() merges a freed page with a free buddy of another mergeable type at pageblock order and above, and retypes the buddy to match. The buddy's pages stay counted under the old type: nothing moves them to the merged type in the free counts. That is unobservable today. NR_FREE_PAGES does not separate types, so the missing move nets to zero there. Any future per-type free count would undercount on a merge from the other side, and allocating the merged run later could wrap it. Move the buddy's pages to the merged type in the count too. Assisted-by: LLM Signed-off-by: Rik van Riel --- mm/page_alloc.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 4658af97be010..ae38e25971559 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -993,6 +993,11 @@ static inline void __free_one_page(struct page *page, account_freepages(zone, 1 << order, migratetype); } else { __del_page_from_free_list(buddy, zone, order, buddy_mt); + /* The buddy's free pages join the merged block's type. */ + if (unlikely(buddy_mt != migratetype)) { + account_freepages(zone, -(1 << order), buddy_mt); + account_freepages(zone, 1 << order, migratetype); + } } if (unlikely(buddy_mt != migratetype)) { -- 2.53.0-Meta