All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: mingo@elte.hu, rusty@rustcorp.com.au, tglx@linutronix.de,
	x86@kernel.org, linux-kernel@vger.kernel.org, hpa@zytor.com,
	Paul Mundt <lethal@linux-sh.org>,
	rmk@arm.linux.org.uk, starvik@axis.com, ralf@linux-mips.org,
	davem@davemloft.net, cooloney@kernel.org, kyle@mcmartin.ca,
	matthew@wil.cx, grundler@parisc-linux.org, takata@linux-m32r.org,
	benh@kernel.crashing.org, rth@twiddle.net,
	ink@jurassic.park.msu.ru, schwidefsky@de.ibm.com,
	heiko.carstens@de.ibm.com
Cc: Tejun Heo <tj@kernel.org>
Subject: [PATCH 3/5] percpu: more flexibility for @dyn_size of pcpu_setup_first_chunk()
Date: Tue, 10 Mar 2009 16:53:49 +0900	[thread overview]
Message-ID: <1236671631-9305-4-git-send-email-tj@kernel.org> (raw)
In-Reply-To: <1236671631-9305-1-git-send-email-tj@kernel.org>

Impact: cleanup, more flexibility for first chunk init

Non-negative @dyn_size used to be allowed iff @unit_size wasn't auto.
This restriction stemmed from implementation detail and made things a
bit less intuitive.  This patch allows @dyn_size to be specified
regardless of @unit_size and swaps the positions of @dyn_size and
@unit_size so that the parameter order makes more sense (static,
reserved and dyn sizes followed by enclosing unit_size).

While at it, add @unit_size >= PCPU_MIN_UNIT_SIZE sanity check.

Signed-off-by: Tejun Heo <tj@kernel.org>
---
 arch/x86/kernel/setup_percpu.c |   13 ++++++-------
 include/linux/percpu.h         |    2 +-
 mm/percpu.c                    |   28 ++++++++++++++--------------
 3 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
index efa615f..e41c51f 100644
--- a/arch/x86/kernel/setup_percpu.c
+++ b/arch/x86/kernel/setup_percpu.c
@@ -233,8 +233,8 @@ proceed:
 		"%zu bytes\n", vm.addr, static_size);
 
 	ret = pcpu_setup_first_chunk(pcpur_get_page, static_size,
-				     PERCPU_FIRST_CHUNK_RESERVE,
-				     PMD_SIZE, dyn_size, vm.addr, NULL);
+				     PERCPU_FIRST_CHUNK_RESERVE, dyn_size,
+				     PMD_SIZE, vm.addr, NULL);
 	goto out_free_ar;
 
 enomem:
@@ -315,9 +315,8 @@ static ssize_t __init setup_pcpu_embed(size_t static_size)
 		pcpue_size >> PAGE_SHIFT, pcpue_ptr, static_size);
 
 	return pcpu_setup_first_chunk(pcpue_get_page, static_size,
-				      PERCPU_FIRST_CHUNK_RESERVE,
-				      pcpue_unit_size, dyn_size,
-				      pcpue_ptr, NULL);
+				      PERCPU_FIRST_CHUNK_RESERVE, dyn_size,
+				      pcpue_unit_size, pcpue_ptr, NULL);
 }
 
 /*
@@ -375,8 +374,8 @@ static ssize_t __init setup_pcpu_4k(size_t static_size)
 		pcpu4k_nr_static_pages, static_size);
 
 	ret = pcpu_setup_first_chunk(pcpu4k_get_page, static_size,
-				     PERCPU_FIRST_CHUNK_RESERVE, -1, -1, NULL,
-				     pcpu4k_populate_pte);
+				     PERCPU_FIRST_CHUNK_RESERVE, -1,
+				     -1, NULL, pcpu4k_populate_pte);
 	goto out_free_ar;
 
 enomem:
diff --git a/include/linux/percpu.h b/include/linux/percpu.h
index 54a968b..fb455dc 100644
--- a/include/linux/percpu.h
+++ b/include/linux/percpu.h
@@ -107,7 +107,7 @@ typedef void (*pcpu_populate_pte_fn_t)(unsigned long addr);
 
 extern size_t __init pcpu_setup_first_chunk(pcpu_get_page_fn_t get_page_fn,
 				size_t static_size, size_t reserved_size,
-				ssize_t unit_size, ssize_t dyn_size,
+				ssize_t dyn_size, ssize_t unit_size,
 				void *base_addr,
 				pcpu_populate_pte_fn_t populate_pte_fn);
 
diff --git a/mm/percpu.c b/mm/percpu.c
index c6f38a2..2f94661 100644
--- a/mm/percpu.c
+++ b/mm/percpu.c
@@ -1027,8 +1027,8 @@ EXPORT_SYMBOL_GPL(free_percpu);
  * @get_page_fn: callback to fetch page pointer
  * @static_size: the size of static percpu area in bytes
  * @reserved_size: the size of reserved percpu area in bytes
- * @unit_size: unit size in bytes, must be multiple of PAGE_SIZE, -1 for auto
  * @dyn_size: free size for dynamic allocation in bytes, -1 for auto
+ * @unit_size: unit size in bytes, must be multiple of PAGE_SIZE, -1 for auto
  * @base_addr: mapped address, NULL for auto
  * @populate_pte_fn: callback to allocate pagetable, NULL if unnecessary
  *
@@ -1053,14 +1053,14 @@ EXPORT_SYMBOL_GPL(free_percpu);
  * limited offset range for symbol relocations to guarantee module
  * percpu symbols fall inside the relocatable range.
  *
+ * @dyn_size, if non-negative, determines the number of bytes
+ * available for dynamic allocation in the first chunk.  Specifying
+ * non-negative value makes percpu leave alone the area beyond
+ * @static_size + @reserved_size + @dyn_size.
+ *
  * @unit_size, if non-negative, specifies unit size and must be
  * aligned to PAGE_SIZE and equal to or larger than @static_size +
- * @reserved_size + @dyn_size.
- *
- * @dyn_size, if non-negative, limits the number of bytes available
- * for dynamic allocation in the first chunk.  Specifying non-negative
- * value make percpu leave alone the area beyond @static_size +
- * @reserved_size + @dyn_size.
+ * @reserved_size + if non-negative, @dyn_size.
  *
  * Non-null @base_addr means that the caller already allocated virtual
  * region for the first chunk and mapped it.  percpu must not mess
@@ -1083,12 +1083,14 @@ EXPORT_SYMBOL_GPL(free_percpu);
  */
 size_t __init pcpu_setup_first_chunk(pcpu_get_page_fn_t get_page_fn,
 				     size_t static_size, size_t reserved_size,
-				     ssize_t unit_size, ssize_t dyn_size,
+				     ssize_t dyn_size, ssize_t unit_size,
 				     void *base_addr,
 				     pcpu_populate_pte_fn_t populate_pte_fn)
 {
 	static struct vm_struct first_vm;
 	static int smap[2], dmap[2];
+	size_t size_sum = static_size + reserved_size +
+			  (dyn_size >= 0 ? dyn_size : 0);
 	struct pcpu_chunk *schunk, *dchunk = NULL;
 	unsigned int cpu;
 	int nr_pages;
@@ -1099,20 +1101,18 @@ size_t __init pcpu_setup_first_chunk(pcpu_get_page_fn_t get_page_fn,
 		     ARRAY_SIZE(dmap) >= PCPU_DFL_MAP_ALLOC);
 	BUG_ON(!static_size);
 	if (unit_size >= 0) {
-		BUG_ON(unit_size < static_size + reserved_size +
-				   (dyn_size >= 0 ? dyn_size : 0));
+		BUG_ON(unit_size < size_sum);
 		BUG_ON(unit_size & ~PAGE_MASK);
-	} else {
-		BUG_ON(dyn_size >= 0);
+		BUG_ON(unit_size < PCPU_MIN_UNIT_SIZE);
+	} else
 		BUG_ON(base_addr);
-	}
 	BUG_ON(base_addr && populate_pte_fn);
 
 	if (unit_size >= 0)
 		pcpu_unit_pages = unit_size >> PAGE_SHIFT;
 	else
 		pcpu_unit_pages = max_t(int, PCPU_MIN_UNIT_SIZE >> PAGE_SHIFT,
-					PFN_UP(static_size + reserved_size));
+					PFN_UP(size_sum));
 
 	pcpu_unit_size = pcpu_unit_pages << PAGE_SHIFT;
 	pcpu_chunk_size = num_possible_cpus() * pcpu_unit_size;
-- 
1.6.0.2


  parent reply	other threads:[~2009-03-10  7:56 UTC|newest]

Thread overview: 95+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-10  7:53 [GIT RFC] percpu: use dynamic percpu allocator as the default percpu allocator Tejun Heo
2009-03-10  7:53 ` [PATCH 1/5] linker script: define __per_cpu_load on all SMP capable archs Tejun Heo
2009-03-10  7:53 ` [PATCH 2/5] percpu: make x86 addr <-> pcpu ptr conversion macros generic Tejun Heo
2009-03-10  7:53 ` Tejun Heo [this message]
2009-03-10  7:53 ` [PATCH 4/5] percpu: generalize embedding first chunk setup helper Tejun Heo
2009-03-10  7:53 ` [PATCH 5/5] percpu: use dynamic percpu allocator as the default percpu allocator Tejun Heo
2009-03-10  7:57 ` test module to verify " Tejun Heo
2009-03-10 10:59 ` [GIT RFC] percpu: use dynamic percpu allocator as the default " David Miller
2009-03-11  6:03   ` Tejun Heo
2009-03-11  5:56 ` [GIT PULL] pull request for safe part Tejun Heo
2009-03-16 18:01 ` [GIT RFC] percpu: use dynamic percpu allocator as the default percpu allocator Martin Schwidefsky
2009-03-20  2:35   ` Tejun Heo
2009-03-24 15:22     ` Tejun Heo
2009-03-25 11:27       ` Martin Schwidefsky
2009-03-25 11:51         ` Tejun Heo
2009-03-25 12:22           ` Ingo Molnar
2009-03-25 12:27             ` Tejun Heo
2009-03-25 12:39               ` Ingo Molnar
2009-03-25 13:13               ` Martin Schwidefsky
2009-03-25 13:21                 ` Tejun Heo
2009-03-25 13:25                   ` Martin Schwidefsky
2009-03-25 13:34                     ` Tejun Heo
2009-03-31 16:54                       ` Martin Schwidefsky
2009-03-31 17:20                         ` Christoph Lameter
2009-03-31 20:18                           ` Martin Schwidefsky
2009-03-31 21:10                             ` Christoph Lameter
2009-04-01  8:01                               ` Martin Schwidefsky
2009-03-31 19:17                         ` Ivan Kokshaysky
2009-03-31 20:19                           ` Martin Schwidefsky
2009-03-31 20:29                             ` Ivan Kokshaysky
2009-04-01  0:07                         ` Tejun Heo
2009-04-01  8:10                           ` Martin Schwidefsky
2009-04-01  8:17                             ` Tejun Heo
2009-04-01  8:32                               ` Martin Schwidefsky
2009-04-01  8:37                                 ` David Miller
2009-04-01  8:47                                   ` Martin Schwidefsky
2009-04-01  8:50                                     ` Tejun Heo
2009-04-01  9:08                                       ` Martin Schwidefsky
2009-04-02  1:54                                         ` Tejun Heo
2009-04-01  8:53                                     ` David Miller
2009-04-01  8:53                                 ` Tejun Heo
2009-04-01 11:07                                   ` Martin Schwidefsky
2009-04-02  1:57                                     ` Tejun Heo
2009-04-02  7:24                                       ` Ivan Kokshaysky
2009-04-02 11:13                                         ` Martin Schwidefsky
2009-04-03  0:31                                           ` Tejun Heo
2009-04-07 16:09                                             ` Ivan Kokshaysky
2009-04-08 20:18                                               ` Tejun Heo
2009-04-09  9:47                                                 ` Ivan Kokshaysky
2009-04-09 11:53                                                   ` Tejun Heo
2009-04-11  1:38                                                     ` Rusty Russell
2009-04-11  1:52                                                       ` Tejun Heo
2009-04-02  0:20                               ` Rusty Russell
2009-03-25 14:00           ` Martin Schwidefsky
2009-03-25 14:14             ` Tejun Heo
2009-03-30 10:07               ` [PATCH UPDATED] " Tejun Heo
2009-03-30 10:42                 ` Martin Schwidefsky
2009-04-01  0:08                   ` Tejun Heo
2009-03-30 11:49                 ` Ingo Molnar
2009-03-30 14:50                   ` Christoph Lameter
2009-03-31 16:12                     ` Christoph Lameter
2009-04-01  0:15                       ` Tejun Heo
2009-04-01 13:49                         ` Christoph Lameter
2009-04-01 15:49                           ` Ingo Molnar
2009-04-01 18:06                             ` Christoph Lameter
2009-04-01 19:01                               ` Ingo Molnar
2009-04-01 19:39                                 ` Linus Torvalds
2009-04-01 20:12                                   ` Matthew Wilcox
2009-04-02  2:13                                     ` Ingo Molnar
2009-04-01 22:32                                   ` Ingo Molnar
2009-04-01 22:57                                     ` Matthew Wilcox
2009-04-02  2:10                                       ` Ingo Molnar
2009-04-02  2:21                                         ` Christoph Lameter
2009-04-02  3:25                                           ` Ingo Molnar
2009-04-02  3:28                                             ` Christoph Lameter
2009-04-02  2:30                                       ` Tejun Heo
2009-04-02  2:18                                     ` Christoph Lameter
2009-04-02  3:42                                       ` Ingo Molnar
2009-04-02 13:53                                         ` Christoph Lameter
2009-04-08 16:26                                           ` Ingo Molnar
2009-04-13 18:18                                             ` Christoph Lameter
2009-04-14 14:04                                               ` Ingo Molnar
2009-04-14 16:48                                                 ` Christoph Lameter
2009-04-14 17:12                                                   ` Ingo Molnar
2009-04-02  2:15                                 ` Christoph Lameter
2009-04-02  4:19                       ` [PATCH 1/2 x86#core/percpu] percpu: don't put the first chunk in reverse-map rbtree Tejun Heo
2009-04-02  4:21                         ` [PATCH 2/2 x86#core/percpu] percpu: remove rbtree and use page->index instead Tejun Heo
2009-04-08 17:03                           ` [tip:core/percpu] " Christoph Lameter
2009-04-08 17:03                         ` [tip:core/percpu] percpu: don't put the first chunk in reverse-map rbtree Tejun Heo
2009-03-31 16:14                     ` [PATCH UPDATED] percpu: use dynamic percpu allocator as the default percpu allocator Christoph Lameter
2009-04-01  0:18                       ` Tejun Heo
2009-03-31  1:34                   ` Rusty Russell
2009-03-31 22:57                     ` David Miller
2009-03-31 23:49                     ` Benjamin Herrenschmidt
2009-04-01  0:19                       ` Tejun Heo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1236671631-9305-4-git-send-email-tj@kernel.org \
    --to=tj@kernel.org \
    --cc=benh@kernel.crashing.org \
    --cc=cooloney@kernel.org \
    --cc=davem@davemloft.net \
    --cc=grundler@parisc-linux.org \
    --cc=heiko.carstens@de.ibm.com \
    --cc=hpa@zytor.com \
    --cc=ink@jurassic.park.msu.ru \
    --cc=kyle@mcmartin.ca \
    --cc=lethal@linux-sh.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthew@wil.cx \
    --cc=mingo@elte.hu \
    --cc=ralf@linux-mips.org \
    --cc=rmk@arm.linux.org.uk \
    --cc=rth@twiddle.net \
    --cc=rusty@rustcorp.com.au \
    --cc=schwidefsky@de.ibm.com \
    --cc=starvik@axis.com \
    --cc=takata@linux-m32r.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.