Skip to content

Commit

Permalink
ipc: delete seq_max field in struct ipc_ids
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Jonathan Gonzalez <[email protected]>
Cc: Aswin Chandramouleeswaran <[email protected]>
Cc: Rik van Riel <[email protected]>
Acked-by: Manfred Spraul <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Davidlohr Bueso authored and torvalds committed Jan 28, 2014
1 parent 8dc5cd0 commit daf948c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 12 deletions.
1 change: 0 additions & 1 deletion include/linux/ipc_namespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ struct user_namespace;
struct ipc_ids {
int in_use;
unsigned short seq;
unsigned short seq_max;
struct rw_semaphore rwsem;
struct idr ipcs_idr;
int next_id;
Expand Down
13 changes: 2 additions & 11 deletions ipc/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,10 @@ __initcall(ipc_init);
*/
void ipc_init_ids(struct ipc_ids *ids)
{
init_rwsem(&ids->rwsem);

ids->in_use = 0;
ids->seq = 0;
ids->next_id = -1;
{
int seq_limit = INT_MAX/SEQ_MULTIPLIER;
if (seq_limit > USHRT_MAX)
ids->seq_max = USHRT_MAX;
else
ids->seq_max = seq_limit;
}

init_rwsem(&ids->rwsem);
idr_init(&ids->ipcs_idr);
}

Expand Down Expand Up @@ -304,7 +295,7 @@ int ipc_addid(struct ipc_ids *ids, struct kern_ipc_perm *new, int size)

if (next_id < 0) {
new->seq = ids->seq++;
if (ids->seq > ids->seq_max)
if (ids->seq > IPCID_SEQ_MAX)
ids->seq = 0;
} else {
new->seq = ipcid_to_seqx(next_id);
Expand Down
1 change: 1 addition & 0 deletions ipc/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ void __init ipc_init_proc_interface(const char *path, const char *header,

#define ipcid_to_idx(id) ((id) % SEQ_MULTIPLIER)
#define ipcid_to_seqx(id) ((id) / SEQ_MULTIPLIER)
#define IPCID_SEQ_MAX min_t(int, INT_MAX/SEQ_MULTIPLIER, USHRT_MAX)

/* must be called with ids->rwsem acquired for writing */
int ipc_addid(struct ipc_ids *, struct kern_ipc_perm *, int);
Expand Down

0 comments on commit daf948c

Please sign in to comment.