[RHEL7] Removed warning from kmalloc in function alloc_rootdomain

Submitted by Denis V. Lunev on July 3, 2020, 4:19 p.m.

Details

Message ID 94b83f53-b805-cb51-d3c9-ae01d3b52e24@virtuozzo.com
State New
Series "Removed warning from kmalloc in function alloc_rootdomain"
Headers show

Commit Message

Denis V. Lunev July 3, 2020, 4:19 p.m.
On 7/3/20 7:12 PM, Valeriy Vdovin wrote:
> 'alloc_rootdomain' is used during cpu hotplug actions when cpu's are
> removed or added. So it's relatively rare occasion. The size of
> allocated structure 'struct root_domain' is ~22k, which is a warnable
> order 3. Because this structure is related to sched domain the code
> accessing it is considered of high priority due to execution in
> scheduling codepaths, so we should not fallback to virtualized page
> continuity in this allocation and suppress order warning instead.
>
> Signed-off-by: Valeriy Vdovin <valeriy.vdovin@virtuozzo.com>
> ---
>  kernel/sched/core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 3fe0d62..8d14614 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -7141,7 +7141,7 @@ static struct root_domain *alloc_rootdomain(void)
>  {
>  	struct root_domain *rd;
>  
> -	rd = kmalloc(sizeof(*rd), GFP_KERNEL);
> +	rd = kmalloc(sizeof(*rd), GFP_KERNEL | __GFP_ORDER_NOWARN);
>  	if (!rd)
>  		return NULL;
>  
NACK

kvmalloc looks to me MUCH better. This item is no
used in HW operations thus we could use virtually
contiguous allocations.

iris ~/src/git/linux-vz7 $ git diff
iris ~/src/git/linux-vz7 $

Patch hide | download patch | download mbox

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 3fe0d62cc51c..d1c489574284 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7051,7 +7051,7 @@  static void free_rootdomain(struct rcu_head *rcu)
        free_cpumask_var(rd->rto_mask);
        free_cpumask_var(rd->online);
        free_cpumask_var(rd->span);
-       kfree(rd);
+       kvfree(rd);
 }
 
 static void rq_attach_root(struct rq *rq, struct root_domain *rd)
@@ -7141,12 +7141,12 @@  static struct root_domain *alloc_rootdomain(void)
 {
        struct root_domain *rd;
 
-       rd = kmalloc(sizeof(*rd), GFP_KERNEL);
+       rd = kvmalloc(sizeof(*rd), GFP_KERNEL);
        if (!rd)
                return NULL;
 
        if (init_rootdomain(rd) != 0) {
-               kfree(rd);
+               kvfree(rd);
                return NULL;
        }
 

Comments

Denis V. Lunev July 3, 2020, 4:41 p.m.
On 7/3/20 7:19 PM, Denis V. Lunev wrote:
> On 7/3/20 7:12 PM, Valeriy Vdovin wrote:
>> 'alloc_rootdomain' is used during cpu hotplug actions when cpu's are
>> removed or added. So it's relatively rare occasion. The size of
>> allocated structure 'struct root_domain' is ~22k, which is a warnable
>> order 3. Because this structure is related to sched domain the code
>> accessing it is considered of high priority due to execution in
>> scheduling codepaths, so we should not fallback to virtualized page
>> continuity in this allocation and suppress order warning instead.
>>
>> Signed-off-by: Valeriy Vdovin <valeriy.vdovin@virtuozzo.com>
>> ---
>>  kernel/sched/core.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
>> index 3fe0d62..8d14614 100644
>> --- a/kernel/sched/core.c
>> +++ b/kernel/sched/core.c
>> @@ -7141,7 +7141,7 @@ static struct root_domain *alloc_rootdomain(void)
>>  {
>>  	struct root_domain *rd;
>>  
>> -	rd = kmalloc(sizeof(*rd), GFP_KERNEL);
>> +	rd = kmalloc(sizeof(*rd), GFP_KERNEL | __GFP_ORDER_NOWARN);
>>  	if (!rd)
>>  		return NULL;
>>  
> NACK
>
> kvmalloc looks to me MUCH better. This item is no
> used in HW operations thus we could use virtually
> contiguous allocations.
>
> iris ~/src/git/linux-vz7 $ git diff
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 3fe0d62cc51c..d1c489574284 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -7051,7 +7051,7 @@ static void free_rootdomain(struct rcu_head *rcu)
>         free_cpumask_var(rd->rto_mask);
>         free_cpumask_var(rd->online);
>         free_cpumask_var(rd->span);
> -       kfree(rd);
> +       kvfree(rd);
>  }
>  
>  static void rq_attach_root(struct rq *rq, struct root_domain *rd)
> @@ -7141,12 +7141,12 @@ static struct root_domain *alloc_rootdomain(void)
>  {
>         struct root_domain *rd;
>  
> -       rd = kmalloc(sizeof(*rd), GFP_KERNEL);
> +       rd = kvmalloc(sizeof(*rd), GFP_KERNEL);
>         if (!rd)
>                 return NULL;
>  
>         if (init_rootdomain(rd) != 0) {
> -               kfree(rd);
> +               kvfree(rd);
>                 return NULL;
>         }
>  
> iris ~/src/git/linux-vz7 $
> _______________________________________________
> Devel mailing list
> Devel@openvz.org
> https://lists.openvz.org/mailman/listinfo/devel
commit 4dac0b638310d2e92f6e19958b73d4c97c9734bb
Author: Peter Zijlstra <peterz@infradead.org>
Date:   Wed May 14 16:04:26 2014 +0200

    sched/cpupri: Replace NR_CPUS arrays
   
    Tejun reported that his resume was failing due to order-3 allocations
    from sched_domain building.
   
    Replace the NR_CPUS arrays in there with a dynamically allocated
    array.
   
    Reported-by: Tejun Heo <tj@kernel.org>
    Signed-off-by: Peter Zijlstra <peterz@infradead.org>
    Cc: Johannes Weiner <hannes@cmpxchg.org>
    Cc: Steven Rostedt <rostedt@goodmis.org>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Link:
http://lkml.kernel.org/n/tip-7cysnkw1gik45r864t1nkudh@git.kernel.org
    Signed-off-by: Ingo Molnar <mingo@kernel.org>