From nobody Sat Jul 25 18:53:15 2026 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (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 96AA82F1FDE for ; Tue, 14 Jul 2026 17:15:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784049315; cv=none; b=eh32FU8IjA5z58biNNiWwAV2nswdKV/36lpsMMeSAfSeK0jvCjpdNc7EIGGn37kEWegZoJlCTTxsKMnOceqOTKskpzmY/mIl5ta7X2a40lh5My5+J5RUH/UUuIuayalwP02i2XIhFj9+poQ74kfPPIXQVXveC9OqQMthd5oG4ms= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784049315; c=relaxed/simple; bh=0O+fCYtAeEL6m2xQKGY4DDGMngZVKDto9UMiyhbPAOQ=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=ZFsdTykdvIkOdfqiW+CJGHQOzfvDqFNNKvvxjMgnI3WeVK+GDxM7tKyHYlEb/biwpClDEm9DG3UPmlRbiBLL5FdiPp/VUYct6zKb6BPs10/ZNuIrS5pFobzAOdPjzuhoCW6j6lIzvvoezJU1RVMM2dhrKpjp+J6OtCYWKK2dnRc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--pratmal.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=vnJMFVzt; arc=none smtp.client-ip=209.85.214.202 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--pratmal.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="vnJMFVzt" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2ca5d2474c7so30211715ad.2 for ; Tue, 14 Jul 2026 10:15:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784049313; x=1784654113; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=HQl/YhNIycgwR9ahJpRcbgcx4L53MFsyko1Sj3ozvDU=; b=vnJMFVztkcbrg5sZe5sweWpoOidwxrUE3yrZhtSXTLYFbyFj5WOpt6uxZa5L6M6hZu de6KetEiAehlp0FC3ODxVXhLXDYwEIM6I1LbEvX7nltBmdllSq9hhn4tsLq47NloG3TJ diohmLW+SS5fxla7omKb+mHpZtua2XKvciEAJ3OcPB7qWobt4YYVs2ik9MyWSstNhlbx 3ptWPoD8C3tLANAbWCBPWBidkPJf7Eu7IgLrSV0gwJORqU8WUfmD9h9hYFOT710icsED kngzBWSnETX4oqGut35ZjNENfJY4wAas8qh//DYlrgoNHl5gyMNBRRP4edf4mcuaeYwK VilA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784049313; x=1784654113; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=HQl/YhNIycgwR9ahJpRcbgcx4L53MFsyko1Sj3ozvDU=; b=TVDhf9I7RtySq+EnutfM4D9ittiZB0zxnqZ+Juen0Zb2zVSMdb9OIcX8tkPY4d9z2T x7Ve1Ek9zCm2UqtuQ+WDDeBq/whns714d7MmKCnqg0+aFP1CXzKX2k1LtLXsxwc/vbCR 2Cno7iPWKoW3xl/zjVFukNYHaoz5j709cOYPC+SOSU2/s7uE802RvDNsULYeKGtHW9ME kUwcEiR8YtjPjWin2H75lUo2P8mpCPHYK2dOIejyqUF8XFYPkFFHPH6tKzsJjFoVsEtX s/koAd6j1pb80omA7k5xvfOTFhH8uZUAcqZt9PAc/GMvJDvTwY4G+3YDbCjhy546MXTN w9Xg== X-Forwarded-Encrypted: i=1; AHgh+Rpr6WlXYvLWRh2wHUpmdaRUwogvkxet5nMExlItoA8IlpLv6lfBLh6di6RqZTAY6GpIr6lhabiAA2jrocE=@vger.kernel.org X-Gm-Message-State: AOJu0Yx/6Y/hPBTpFjn2aELosYMjZ7EeCKYoNvAWIophSJy3WIti1W/1 IuTo1sfDdbzDy+QFCLREvr5tfF48JXkCyBAxWNIeLUDWfc8CMc6ynwtSORD8ZmsBHZ1Lpuln4kG CK4bKKTQfIg== X-Received: from dled1-n2.prod.google.com ([2002:a05:701b:42c1:20b0:13b:9e9c:c86a]) (user=pratmal job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:3394:b0:3a8:21e0:1ffa with SMTP id adf61e73a8af0-3c110160cabmr18302925637.27.1784049311355; Tue, 14 Jul 2026 10:15:11 -0700 (PDT) Date: Tue, 14 Jul 2026 17:14:55 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.55.0.141.g00534a21ce-goog Message-ID: <20260714171456.2350037-1-pratmal@google.com> Subject: [RFC PATCH] mm/page_reporting: Add page_reporting_delay sysctl From: pratmal@google.com To: Andrew Morton , Vlastimil Babka Cc: David Hildenbrand , Greg Thelen , Pratyush Mallick , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan , linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Pratyush Mallick Currently, the free page reporting daemon uses a hardcoded delay of (2 HZ) between reporting intervals. While this is a reasonable default, it lacks the flexibility to adapt to varying guest workloads. A low delay allows aggressive memory reclamation, returning unused pages to the hypervisor as quickly as possible. However, during spiky allocation/free churn, this immediate reporting can lead to a severe performance penalty (nested page faults) as the guest re-allocates memory that the hypervisor has just unmapped. In these scenarios, there is benefit from increasing the delay to batch free pages over a longer window, absorbing the churn without hypercall and re-fault overhead. This patch refactors the delay into a dynamically tunable sysctl, /proc/sys/vm/page_reporting_delay, measured in milliseconds. The value defaults to 2000ms to precisely match the original (2 HZ) behavior. If the sysctl is modified across reporting windows, the sysctl handler immediately issues a mod_delayed_work() to honor the new configuration without waiting for the prior timeout to lapse. Signed-off-by: Pratyush Mallick --- Sending this as an RFC to get thoughts on exposing this delay as a sysctl.=20 =20 Benchmark Results: We kill a process allocated with 10GB memory within the VM and mesure the time it takes to report all the memory to host as well the delay in initiating the reporting. =20 default(2s delay): https://drive.google.com/file/d/1Ouxm_raj4xPNthc_ryk0Mdb= o-c_zXKiP/view?usp=3Dsharing Tuned to 0s delay: https://drive.google.com/file/d/1mk58LPiYgIF4Yk6kmX5JHpl= hrwIw0NbC/view?usp=3Dsharing =20 The data shows (sysctl.vm.page_reporting_delay=3D0) that within ~2 seconds, the guest reports ~10 GiB and the reporting is initiated as soon as 100ms.=20 With the default 2s delay, it takes around ~7 sec to report the same and initiation delay is around 2 sec. mm/page_reporting.c | 47 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/mm/page_reporting.c b/mm/page_reporting.c index f0042d5743af..6fde542cbe09 100644 --- a/mm/page_reporting.c +++ b/mm/page_reporting.c @@ -6,6 +6,7 @@ #include #include #include +#include #include =20 #include "page_reporting.h" @@ -47,15 +48,44 @@ MODULE_PARM_DESC(page_reporting_order, "Set page report= ing order"); */ EXPORT_SYMBOL_GPL(page_reporting_order); =20 -#define PAGE_REPORTING_DELAY (2 * HZ) -static struct page_reporting_dev_info __rcu *pr_dev_info __read_mostly; - enum { PAGE_REPORTING_IDLE =3D 0, PAGE_REPORTING_REQUESTED, PAGE_REPORTING_ACTIVE }; =20 +static unsigned int page_reporting_delay =3D 2000; +static struct page_reporting_dev_info __rcu *pr_dev_info __read_mostly; + +static int page_reporting_delay_sysctl(const struct ctl_table *table, int = write, + void *buffer, size_t *lenp, loff_t *ppos) +{ + int ret; + struct page_reporting_dev_info *prdev; + + ret =3D proc_dointvec(table, write, buffer, lenp, ppos); + if (ret < 0 || !write) + return ret; + + rcu_read_lock(); + prdev =3D rcu_dereference(pr_dev_info); + if (prdev && atomic_read(&prdev->state) =3D=3D PAGE_REPORTING_REQUESTED) + mod_delayed_work(system_wq, &prdev->work, msecs_to_jiffies(page_reportin= g_delay)); + rcu_read_unlock(); + + return 0; +} + +static struct ctl_table page_reporting_sysctls[] =3D { + { + .procname =3D "page_reporting_delay", + .data =3D &page_reporting_delay, + .maxlen =3D sizeof(unsigned int), + .mode =3D 0644, + .proc_handler =3D page_reporting_delay_sysctl, + }, +}; + /* request page reporting */ static void __page_reporting_request(struct page_reporting_dev_info *prdev) @@ -80,7 +110,7 @@ __page_reporting_request(struct page_reporting_dev_info = *prdev) * now we are limiting this to running no more than once every * couple of seconds. */ - schedule_delayed_work(&prdev->work, PAGE_REPORTING_DELAY); + schedule_delayed_work(&prdev->work, msecs_to_jiffies(page_reporting_delay= )); } =20 /* notify prdev of free page reporting request */ @@ -343,7 +373,7 @@ static void page_reporting_process(struct work_struct *= work) */ state =3D atomic_cmpxchg(&prdev->state, state, PAGE_REPORTING_IDLE); if (state =3D=3D PAGE_REPORTING_REQUESTED) - schedule_delayed_work(&prdev->work, PAGE_REPORTING_DELAY); + schedule_delayed_work(&prdev->work, msecs_to_jiffies(page_reporting_dela= y)); } =20 static DEFINE_MUTEX(page_reporting_mutex); @@ -415,3 +445,10 @@ void page_reporting_unregister(struct page_reporting_d= ev_info *prdev) mutex_unlock(&page_reporting_mutex); } EXPORT_SYMBOL_GPL(page_reporting_unregister); + +static int __init page_reporting_sysctl_init(void) +{ + register_sysctl_init("vm", page_reporting_sysctls); + return 0; +} +late_initcall(page_reporting_sysctl_init); --=20 2.55.0.141.g00534a21ce-goog