LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] Fix KMALLOC_MAX_SIZE overflow during cpumask allocation
@ 2014-12-02 17:17 Alex Thorlton
  2014-12-08 10:42 ` Ingo Molnar
  0 siblings, 1 reply; 3+ messages in thread
From: Alex Thorlton @ 2014-12-02 17:17 UTC (permalink / raw)
  To: linux-kernel
  Cc: Alex Thorlton, George Beshers, Russ Anderson, Ingo Molnar,
	Peter Zijlstra

When allocating space for load_balance_mask, in sched_init, when
CPUMASK_OFFSTACK is set, we've managed to spill over KMALLOC_MAX_SIZE on our
6144 core machine.  The patch below breaks up the allocations so that they don't
overflow the max alloc size.  It also allocates the masks on the the node from
which they'll most commonly be accessed, to minimize remote accesses on NUMA
machines.

Any input is appreciated!

- Alex

Signed-off-by: Alex Thorlton <athorlton@sgi.com>
Suggested-by: George Beshers <gbeshers@sgi.com>
Cc: George Beshers <gbeshers@sgi.com>
Cc: Russ Anderson <rja@sgi.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: linux-kernel@vger.kernel.org

---
 kernel/sched/core.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 4499950..8f06655 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6981,9 +6981,6 @@ void __init sched_init(void)
 #ifdef CONFIG_RT_GROUP_SCHED
 	alloc_size += 2 * nr_cpu_ids * sizeof(void **);
 #endif
-#ifdef CONFIG_CPUMASK_OFFSTACK
-	alloc_size += num_possible_cpus() * cpumask_size();
-#endif
 	if (alloc_size) {
 		ptr = (unsigned long)kzalloc(alloc_size, GFP_NOWAIT);
 
@@ -7003,12 +7000,10 @@ void __init sched_init(void)
 		ptr += nr_cpu_ids * sizeof(void **);
 
 #endif /* CONFIG_RT_GROUP_SCHED */
-#ifdef CONFIG_CPUMASK_OFFSTACK
-		for_each_possible_cpu(i) {
-			per_cpu(load_balance_mask, i) = (void *)ptr;
-			ptr += cpumask_size();
-		}
-#endif /* CONFIG_CPUMASK_OFFSTACK */
+	}
+	for_each_possible_cpu(i) {
+		per_cpu(load_balance_mask, i) = kzalloc_node(
+			cpumask_size(), GFP_KERNEL, cpu_to_node(i));
 	}
 
 	init_rt_bandwidth(&def_rt_bandwidth,
-- 
1.7.12.4


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix KMALLOC_MAX_SIZE overflow during cpumask allocation
  2014-12-02 17:17 [PATCH] Fix KMALLOC_MAX_SIZE overflow during cpumask allocation Alex Thorlton
@ 2014-12-08 10:42 ` Ingo Molnar
  2014-12-08 20:02   ` Alex Thorlton
  0 siblings, 1 reply; 3+ messages in thread
From: Ingo Molnar @ 2014-12-08 10:42 UTC (permalink / raw)
  To: Alex Thorlton
  Cc: linux-kernel, George Beshers, Russ Anderson, Ingo Molnar, Peter Zijlstra


* Alex Thorlton <athorlton@sgi.com> wrote:

> When allocating space for load_balance_mask, in sched_init, when
> CPUMASK_OFFSTACK is set, we've managed to spill over KMALLOC_MAX_SIZE on our
> 6144 core machine.  The patch below breaks up the allocations so that they don't
> overflow the max alloc size.  It also allocates the masks on the the node from
> which they'll most commonly be accessed, to minimize remote accesses on NUMA
> machines.
> 
> Any input is appreciated!
> 
> - Alex
> 
> Signed-off-by: Alex Thorlton <athorlton@sgi.com>
> Suggested-by: George Beshers <gbeshers@sgi.com>
> Cc: George Beshers <gbeshers@sgi.com>
> Cc: Russ Anderson <rja@sgi.com>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: linux-kernel@vger.kernel.org
> 
> ---
>  kernel/sched/core.c | 13 ++++---------
>  1 file changed, 4 insertions(+), 9 deletions(-)
> 
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 4499950..8f06655 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -6981,9 +6981,6 @@ void __init sched_init(void)
>  #ifdef CONFIG_RT_GROUP_SCHED
>  	alloc_size += 2 * nr_cpu_ids * sizeof(void **);
>  #endif
> -#ifdef CONFIG_CPUMASK_OFFSTACK
> -	alloc_size += num_possible_cpus() * cpumask_size();
> -#endif
>  	if (alloc_size) {
>  		ptr = (unsigned long)kzalloc(alloc_size, GFP_NOWAIT);
>  
> @@ -7003,12 +7000,10 @@ void __init sched_init(void)
>  		ptr += nr_cpu_ids * sizeof(void **);
>  
>  #endif /* CONFIG_RT_GROUP_SCHED */
> -#ifdef CONFIG_CPUMASK_OFFSTACK
> -		for_each_possible_cpu(i) {
> -			per_cpu(load_balance_mask, i) = (void *)ptr;
> -			ptr += cpumask_size();
> -		}
> -#endif /* CONFIG_CPUMASK_OFFSTACK */
> +	}
> +	for_each_possible_cpu(i) {
> +		per_cpu(load_balance_mask, i) = kzalloc_node(
> +			cpumask_size(), GFP_KERNEL, cpu_to_node(i));
>  	}
>  
>  	init_rt_bandwidth(&def_rt_bandwidth,

This patch fails to build with certain configs:

kernel/sched/core.c:7130:33: error: incompatible types when assigning to type ‘cpumask_var_t’ from type ‘void *’

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix KMALLOC_MAX_SIZE overflow during cpumask allocation
  2014-12-08 10:42 ` Ingo Molnar
@ 2014-12-08 20:02   ` Alex Thorlton
  0 siblings, 0 replies; 3+ messages in thread
From: Alex Thorlton @ 2014-12-08 20:02 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Alex Thorlton, linux-kernel, George Beshers, Russ Anderson,
	Ingo Molnar, Peter Zijlstra

On Mon, Dec 08, 2014 at 11:42:14AM +0100, Ingo Molnar wrote:
> This patch fails to build with certain configs:
> 
> kernel/sched/core.c:7130:33: error: incompatible types when assigning to type ‘cpumask_var_t’ from type ‘void *’

Thanks for letting us know, Ingo.  I believe George has something in
mind to fix this.  We'll take a look and get another version out ASAP!

- Alex

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-12-08 20:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-02 17:17 [PATCH] Fix KMALLOC_MAX_SIZE overflow during cpumask allocation Alex Thorlton
2014-12-08 10:42 ` Ingo Molnar
2014-12-08 20:02   ` Alex Thorlton

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).