aboutsummaryrefslogtreecommitdiffstats
path: root/ipc/shm.c
diff options
context:
space:
mode:
authorPierre Peiffer <pierre.peiffer@bull.net>2008-02-08 07:18:57 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2008-02-08 12:22:26 -0500
commited2ddbf88c0ddeeae4c78bb306a116dfd867c55c (patch)
treede6d6828c03f98be6fc41e8acf3b3e52df28be9b /ipc/shm.c
parent4b9fcb0ec60584d639ad105c42b75a3447071e47 (diff)
IPC: make struct ipc_ids static in ipc_namespace
Each ipc_namespace contains a table of 3 pointers to struct ipc_ids (3 for msg, sem and shm, structure used to store all ipcs) These 'struct ipc_ids' are dynamically allocated for each icp_namespace as the ipc_namespace itself (for the init namespace, they are initialized with pointers to static variables instead) It is so for historical reason: in fact, before the use of idr to store the ipcs, the ipcs were stored in tables of variable length, depending of the maximum number of ipc allowed. Now, these 'struct ipc_ids' have a fixed size. As they are allocated in any cases for each new ipc_namespace, there is no gain of memory in having them allocated separately of the struct ipc_namespace. This patch proposes to make this table static in the struct ipc_namespace. Thus, we can allocate all in once and get rid of all the code needed to allocate and free these ipc_ids separately. Signed-off-by: Pierre Peiffer <pierre.peiffer@bull.net> Acked-by: Cedric Le Goater <clg@fr.ibm.com> Cc: Pavel Emelyanov <xemul@openvz.org> Cc: Nadia Derbey <Nadia.Derbey@bull.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'ipc/shm.c')
-rw-r--r--ipc/shm.c26
1 files changed, 4 insertions, 22 deletions
diff --git a/ipc/shm.c b/ipc/shm.c
index 07f4b7abc80a..fe92471e19c7 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -56,9 +56,7 @@ struct shm_file_data {
56static const struct file_operations shm_file_operations; 56static const struct file_operations shm_file_operations;
57static struct vm_operations_struct shm_vm_ops; 57static struct vm_operations_struct shm_vm_ops;
58 58
59static struct ipc_ids init_shm_ids; 59#define shm_ids(ns) ((ns)->ids[IPC_SHM_IDS])
60
61#define shm_ids(ns) (*((ns)->ids[IPC_SHM_IDS]))
62 60
63#define shm_unlock(shp) \ 61#define shm_unlock(shp) \
64 ipc_unlock(&(shp)->shm_perm) 62 ipc_unlock(&(shp)->shm_perm)
@@ -72,14 +70,13 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
72static int sysvipc_shm_proc_show(struct seq_file *s, void *it); 70static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
73#endif 71#endif
74 72
75static void __shm_init_ns(struct ipc_namespace *ns, struct ipc_ids *ids) 73void shm_init_ns(struct ipc_namespace *ns)
76{ 74{
77 ns->ids[IPC_SHM_IDS] = ids;
78 ns->shm_ctlmax = SHMMAX; 75 ns->shm_ctlmax = SHMMAX;
79 ns->shm_ctlall = SHMALL; 76 ns->shm_ctlall = SHMALL;
80 ns->shm_ctlmni = SHMMNI; 77 ns->shm_ctlmni = SHMMNI;
81 ns->shm_tot = 0; 78 ns->shm_tot = 0;
82 ipc_init_ids(ids); 79 ipc_init_ids(&ns->ids[IPC_SHM_IDS]);
83} 80}
84 81
85/* 82/*
@@ -98,18 +95,6 @@ static void do_shm_rmid(struct ipc_namespace *ns, struct shmid_kernel *shp)
98} 95}
99 96
100#ifdef CONFIG_IPC_NS 97#ifdef CONFIG_IPC_NS
101int shm_init_ns(struct ipc_namespace *ns)
102{
103 struct ipc_ids *ids;
104
105 ids = kmalloc(sizeof(struct ipc_ids), GFP_KERNEL);
106 if (ids == NULL)
107 return -ENOMEM;
108
109 __shm_init_ns(ns, ids);
110 return 0;
111}
112
113void shm_exit_ns(struct ipc_namespace *ns) 98void shm_exit_ns(struct ipc_namespace *ns)
114{ 99{
115 struct shmid_kernel *shp; 100 struct shmid_kernel *shp;
@@ -131,15 +116,12 @@ void shm_exit_ns(struct ipc_namespace *ns)
131 total++; 116 total++;
132 } 117 }
133 up_write(&shm_ids(ns).rw_mutex); 118 up_write(&shm_ids(ns).rw_mutex);
134
135 kfree(ns->ids[IPC_SHM_IDS]);
136 ns->ids[IPC_SHM_IDS] = NULL;
137} 119}
138#endif 120#endif
139 121
140void __init shm_init (void) 122void __init shm_init (void)
141{ 123{
142 __shm_init_ns(&init_ipc_ns, &init_shm_ids); 124 shm_init_ns(&init_ipc_ns);
143 ipc_init_proc_interface("sysvipc/shm", 125 ipc_init_proc_interface("sysvipc/shm",
144 " key shmid perms size cpid lpid nattch uid gid cuid cgid atime dtime ctime\n", 126 " key shmid perms size cpid lpid nattch uid gid cuid cgid atime dtime ctime\n",
145 IPC_SHM_IDS, sysvipc_shm_proc_show); 127 IPC_SHM_IDS, sysvipc_shm_proc_show);