2

[Although I'm working in perl I believe that this question relate to Linux System V IPC APIs and limits rather that the anything perl-specific.]

I have two Centos machines, each at CentOS Linux release 7.9.2009 (Core).

I have a program that forks a child and then uses System V IPC messages to communicate with the child, the child prepares answers ands sends them to the parent.

On one machine we see expected behaviour. The child produces batches of messages, the parent consumes them. Occasionally the child works a little faster than the parent, and so may fill the queue, the child then waits until the parent consumes some messages and proceeds.

We can inspect the queue sizes with ipcs -q and see that the default limit of 10 messages per queue is occasionally reached, the child pauses, and then we see the queue empty as expected.

We believe that the queue limits are specified in files in /proc/sys/fs/mqueue/ and for example msg_max is seen to be the expected 10. These values are identical on both machines.

We also can view user ulimits relating to queue using ulimit -q and see a value in excess of 800,000 bytes on both machines.

The puzzle is that on our second machine we see the child write three messages to the queue and attempt to write the fourth and wait - we deliberately set no timeout. It is as though the writer believes that the queue is full, even though ipcs -q shows only 3 items in the queue. At this point in time the parent is not yet attempting to read the messages.

------ Message Queues --------
key        msqid      owner      perms      used-bytes   messages    
0x0000002a 1474560    dave      600        15020        3  

The question: what, other than the queue being full, would cause msgsnd() to pause? The pause seems to continue indefinitely, the child proceeds when the parent becomes active and reads some messages.

We have many machines running this code without issue. It fails on three new machines. Presumably there is some environment-specific feature that interacts with our code?

The perl code uses a thin library above the system calls (details elided)

$mQueue = msgget(IPC_PRIVATE, IPC_CREAT | S_IRUSR | S_IWUSR);
msgsnd( $mQueue, pack("l! a*", length($msg), $msg);
djna
  • 285
  • 1
  • 3
  • 9

1 Answers1

2

The problem was that the default max size of queue kernel setting was set to a low value.

This cal be viewed using the -l option to ipcs.

ipcs -q -l

------ Messages Limits --------
max queues system wide = 3671
max size of message (bytes) = 8192
default max size of queue (bytes) = 16384

The kernel setting in question is stored in

/proc/sys/kernel/msgmnb

and can be changed (as root) using the command

 sysctl -w kernel.msgmnb=65536
 kernel.msgmnb = 65536
djna
  • 285
  • 1
  • 3
  • 9