From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 B1A0B3AFD16 for ; Mon, 8 Jun 2026 08:34:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780907713; cv=none; b=ZsOAbDa3pa8IavMc8UHV33vpH8UZQq8XO9NW7awFmduFE5VjwQTmEwuuy9hei8PVgCS+wYICvKitrPiYud1lVn7N2/XgM+tYyawb0q21K1XvCwbCJ1mrQUurfp8fhnjfhCflzKeYwskuYbbhThVsQnMW3kjm6DkDj0dMWYk2pQU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780907713; c=relaxed/simple; bh=9FkU2pdAQ7jw+NV4TdycQajDAfwAm44W9k92o71ADO8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IVJ4rjPteArRNCeAjOSbEme1ks60TgfhOl/b6NV4tfOyFKoUNN4vWHgnUW4lPrmEoeiB+Cnp0TyBnLf8Mz6x0hkngNcZ5Nys5O6dKwWuVElOQu5c1/a0ueUbnT4gMeNNB+NSy8Ai3y4vPtfwd1x2bDNrgglfV7lV10+9n84ClVs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=GlvlVEzX; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=nAurjDSW; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GlvlVEzX"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="nAurjDSW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780907693; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=BG5vFIZuWkBfCpPnsH5jvRyFO8VXn5agYH6VILwADzw=; b=GlvlVEzXF2/x4tTmzwSSU3dKXk6YHAkjBM2z8Zw5T/FHg8lI01TnFdXVANRpFzkIHpNJi8 GAyxBUdFxcEeY/sAxJ3uQDEZcsgJkgeUUVS6X0mQpXs4xbMWo2h97zIxB95f3Lw2432TOs 9mwSM31G34DNB7h3qL2G5NZdlLAOfdg= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-453-kKiZ3_74P9aFzL32niqs0w-1; Mon, 08 Jun 2026 04:34:52 -0400 X-MC-Unique: kKiZ3_74P9aFzL32niqs0w-1 X-Mimecast-MFC-AGG-ID: kKiZ3_74P9aFzL32niqs0w_1780907691 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-490addd42bbso25944205e9.3 for ; Mon, 08 Jun 2026 01:34:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1780907691; x=1781512491; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=BG5vFIZuWkBfCpPnsH5jvRyFO8VXn5agYH6VILwADzw=; b=nAurjDSWRz+WK/aOMw/hzwHjkaasX+pkmUWaQzcnRdAMPROglSVafIBWNbwUuvrkKO kSZsbREA8xHUQT1jviyCSq1cQBuG84L1jwsV7XK5BsFbWKio+Tjr7+qrNetG1nuAHugr VVAOLZvpJ5ruBH0OMKRlMbJxTlii3lcuvyRO7NrzwnMSubxQOdXNH8xreW1/nGne7bia uRSalCiQ8vBtqaKw2hT1hvXmiuvlVyyKkXzvlTIxOjjCvc0Zf+siGmjMSr/ch70fYipJ pGwKzFzoZk7cjxeb2tNLn+X41l3vyqK/8f9mH4/3sDjzWF7deuWADRKFFeVcMBNLzJkG eDbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780907691; x=1781512491; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BG5vFIZuWkBfCpPnsH5jvRyFO8VXn5agYH6VILwADzw=; b=Soe/QSChRmYBOKuntHh9HfRorciInpfS5aQNN2hcDSA88DZ/3dUAwLNjCHKdjXyEsW WjSJX5YVFAybjzRiR9S5xMrNiYpht4mv3ybeTRVGpT1kX6ea+eiw/DMYSNbsglDQB6+/ QYxlTSatrURbT6wyW4ocnPjgOSnQPzU0+CHThdztr8tE2NqIaTmOs+nP0WB4L8OBiOyS /oVQm//oPtoemJ06bKA/Kgnu2ePvYRm/78l30rMsDkkhGfpMLhFnpHLmXdM60VKsl1gC 6QQ5Jm42cV91HFlN5Gf4pjgMm+8yIMTGEI8s/7kjFS+LBbrrMqXR1igYem8BcaWBWXb1 mlAQ== X-Gm-Message-State: AOJu0YwtoC1DrE0hQCagsMYUEF4kIXQCQE/nD+SJqXJbi0JfndwF2rBG wJrOfKndeiSkIIlJXAteLdc7c+MC8oqQEMJZ88GQHM8harjk8QnoU4+3es4XdcR9luho82ilSy1 WoJogceP3XVi5JmiTaUVmPysCPvHuCRcn/s17nX5LApwODFq7nbJ9KjQ7izKQeuSIB9wVq9cTAb 17x62rCkzUrZfjvmpACbqbjeNRZTNp0lkDqtNBNRIhElQ= X-Gm-Gg: Acq92OFEvPsQOs0VcVUn/SgjpWG0toS+GO9MzehGXSg1p5Jy5EJ3eucm1W7uVE/+joo ngNtYUwn1X11vulkDqNUoyUnFdZc6A7DCvKuOS0GAK1pQ0aMoqcvF9uEgmwgViqyQ9fo0csAkub HLeqUBcxiRthPCVYFVI3HOY3BvN35U/qlsHuQEOk2rp5hasM920xKjEywBnvGU1/uk2N+qWJQjR H5Ii3Q3IVSQCbvdNp9cC0X9J2fyvhpm5Hu0EBig3ppLMDjrysPatPft229cbt5vcnwgexYAquFF UIhk3piXcjnH82eSmlUTrV40zZYesEsMc2HVW0oyWASdL+Nn/mXidPPf5KCdoVX0Gcrg0UAc4CV 3tzfftjfGnPPPQ9qwPWnxWyI= X-Received: by 2002:a05:600c:a011:b0:490:58ef:cea7 with SMTP id 5b1f17b1804b1-490c25ee058mr246872965e9.22.1780907690796; Mon, 08 Jun 2026 01:34:50 -0700 (PDT) X-Received: by 2002:a05:600c:a011:b0:490:58ef:cea7 with SMTP id 5b1f17b1804b1-490c25ee058mr246870995e9.22.1780907690081; Mon, 08 Jun 2026 01:34:50 -0700 (PDT) Received: from redhat.com ([31.152.37.159]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f2ed944sm52009994f8f.13.2026.06.08.01.34.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jun 2026 01:34:49 -0700 (PDT) Date: Mon, 8 Jun 2026 04:34:39 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: "David Hildenbrand (Arm)" , Jason Wang , Xuan Zhuo , Eugenio =?utf-8?B?UMOpcmV6?= , Muchun Song , Oscar Salvador , Andrew Morton , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan , Baolin Wang , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Hugh Dickins , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Christoph Lameter , David Rientjes , Roman Gushchin , Harry Yoo , Axel Rasmussen , Yuanchu Xie , Wei Xu , Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Baoquan He , virtualization@lists.linux.dev, linux-mm@kvack.org, Andrea Arcangeli Subject: [PATCH v10 03/37] mm: page_alloc: propagate PageReported flag across buddy splits Message-ID: <1a407d39a9ebd95e9de67e44f9ad2db37c9f31e9.1780906288.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.51.2.2891.g4157995a80.dirty X-Mutt-Fcc: =sent When a reported free page is split via expand() to satisfy a smaller allocation, the sub-pages placed back on the free lists lose the PageReported flag. This means they will be unnecessarily re-reported to the hypervisor in the next reporting cycle, wasting work. While I was unable to quantify the performance difference, it is an obvious waste, even if small. Propagate the PageReported flag to sub-pages during expand(), both in page_del_and_expand() and try_to_claim_block(), so split_large_buddy() also propagates PageReported via a bool parameter: the caller saves PageReported before del_page_from_free_list() clears it, then passes the saved value. The flag is set after __free_one_page() with a PageBuddy check, matching the page_reporting_drain() pattern. Free-path callers pass false (freshly freed pages are never reported). that they are recognized as already-reported. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- mm/page_alloc.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index d49c254174da..8dae5b3f5876 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1502,7 +1502,8 @@ static void free_pcppages_bulk(struct zone *zone, int count, /* Split a multi-block free page into its individual pageblocks. */ static void split_large_buddy(struct zone *zone, struct page *page, - unsigned long pfn, int order, fpi_t fpi) + unsigned long pfn, int order, fpi_t fpi, + bool reported) { unsigned long end = pfn + (1 << order); @@ -1517,6 +1518,8 @@ static void split_large_buddy(struct zone *zone, struct page *page, int mt = get_pfnblock_migratetype(page, pfn); __free_one_page(page, pfn, zone, order, mt, fpi); + if (reported && PageBuddy(page) && buddy_order(page) == order) + __SetPageReported(page); pfn += 1 << order; if (pfn == end) break; @@ -1559,11 +1562,12 @@ static void free_one_page(struct zone *zone, struct page *page, llist_for_each_entry_safe(p, tmp, llnode, pcp_llist) { unsigned int p_order = p->private; - split_large_buddy(zone, p, page_to_pfn(p), p_order, fpi_flags); + split_large_buddy(zone, p, page_to_pfn(p), p_order, + fpi_flags, false); __count_vm_events(PGFREE, 1 << p_order); } } - split_large_buddy(zone, page, pfn, order, fpi_flags); + split_large_buddy(zone, page, pfn, order, fpi_flags, false); spin_unlock_irqrestore(&zone->lock, flags); __count_vm_events(PGFREE, 1 << order); @@ -1694,7 +1698,7 @@ struct page *__pageblock_pfn_to_page(unsigned long start_pfn, * -- nyc */ static inline unsigned int expand(struct zone *zone, struct page *page, int low, - int high, int migratetype) + int high, int migratetype, bool reported) { unsigned int size = 1 << high; unsigned int nr_added = 0; @@ -1716,6 +1720,15 @@ static inline unsigned int expand(struct zone *zone, struct page *page, int low, __add_to_free_list(&page[size], zone, high, migratetype, false); set_buddy_order(&page[size], high); nr_added += size; + + /* + * The parent page has been reported to the host. The + * sub-pages are part of the same reported block, so mark + * them reported too. This avoids re-reporting pages that + * the host already knows about. + */ + if (reported) + __SetPageReported(&page[size]); } return nr_added; @@ -1726,9 +1739,10 @@ static __always_inline void page_del_and_expand(struct zone *zone, int high, int migratetype) { int nr_pages = 1 << high; + bool was_reported = page_reported(page); __del_page_from_free_list(page, zone, high, migratetype); - nr_pages -= expand(zone, page, low, high, migratetype); + nr_pages -= expand(zone, page, low, high, migratetype, was_reported); account_freepages(zone, -nr_pages, migratetype); } @@ -2116,11 +2130,13 @@ static bool __move_freepages_block_isolate(struct zone *zone, /* We're a part of a larger buddy */ if (PageBuddy(buddy) && buddy_order(buddy) > pageblock_order) { int order = buddy_order(buddy); + bool reported = PageReported(buddy); del_page_from_free_list(buddy, zone, order, get_pfnblock_migratetype(buddy, buddy_pfn)); toggle_pageblock_isolate(page, isolate); - split_large_buddy(zone, buddy, buddy_pfn, order, FPI_NONE); + split_large_buddy(zone, buddy, buddy_pfn, order, FPI_NONE, + reported); return true; } @@ -2283,10 +2299,12 @@ try_to_claim_block(struct zone *zone, struct page *page, /* Take ownership for orders >= pageblock_order */ if (current_order >= pageblock_order) { unsigned int nr_added; + bool was_reported = page_reported(page); del_page_from_free_list(page, zone, current_order, block_type); change_pageblock_range(page, current_order, start_type); - nr_added = expand(zone, page, order, current_order, start_type); + nr_added = expand(zone, page, order, current_order, start_type, + was_reported); account_freepages(zone, nr_added, start_type); return page; } -- MST