mm: vmpressure: don't need call kfree if kstrndup fails
Subsystems (2)
PATCH 1/2 mm: vmpressure: don't need call kfree if kstrndup fails
When kstrndup fails (returns NULL) there is no memory is allocated by kmalloc, so no need to call kfree().
--- mm/vmpressure.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
mm/vmpressure.c +2 -4
@@ -371,10 +371,8 @@ int vmpressure_register_event(struct mem_cgroup *memcg,int ret =0 ; spec_orig = spec =kstrndup (args,MAX_VMPRESSURE_ARGS_LEN ,GFP_KERNEL ); -if (!spec) { - ret = -ENOMEM ; - goto out; - } +if (!spec) +return -ENOMEM ;/* Find required level */ token =strsep (&spec,"," );
Signature · 1 line
1.8.3.1
PATCH 2/2 mm: vmpressure: use mem_cgroup_is_root API
Use mem_cgroup_is_root() API to check if memcg is root memcg instead of open coding.
--- mm/vmpressure.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/vmpressure.c +1 -1
@@ -280,7 +280,7 @@ void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, bool tree,enum vmpressure_levels level;/* For now, no users for root-level efficiency */ -if (!memcg || memcg == root_mem_cgroup) +if (!memcg ||mem_cgroup_is_root (memcg))return ;spin_lock (&vmpr->sr_lock);
Signature · 1 line
1.8.3.1
Re: [PATCH 2/2] mm: vmpressure: use mem_cgroup_is_root API
Quoted 4 lines · Yang Shi
Use
mem_cgroup_is_root()API to check if memcg is root memcg instead of open coding.Signed-off-by Yang Shi <[email protected]>
Re: [PATCH 2/2] mm: vmpressure: use mem_cgroup_is_root API
In reply to Yang ShiQuoted 2 lines · Yang Shi
Use
mem_cgroup_is_root()API to check if memcg is root memcg instead of open coding.
Yes, the direct use outside of memcontrol.c should be really an exception. The only other similar case is cgwb_bdi_init and there is no easy way to replace - except for adding a helper which is not worth it.
Quoted 1 line
Signed-off-by Yang Shi <[email protected]>
Thanks!
Quoted 20 lines
--- mm/vmpressure.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/vmpressure.c +1
-1@@ -280,7 +280,7 @@ void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, bool tree,enum vmpressure_levels level;/* For now, no users for root-level efficiency */ -if (!memcg || memcg == root_mem_cgroup) +if (!memcg ||mem_cgroup_is_root (memcg))return ;spin_lock (&vmpr->sr_lock);Signature · 1 line
1.8.3.1
Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH 2/2] mm: vmpressure: use mem_cgroup_is_root API
Quoted 6 lines · Michal Hocko
Quoted 2 lines · Yang Shi
Use
mem_cgroup_is_root()API to check if memcg is root memcg instead of open coding.Yes, the direct use outside of
memcontrol.cshould be really an exception. The only other similar case iscgwb_bdi_initand there is no easy way to replace - except for adding a helper which is not worth it.
Yes, it seems so. cgwb_bdi_init just deferences root_mem_cgroup to access its css. It is the only user outside memcontrol.c, so I agree a helper for it might be overkilling. Once we have more users, it should be considered.
Quoted 3 lines
Quoted 2 lines
Signed-off-by Yang Shi <[email protected]>Acked-by Michal Hocko <[email protected]>
Thanks.
Quoted 23 lines
Thanks!
Quoted 20 lines
--- mm/vmpressure.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/vmpressure.c +1
-1@@ -280,7 +280,7 @@ void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, bool tree,enum vmpressure_levels level;/* For now, no users for root-level efficiency */ -if (!memcg || memcg == root_mem_cgroup) +if (!memcg ||mem_cgroup_is_root (memcg))return ;spin_lock (&vmpr->sr_lock);Signature · 1 line
1.8.3.1
Re: [PATCH 2/2] mm: vmpressure: use mem_cgroup_is_root API
In reply to Yang ShiQuoted 14 lines · Yang Shi
Use
mem_cgroup_is_root()API to check if memcg is root memcg instead of open coding.Signed-off-by Yang Shi <[email protected]>--- mm/vmpressure.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/vmpressure.c +0
-0
mm/vmpressure.c void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, bool tree, · line 286
Quoted 8 lines
mm/vmpressure.c +1
-1@@ -280,7 +280,7 @@ void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, bool tree,enum vmpressure_levels level;/* For now, no users for root-level efficiency */ -if (!memcg || memcg == root_mem_cgroup) +if (!memcg ||mem_cgroup_is_root (memcg))return ;spin_lock (&vmpr->sr_lock);
Signature · 3 lines
Thanks, David / dhildenb
Quoted 4 lines · Yang Shi
When kstrndup fails (returns NULL) there is no memory is allocated by kmalloc, so no need to call
kfree().Signed-off-by Yang Shi <[email protected]>
Quoted 2 lines · Yang Shi
When kstrndup fails (returns NULL) there is no memory is allocated by kmalloc, so no need to call
kfree().
"When kstrndup fails, no memory was allocated and we can exit directly."
Quoted 24 lines
Signed-off-by Yang Shi <[email protected]>--- mm/vmpressure.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)mm/vmpressure.c +2
-4@@ -371,10 +371,8 @@ int vmpressure_register_event(struct mem_cgroup *memcg,int ret =0 ; spec_orig = spec =kstrndup (args,MAX_VMPRESSURE_ARGS_LEN ,GFP_KERNEL ); -if (!spec) { - ret = -ENOMEM ; - goto out; - } +if (!spec) +return -ENOMEM ;/* Find required level */ token =strsep (&spec,"," );
Signature · 3 lines
Thanks, David / dhildenb
Quoted 4 lines · David Hildenbrand
Quoted 2 lines · Yang Shi
When kstrndup fails (returns NULL) there is no memory is allocated by kmalloc, so no need to call
kfree()."When kstrndup fails, no memory was allocated and we can exit directly."
Thanks for correcting the commit log.
Andrew, do you prefer I send an updated version or you would just update the patch in -mm tree?
Quoted 27 lines
Reviewed-by David Hildenbrand <[email protected]>Quoted 23 lines
Signed-off-by Yang Shi <[email protected]>--- mm/vmpressure.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)mm/vmpressure.c +2
-4@@ -371,10 +371,8 @@ int vmpressure_register_event(struct mem_cgroup *memcg,int ret =0 ; spec_orig = spec =kstrndup (args,MAX_VMPRESSURE_ARGS_LEN ,GFP_KERNEL ); -if (!spec) { - ret = -ENOMEM ; - goto out; - } +if (!spec) +return -ENOMEM ;/* Find required level */ token =strsep (&spec,"," );
Quoted 10 lines · On Wed, 12 Feb 2020 19:14:27 -0800 Yang Shi <[email protected]> wrote:
Quoted 4 lines · David Hildenbrand
Quoted 2 lines · Yang Shi
When kstrndup fails (returns NULL) there is no memory is allocated by kmalloc, so no need to call
kfree()."When kstrndup fails, no memory was allocated and we can exit directly."
Thanks for correcting the commit log.
Andrew, do you prefer I send an updated version or you would just update the patch in -mm tree?
I have already done this.
From: Yang Shi <[email protected]>
Subject: mm: vmpressure: don't need call kfree if kstrndup fails
When kstrndup fails, no memory was allocated and we can exit directly.
---
mm/vmpressure.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
mm/vmpressure.c renamed from mm/vmpressure.c~mm-vmpressure-dont-need-call-kfree-if-kstrndup-fails +2 -4
@@ -371,10 +371,8 @@ int vmpressure_register_event(struct memint ret =0 ; spec_orig = spec =kstrndup (args,MAX_VMPRESSURE_ARGS_LEN ,GFP_KERNEL ); -if (!spec) { - ret = -ENOMEM ; - goto out; - } +if (!spec) +return -ENOMEM ;/* Find required level */ token =strsep (&spec,"," );
_
Quoted 4 lines · Andrew Morton
Quoted 2 lines · On Wed, 12 Feb 2020 19:14:27 -0800 Yang Shi <[email protected]> wrote:
Quoted 1 line · David Hildenbrand
On 11.02.20 06:24, Yang Shi wrote:
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines
When kstrndup fails (returns NULL) there is no memory is allocated by kmalloc, so no need to call
kfree()."When kstrndup fails, no memory was allocated and we can exit directly."
Thanks for correcting the commit log.
Andrew, do you prefer I send an updated version or you would just update the patch in -mm tree?
I have already done this.
Thanks!
Quoted 34 lines
From: Yang Shi <[email protected]>
Subject: mm: vmpressure: don't need call kfree if kstrndup failsWhen kstrndup fails, no memory was allocated and we can exit directly.
[[email protected]: reword changelog]Signed-off-by Yang Shi <[email protected]>Reviewed-by Andrew Morton <[email protected]>Reviewed-by David Hildenbrand <[email protected]>Acked-by David Rientjes <[email protected]>Signed-off-by Andrew Morton <[email protected]>---
mm/vmpressure.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)mm/vmpressure.c renamed from mm/vmpressure.c~mm-vmpressure-dont-need-call-kfree-if-kstrndup-fails +2
-4@@ -371,10 +371,8 @@ int vmpressure_register_event(struct memint ret =0 ; spec_orig = spec =kstrndup (args,MAX_VMPRESSURE_ARGS_LEN ,GFP_KERNEL ); -if (!spec) { - ret = -ENOMEM ; - goto out; - } +if (!spec) +return -ENOMEM ;/* Find required level */ token =strsep (&spec,"," );_