mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Davidlohr Bueso <davidlohr@hp.com>
To: akpm@linux-foundation.org, manfred@colorfullife.com
Cc: riel@redhat.com, aswin@hp.com, davidlohr@hp.com,
	linux-kernel@vger.kernel.org
Subject: [PATCH 5/7] ipc: delete seq_max field in struct ipc_ids
Date: Fri, 10 Jan 2014 10:48:25 -0800	[thread overview]
Message-ID: <1389379707-20298-6-git-send-email-davidlohr@hp.com> (raw)
In-Reply-To: <1389379707-20298-1-git-send-email-davidlohr@hp.com>

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

Reviewed-by: Jonathan Gonzalez <jgonzalez@linets.cl>
Signed-off-by: Davidlohr Bueso <davidlohr@hp.com>
---
 include/linux/ipc_namespace.h |  1 -
 ipc/util.c                    | 13 ++-----------
 ipc/util.h                    |  1 +
 3 files changed, 3 insertions(+), 12 deletions(-)

diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
index f6c82de..e7831d2 100644
--- a/include/linux/ipc_namespace.h
+++ b/include/linux/ipc_namespace.h
@@ -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;
diff --git a/ipc/util.c b/ipc/util.c
index cecb46e..e1b4c6d 100644
--- a/ipc/util.c
+++ b/ipc/util.c
@@ -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);
 }
 
@@ -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);
diff --git a/ipc/util.h b/ipc/util.h
index d64db3e..9c47d6f 100644
--- a/ipc/util.h
+++ b/ipc/util.h
@@ -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);
-- 
1.8.1.4


  parent reply	other threads:[~2014-01-10 18:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-10 18:48 [PATCH -next 0/7] ipc: some misc updates & optimizations Davidlohr Bueso
2014-01-10 18:48 ` [PATCH 1/7] ipc: standardize code comments Davidlohr Bueso
2014-01-10 18:48 ` [PATCH 2/7] ipc: remove braces for single statements Davidlohr Bueso
2014-01-10 18:48 ` [PATCH 3/7] ipc: remove useless return statement Davidlohr Bueso
2014-01-10 18:48 ` [PATCH 4/7] ipc: simplify sysvipc_proc_open return Davidlohr Bueso
2014-01-10 18:48 ` Davidlohr Bueso [this message]
2014-01-10 18:48 ` [PATCH 6/7] ipc: share ids rwsem when possible in ipcget_public Davidlohr Bueso
2014-01-10 18:48 ` [PATCH 7/7] ipc,msg: document barriers Davidlohr Bueso
2014-01-11  4:18   ` Mike Galbraith
2014-01-11  9:02 ` [PATCH -next 0/7] ipc: some misc updates & optimizations Manfred Spraul
2014-01-11 17:54   ` Davidlohr Bueso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1389379707-20298-6-git-send-email-davidlohr@hp.com \
    --to=davidlohr@hp.com \
    --cc=akpm@linux-foundation.org \
    --cc=aswin@hp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=manfred@colorfullife.com \
    --cc=riel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®