Skip to content

Commit bd77c04

Browse files
Eric Dumazetrustyrussell
authored andcommitted
module: struct module_ref should contains long fields
module_ref contains two "unsigned int" fields. Thats now too small, since some machines can open more than 2^32 files. Check commit 518de9b (fs: allow for more than 2^31 files) for reference. We can add an aligned(2 * sizeof(unsigned long)) attribute to force alloc_percpu() allocating module_ref areas in single cache lines. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> CC: Rusty Russell <rusty@rustcorp.com.au> CC: Tejun Heo <tj@kernel.org> CC: Robin Holt <holt@sgi.com> CC: David Miller <davem@davemloft.net> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 48fd118 commit bd77c04

3 files changed

Lines changed: 21 additions & 10 deletions

File tree

‎include/linux/module.h‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,20 @@ enum module_state
205205
MODULE_STATE_GOING,
206206
};
207207

208+
/**
209+
* struct module_ref - per cpu module reference counts
210+
* @incs: number of module get on this cpu
211+
* @decs: number of module put on this cpu
212+
*
213+
* We force an alignment on 8 or 16 bytes, so that alloc_percpu()
214+
* put @incs/@decs in same cache line, with no extra memory cost,
215+
* since alloc_percpu() is fine grained.
216+
*/
217+
struct module_ref {
218+
unsigned long incs;
219+
unsigned long decs;
220+
} __attribute((aligned(2 * sizeof(unsigned long))));
221+
208222
struct module
209223
{
210224
enum module_state state;
@@ -347,10 +361,7 @@ struct module
347361
/* Destruction function. */
348362
void (*exit)(void);
349363

350-
struct module_ref {
351-
unsigned int incs;
352-
unsigned int decs;
353-
} __percpu *refptr;
364+
struct module_ref __percpu *refptr;
354365
#endif
355366

356367
#ifdef CONFIG_CONSTRUCTORS
@@ -434,7 +445,7 @@ extern void __module_put_and_exit(struct module *mod, long code)
434445
#define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code);
435446

436447
#ifdef CONFIG_MODULE_UNLOAD
437-
unsigned int module_refcount(struct module *mod);
448+
unsigned long module_refcount(struct module *mod);
438449
void __symbol_put(const char *symbol);
439450
#define symbol_put(x) __symbol_put(MODULE_SYMBOL_PREFIX #x)
440451
void symbol_put_addr(void *addr);

‎kernel/debug/kdb/kdb_main.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1982,7 +1982,7 @@ static int kdb_lsmod(int argc, const char **argv)
19821982
kdb_printf("%-20s%8u 0x%p ", mod->name,
19831983
mod->core_size, (void *)mod);
19841984
#ifdef CONFIG_MODULE_UNLOAD
1985-
kdb_printf("%4d ", module_refcount(mod));
1985+
kdb_printf("%4ld ", module_refcount(mod));
19861986
#endif
19871987
if (mod->state == MODULE_STATE_GOING)
19881988
kdb_printf(" (Unloading)");

‎kernel/module.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -725,9 +725,9 @@ static int try_stop_module(struct module *mod, int flags, int *forced)
725725
}
726726
}
727727

728-
unsigned int module_refcount(struct module *mod)
728+
unsigned long module_refcount(struct module *mod)
729729
{
730-
unsigned int incs = 0, decs = 0;
730+
unsigned long incs = 0, decs = 0;
731731
int cpu;
732732

733733
for_each_possible_cpu(cpu)
@@ -853,7 +853,7 @@ static inline void print_unload_info(struct seq_file *m, struct module *mod)
853853
struct module_use *use;
854854
int printed_something = 0;
855855

856-
seq_printf(m, " %u ", module_refcount(mod));
856+
seq_printf(m, " %lu ", module_refcount(mod));
857857

858858
/* Always include a trailing , so userspace can differentiate
859859
between this and the old multi-field proc format. */
@@ -903,7 +903,7 @@ EXPORT_SYMBOL_GPL(symbol_put_addr);
903903
static ssize_t show_refcnt(struct module_attribute *mattr,
904904
struct module_kobject *mk, char *buffer)
905905
{
906-
return sprintf(buffer, "%u\n", module_refcount(mk->mod));
906+
return sprintf(buffer, "%lu\n", module_refcount(mk->mod));
907907
}
908908

909909
static struct module_attribute refcnt = {

0 commit comments

Comments
 (0)