* [PATCH 1/2] mm: vmpressure: don't need call kfree if kstrndup fails
@ 2020-02-11 5:24 Yang Shi
2020-02-11 5:24 ` [PATCH 2/2] mm: vmpressure: use mem_cgroup_is_root API Yang Shi
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Yang Shi @ 2020-02-11 5:24 UTC (permalink / raw)
To: akpm; +Cc: yang.shi, linux-mm, linux-kernel
When kstrndup fails (returns NULL) there is no memory is allocated by
kmalloc, so no need to call kfree().
Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
---
mm/vmpressure.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/mm/vmpressure.c b/mm/vmpressure.c
index 4bac22f..0590f00 100644
--- a/mm/vmpressure.c
+++ b/mm/vmpressure.c
@@ -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, ",");
--
1.8.3.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/2] mm: vmpressure: use mem_cgroup_is_root API
2020-02-11 5:24 [PATCH 1/2] mm: vmpressure: don't need call kfree if kstrndup fails Yang Shi
@ 2020-02-11 5:24 ` Yang Shi
2020-02-12 2:08 ` David Rientjes
` (2 more replies)
2020-02-12 2:07 ` [PATCH 1/2] mm: vmpressure: don't need call kfree if kstrndup fails David Rientjes
2020-02-12 11:21 ` David Hildenbrand
2 siblings, 3 replies; 11+ messages in thread
From: Yang Shi @ 2020-02-11 5:24 UTC (permalink / raw)
To: akpm; +Cc: yang.shi, linux-mm, linux-kernel
Use mem_cgroup_is_root() API to check if memcg is root memcg instead of
open coding.
Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
---
mm/vmpressure.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/vmpressure.c b/mm/vmpressure.c
index 0590f00..d69019f 100644
--- a/mm/vmpressure.c
+++ b/mm/vmpressure.c
@@ -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);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] mm: vmpressure: don't need call kfree if kstrndup fails
2020-02-11 5:24 [PATCH 1/2] mm: vmpressure: don't need call kfree if kstrndup fails Yang Shi
2020-02-11 5:24 ` [PATCH 2/2] mm: vmpressure: use mem_cgroup_is_root API Yang Shi
@ 2020-02-12 2:07 ` David Rientjes
2020-02-12 11:21 ` David Hildenbrand
2 siblings, 0 replies; 11+ messages in thread
From: David Rientjes @ 2020-02-12 2:07 UTC (permalink / raw)
To: Yang Shi; +Cc: akpm, linux-mm, linux-kernel
On Tue, 11 Feb 2020, Yang Shi wrote:
> When kstrndup fails (returns NULL) there is no memory is allocated by
> kmalloc, so no need to call kfree().
>
> Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
Acked-by: David Rientjes <rientjes@google.com>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] mm: vmpressure: use mem_cgroup_is_root API
2020-02-11 5:24 ` [PATCH 2/2] mm: vmpressure: use mem_cgroup_is_root API Yang Shi
@ 2020-02-12 2:08 ` David Rientjes
2020-02-12 8:23 ` Michal Hocko
2020-02-12 11:19 ` David Hildenbrand
2 siblings, 0 replies; 11+ messages in thread
From: David Rientjes @ 2020-02-12 2:08 UTC (permalink / raw)
To: Yang Shi; +Cc: akpm, linux-mm, linux-kernel
On Tue, 11 Feb 2020, Yang Shi wrote:
> Use mem_cgroup_is_root() API to check if memcg is root memcg instead of
> open coding.
>
> Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
Acked-by: David Rientjes <rientjes@google.com>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] mm: vmpressure: use mem_cgroup_is_root API
2020-02-11 5:24 ` [PATCH 2/2] mm: vmpressure: use mem_cgroup_is_root API Yang Shi
2020-02-12 2:08 ` David Rientjes
@ 2020-02-12 8:23 ` Michal Hocko
2020-02-13 3:18 ` Yang Shi
2020-02-12 11:19 ` David Hildenbrand
2 siblings, 1 reply; 11+ messages in thread
From: Michal Hocko @ 2020-02-12 8:23 UTC (permalink / raw)
To: Yang Shi; +Cc: akpm, linux-mm, linux-kernel
On Tue 11-02-20 13:24:09, Yang Shi wrote:
> 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.
> Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Thanks!
> ---
> mm/vmpressure.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/vmpressure.c b/mm/vmpressure.c
> index 0590f00..d69019f 100644
> --- a/mm/vmpressure.c
> +++ b/mm/vmpressure.c
> @@ -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);
> --
> 1.8.3.1
>
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] mm: vmpressure: use mem_cgroup_is_root API
2020-02-11 5:24 ` [PATCH 2/2] mm: vmpressure: use mem_cgroup_is_root API Yang Shi
2020-02-12 2:08 ` David Rientjes
2020-02-12 8:23 ` Michal Hocko
@ 2020-02-12 11:19 ` David Hildenbrand
2 siblings, 0 replies; 11+ messages in thread
From: David Hildenbrand @ 2020-02-12 11:19 UTC (permalink / raw)
To: Yang Shi, akpm; +Cc: linux-mm, linux-kernel
On 11.02.20 06:24, Yang Shi wrote:
> Use mem_cgroup_is_root() API to check if memcg is root memcg instead of
> open coding.
>
> Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
> ---
> mm/vmpressure.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/vmpressure.c b/mm/vmpressure.c
> index 0590f00..d69019f 100644
> --- a/mm/vmpressure.c
> +++ b/mm/vmpressure.c
> @@ -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);
>
Reviewed-by: David Hildenbrand <david@redhat.com>
--
Thanks,
David / dhildenb
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] mm: vmpressure: don't need call kfree if kstrndup fails
2020-02-11 5:24 [PATCH 1/2] mm: vmpressure: don't need call kfree if kstrndup fails Yang Shi
2020-02-11 5:24 ` [PATCH 2/2] mm: vmpressure: use mem_cgroup_is_root API Yang Shi
2020-02-12 2:07 ` [PATCH 1/2] mm: vmpressure: don't need call kfree if kstrndup fails David Rientjes
@ 2020-02-12 11:21 ` David Hildenbrand
2020-02-13 3:14 ` Yang Shi
2 siblings, 1 reply; 11+ messages in thread
From: David Hildenbrand @ 2020-02-12 11:21 UTC (permalink / raw)
To: Yang Shi, akpm; +Cc: linux-mm, linux-kernel
On 11.02.20 06:24, Yang Shi wrote:
> 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."
Reviewed-by: David Hildenbrand <david@redhat.com>
>
> Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
> ---
> mm/vmpressure.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/mm/vmpressure.c b/mm/vmpressure.c
> index 4bac22f..0590f00 100644
> --- a/mm/vmpressure.c
> +++ b/mm/vmpressure.c
> @@ -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, ",");
>
--
Thanks,
David / dhildenb
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] mm: vmpressure: don't need call kfree if kstrndup fails
2020-02-12 11:21 ` David Hildenbrand
@ 2020-02-13 3:14 ` Yang Shi
2020-02-13 4:48 ` Andrew Morton
0 siblings, 1 reply; 11+ messages in thread
From: Yang Shi @ 2020-02-13 3:14 UTC (permalink / raw)
To: David Hildenbrand, akpm; +Cc: linux-mm, linux-kernel
On 2/12/20 3:21 AM, David Hildenbrand wrote:
> On 11.02.20 06:24, Yang Shi wrote:
>> 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?
>
> Reviewed-by: David Hildenbrand <david@redhat.com>
>
>> Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
>> ---
>> mm/vmpressure.c | 6 ++----
>> 1 file changed, 2 insertions(+), 4 deletions(-)
>>
>> diff --git a/mm/vmpressure.c b/mm/vmpressure.c
>> index 4bac22f..0590f00 100644
>> --- a/mm/vmpressure.c
>> +++ b/mm/vmpressure.c
>> @@ -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, ",");
>>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] mm: vmpressure: use mem_cgroup_is_root API
2020-02-12 8:23 ` Michal Hocko
@ 2020-02-13 3:18 ` Yang Shi
0 siblings, 0 replies; 11+ messages in thread
From: Yang Shi @ 2020-02-13 3:18 UTC (permalink / raw)
To: Michal Hocko; +Cc: akpm, linux-mm, linux-kernel
On 2/12/20 12:23 AM, Michal Hocko wrote:
> On Tue 11-02-20 13:24:09, Yang Shi wrote:
>> 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.
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.
>
>> Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
> Acked-by: Michal Hocko <mhocko@suse.com>
Thanks.
>
> Thanks!
>
>> ---
>> mm/vmpressure.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/mm/vmpressure.c b/mm/vmpressure.c
>> index 0590f00..d69019f 100644
>> --- a/mm/vmpressure.c
>> +++ b/mm/vmpressure.c
>> @@ -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);
>> --
>> 1.8.3.1
>>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] mm: vmpressure: don't need call kfree if kstrndup fails
2020-02-13 3:14 ` Yang Shi
@ 2020-02-13 4:48 ` Andrew Morton
2020-02-13 4:51 ` Yang Shi
0 siblings, 1 reply; 11+ messages in thread
From: Andrew Morton @ 2020-02-13 4:48 UTC (permalink / raw)
To: Yang Shi; +Cc: David Hildenbrand, linux-mm, linux-kernel
On Wed, 12 Feb 2020 19:14:27 -0800 Yang Shi <yang.shi@linux.alibaba.com> wrote:
> On 2/12/20 3:21 AM, David Hildenbrand wrote:
> > On 11.02.20 06:24, Yang Shi wrote:
> >> 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 <yang.shi@linux.alibaba.com>
Subject: mm: vmpressure: don't need call kfree if kstrndup fails
When kstrndup fails, no memory was allocated and we can exit directly.
[david@redhat.com: reword changelog]
Link: http://lkml.kernel.org/r/1581398649-125989-1-git-send-email-yang.shi@linux.alibaba.com
Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: David Hildenbrand <david@redhat.com>
Acked-by: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
mm/vmpressure.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
--- a/mm/vmpressure.c~mm-vmpressure-dont-need-call-kfree-if-kstrndup-fails
+++ a/mm/vmpressure.c
@@ -371,10 +371,8 @@ int vmpressure_register_event(struct mem
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, ",");
_
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] mm: vmpressure: don't need call kfree if kstrndup fails
2020-02-13 4:48 ` Andrew Morton
@ 2020-02-13 4:51 ` Yang Shi
0 siblings, 0 replies; 11+ messages in thread
From: Yang Shi @ 2020-02-13 4:51 UTC (permalink / raw)
To: Andrew Morton; +Cc: David Hildenbrand, linux-mm, linux-kernel
On 2/12/20 8:48 PM, Andrew Morton wrote:
> On Wed, 12 Feb 2020 19:14:27 -0800 Yang Shi <yang.shi@linux.alibaba.com> wrote:
>
>> On 2/12/20 3:21 AM, David Hildenbrand wrote:
>>> On 11.02.20 06:24, Yang Shi wrote:
>>>> 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!
>
> From: Yang Shi <yang.shi@linux.alibaba.com>
> Subject: mm: vmpressure: don't need call kfree if kstrndup fails
>
> When kstrndup fails, no memory was allocated and we can exit directly.
>
> [david@redhat.com: reword changelog]
> Link: http://lkml.kernel.org/r/1581398649-125989-1-git-send-email-yang.shi@linux.alibaba.com
> Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
> Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
> Reviewed-by: David Hildenbrand <david@redhat.com>
> Acked-by: David Rientjes <rientjes@google.com>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> ---
>
> mm/vmpressure.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> --- a/mm/vmpressure.c~mm-vmpressure-dont-need-call-kfree-if-kstrndup-fails
> +++ a/mm/vmpressure.c
> @@ -371,10 +371,8 @@ int vmpressure_register_event(struct mem
> 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, ",");
> _
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2020-02-13 4:51 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-11 5:24 [PATCH 1/2] mm: vmpressure: don't need call kfree if kstrndup fails Yang Shi
2020-02-11 5:24 ` [PATCH 2/2] mm: vmpressure: use mem_cgroup_is_root API Yang Shi
2020-02-12 2:08 ` David Rientjes
2020-02-12 8:23 ` Michal Hocko
2020-02-13 3:18 ` Yang Shi
2020-02-12 11:19 ` David Hildenbrand
2020-02-12 2:07 ` [PATCH 1/2] mm: vmpressure: don't need call kfree if kstrndup fails David Rientjes
2020-02-12 11:21 ` David Hildenbrand
2020-02-13 3:14 ` Yang Shi
2020-02-13 4:48 ` Andrew Morton
2020-02-13 4:51 ` Yang Shi
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).