public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] module: kzalloc mod->ref
@ 2009-01-14  3:35 Kyle McMartin
  2009-01-14  5:54 ` [PATCHv2] " Kyle McMartin
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Kyle McMartin @ 2009-01-14  3:35 UTC (permalink / raw)
  To: rusty; +Cc: linux-kernel

From: Kyle McMartin <kyle@redhat.com>

Dynamically allocate mod->ref instead of fixing it in the struct module.
Reduces on disk space wasted in the module .ko, and kills a loop
initializing the local_t it contains since we can just kzalloc it.

This matters when we're talking about large NR_CPUS.

Signed-off-by: Kyle McMartin <kyle@redhat.com>
---
The patch removing cacheline_aligned from struct module_ref should be
applied as well to cut down on the amount of memory we allocate. This
patch makes a nice stopgap until we have per_cpu module references.

cheers, Kyle

diff --git a/include/linux/module.h b/include/linux/module.h
index 4f7ea12..5863998 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -345,7 +345,7 @@ struct module
 	void (*exit)(void);
 
 	/* Reference counts */
-	struct module_ref ref[NR_CPUS];
+	struct module_ref *ref;
 #endif
 };
 #ifndef MODULE_ARCH_INIT
diff --git a/kernel/module.c b/kernel/module.c
index c9332c9..bc0a9b0 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -571,17 +571,19 @@ static char last_unloaded_module[MODULE_NAME_LEN+1];
 
 #ifdef CONFIG_MODULE_UNLOAD
 /* Init the unload section of the module. */
-static void module_unload_init(struct module *mod)
+static int module_unload_init(struct module *mod)
 {
-	unsigned int i;
+	mod->ref = kzalloc(NR_CPUS * sizeof(*mod->ref), GFP_KERNEL);
+	if (!mod->ref)
+		return -ENOMEM;
 
 	INIT_LIST_HEAD(&mod->modules_which_use_me);
-	for (i = 0; i < NR_CPUS; i++)
-		local_set(&mod->ref[i].count, 0);
 	/* Hold reference count during initialization. */
 	local_set(&mod->ref[raw_smp_processor_id()].count, 1);
 	/* Backwards compatibility macros put refcount during init. */
 	mod->waiter = current;
+
+	return 0;
 }
 
 /* modules using other modules */
@@ -919,8 +921,9 @@ static inline int use_module(struct module *a, struct module *b)
 	return strong_try_module_get(b) == 0;
 }
 
-static inline void module_unload_init(struct module *mod)
+static inline int module_unload_init(struct module *mod)
 {
+	return 0;
 }
 #endif /* CONFIG_MODULE_UNLOAD */
 
@@ -2071,7 +2074,9 @@ static noinline struct module *load_module(void __user *umod,
 	mod = (void *)sechdrs[modindex].sh_addr;
 
 	/* Now we've moved module, initialize linked lists, etc. */
-	module_unload_init(mod);
+	err = module_unload_init(mod);
+	if (err < 0)
+		goto free_unload;
 
 	/* add kobject, so we can reference it. */
 	err = mod_sysfs_init(mod);

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

end of thread, other threads:[~2009-01-28 12:25 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-14  3:35 [PATCH] module: kzalloc mod->ref Kyle McMartin
2009-01-14  5:54 ` [PATCHv2] " Kyle McMartin
2009-01-14  9:09 ` [PATCH] " Takashi Iwai
2009-01-14 15:58   ` Kyle McMartin
2009-01-14 16:25     ` Takashi Iwai
2009-01-14 19:29       ` Valdis.Kletnieks
2009-01-14 20:37         ` Takashi Iwai
2009-01-14 20:53           ` Kyle McMartin
2009-01-14 17:51     ` richard kennedy
2009-01-14 18:17       ` Kyle McMartin
     [not found]         ` <200901151303.20006.rusty@rustcorp.com.au>
2009-01-25 15:52           ` Richard Kennedy
     [not found]   ` <200901151521.47326.rusty@rustcorp.com.au>
2009-01-15  6:03     ` Kyle McMartin
     [not found]     ` <200901261751.21817.rusty@rustcorp.com.au>
2009-01-27  1:36       ` Rusty Russell
2009-01-27  1:58         ` Tejun Heo
2009-01-27 13:15         ` Ingo Molnar
2009-01-28 12:24           ` Rusty Russell
2009-01-14 10:15 ` richard kennedy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox