From: Stanislav Kinsbursky <skinsbursky@parallels.com>
To: akpm@linux-foundation.org
Cc: serge.hallyn@canonical.com, ebiederm@xmission.com,
linux-kernel@vger.kernel.org, xemul@parallels.com,
catalin.marinas@arm.com, will.deacon@arm.com, jmorris@namei.org,
cmetcalf@tilera.com, joe.korty@ccur.com, dhowells@redhat.com,
dledford@redhat.com, viro@zeniv.linux.org.uk,
kosaki.motohiro@jp.fujitsu.com, linux-api@vger.kernel.org,
serue@us.ibm.com, tglx@linutronix.de, paulmck@linux.vnet.ibm.com,
devel@openvz.org, mtk.manpages@gmail.com
Subject: [PATCH v8 2/5] ipc: add sysctl to specify desired next object id
Date: Wed, 24 Oct 2012 19:35:09 +0400 [thread overview]
Message-ID: <20121024153509.5642.76385.stgit@localhost.localdomain> (raw)
In-Reply-To: <20121024151555.5642.79086.stgit@localhost.localdomain>
This patch adds 3 new variables and sysctls to tune them (by one "next_id"
variable for messages, semaphores and shared memory respectively).
This variable can be used to set desired id for next allocated IPC object.
By default it's equal to -1 and old behaviour is preserved.
If this variable is non-negative, then desired idr will be extracted from it
and used as a start value to search for free IDR slot.
Notes:
1) this patch doesn't garantee, that new object will have desired id. So it's
up to user space how to handle new object with wrong id.
2) After sucessfull id allocation attempt, "next_id" will be set back to -1
(if it was non-negative).
Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com>
---
include/linux/ipc_namespace.h | 1 +
ipc/ipc_sysctl.c | 28 ++++++++++++++++++++++++++++
ipc/util.c | 16 ++++++++++++----
ipc/util.h | 1 +
4 files changed, 42 insertions(+), 4 deletions(-)
diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
index 5499c92..8704e40 100644
--- a/include/linux/ipc_namespace.h
+++ b/include/linux/ipc_namespace.h
@@ -24,6 +24,7 @@ struct ipc_ids {
unsigned short seq_max;
struct rw_semaphore rw_mutex;
struct idr ipcs_idr;
+ int next_id;
};
struct ipc_namespace {
diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
index 00fba2b..d06d77a 100644
--- a/ipc/ipc_sysctl.c
+++ b/ipc/ipc_sysctl.c
@@ -158,6 +158,7 @@ static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
static int zero;
static int one = 1;
+static int int_max = INT_MAX;
static struct ctl_table ipc_kern_table[] = {
{
@@ -227,6 +228,33 @@ static struct ctl_table ipc_kern_table[] = {
.extra1 = &zero,
.extra2 = &one,
},
+ {
+ .procname = "sem_next_id",
+ .data = &init_ipc_ns.ids[IPC_SEM_IDS].next_id,
+ .maxlen = sizeof(init_ipc_ns.ids[IPC_SEM_IDS].next_id),
+ .mode = 0644,
+ .proc_handler = proc_ipc_dointvec_minmax,
+ .extra1 = &zero,
+ .extra2 = &int_max,
+ },
+ {
+ .procname = "msg_next_id",
+ .data = &init_ipc_ns.ids[IPC_MSG_IDS].next_id,
+ .maxlen = sizeof(init_ipc_ns.ids[IPC_MSG_IDS].next_id),
+ .mode = 0644,
+ .proc_handler = proc_ipc_dointvec_minmax,
+ .extra1 = &zero,
+ .extra2 = &int_max,
+ },
+ {
+ .procname = "shm_next_id",
+ .data = &init_ipc_ns.ids[IPC_SHM_IDS].next_id,
+ .maxlen = sizeof(init_ipc_ns.ids[IPC_SHM_IDS].next_id),
+ .mode = 0644,
+ .proc_handler = proc_ipc_dointvec_minmax,
+ .extra1 = &zero,
+ .extra2 = &int_max,
+ },
{}
};
diff --git a/ipc/util.c b/ipc/util.c
index 72fd078..a961e46 100644
--- a/ipc/util.c
+++ b/ipc/util.c
@@ -122,6 +122,7 @@ void ipc_init_ids(struct ipc_ids *ids)
ids->in_use = 0;
ids->seq = 0;
+ ids->next_id = -1;
{
int seq_limit = INT_MAX/SEQ_MULTIPLIER;
if (seq_limit > USHRT_MAX)
@@ -252,6 +253,7 @@ int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size)
kuid_t euid;
kgid_t egid;
int id, err;
+ int next_id = ids->next_id;
if (size > IPCMNI)
size = IPCMNI;
@@ -264,7 +266,8 @@ int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size)
rcu_read_lock();
spin_lock(&new->lock);
- err = idr_get_new(&ids->ipcs_idr, new, &id);
+ err = idr_get_new_above(&ids->ipcs_idr, new,
+ (next_id < 0) ? 0 : ipcid_to_idx(next_id), &id);
if (err) {
spin_unlock(&new->lock);
rcu_read_unlock();
@@ -277,9 +280,14 @@ int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size)
new->cuid = new->uid = euid;
new->gid = new->cgid = egid;
- new->seq = ids->seq++;
- if(ids->seq > ids->seq_max)
- ids->seq = 0;
+ if (next_id < 0) {
+ new->seq = ids->seq++;
+ if(ids->seq > ids->seq_max)
+ ids->seq = 0;
+ } else {
+ new->seq = ipcid_to_seqx(next_id);
+ ids->next_id = -1;
+ }
new->id = ipc_buildid(id, new->seq);
return id;
diff --git a/ipc/util.h b/ipc/util.h
index c8fe2f7..a61e0ca 100644
--- a/ipc/util.h
+++ b/ipc/util.h
@@ -92,6 +92,7 @@ void __init ipc_init_proc_interface(const char *path, const char *header,
#define IPC_SHM_IDS 2
#define ipcid_to_idx(id) ((id) % SEQ_MULTIPLIER)
+#define ipcid_to_seqx(id) ((id) / SEQ_MULTIPLIER)
/* must be called with ids->rw_mutex acquired for writing */
int ipc_addid(struct ipc_ids *, struct kern_ipc_perm *, int);
next prev parent reply other threads:[~2012-10-24 15:35 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-24 15:34 [RFC PATCH v8 0/5] IPC: checkpoint/restore in userspace enhancements Stanislav Kinsbursky
[not found] ` <20121024151555.5642.79086.stgit-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2012-10-24 15:35 ` [PATCH v8 1/5] ipc: remove forced assignment of selected message Stanislav Kinsbursky
2012-10-24 21:42 ` [RFC PATCH v8 0/5] IPC: checkpoint/restore in userspace enhancements Andrew Morton
2012-12-18 20:36 ` Andrew Morton
[not found] ` <20121218123601.113a29c0.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2012-12-20 4:06 ` Stanislav Kinsbursky
[not found] ` <50D28EC8.7000708-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2012-12-20 20:47 ` Andrew Morton
[not found] ` <20121220124751.d7ccbd8e.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2012-12-21 20:46 ` Stanislav Kinsbursky
[not found] ` <50D4CA90.60205-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2012-12-21 21:57 ` Sasha Levin
[not found] ` <50D4DB5D.9020309-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2012-12-22 15:43 ` Sasha Levin
[not found] ` <50D5D50B.8090309-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2013-01-09 8:24 ` Stanislav Kinsbursky
2013-01-14 6:31 ` Sasha Levin
2012-10-24 15:35 ` Stanislav Kinsbursky [this message]
2012-10-24 21:41 ` [PATCH v8 2/5] ipc: add sysctl to specify desired next object id Andrew Morton
[not found] ` <20121024144123.0a77584b.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2012-10-25 7:53 ` Stanislav Kinsbursky
2012-10-24 15:35 ` [PATCH v8 3/5] ipc: message queue receive cleanup Stanislav Kinsbursky
2012-10-24 15:35 ` [PATCH v8 4/5] ipc: message queue copy feature introduced Stanislav Kinsbursky
2012-10-24 21:41 ` Andrew Morton
2012-10-24 15:35 ` [PATCH v8 5/5] test: IPC message queue copy feture test Stanislav Kinsbursky
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=20121024153509.5642.76385.stgit@localhost.localdomain \
--to=skinsbursky@parallels.com \
--cc=akpm@linux-foundation.org \
--cc=catalin.marinas@arm.com \
--cc=cmetcalf@tilera.com \
--cc=devel@openvz.org \
--cc=dhowells@redhat.com \
--cc=dledford@redhat.com \
--cc=ebiederm@xmission.com \
--cc=jmorris@namei.org \
--cc=joe.korty@ccur.com \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mtk.manpages@gmail.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=serge.hallyn@canonical.com \
--cc=serue@us.ibm.com \
--cc=tglx@linutronix.de \
--cc=viro@zeniv.linux.org.uk \
--cc=will.deacon@arm.com \
--cc=xemul@parallels.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;
as well as URLs for NNTP newsgroup(s).