All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/percpu.c: use smarter memory allocation for struct pcpu_alloc_info
@ 2017-10-03 20:57 ` Nicolas Pitre
  0 siblings, 0 replies; 58+ messages in thread
From: Nicolas Pitre @ 2017-10-03 20:57 UTC (permalink / raw)
  To: Tejun Heo, Christoph Lameter; +Cc: linux-mm, linux-kernel

This can be much smaller than a page on very small memory systems. 
Always rounding up the size to a page is wasteful in that case, and 
required alignment is smaller than the memblock default. Let's round 
things up to a page size only when the actual size is >= page size, and 
then it makes sense to page-align for a nicer allocation pattern.

Signed-off-by: Nicolas Pitre <nico@linaro.org>

diff --git a/mm/percpu.c b/mm/percpu.c
index 434844415d..fe37f85cc2 100644
--- a/mm/percpu.c
+++ b/mm/percpu.c
@@ -1410,13 +1410,17 @@ struct pcpu_alloc_info * __init pcpu_alloc_alloc_info(int nr_groups,
 	struct pcpu_alloc_info *ai;
 	size_t base_size, ai_size;
 	void *ptr;
-	int unit;
+	int unit, align;
 
-	base_size = ALIGN(sizeof(*ai) + nr_groups * sizeof(ai->groups[0]),
-			  __alignof__(ai->groups[0].cpu_map[0]));
+	align = __alignof__(ai->groups[0].cpu_map[0]);
+	base_size = ALIGN(sizeof(*ai) + nr_groups * sizeof(ai->groups[0]), align);
 	ai_size = base_size + nr_units * sizeof(ai->groups[0].cpu_map[0]);
+	if (ai_size >= PAGE_SIZE) {
+		ai_size = PFN_ALIGN(ai_size);
+		align = PAGE_SIZE;
+	}
 
-	ptr = memblock_virt_alloc_nopanic(PFN_ALIGN(ai_size), 0);
+	ptr = memblock_virt_alloc_nopanic(ai_size, align);
 	if (!ptr)
 		return NULL;
 	ai = ptr;
@@ -1428,7 +1432,7 @@ struct pcpu_alloc_info * __init pcpu_alloc_alloc_info(int nr_groups,
 		ai->groups[0].cpu_map[unit] = NR_CPUS;
 
 	ai->nr_groups = nr_groups;
-	ai->__ai_size = PFN_ALIGN(ai_size);
+	ai->__ai_size = ai_size;
 
 	return ai;
 }

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

end of thread, other threads:[~2017-11-28  8:19 UTC | newest]

Thread overview: 58+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-03 20:57 [PATCH] mm/percpu.c: use smarter memory allocation for struct pcpu_alloc_info Nicolas Pitre
2017-10-03 20:57 ` Nicolas Pitre
2017-10-03 21:05 ` Tejun Heo
2017-10-03 21:05   ` Tejun Heo
2017-10-03 22:29   ` Nicolas Pitre
2017-10-03 22:29     ` Nicolas Pitre
2017-10-03 22:36     ` Tejun Heo
2017-10-03 22:36       ` Tejun Heo
2017-10-03 23:48       ` Dennis Zhou
2017-10-03 23:48         ` Dennis Zhou
2017-10-04  0:13         ` Nicolas Pitre
2017-10-04  0:13           ` Nicolas Pitre
2017-10-04 14:15     ` Tejun Heo
2017-10-04 14:15       ` Tejun Heo
2017-11-18 18:25     ` mm/percpu.c: use smarter memory allocation for struct pcpu_alloc_info (crisv32 hang) Guenter Roeck
2017-11-18 18:25       ` Guenter Roeck
2017-11-19 20:36       ` Nicolas Pitre
2017-11-19 20:36         ` Nicolas Pitre
2017-11-20  2:03         ` Guenter Roeck
2017-11-20  2:03           ` Guenter Roeck
2017-11-20  4:08           ` Nicolas Pitre
2017-11-20  4:08             ` Nicolas Pitre
2017-11-20  5:05             ` Guenter Roeck
2017-11-20  5:05               ` Guenter Roeck
2017-11-20 18:18               ` Nicolas Pitre
2017-11-20 18:18                 ` Nicolas Pitre
2017-11-20 18:51                 ` Guenter Roeck
2017-11-20 18:51                   ` Guenter Roeck
2017-11-20 20:21                   ` Nicolas Pitre
2017-11-20 20:21                     ` Nicolas Pitre
2017-11-20 21:11                     ` Guenter Roeck
2017-11-20 21:11                       ` Guenter Roeck
2017-11-21  0:28                       ` Nicolas Pitre
2017-11-21  0:28                         ` Nicolas Pitre
2017-11-21  1:48                         ` Guenter Roeck
2017-11-21  1:48                           ` Guenter Roeck
2017-11-21  3:50                           ` Nicolas Pitre
2017-11-21  3:50                             ` Nicolas Pitre
2017-11-22 15:34                             ` Jesper Nilsson
2017-11-22 15:34                               ` Jesper Nilsson
2017-11-22 20:17                               ` Nicolas Pitre
2017-11-22 20:17                                 ` Nicolas Pitre
2017-11-23  7:56                                 ` Jesper Nilsson
2017-11-23  7:56                                   ` Jesper Nilsson
2017-11-27 19:41       ` Tejun Heo
2017-11-27 19:41         ` Tejun Heo
2017-11-27 20:31         ` Nicolas Pitre
2017-11-27 20:31           ` Nicolas Pitre
2017-11-27 20:33           ` Tejun Heo
2017-11-27 20:33             ` Tejun Heo
2017-11-27 20:51             ` Nicolas Pitre
2017-11-27 20:51               ` Nicolas Pitre
2017-11-27 20:54               ` Tejun Heo
2017-11-27 20:54                 ` Tejun Heo
2017-11-27 21:11                 ` Guenter Roeck
2017-11-27 21:11                   ` Guenter Roeck
2017-11-28  8:19               ` Jesper Nilsson
2017-11-28  8:19                 ` Jesper Nilsson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.