From: yongw.pur@gmail.com
To: tj@kernel.org, mhocko@suse.com, mhocko@kernel.org,
peterz@infradead.org, wang.yong12@zte.com.cn,
cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, yang.yang29@zte.com.cn
Subject: [PATCH v1] vmpressure: wake up work only when there is registration event
Date: Mon, 13 Sep 2021 08:54:01 -0700 [thread overview]
Message-ID: <1631548441-2784-1-git-send-email-wang.yong12@zte.com.cn> (raw)
From: wangyong <wang.yong12@zte.com.cn>
Use the global variable num_events to record the number of vmpressure
events registered by the system, and wake up work only when there is
registration event.
Usually, the vmpressure event is not registered in the system, this patch
can avoid waking up work and doing nothing.
Refer to Michal Hocko's suggestion:
https://lore.kernel.org/linux-mm/YR%2FNRJEhPKRQ1r22@dhcp22.suse.cz/
Tested-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: wangyong <wang.yong12@zte.com.cn>
---
mm/vmpressure.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/mm/vmpressure.c b/mm/vmpressure.c
index 76518e4..dfac76b 100644
--- a/mm/vmpressure.c
+++ b/mm/vmpressure.c
@@ -67,6 +67,11 @@ static const unsigned int vmpressure_level_critical = 95;
*/
static const unsigned int vmpressure_level_critical_prio = ilog2(100 / 10);
+/*
+ * Count the number of vmpressure events registered in the system.
+ */
+static atomic_t num_events = ATOMIC_INIT(0);
+
static struct vmpressure *work_to_vmpressure(struct work_struct *work)
{
return container_of(work, struct vmpressure, work);
@@ -277,7 +282,7 @@ void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, bool tree,
vmpr->tree_reclaimed += reclaimed;
spin_unlock(&vmpr->sr_lock);
- if (scanned < vmpressure_win)
+ if (scanned < vmpressure_win || atomic_read(&num_events) == 0)
return;
schedule_work(&vmpr->work);
} else {
@@ -407,6 +412,7 @@ int vmpressure_register_event(struct mem_cgroup *memcg,
mutex_lock(&vmpr->events_lock);
list_add(&ev->node, &vmpr->events);
mutex_unlock(&vmpr->events_lock);
+ atomic_add(1, &num_events);
ret = 0;
out:
kfree(spec_orig);
@@ -435,6 +441,7 @@ void vmpressure_unregister_event(struct mem_cgroup *memcg,
if (ev->efd != eventfd)
continue;
list_del(&ev->node);
+ atomic_sub(1, &num_events);
kfree(ev);
break;
}
--
2.7.4
next reply other threads:[~2021-09-13 15:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-13 15:54 yongw.pur [this message]
2021-09-13 16:03 ` Michal Hocko
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=1631548441-2784-1-git-send-email-wang.yong12@zte.com.cn \
--to=yongw.pur@gmail.com \
--cc=cgroups@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=mhocko@suse.com \
--cc=peterz@infradead.org \
--cc=tj@kernel.org \
--cc=wang.yong12@zte.com.cn \
--cc=yang.yang29@zte.com.cn \
/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