Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1326163lqj; Mon, 3 Jun 2024 19:06:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVtYiGIcdiJmKhWhBRlsLLbAFL3G4YLaP4GHbLq+JhXybw2h7oo+XnXhZUook+O/b+Ef2tLTYYihtv9hciLRl9H5O6kOL4+iIRb38YcZw== X-Google-Smtp-Source: AGHT+IHmcu+lFlMYbRojjrv7p3RhEjsfU54XHH+Mnjad2NmsuHrjVfqi5kYLYP8ZqXXHg5BWdZ3/ X-Received: by 2002:a17:906:5910:b0:a68:c6c1:cd61 with SMTP id a640c23a62f3a-a695441f829mr90350866b.29.1717466817923; Mon, 03 Jun 2024 19:06:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717466817; cv=pass; d=google.com; s=arc-20160816; b=yfFQbW32x03144khUTDJpndSJeqW+WFWXEr6l5ypzdMrAhMK9+gdn49UTfmXFaeHTP 67cWyYGDL3PibZM0Zyt4irMVgaOJSJqnopglUuyp4HMbroL1Dv8majAPawdN255AyBPy sa1BRzZUzv2aLEht4Ve+wx3Ho6AEhj15Jml5m3PF2oW5TLHRRpr71Yoej9oj08rmeuFG wxeJL4KBLoemX35Y0pKxbNGLZPiClYBmg9xabtTKGLlMF3C7Yy4XWM0SeJBHGJfcs/Gq cYjvITDt2re+MwvCWh+2mo2OhrrEZIhIWEusMnSUZNI+0rAmUVcZ2BdqmIhhBBpDqc9a 3k4Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=lTOg/v4agW4t4UIoB+YneZrty+w+zSP5tjy7abHeLhs=; fh=dXxiv9yq4bZtI/kGwmnnUQdfkg5pEKlsIGtaaoPXC8I=; b=MuP9MkEQ9j6dcxV/Tad4uuHSe+T3GOhPaf1b7P37zQqMIwdqM7FNZ3hkUJzK1LGVYI kTfX3hySQUsXujvWg2zYAW4mTyKyhvixWO+EE10jbsuuGNXIg/n2nGrLxB3M9AA3wY4d HnQTSLEm1QW2/97dHl7vGqqFNASuUKtp3RLWvpPGaiiQdUnWaThcNQ8Lt6GLB6HUQ/nI ZXMPp705drT4OOBuhgzxte8dTCcvIeXZzPzEoUUTjuKI2f4+VlQeF2nFPiOZC+kvFbxi 0waL9INbmQUIXl6T5Am1BlVwDRlA6vbRLB7PZYeXjFwUCLm5Lj9ENgNSO/BUCEi3BLy/ VxNw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jCspLKne; arc=pass (i=1 spf=pass spfdomain=flex--yuanchu.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-199951-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199951-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a67e73fb470si428013466b.248.2024.06.03.19.06.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 19:06:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199951-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jCspLKne; arc=pass (i=1 spf=pass spfdomain=flex--yuanchu.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-199951-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199951-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 72B811F25D66 for ; Tue, 4 Jun 2024 02:06:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EC51813D2BA; Tue, 4 Jun 2024 02:06:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jCspLKne" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.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 3502613D89C for ; Tue, 4 Jun 2024 02:06:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717466774; cv=none; b=eL1q1v3z615DmG2CqxDZdRKLgi8f6kbWcg9Dc0xV0vqbbYshjQ/m+sbDKioqLLCMECh/BnlCYChdnRgfclXkGOFviZu/XQJPV95syyWKmiYoPev/dD2MvwwtFBss8gfC/NsECadGvyIZCGh56o2a27MM1Opl1fxaThT8grR8/V8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717466774; c=relaxed/simple; bh=fth2mh5hLwZQ+6IzfCTKsQwbyjH8dDmVn+u6o0NiQiY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Xz9Jvz7IBDSJzH6jExNCVMhCuvHorIpgXfKU0Qef366EmwR58mQPkulL3D8VR8Bo36hZ3Eqnue5gJNl0x8eMrVWipJIS1tbdv5pEOIZzCSqIi8ljm8HOdj6UVmHrGBy/qFotZt/IEQcoXKiHCtttz1ZhH/m1VsT9/Iql/rGPAB8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--yuanchu.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=jCspLKne; arc=none smtp.client-ip=209.85.219.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--yuanchu.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-df78efda253so8012825276.1 for ; Mon, 03 Jun 2024 19:06:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717466772; x=1718071572; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=lTOg/v4agW4t4UIoB+YneZrty+w+zSP5tjy7abHeLhs=; b=jCspLKneDnH+idREYlO67FAi3+wE4vd8Jfq2IhxHwrPsqIS32F9zj/RbRdHvwxamwT Mi0CeLnfWoCrqrNWlvZ1FbotXhb8JVwsArJ8ypAibCmOC5pW6IAR6AwmqFOJkO6bQ7je QTSUVAHjetrJ+VzR1ybIQTlNfwQkGJnyWhP0e6sGn73CdoYv4yJD3UfhMgF82ShVD6DR HmsU+sThhR+ZPtpGy1+xF32KBn2TngHFbOZ11kS0hXI2rceqwfGd9+nmRmsBzQZakpGo gJCEnfQHa599ZqwogsTdStYQC7JCgtYvss9EwytDm1RDcPEaPNJp7qEHvR9uGCYbsNm/ aGjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717466772; x=1718071572; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lTOg/v4agW4t4UIoB+YneZrty+w+zSP5tjy7abHeLhs=; b=FKWt42B4HAb/a2swj6ZkFjfMGCrLzyisoap4XfOFzd599s1eSJanoJ7QqRI9hZPiR/ /aPJKDW/NAryu9IjcjPfj+06iR4Axjo+8MidVckJTOhr38C9grW0plNKYAofuNdZ9WAv NE68XfPq7TzQIeSjUH7l/GMUbUHbH56Nu+WhzOld32QUZkhS/DPwGW5UCe948Od/zrM0 j9GeIrVz2LG1R9aBk8wwOb3jSfILqkHCGtCFtv+y33sj9t1kut3xpwgofNvW4P/m6J0Z rjcW7jw32+qh5SIO4IkUPy4v/F1me4qHN1VZjGaHB+RnnimkiAoegXgZ77zUKR1lcnPj Pc6A== X-Forwarded-Encrypted: i=1; AJvYcCVqEN4jBcKLnm0cDr4v+uT7sefFbKHmzOx/87uSMeGKzbE0No5x/LEoLIi58zL1QQPYY5zVnetPN8u08/Yl36oo/AibidsM/HYACro6 X-Gm-Message-State: AOJu0YyOkY9FI/ILvFEQgDOztTSOGZGGbjJYS+EnKZXAr/zyagQoIhhd NlDHrWNY+J816WKTSruxBSLU5e2mx+dXW5X6xtsCR3dFNB4omGuI3XE5oFHGQ959vuczPpFj601 mh/gryg== X-Received: from yuanchu-desktop.svl.corp.google.com ([2620:15c:2a3:200:367f:7387:3dd2:73f1]) (user=yuanchu job=sendgmr) by 2002:a05:6902:2d42:b0:df7:83fa:2736 with SMTP id 3f1490d57ef6-dfa73dbc831mr913449276.11.1717466772327; Mon, 03 Jun 2024 19:06:12 -0700 (PDT) Date: Mon, 3 Jun 2024 19:05:44 -0700 In-Reply-To: <20240604020549.1017540-1-yuanchu@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240604020549.1017540-1-yuanchu@google.com> X-Mailer: git-send-email 2.45.1.467.gbab1589fc0-goog Message-ID: <20240604020549.1017540-4-yuanchu@google.com> Subject: [PATCH v2 3/8] mm: use refresh interval to rate-limit workingset report aggregation From: Yuanchu Xie To: David Hildenbrand , "Aneesh Kumar K.V" , Khalid Aziz , Henry Huang , Yu Zhao , Dan Williams , Gregory Price , Huang Ying , Muhammad Usama Anjum Cc: Kalesh Singh , Wei Xu , David Rientjes , Greg Kroah-Hartman , "Rafael J. Wysocki" , Andrew Morton , Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , Shuah Khan , Yosry Ahmed , Matthew Wilcox , Sudarshan Rajagopalan , Kairui Song , "Michael S. Tsirkin" , Vasily Averin , Nhat Pham , Miaohe Lin , Qi Zheng , Abel Wu , "Vishal Moola (Oracle)" , Kefeng Wang , Yuanchu Xie , linux-kernel@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org Content-Type: text/plain; charset="UTF-8" The refresh interval is a rate limiting factor to workingset page age histogram reads. When a workingset report is generated, a timestamp is noted, and the same report will be read until it expires beyond the refresh interval, at which point a new report is generated. Sysfs interface /sys/devices/system/node/nodeX/workingset_report/refresh_interval time in milliseconds specifying how long the report is valid for Signed-off-by: Yuanchu Xie --- include/linux/workingset_report.h | 1 + mm/workingset_report.c | 84 +++++++++++++++++++++++++------ 2 files changed, 70 insertions(+), 15 deletions(-) diff --git a/include/linux/workingset_report.h b/include/linux/workingset_report.h index d7c2ee14ec87..8bae6a600410 100644 --- a/include/linux/workingset_report.h +++ b/include/linux/workingset_report.h @@ -37,6 +37,7 @@ struct wsr_page_age_histo { }; struct wsr_state { + unsigned long refresh_interval; /* breakdown of workingset by page age */ struct mutex page_age_lock; struct wsr_page_age_histo *page_age; diff --git a/mm/workingset_report.c b/mm/workingset_report.c index a4dcf62fcd96..fe553c0a653e 100644 --- a/mm/workingset_report.c +++ b/mm/workingset_report.c @@ -195,7 +195,8 @@ static void collect_page_age(struct wsr_page_age_histo *page_age, /* First step: hierarchically scan child memcgs. */ static void refresh_scan(struct wsr_state *wsr, struct mem_cgroup *root, - struct pglist_data *pgdat) + struct pglist_data *pgdat, + unsigned long refresh_interval) { struct mem_cgroup *memcg; unsigned int flags; @@ -208,12 +209,15 @@ static void refresh_scan(struct wsr_state *wsr, struct mem_cgroup *root, do { struct lruvec *lruvec = mem_cgroup_lruvec(memcg, pgdat); unsigned long max_seq = READ_ONCE((lruvec)->lrugen.max_seq); + int gen = lru_gen_from_seq(max_seq); + unsigned long birth = READ_ONCE(lruvec->lrugen.timestamps[gen]); /* * setting can_swap=true and force_scan=true ensures * proper workingset stats when the system cannot swap. */ - try_to_inc_max_seq(lruvec, max_seq, true, true); + if (time_is_before_jiffies(birth + refresh_interval)) + try_to_inc_max_seq(lruvec, max_seq, true, true); cond_resched(); } while ((memcg = mem_cgroup_iter(root, memcg, NULL))); @@ -270,17 +274,25 @@ bool wsr_refresh_report(struct wsr_state *wsr, struct mem_cgroup *root, struct pglist_data *pgdat) { struct wsr_page_age_histo *page_age; + unsigned long refresh_interval = READ_ONCE(wsr->refresh_interval); if (!READ_ONCE(wsr->page_age)) return false; - refresh_scan(wsr, root, pgdat); + if (!refresh_interval) + return false; + mutex_lock(&wsr->page_age_lock); page_age = READ_ONCE(wsr->page_age); - if (page_age) { - copy_node_bins(pgdat, page_age); - refresh_aggregate(page_age, root, pgdat); - } + if (!page_age) + goto unlock; + if (page_age->timestamp && + time_is_after_jiffies(page_age->timestamp + refresh_interval)) + goto unlock; + refresh_scan(wsr, root, pgdat, refresh_interval); + copy_node_bins(pgdat, page_age); + refresh_aggregate(page_age, root, pgdat); +unlock: mutex_unlock(&wsr->page_age_lock); return !!page_age; } @@ -299,6 +311,52 @@ static struct wsr_state *kobj_to_wsr(struct kobject *kobj) return &mem_cgroup_lruvec(NULL, kobj_to_pgdat(kobj))->wsr; } +static ssize_t refresh_interval_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct wsr_state *wsr = kobj_to_wsr(kobj); + unsigned int interval = READ_ONCE(wsr->refresh_interval); + + return sysfs_emit(buf, "%u\n", jiffies_to_msecs(interval)); +} + +static ssize_t refresh_interval_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t len) +{ + unsigned int interval; + int err; + struct wsr_state *wsr = kobj_to_wsr(kobj); + + err = kstrtouint(buf, 0, &interval); + if (err) + return err; + + mutex_lock(&wsr->page_age_lock); + if (interval && !wsr->page_age) { + struct wsr_page_age_histo *page_age = + kzalloc(sizeof(struct wsr_page_age_histo), GFP_KERNEL); + + if (!page_age) { + err = -ENOMEM; + goto unlock; + } + wsr->page_age = page_age; + } + if (!interval && wsr->page_age) { + kfree(wsr->page_age); + wsr->page_age = NULL; + } + + WRITE_ONCE(wsr->refresh_interval, msecs_to_jiffies(interval)); +unlock: + mutex_unlock(&wsr->page_age_lock); + return err ?: len; +} + +static struct kobj_attribute refresh_interval_attr = + __ATTR_RW(refresh_interval); + static ssize_t page_age_intervals_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { @@ -382,13 +440,6 @@ static ssize_t page_age_show(struct kobject *kobj, struct kobj_attribute *attr, int ret = 0; struct wsr_state *wsr = kobj_to_wsr(kobj); - - mutex_lock(&wsr->page_age_lock); - if (!wsr->page_age) - wsr->page_age = - kzalloc(sizeof(struct wsr_page_age_histo), GFP_KERNEL); - mutex_unlock(&wsr->page_age_lock); - wsr_refresh_report(wsr, NULL, kobj_to_pgdat(kobj)); mutex_lock(&wsr->page_age_lock); @@ -414,7 +465,10 @@ static ssize_t page_age_show(struct kobject *kobj, struct kobj_attribute *attr, static struct kobj_attribute page_age_attr = __ATTR_RO(page_age); static struct attribute *workingset_report_attrs[] = { - &page_age_intervals_attr.attr, &page_age_attr.attr, NULL + &refresh_interval_attr.attr, + &page_age_intervals_attr.attr, + &page_age_attr.attr, + NULL }; static const struct attribute_group workingset_report_attr_group = { -- 2.45.1.467.gbab1589fc0-goog