Set linux mq_queue size for user

设置调整mq_queue的size*num如果大于默认(POSIX message queues),则需要调整系统限制和用户限制,不然在mq_open是会报"Too many open files"的错误

1. man mq_overview命令可以了解到mq可以设置msg_max和msgsize_max的路径,默认是10与8192.这个限制是系统限制

/proc/sys/fs/mqueue/msg_max
This file can be used to view and change the ceiling value for
the maximum number of messages in a queue. This value acts as a
ceiling on the attr->mq_maxmsg argument given to mq_open(3).
The default value for msg_max is 10. The minimum value is 1 (10
in kernels before 2.6.28). The upper limit is HARD_MSGMAX. The
msg_max limit is ignored for privileged processes
(CAP_SYS_RESOURCE), but the HARD_MSGMAX ceiling is nevertheless
imposed.

The definition of HARD_MSGMAX has changed across kernel ver‐
sions:

* Up to Linux 2.6.32: 131072 / sizeof(void *)

* Linux 2.6.33 to 3.4: (32768 * sizeof(void *) / 4)

* Since Linux 3.5: 65,536

/proc/sys/fs/mqueue/msgsize_max
This file can be used to view and change the ceiling on the max‐
imum message size. This value acts as a ceiling on the
attr->mq_msgsize argument given to mq_open(3). The default
value for msgsize_max is 8192 bytes. The minimum value is 128
(8192 in kernels before 2.6.28). The upper limit for msg‐
size_max has varied across kernel versions:

* Before Linux 2.6.28, the upper limit is INT_MAX.

* From Linux 2.6.28 to 3.4, the limit is 1,048,576.

* Since Linux 3.5, the limit is 16,777,216 (HARD_MSGSIZEMAX).

The msgsize_max limit is ignored for privileged process
(CAP_SYS_RESOURCE), but, since Linux 3.5, the HARD_MSGSIZEMAX
ceiling is enforced for privileged processes.

2. ulimit -a命令可以显示POSIX message queues     (bytes, -q) 819200, ulimit -q xxx对于普通用户无法进行调整

一般用户调整该项设置会提示权限问题,或者无法看到该项显示。

这样就需要root权限或者sudo修改/etc/security/limits.conf, 比如调整为* - msgqueue 921600

明确在/etc/pam.d/login加载中生效, 有这项纪录session required pam_limits.so即表明会加载,但需要重启系统进行加载,加载成功后,一般用户的该值就会被设置为新限制。

 

注:mq_name需要注意,open后必须删掉,否则即使调整属性也是无法生效的。

 

posted @ 2017-10-17 11:43  sciapex  阅读(810)  评论(0编辑  收藏  举报