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.133.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 A15FD3BCD3A for ; Fri, 29 May 2026 15:22:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780068146; cv=none; b=G6ubP4yjdzMvzdaGxErm9Ap8gPfejudVSO3Q4bwPYMXCRU3wEP7V+Sp75fKmAEJ12xzdnOFR1rPIgdMDgWvk0CGZbgh/xsx+/9iKyx/qMiJHaaSWspni58qWU89xgvmPrTZNylC4BQm12vmE7DsznXOsLD5t3r3IlZ7Vv6pCW/w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780068146; c=relaxed/simple; bh=2SCjG0p+gTn8qm5MHLYDPQz8gTh6+lwWx6Kgl/LoFJQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=s3n8VnF4685TV7K51x6d6mrxqkEVh7M5N7tbhvfz1jtZtqWR92cXcabZcgzjLvboosBpWOtmU90W4IEE7yqGBE8NLxy2TawECxEt0aAl6/d851VZH6iZz2bjLwpg78briXUZQSkpmzlalC7JTHjHrJ7Spmh7nDfecWcNwDhlMag= 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=bvdAz3Yy; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=LhYPA+6e; arc=none smtp.client-ip=170.10.133.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="bvdAz3Yy"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="LhYPA+6e" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780068144; 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=6a9U/grsiUVqQvDGNE/rE2t/3gE4VHHRcC3EwM49fXU=; b=bvdAz3Yy2b+2L7ZCUqVryV/aByeZ7IZimErgqW0dBKXHkJcdPTG+ol/RWC6HFRb/v/XeZX 0ZzAYlYPhL0qgbMCDNtbDT2wPYb4nh3FaRtOb/vT7maP60ztWN7oHIP0xs9QiB8ZshEnbX Wj84L/lLz6co04H9wCro/wtpFCkfHKo= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-206-d47kFWgrN8Kv_bgjwjxDTQ-1; Fri, 29 May 2026 11:22:23 -0400 X-MC-Unique: d47kFWgrN8Kv_bgjwjxDTQ-1 X-Mimecast-MFC-AGG-ID: d47kFWgrN8Kv_bgjwjxDTQ_1780068142 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-45eec27f5a5so1055655f8f.2 for ; Fri, 29 May 2026 08:22:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1780068142; x=1780672942; 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=6a9U/grsiUVqQvDGNE/rE2t/3gE4VHHRcC3EwM49fXU=; b=LhYPA+6elEb87i1rdq/nNEOOY64EF0CFABbcl6oRfk74IBxbrmIRx5cMc+gAc5AvnY LZveU2tKcoMf4fXZrNTxsbxrlqXVy8j63kWTmN8D87Nra+3f+ahfAuEKgeKfpyuwTQsd nqMMYRHqU2w+Gdt/+gMM/5IsWCc490ajluBsFQtlcjfHFoDrp/eqoisVXFKP8xdsC+Od A3ecvjS5b15vvPx+347hriAu6i8OpttwvW/15wTjK4MxSKML9rX8eeG35a62tP63ZqX3 7jje2PkGVP6ZWLb+I2HbvjMBl/tFxGFmT6c6PmWLm9oJoipBn9AzTmMS26BKEt78jTWU Ztcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780068142; x=1780672942; 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=6a9U/grsiUVqQvDGNE/rE2t/3gE4VHHRcC3EwM49fXU=; b=UdWL15G1yo0veDIcaKayfQtQMQbJeaedSLjfX/XJk8KzMRalsTd+nQVNDrIuQn/v/S URgn5DpKKSb03PFAA4F+EYwUVaL0BEf+XOtFtgkm0oRGr3++Obp1UdJvwGUe23V6RVEw ynF9hlMA/Vd5mmHnN8sT059sVzqa0LpE4eYzFRmLgHYBTFwguy+wEOxLqL7F1i5y4DNi zTTcjO+byoVVO08L6VyuboV/KWFGGeWNZZrafvy2YB+eIcfQggWu3jSvp9TGf6IR2uhh 3LgW+P7peB4hZKmkWfse44UXS0EyM4LJ11JfWzIb9PY8Cv9KrnIVZaCmFQ5nrYw3b1FC qhqw== X-Gm-Message-State: AOJu0YxfBTgcaBt5pvjjzfjiNkPmu5FcZpyjsah5noSyVTsLWVlPsUGM PTUadPqmuJHWcnJ1Wku+4d95DlZZe0CM07vuLh1T7Jc2Edl++Jl5BfsU2yyzViZ2oQM0YtyI5CQ /KR4c8MJjgWfe2dH8XStv9x0V0tcRSfCzaGMsSame3XkDbK2S/VNOUFWiBePb4b9ojt7oqG0zbG 0A4csbiSXeT7N4qiB6ykC9zbcRfHwPGyXPJ9OiCfPu/jA= X-Gm-Gg: Acq92OErlrMaS2j9HMLJjZAhGlyaE9YH1ZefucjOwqMGwUtX+ehP/v2RqNZxWjVE2ex UBnUyoxXzKRuk8lADZa3ySjQeTV1W5ZjyO5s8eJstFSMdAbmIQvQAwEUup+TDSoGbdJu1RsAeHM Tc8/2c04/V1rHi3jaEPihl3QZ7CqtI1zhQLpaNZDdk/Clzr+BrvY4M+5bpQQNsas/PTKR1G+vi5 5ttqBJQ744TgX4RA7dbqQSCukyK59iSLJTuZnx1DrJUV0fG4oqxvPeLFAZ3oUMDrRF6jdjzuYNi HupenkODDMNlcR0gcWxa2Y20Z41w0L+I8/Vudh/G/A/4hiCLpA1pY2Q5CUIog2hCawzVYIuIiOD I5cKDhrDVh447rvruVIv2zlY9k82Qzy2QCNxp1Js3HnwPIQr3ppK/EA== X-Received: by 2002:adf:f2cf:0:b0:45e:f672:40fb with SMTP id ffacd0b85a97d-45ef6b4f72bmr394897f8f.22.1780068141795; Fri, 29 May 2026 08:22:21 -0700 (PDT) X-Received: by 2002:adf:f2cf:0:b0:45e:f672:40fb with SMTP id ffacd0b85a97d-45ef6b4f72bmr394796f8f.22.1780068141211; Fri, 29 May 2026 08:22:21 -0700 (PDT) Received: from redhat.com (IGLD-80-230-25-45.inter.net.il. [80.230.25.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45ef354cd87sm3989750f8f.24.2026.05.29.08.22.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 08:22:20 -0700 (PDT) Date: Fri, 29 May 2026 11:22:16 -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 v9 03/37] mm: page_alloc: propagate PageReported flag across buddy splits Message-ID: <35539ca539f76bec575e8a6abc0cf42add858c0f.1780067977.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.27.0.106.g8ac3dc51b1 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 that they are recognized as already-reported. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- mm/page_alloc.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 227d58dc3de6..1192c4e47da4 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1510,6 +1510,7 @@ static void split_large_buddy(struct zone *zone, struct page *page, unsigned long pfn, int order, fpi_t fpi) { unsigned long end = pfn + (1 << order); + bool reported = PageReported(page); VM_WARN_ON_ONCE(!IS_ALIGNED(pfn, 1 << order)); /* Caller removed page from freelist, buddy info cleared! */ @@ -1521,6 +1522,8 @@ static void split_large_buddy(struct zone *zone, struct page *page, do { int mt = get_pfnblock_migratetype(page, pfn); + if (reported) + __SetPageReported(page); __free_one_page(page, pfn, zone, order, mt, fpi); pfn += 1 << order; if (pfn == end) @@ -1699,7 +1702,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; @@ -1721,6 +1724,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; @@ -1731,9 +1743,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); } @@ -2288,10 +2301,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