Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ipc: delete seq_max field in struct ipc_ids

This field is only used to reset the ids seq number if it exceeds the
smaller of INT_MAX/SEQ_MULTIPLIER and USHRT_MAX, and can therefore be
moved out of the structure and into its own macro. Since each
ipc_namespace contains a table of 3 pointers to struct ipc_ids we can
save space in instruction text:

text data bss dec hex filename
56232 2348 24 58604 e4ec ipc/built-in.o
56216 2348 24 58588 e4dc ipc/built-in.o-after

Signed-off-by: Davidlohr Bueso <davidlohr@hp.com>
Reviewed-by: Jonathan Gonzalez <jgonzalez@linets.cl>
Cc: Aswin Chandramouleeswaran <aswin@hp.com>
Cc: Rik van Riel <riel@redhat.com>
Acked-by: Manfred Spraul <manfred@colorfullife.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Davidlohr Bueso and committed by
Linus Torvalds
daf948c7 8dc5cd04

+3 -12
-1
include/linux/ipc_namespace.h
··· 21 21 struct ipc_ids { 22 22 int in_use; 23 23 unsigned short seq; 24 - unsigned short seq_max; 25 24 struct rw_semaphore rwsem; 26 25 struct idr ipcs_idr; 27 26 int next_id;
+2 -11
ipc/util.c
··· 139 139 */ 140 140 void ipc_init_ids(struct ipc_ids *ids) 141 141 { 142 - init_rwsem(&ids->rwsem); 143 - 144 142 ids->in_use = 0; 145 143 ids->seq = 0; 146 144 ids->next_id = -1; 147 - { 148 - int seq_limit = INT_MAX/SEQ_MULTIPLIER; 149 - if (seq_limit > USHRT_MAX) 150 - ids->seq_max = USHRT_MAX; 151 - else 152 - ids->seq_max = seq_limit; 153 - } 154 - 145 + init_rwsem(&ids->rwsem); 155 146 idr_init(&ids->ipcs_idr); 156 147 } 157 148 ··· 295 304 296 305 if (next_id < 0) { 297 306 new->seq = ids->seq++; 298 - if (ids->seq > ids->seq_max) 307 + if (ids->seq > IPCID_SEQ_MAX) 299 308 ids->seq = 0; 300 309 } else { 301 310 new->seq = ipcid_to_seqx(next_id);
+1
ipc/util.h
··· 100 100 101 101 #define ipcid_to_idx(id) ((id) % SEQ_MULTIPLIER) 102 102 #define ipcid_to_seqx(id) ((id) / SEQ_MULTIPLIER) 103 + #define IPCID_SEQ_MAX min_t(int, INT_MAX/SEQ_MULTIPLIER, USHRT_MAX) 103 104 104 105 /* must be called with ids->rwsem acquired for writing */ 105 106 int ipc_addid(struct ipc_ids *, struct kern_ipc_perm *, int);