Skip to content

Commit cef0184

Browse files
kosakitorvalds
authored andcommitted
mqueue: separate mqueue default value from maximum value
Commit b231cca ("message queues: increase range limits") changed mqueue default value when attr parameter is specified NULL from hard coded value to fs.mqueue.{msg,msgsize}_max sysctl value. This made large side effect. When user need to use two mqueue applications 1) using !NULL attr parameter and it require big message size and 2) using NULL attr parameter and only need small size message, app (1) require to raise fs.mqueue.msgsize_max and app (2) consume large memory size even though it doesn't need. Doug Ledford propsed to switch back it to static hard coded value. However it also has a compatibility problem. Some applications might started depend on the default value is tunable. The solution is to separate default value from maximum value. Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Signed-off-by: Doug Ledford <dledford@redhat.com> Acked-by: Doug Ledford <dledford@redhat.com> Acked-by: Joe Korty <joe.korty@ccur.com> Cc: Amerigo Wang <amwang@redhat.com> Acked-by: Serge E. Hallyn <serue@us.ibm.com> Cc: Jiri Slaby <jslaby@suse.cz> Cc: Manfred Spraul <manfred@colorfullife.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent fd1f87d commit cef0184

4 files changed

Lines changed: 33 additions & 3 deletions

File tree

‎Documentation/sysctl/fs.txt‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,13 @@ a queue must be less or equal then msg_max.
225225
maximum message size value (it is every message queue's attribute set during
226226
its creation).
227227

228+
/proc/sys/fs/mqueue/msg_default is a read/write file for setting/getting the
229+
default number of messages in a queue value if attr parameter of mq_open(2) is
230+
NULL. If it exceed msg_max, the default value is initialized msg_max.
231+
232+
/proc/sys/fs/mqueue/msgsize_default is a read/write file for setting/getting
233+
the default message size value if attr parameter of mq_open(2) is NULL. If it
234+
exceed msgsize_max, the default value is initialized msgsize_max.
228235

229236
4. /proc/sys/fs/epoll - Configuration options for the epoll interface
230237
--------------------------------------------------------

‎include/linux/ipc_namespace.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ struct ipc_namespace {
6262
unsigned int mq_queues_max; /* initialized to DFLT_QUEUESMAX */
6363
unsigned int mq_msg_max; /* initialized to DFLT_MSGMAX */
6464
unsigned int mq_msgsize_max; /* initialized to DFLT_MSGSIZEMAX */
65+
unsigned int mq_msg_default;
66+
unsigned int mq_msgsize_default;
6567

6668
/* user_ns which owns the ipc ns */
6769
struct user_namespace *user_ns;

‎ipc/mq_sysctl.c‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,24 @@ static ctl_table mq_sysctls[] = {
7373
.extra1 = &msg_maxsize_limit_min,
7474
.extra2 = &msg_maxsize_limit_max,
7575
},
76+
{
77+
.procname = "msg_default",
78+
.data = &init_ipc_ns.mq_msg_default,
79+
.maxlen = sizeof(int),
80+
.mode = 0644,
81+
.proc_handler = proc_mq_dointvec_minmax,
82+
.extra1 = &msg_max_limit_min,
83+
.extra2 = &msg_max_limit_max,
84+
},
85+
{
86+
.procname = "msgsize_default",
87+
.data = &init_ipc_ns.mq_msgsize_default,
88+
.maxlen = sizeof(int),
89+
.mode = 0644,
90+
.proc_handler = proc_mq_dointvec_minmax,
91+
.extra1 = &msg_maxsize_limit_min,
92+
.extra2 = &msg_maxsize_limit_max,
93+
},
7694
{}
7795
};
7896

‎ipc/mqueue.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,10 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
145145
info->qsize = 0;
146146
info->user = NULL; /* set when all is ok */
147147
memset(&info->attr, 0, sizeof(info->attr));
148-
info->attr.mq_maxmsg = min(ipc_ns->mq_msg_max, DFLT_MSG);
149-
info->attr.mq_msgsize =
150-
min(ipc_ns->mq_msgsize_max, DFLT_MSGSIZE);
148+
info->attr.mq_maxmsg = min(ipc_ns->mq_msg_max,
149+
ipc_ns->mq_msg_default);
150+
info->attr.mq_msgsize = min(ipc_ns->mq_msgsize_max,
151+
ipc_ns->mq_msgsize_default);
151152
if (attr) {
152153
info->attr.mq_maxmsg = attr->mq_maxmsg;
153154
info->attr.mq_msgsize = attr->mq_msgsize;
@@ -1261,6 +1262,8 @@ int mq_init_ns(struct ipc_namespace *ns)
12611262
ns->mq_queues_max = DFLT_QUEUESMAX;
12621263
ns->mq_msg_max = DFLT_MSGMAX;
12631264
ns->mq_msgsize_max = DFLT_MSGSIZEMAX;
1265+
ns->mq_msg_default = DFLT_MSG;
1266+
ns->mq_msgsize_default = DFLT_MSGSIZE;
12641267

12651268
ns->mq_mnt = kern_mount_data(&mqueue_fs_type, ns);
12661269
if (IS_ERR(ns->mq_mnt)) {

0 commit comments

Comments
 (0)