mm/memcg: bail out early when !memcg in mem_cgroup_lruvec
PATCH 1/1 mm/memcg: bail out early when !memcg in mem_cgroup_lruvec
Sometime, we use NULL memcg in mem_cgroup_lruvec(memcg, pgdat) so we could get out early in the situation to avoid useless checking.
Also warning if both parameter are NULL.
--- include/linux/memcontrol.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
include/linux/memcontrol.h +3 -4
@@ -613,14 +613,13 @@ static inline struct lruvec *mem_cgroup_lruvec(struct mem_cgroup *memcg,struct mem_cgroup_per_node *mz;struct lruvec *lruvec; -if (mem_cgroup_disabled ()) { +VM_WARN_ON_ONCE (!memcg && !pgdat); + +if (mem_cgroup_disabled () || !memcg) { lruvec = &pgdat->__lruvec; goto out; } -if (!memcg) - memcg = root_mem_cgroup; - mz =mem_cgroup_nodeinfo (memcg, pgdat->node_id); lruvec = &mz->lruvec; out:
Signature · 1 line
2.29.GIT
Quoted 4 lines · On Fri, 27 Nov 2020 11:08:35 +0800 Alex Shi <[email protected]> wrote:
Sometime, we use NULL memcg in
mem_cgroup_lruvec(memcg, pgdat)so we could get out early in the situation to avoid useless checking.Also warning if both parameter are NULL.
Why do you think a warning is needed here?
Quoted 7 lines
include/linux/memcontrol.h +0
-1@@ -613,14 +613,13 @@ static inline struct lruvec *mem_cgroup_lruvec(struct mem_cgroup *memcg,struct mem_cgroup_per_node *mz;struct lruvec *lruvec; -if (mem_cgroup_disabled ()) {
include/linux/memcontrol.h static inline struct lruvec *mem_cgroup_lruvec(struct mem_cgroup *memcg, · line 623
Quoted 10 lines
include/linux/memcontrol.h +3
-3+VM_WARN_ON_ONCE (!memcg && !pgdat); + +if (mem_cgroup_disabled () || !memcg) { lruvec = &pgdat->__lruvec; goto out; } -if (!memcg) - memcg = root_mem_cgroup; -
This change isn't obviously equivalent, is it?
include/linux/memcontrol.h static inline struct lruvec *mem_cgroup_lruvec(struct mem_cgroup *memcg, · line 625
Quoted 3 lines
include/linux/memcontrol.h +0
-0mz =mem_cgroup_nodeinfo (memcg, pgdat->node_id); lruvec = &mz->lruvec; out:
And the resulting code is awkward:
if (mem_cgroup_disabled() || !memcg) {
lruvec = &pgdat->__lruvec;
goto out;
}
mz = mem_cgroup_nodeinfo(memcg, pgdat->node_id);
lruvec = &mz->lruvec;out:
could be
if (mem_cgroup_disabled() || !memcg) {
lruvec = &pgdat->__lruvec;
} else {
mem_cgroup_per_node mz;
mz = mem_cgroup_nodeinfo(memcg, pgdat->node_id);
lruvec = &mz->lruvec;
}Quoted 8 lines · Andrew Morton
Quoted 4 lines · On Fri, 27 Nov 2020 11:08:35 +0800 Alex Shi <[email protected]> wrote:
Sometime, we use NULL memcg in
mem_cgroup_lruvec(memcg, pgdat)so we could get out early in the situation to avoid useless checking.Also warning if both parameter are NULL.
Why do you think a warning is needed here?
Uh, Consider there are no problem for long time, it could be saved.
Quoted 15 lines
Quoted 15 lines
include/linux/memcontrol.h +3
-1@@ -613,14 +613,13 @@ static inline struct lruvec *mem_cgroup_lruvec(struct mem_cgroup *memcg,struct mem_cgroup_per_node *mz;struct lruvec *lruvec; -if (mem_cgroup_disabled ()) { +VM_WARN_ON_ONCE (!memcg && !pgdat); + +if (mem_cgroup_disabled () || !memcg) { lruvec = &pgdat->__lruvec; goto out; }
Quoted 5 lines
include/linux/memcontrol.h static inline struct lruvec *mem_cgroup_lruvec(struct mem_cgroup *memcg, · line 623
Quoted 3 lines
include/linux/memcontrol.h +0
-3-if (!memcg) - memcg = root_mem_cgroup; -This change isn't obviously equivalent, is it?
If !memcg, the root_mem_cgroup will still lead the lruvec to a pgdat same as parameter.
Quoted 19 lines
include/linux/memcontrol.h static inline struct lruvec *mem_cgroup_lruvec(struct mem_cgroup *memcg, · line 625
Quoted 4 lines
include/linux/memcontrol.h +0
-0mz =mem_cgroup_nodeinfo (memcg, pgdat->node_id); lruvec = &mz->lruvec; out:And the resulting code is awkward:
if (mem_cgroup_disabled() || !memcg) { lruvec = &pgdat->__lruvec; goto out; } mz = mem_cgroup_nodeinfo(memcg, pgdat->node_id); lruvec = &mz->lruvec;out:
could be
Quoted 9 lines
if (mem_cgroup_disabled() || !memcg) {
lruvec = &pgdat->__lruvec;
} else {
mem_cgroup_per_node mz;
mz = mem_cgroup_nodeinfo(memcg, pgdat->node_id);
lruvec = &mz->lruvec;
}Right. remove 'goto' is better for understander.
So, is the following patch ok?
From 225f29e03b40a7cbaeb4e3bb76f8efbcd7d648a2 Mon Sep 17 00:00:00 2001
From: Alex Shi <[email protected]>
Date: Wed, 25 Nov 2020 14:06:33 +0800
Subject: [PATCH v2] mm/memcg: bail out early when !memcg in mem_cgroup_lruvec
Sometime, we use NULL memcg in mem_cgroup_lruvec(memcg, pgdat) so we could get out early in the situation to avoid useless checking.
Polished as Andrew Morton's suggestion.
--- include/linux/memcontrol.h | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
include/linux/memcontrol.h +6 -9
@@ -610,20 +610,17 @@ mem_cgroup_nodeinfo(struct mem_cgroup *memcg, int nid)static inline struct lruvec *mem_cgroup_lruvec (struct mem_cgroup *memcg,struct pglist_data *pgdat) { -struct mem_cgroup_per_node *mz;struct lruvec *lruvec; -if (mem_cgroup_disabled ()) { +if (mem_cgroup_disabled () || !memcg) { lruvec = &pgdat->__lruvec; - goto out; - } + }else { +struct mem_cgroup_per_node *mz; -if (!memcg) - memcg = root_mem_cgroup; + mz =mem_cgroup_nodeinfo (memcg, pgdat->node_id); + lruvec = &mz->lruvec; + } - mz =mem_cgroup_nodeinfo (memcg, pgdat->node_id); - lruvec = &mz->lruvec; -out:/* * Since a node can be onlined after the mem_cgroup was created, * we have to be prepared to initialize lruvec->pgdat here;
Signature · 1 line
2.29.GIT
29.11.2020 07:43, Alex Shi пишет:
Quoted 118 lines · Andrew Morton
Quoted 8 lines · On Fri, 27 Nov 2020 11:08:35 +0800 Alex Shi <[email protected]> wrote:
Quoted 5 lines
Sometime, we use NULL memcg in
mem_cgroup_lruvec(memcg, pgdat)so we could get out early in the situation to avoid useless checking.Also warning if both parameter are NULL.
Why do you think a warning is needed here?
Uh, Consider there are no problem for long time, it could be saved.
Quoted 15 lines
Quoted 15 lines
include/linux/memcontrol.h +3
-1@@ -613,14 +613,13 @@ static inline struct lruvec *mem_cgroup_lruvec(struct mem_cgroup *memcg,struct mem_cgroup_per_node *mz;struct lruvec *lruvec; -if (mem_cgroup_disabled ()) { +VM_WARN_ON_ONCE (!memcg && !pgdat); + +if (mem_cgroup_disabled () || !memcg) { lruvec = &pgdat->__lruvec; goto out; }Quoted 5 lines
include/linux/memcontrol.h mem_cgroup_nodeinfo(struct mem_cgroup *memcg, int nid)
Quoted 3 lines
include/linux/memcontrol.h +0
-3-if (!memcg) - memcg = root_mem_cgroup; -This change isn't obviously equivalent, is it?
If !memcg, the
root_mem_cgroupwill still lead the lruvec to a pgdat same as parameter.Quoted 19 lines
include/linux/memcontrol.h static inline struct lruvec *mem_cgroup_lruvec(struct mem_cgroup *memcg, · line 625
Quoted 4 lines
include/linux/memcontrol.h +0
-0mz =mem_cgroup_nodeinfo (memcg, pgdat->node_id); lruvec = &mz->lruvec; out:And the resulting code is awkward:
if (mem_cgroup_disabled() || !memcg) { lruvec = &pgdat->__lruvec; goto out; } mz = mem_cgroup_nodeinfo(memcg, pgdat->node_id); lruvec = &mz->lruvec;out:
could be
Quoted 9 lines
if (mem_cgroup_disabled() || !memcg) { lruvec = &pgdat->__lruvec; } else { mem_cgroup_per_node mz; mz = mem_cgroup_nodeinfo(memcg, pgdat->node_id); lruvec = &mz->lruvec; }Right. remove 'goto' is better for understander.
So, is the following patch ok?
From
225f29e03b40a7cbaeb4e3bb76f8efbcd7d648a2Mon Sep 17 00:00:00 2001
From: Alex Shi <[email protected]>
Date: Wed, 25 Nov 2020 14:06:33 +0800
Subject: [PATCH v2] mm/memcg: bail out early when !memcg inmem_cgroup_lruvecSometime, we use NULL memcg in
mem_cgroup_lruvec(memcg, pgdat)so we could get out early in the situation to avoid useless checking.Polished as Andrew Morton's suggestion.
Signed-off-by Alex Shi <[email protected]>Cc Andrew Morton <[email protected]>Cc Johannes Weiner <[email protected]>Cc Shakeel Butt <[email protected]>Cc Roman Gushchin <[email protected]>Cc Lorenzo Stoakes <[email protected]>Cc Stephen Rothwell <[email protected]>Cc Alexander Duyck <[email protected]>Cc Yafang Shao <[email protected]>Cc Wei Yang <[email protected]>--- include/linux/memcontrol.h | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)include/linux/memcontrol.h +3
-6@@ -610,20 +610,17 @@ mem_cgroup_nodeinfo(struct mem_cgroup *memcg, int nid)static inline struct lruvec *mem_cgroup_lruvec (struct mem_cgroup *memcg,struct pglist_data *pgdat) { -struct mem_cgroup_per_node *mz;struct lruvec *lruvec; -if (mem_cgroup_disabled ()) { +if (mem_cgroup_disabled () || !memcg) { lruvec = &pgdat->__lruvec; - goto out; - } + }else { +struct mem_cgroup_per_node *mz; -if (!memcg) - memcg = root_mem_cgroup;
include/linux/memcontrol.h mem_cgroup_nodeinfo(struct mem_cgroup *memcg, int nid) · line 626
Quoted 10 lines
include/linux/memcontrol.h +3
-3+ mz =mem_cgroup_nodeinfo (memcg, pgdat->node_id); + lruvec = &mz->lruvec; + } - mz =mem_cgroup_nodeinfo (memcg, pgdat->node_id); - lruvec = &mz->lruvec; -out:/* * Since a node can be onlined after the mem_cgroup was created, * we have to be prepared to initialize lruvec->pgdat here;
Hi,
This patch causes a hard lock on one of my ARM32 devices using today's linux-next, please fix.
Quoted 42 lines · On Mon, 30 Nov 2020 22:44:11 +0300 Dmitry Osipenko <[email protected]> wrote:
Quoted 29 lines
From: Alex Shi <[email protected]>
Date: Wed, 25 Nov 2020 14:06:33 +0800
Subject: [PATCH v2] mm/memcg: bail out early when !memcg inmem_cgroup_lruvecSometime, we use NULL memcg in
mem_cgroup_lruvec(memcg, pgdat)so we could get out early in the situation to avoid useless checking.Polished as Andrew Morton's suggestion.
include/linux/memcontrol.h +3
-6@@ -610,20 +610,17 @@ mem_cgroup_nodeinfo(struct mem_cgroup *memcg, int nid)static inline struct lruvec *mem_cgroup_lruvec (struct mem_cgroup *memcg,struct pglist_data *pgdat) { -struct mem_cgroup_per_node *mz;struct lruvec *lruvec; -if (mem_cgroup_disabled ()) { +if (mem_cgroup_disabled () || !memcg) { lruvec = &pgdat->__lruvec; - goto out; - } + }else { +struct mem_cgroup_per_node *mz; -if (!memcg) - memcg = root_mem_cgroup;include/linux/memcontrol.h mem_cgroup_nodeinfo(struct mem_cgroup *memcg, int nid) · line 626
Quoted 10 lines
include/linux/memcontrol.h +3
-3+ mz =mem_cgroup_nodeinfo (memcg, pgdat->node_id); + lruvec = &mz->lruvec; + } - mz =mem_cgroup_nodeinfo (memcg, pgdat->node_id); - lruvec = &mz->lruvec; -out:/* * Since a node can be onlined after the mem_cgroup was created, * we have to be prepared to initialize lruvec->pgdat here; Hi,
Quoted 2 lines
This patch causes a hard lock on one of my ARM32 devices using today's linux-next, please fix.
Thanks.
This is unexpected. I assume you've confirmed that reverting this change from linux-next fixes things?