diff options
author | Nadia Derbey <Nadia.Derbey@bull.net> | 2008-04-29 04:00:39 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-04-29 11:06:12 -0400 |
commit | f7bf3df8be72d98afa84f5ff183e14c1ba1e560d (patch) | |
tree | 7946f8b139da1690508f11347929a9bd31f12429 /ipc/msg.c | |
parent | 48dea404ed01869313f1908cca8a15774dcd8ee5 (diff) |
ipc: scale msgmni to the amount of lowmem
On large systems we'd like to allow a larger number of message queues. In
some cases up to 32K. However simply setting MSGMNI to a larger value may
cause problems for smaller systems.
The first patch of this series introduces a default maximum number of message
queue ids that scales with the amount of lowmem.
Since msgmni is per namespace and there is no amount of memory dedicated to
each namespace so far, the second patch of this series scales msgmni to the
number of ipc namespaces too.
Since msgmni depends on the amount of memory, it becomes necessary to
recompute it upon memory add/remove. In the 4th patch, memory hotplug
management is added: a notifier block is registered into the memory hotplug
notifier chain for the ipc subsystem. Since the ipc namespaces are not linked
together, they have their own notification chain: one notifier_block is
defined per ipc namespace. Each time an ipc namespace is created (removed) it
registers (unregisters) its notifier block in (from) the ipcns chain. The
callback routine registered in the memory chain invokes the ipcns notifier
chain with the IPCNS_MEMCHANGE event. Each callback routine registered in the
ipcns namespace, in turn, recomputes msgmni for the owning namespace.
The 5th patch makes it possible to keep the memory hotplug notifier chain's
lock for a lesser amount of time: instead of directly notifying the ipcns
notifier chain upon memory add/remove, a work item is added to the global
workqueue. When activated, this work item is the one who notifies the ipcns
notifier chain.
Since msgmni depends on the number of ipc namespaces, it becomes necessary to
recompute it upon ipc namespace creation / removal. The 6th patch uses the
ipc namespace notifier chain for that purpose: that chain is notified each
time an ipc namespace is created or removed. This makes it possible to
recompute msgmni for all the namespaces each time one of them is created or
removed.
When msgmni is explicitely set from userspace, we should avoid recomputing it
upon memory add/remove or ipcns creation/removal. This is what the 7th patch
does: it simply unregisters the ipcns callback routine as soon as msgmni has
been changed from procfs or sysctl().
Even if msgmni is set by hand, it should be possible to make it back
automatically recomputed upon memory add/remove or ipcns creation/removal.
This what is achieved in patch 8: if set to a negative value, msgmni is added
back to the ipcns notifier chain, making it automatically recomputed again.
This patch:
Compute msg_ctlmni to make it scale with the amount of lowmem. msg_ctlmni is
now set to make the message queues occupy 1/32 of the available lowmem.
Some cleaning has also been done for the MSGPOOL constant: the msgctl man page
says it's not used, but it also defines it as a size in bytes (the code
expresses it in Kbytes).
Signed-off-by: Nadia Derbey <Nadia.Derbey@bull.net>
Cc: Yasunori Goto <y-goto@jp.fujitsu.com>
Cc: Matt Helsley <matthltc@us.ibm.com>
Cc: Mingming Cao <cmm@us.ibm.com>
Cc: Pierre Peiffer <pierre.peiffer@bull.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'ipc/msg.c')
-rw-r--r-- | ipc/msg.c | 37 |
1 files changed, 36 insertions, 1 deletions
@@ -27,6 +27,7 @@ | |||
27 | #include <linux/msg.h> | 27 | #include <linux/msg.h> |
28 | #include <linux/spinlock.h> | 28 | #include <linux/spinlock.h> |
29 | #include <linux/init.h> | 29 | #include <linux/init.h> |
30 | #include <linux/mm.h> | ||
30 | #include <linux/proc_fs.h> | 31 | #include <linux/proc_fs.h> |
31 | #include <linux/list.h> | 32 | #include <linux/list.h> |
32 | #include <linux/security.h> | 33 | #include <linux/security.h> |
@@ -77,11 +78,45 @@ static int newque(struct ipc_namespace *, struct ipc_params *); | |||
77 | static int sysvipc_msg_proc_show(struct seq_file *s, void *it); | 78 | static int sysvipc_msg_proc_show(struct seq_file *s, void *it); |
78 | #endif | 79 | #endif |
79 | 80 | ||
81 | /* | ||
82 | * Scale msgmni with the available lowmem size: the memory dedicated to msg | ||
83 | * queues should occupy at most 1/MSG_MEM_SCALE of lowmem. | ||
84 | * This should be done staying within the (MSGMNI , IPCMNI) range. | ||
85 | */ | ||
86 | static void recompute_msgmni(struct ipc_namespace *ns) | ||
87 | { | ||
88 | struct sysinfo i; | ||
89 | unsigned long allowed; | ||
90 | |||
91 | si_meminfo(&i); | ||
92 | allowed = (((i.totalram - i.totalhigh) / MSG_MEM_SCALE) * i.mem_unit) | ||
93 | / MSGMNB; | ||
94 | |||
95 | if (allowed < MSGMNI) { | ||
96 | ns->msg_ctlmni = MSGMNI; | ||
97 | goto out_callback; | ||
98 | } | ||
99 | |||
100 | if (allowed > IPCMNI) { | ||
101 | ns->msg_ctlmni = IPCMNI; | ||
102 | goto out_callback; | ||
103 | } | ||
104 | |||
105 | ns->msg_ctlmni = allowed; | ||
106 | |||
107 | out_callback: | ||
108 | |||
109 | printk(KERN_INFO "msgmni has been set to %d for ipc namespace %p\n", | ||
110 | ns->msg_ctlmni, ns); | ||
111 | } | ||
112 | |||
80 | void msg_init_ns(struct ipc_namespace *ns) | 113 | void msg_init_ns(struct ipc_namespace *ns) |
81 | { | 114 | { |
82 | ns->msg_ctlmax = MSGMAX; | 115 | ns->msg_ctlmax = MSGMAX; |
83 | ns->msg_ctlmnb = MSGMNB; | 116 | ns->msg_ctlmnb = MSGMNB; |
84 | ns->msg_ctlmni = MSGMNI; | 117 | |
118 | recompute_msgmni(ns); | ||
119 | |||
85 | atomic_set(&ns->msg_bytes, 0); | 120 | atomic_set(&ns->msg_bytes, 0); |
86 | atomic_set(&ns->msg_hdrs, 0); | 121 | atomic_set(&ns->msg_hdrs, 0); |
87 | ipc_init_ids(&ns->ids[IPC_MSG_IDS]); | 122 | ipc_init_ids(&ns->ids[IPC_MSG_IDS]); |