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 3D6933BED4A for ; Wed, 20 May 2026 22:20:36 +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=1779315637; cv=none; b=roMCaFdJ5tfed8ONaxmdwqUmXytSFR4BsL06cZFmZQKiD1/XcEVb2S4TtSQ2R+7t6IIzAL3wbN0IZHg6nJNXZYwo/lKmqdQ+wTs1VTr49jzyIorhV/hcVwG9I1pKBc034w0vybwjppeUWG7iGLJXN0alpI1plBFA/Hc0sg/15Es= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779315637; 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=oZkYOaWv+RleaFpQAqXYaOE5Uok1jPMD+/GO/oCgDC8S4SFjuP3aoNzUf1B1IInaK0MaSZu7yrb6Xu0DlPj43kKPx2bt/aFNOLiZM5zl5lSaySqYSA0ZprF6xvCt1M21UXdV1AHFLP+ccp/+0TuWqPOq74WthTZBVqOvMz5KYVc= 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=aAVqiMoN; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=DHvCj154; 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="aAVqiMoN"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="DHvCj154" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779315635; 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=aAVqiMoNB22r5mum0UOteSdqPBHBTKFWmqxarFemkqT50JtqE6izqWP4KPKNNox94/++to g8JAPypjhbhtUdJtYepVBxr0LIx43S0OHHBxeDCJKnPbPhKcLUvbZZAdFRlCJHXfY+j4G7 t+9P7bCMsl5FYubRhELGqpLeJt0T06k= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-456-4MM78GcFMFi3y4r2ZjgdgQ-1; Wed, 20 May 2026 18:20:34 -0400 X-MC-Unique: 4MM78GcFMFi3y4r2ZjgdgQ-1 X-Mimecast-MFC-AGG-ID: 4MM78GcFMFi3y4r2ZjgdgQ_1779315632 Received: by mail-lj1-f200.google.com with SMTP id 38308e7fff4ca-393e64f3d68so21437471fa.0 for ; Wed, 20 May 2026 15:20:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1779315632; x=1779920432; 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=DHvCj154KBaz0mdArezigE3zjpmpGHBV6ML6n06cN8DGeqqkU1GTGKGBxeJDTubGKt 3bKl6wSAqHvOvpa5XUZQuR2m3wVifqvtgebzIGTUoAn1gmsexEVK3537FeDZHQ4wtYow 7UIcnR9ijaWrS2duM76JevsQr+hvt2Hk4glmi5Oh0Z5ooGn9DuY+UX1LhfyQi/8JQ+9X bWrGIHg0cBOWsFo4E4/0T3QxpBQ6aLu0cjWNv/kjHCQvZlvw5RVhYpRFtvecUQJAhyTP wfW5Fh8x9wWOxD39Idm7R0n2PxCqTHrX7OpBFRId+gNpVangH9xLuPtgYDcZKMfM+2LR koJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779315632; x=1779920432; 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=aWOBh9ZEOFhpPhrlPUBvk7onrfVbaoXi8eiEwx4k3YlpyQGDZ4bfYBw4c2F+gctKQF va3dkIxkJ3XBfRz1bd675ktvTktv20yL2v8wN0REuF7ShUPsI+f9/rNrUnYQz0C4Ps5Y eP+pYVOkp+kMiIdh8SIKIbxfN5/ZZzpVaoSiLDz+RcU2DjDwbvyQMqRMk5LzBvX/lJaj 0drrRqhNGCBm10RlnRzYY3Dn9jM+tmQ5QC6b6oXhosdJlHPVtamUZFrASdfGLf0x+xuk GH8GgnVQmq8DFlZSDgsDvpOOkJ8QlXlXex9RJjIcjCq0jOknzQL3rNh95hj/zvwhiBos S3zw== X-Gm-Message-State: AOJu0Ywvi21NHyIvAZAD+hMQfUaxLA+U3SWzHXOV9P0ODHkDzVaxcy5r JpFKQjjotLb+JCPewvue7OWXANcN3441McEa20W7D/x9s+tJqrVtHVzNGhNjIfBC7XcIPc56E4w FIbjLVX5mZphQM74X2pu96pWCEBsbv5XrGqlxjdScK6Kc06V5ojRSTci6aNywfxjM09TerHv016 SzIvD7ZKMzcQFNQ5bfeH0F0VA75ZDQM8ziOREqRyV7sTM= X-Gm-Gg: Acq92OEWlmvu4Kl62u9CR+iaiLllN9Gc/O/dTLR7+8fmdhydjD6DqYvYKcmb/ccCZCC Edk8Ldmg3Lo8I1pFu2WxsCt8Dh3/eYA3dI7McbiWxRGM0O6+lEEXwzjtUM5QTiTjOSLpzgyxXA1 1SoY2CFT3r48zejfXtxYc5CV4jYky9IyKAIKk8hLdQhYaDTeWsdC6LzS1w4xBdAnkXu0C1IpgK5 n9f18EMje9CIVofCEyKgRPNqiz13ookcjelVD4BSP/rvXNfqKs50UjwoCMCG6YT5B8ReBD5D7Ss 4wIl1GCZ79nBTJErXQXZEVzKKOCYEtp5M1tIkvPmyGqHxQ9D+934AUqau1D8DbysrMFC1FD3iRA 2WZGjLsIuiN/IlPPmkgDlMvYgc9qlCHE1CKmcgn9mqUE= X-Received: by 2002:a2e:bc90:0:b0:393:fa0f:d64a with SMTP id 38308e7fff4ca-395ca6449bbmr948531fa.28.1779315632050; Wed, 20 May 2026 15:20:32 -0700 (PDT) X-Received: by 2002:a2e:bc90:0:b0:393:fa0f:d64a with SMTP id 38308e7fff4ca-395ca6449bbmr948031fa.28.1779315631503; Wed, 20 May 2026 15:20:31 -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 38308e7fff4ca-3958828150csm32418221fa.7.2026.05.20.15.20.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2026 15:20:30 -0700 (PDT) Date: Wed, 20 May 2026 18:20:23 -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 v8 03/37] mm: page_alloc: propagate PageReported flag across buddy splits Message-ID: <20af8010c2e8ebeb736ae6754e640267b96b8c2d.1779315441.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