From: Muchun Song <songmuchun@bytedance.com>
To: gregkh@linuxfoundation.org, rafael@kernel.org,
adobriyan@gmail.com, akpm@linux-foundation.org,
hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com,
hughd@google.com, will@kernel.org, guro@fb.com, rppt@kernel.org,
tglx@linutronix.de, esyr@redhat.com, peterx@redhat.com,
krisman@collabora.com, surenb@google.com, avagin@openvz.org,
elver@google.com, rdunlap@infradead.org, iamjoonsoo.kim@lge.com
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-mm@kvack.org, cgroups@vger.kernel.org,
Muchun Song <songmuchun@bytedance.com>
Subject: [RESEND PATCH v2 10/12] mm: memcontrol: scale stat_threshold for byted-sized vmstat
Date: Sun, 6 Dec 2020 18:14:49 +0800 [thread overview]
Message-ID: <20201206101451.14706-11-songmuchun@bytedance.com> (raw)
In-Reply-To: <20201206101451.14706-1-songmuchun@bytedance.com>
Some vmstat counters are being accounted in bytes not pages, so the
stat_threshold should also scale to bytes.
The vmstat counters are already long type for memcg (can reference
to struct lruvec_stat). For the global per-node vmstat counters
also can scale to long. But the maximum vmstat threshold is 125,
so the type of s32 is enough.
Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
include/linux/mmzone.h | 17 ++++++-----------
include/linux/vmstat.h | 1 -
mm/vmstat.c | 24 +++++++++++++-----------
3 files changed, 19 insertions(+), 23 deletions(-)
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 1f9c83778629..d53328551225 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -216,17 +216,12 @@ enum node_stat_item {
*/
static __always_inline bool vmstat_item_in_bytes(int idx)
{
- /*
- * Global and per-node slab counters track slab pages.
- * It's expected that changes are multiples of PAGE_SIZE.
- * Internally values are stored in pages.
- *
- * Per-memcg and per-lruvec counters track memory, consumed
- * by individual slab objects. These counters are actually
- * byte-precise.
- */
return (idx == NR_SLAB_RECLAIMABLE_B ||
- idx == NR_SLAB_UNRECLAIMABLE_B);
+ idx == NR_SLAB_UNRECLAIMABLE_B ||
+#if IS_ENABLED(CONFIG_SHADOW_CALL_STACK)
+ idx == NR_KERNEL_SCS_B ||
+#endif
+ idx == NR_KERNEL_STACK_B);
}
/*
@@ -340,7 +335,7 @@ struct per_cpu_pageset {
struct per_cpu_nodestat {
s8 stat_threshold;
- s8 vm_node_stat_diff[NR_VM_NODE_STAT_ITEMS];
+ s32 vm_node_stat_diff[NR_VM_NODE_STAT_ITEMS];
};
#endif /* !__GENERATING_BOUNDS.H */
diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
index fd1a3d5d4926..afd84dc2398c 100644
--- a/include/linux/vmstat.h
+++ b/include/linux/vmstat.h
@@ -211,7 +211,6 @@ static inline unsigned long global_node_page_state(enum node_stat_item item)
{
long x = atomic_long_read(&vm_node_stat[item]);
- VM_WARN_ON_ONCE(vmstat_item_in_bytes(item));
#ifdef CONFIG_SMP
if (x < 0)
x = 0;
diff --git a/mm/vmstat.c b/mm/vmstat.c
index 7fb0c7cb9516..25751b1d8e2e 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -341,13 +341,15 @@ void __mod_node_page_state(struct pglist_data *pgdat, enum node_stat_item item,
long delta)
{
struct per_cpu_nodestat __percpu *pcp = pgdat->per_cpu_nodestats;
- s8 __percpu *p = pcp->vm_node_stat_diff + item;
+ s32 __percpu *p = pcp->vm_node_stat_diff + item;
long x;
long t;
x = delta + __this_cpu_read(*p);
t = __this_cpu_read(pcp->stat_threshold);
+ if (vmstat_item_in_bytes(item))
+ t <<= PAGE_SHIFT;
if (unlikely(abs(x) > t)) {
node_page_state_add(x, pgdat, item);
@@ -399,15 +401,15 @@ void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
void __inc_node_state(struct pglist_data *pgdat, enum node_stat_item item)
{
struct per_cpu_nodestat __percpu *pcp = pgdat->per_cpu_nodestats;
- s8 __percpu *p = pcp->vm_node_stat_diff + item;
- s8 v, t;
+ s32 __percpu *p = pcp->vm_node_stat_diff + item;
+ s32 v, t;
VM_WARN_ON_ONCE(vmstat_item_in_bytes(item));
v = __this_cpu_inc_return(*p);
t = __this_cpu_read(pcp->stat_threshold);
if (unlikely(v > t)) {
- s8 overstep = t >> 1;
+ s32 overstep = t >> 1;
node_page_state_add(v + overstep, pgdat, item);
__this_cpu_write(*p, -overstep);
@@ -445,8 +447,8 @@ void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
void __dec_node_state(struct pglist_data *pgdat, enum node_stat_item item)
{
struct per_cpu_nodestat __percpu *pcp = pgdat->per_cpu_nodestats;
- s8 __percpu *p = pcp->vm_node_stat_diff + item;
- s8 v, t;
+ s32 __percpu *p = pcp->vm_node_stat_diff + item;
+ s32 v, t;
VM_WARN_ON_ONCE(vmstat_item_in_bytes(item));
@@ -546,7 +548,7 @@ static inline void mod_node_state(struct pglist_data *pgdat,
enum node_stat_item item, int delta, int overstep_mode)
{
struct per_cpu_nodestat __percpu *pcp = pgdat->per_cpu_nodestats;
- s8 __percpu *p = pcp->vm_node_stat_diff + item;
+ s32 __percpu *p = pcp->vm_node_stat_diff + item;
long o, n, t, z;
do {
@@ -563,6 +565,8 @@ static inline void mod_node_state(struct pglist_data *pgdat,
* for all cpus in a node.
*/
t = this_cpu_read(pcp->stat_threshold);
+ if (vmstat_item_in_bytes(item))
+ t <<= PAGE_SHIFT;
o = this_cpu_read(*p);
n = delta + o;
@@ -829,7 +833,7 @@ static int refresh_cpu_vm_stats(bool do_pagesets)
struct per_cpu_nodestat __percpu *p = pgdat->per_cpu_nodestats;
for (i = 0; i < NR_VM_NODE_STAT_ITEMS; i++) {
- int v;
+ s32 v;
v = this_cpu_xchg(p->vm_node_stat_diff[i], 0);
if (v) {
@@ -899,7 +903,7 @@ void cpu_vm_stats_fold(int cpu)
for (i = 0; i < NR_VM_NODE_STAT_ITEMS; i++)
if (p->vm_node_stat_diff[i]) {
- int v;
+ s32 v;
v = p->vm_node_stat_diff[i];
p->vm_node_stat_diff[i] = 0;
@@ -1017,8 +1021,6 @@ unsigned long node_page_state(struct pglist_data *pgdat,
{
long x = atomic_long_read(&pgdat->vm_stat[item]);
- VM_WARN_ON_ONCE(vmstat_item_in_bytes(item));
-
#ifdef CONFIG_SMP
if (x < 0)
x = 0;
--
2.11.0
next prev parent reply other threads:[~2020-12-06 10:19 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-06 10:14 [RESEND PATCH v2 00/12] Convert all vmstat counters to pages or bytes Muchun Song
2020-12-06 10:14 ` [RESEND PATCH v2 01/12] mm: memcontrol: fix NR_ANON_THPS account Muchun Song
2020-12-07 12:52 ` Michal Hocko
2020-12-10 16:00 ` Johannes Weiner
2020-12-10 16:02 ` Johannes Weiner
2020-12-10 16:04 ` Johannes Weiner
2020-12-10 16:56 ` [External] " Muchun Song
2020-12-06 10:14 ` [RESEND PATCH v2 02/12] mm: memcontrol: convert NR_ANON_THPS account to pages Muchun Song
2020-12-10 16:10 ` Johannes Weiner
2020-12-10 17:05 ` [External] " Muchun Song
2020-12-06 10:14 ` [RESEND PATCH v2 03/12] mm: memcontrol: convert NR_FILE_THPS " Muchun Song
2020-12-06 10:14 ` [RESEND PATCH v2 04/12] mm: memcontrol: convert NR_SHMEM_THPS " Muchun Song
2020-12-06 10:14 ` [RESEND PATCH v2 05/12] mm: memcontrol: convert NR_SHMEM_PMDMAPPED " Muchun Song
2020-12-06 10:14 ` [RESEND PATCH v2 06/12] mm: memcontrol: convert NR_FILE_PMDMAPPED " Muchun Song
2020-12-06 10:14 ` [RESEND PATCH v2 07/12] mm: memcontrol: convert kernel stack account to bytes Muchun Song
2020-12-06 10:14 ` [RESEND PATCH v2 08/12] mm: memcontrol: convert NR_KERNEL_SCS_KB " Muchun Song
2020-12-06 10:14 ` [RESEND PATCH v2 09/12] mm: memcontrol: convert vmstat slab counters " Muchun Song
2020-12-07 19:46 ` Roman Gushchin
2020-12-07 20:01 ` Roman Gushchin
2020-12-08 2:44 ` [External] " Muchun Song
2020-12-06 10:14 ` Muchun Song [this message]
2020-12-06 10:14 ` [RESEND PATCH v2 11/12] mm: memcontrol: make the slab calculation consistent Muchun Song
2020-12-06 10:14 ` [RESEND PATCH v2 12/12] mm: memcontrol: remove {global_}node_page_state_pages Muchun Song
2020-12-07 13:00 ` [RESEND PATCH v2 00/12] Convert all vmstat counters to pages or bytes Michal Hocko
2020-12-07 14:52 ` [External] " Muchun Song
2020-12-07 15:02 ` Michal Hocko
2020-12-07 18:51 ` Randy Dunlap
2020-12-08 2:29 ` Muchun Song
2020-12-07 19:51 ` Roman Gushchin
2020-12-07 20:33 ` Hugh Dickins
2020-12-08 2:42 ` Muchun Song
2020-12-08 2:40 ` Muchun Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201206101451.14706-11-songmuchun@bytedance.com \
--to=songmuchun@bytedance.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=avagin@openvz.org \
--cc=cgroups@vger.kernel.org \
--cc=elver@google.com \
--cc=esyr@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=guro@fb.com \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=krisman@collabora.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=peterx@redhat.com \
--cc=rafael@kernel.org \
--cc=rdunlap@infradead.org \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=tglx@linutronix.de \
--cc=vdavydov.dev@gmail.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).