3

I'm having a problem with creating mqueues, namely my system appears to block me from creating more than 5 mqueues, even though /proc/sys/fs/mqueue/queues_max is set to 256. I'm running Ubuntu 13.04 server on an a Q7 module system with a Atom E680T, I'm also running a custom compiled kernel (3.8.0) to reduce the kernel size and to add watchdog and i2c access that was missing from the default.

I've checked to make sure that only 5 mqueues are being used by mounting the mqueue interface, after 5 have been created it won't let me create a 6th, returning a "Too many open files." error. To make sure there was nothing wrong with the function call I deleted one of the existing queues and ran my program again and it successfully created the queue.

I'm currently at a loss, the information I can find indicates that /proc/sys/fs/mqueue/queues_max should control the limit, and that defaults to 256. But modifiying this or any other file in that folder doesn't appeart to help.

So if anyone can point me in the right direction as to where this limit could be I would be grateful, for the most part the mqueues are being created with variations of this:

    mq_attr attribs;
//initialise the incoming message queue.
printLog ("I2C MANAGER: Registering mqueue.\n");
// Set attributes for main message queue
attribs.mq_maxmsg = 512;
attribs.mq_msgsize = sizeof(t_io_message);
attribs.mq_flags=0;
// Create the queue
in_queue = mq_open(I2C_MQUEUE, O_RDONLY|O_CREAT, 0666, &attribs);
// Check queue was successfully created
if (-1 == in_queue)
{
    printLogf ("I2C MANAGER: Error unable to register mqueue /i2c-manager: %s.\n", strerror(errno));
    exit(1);
}
else
{
    printLog ("I2C MANAGER: Mqueue Initialisation succesfull.\n");
}
Marcos Gonzalez
  • 1,086
  • 2
  • 12
  • 19
Skid
  • 95
  • 6
  • I worked it out, the error message was misleading, it wasn't that I had too many mqueues open, it was that the mqueues had allocated for these-selves most of the memory assigned to the mqueue system. So when I tried to open a new mqueue it couldn't get enough memory for it and failed to open. Seems maxmsg is the key, some our processes are using queue sizes of 1000, the one above I copy pasted from another process is set to 512 messages, which seems very excessive. Did a quick test by halving that value in two processes and now I have my 6th queue running. – Skid May 29 '13 at 15:31
  • what error do you get? – BЈовић May 30 '13 at 06:24
  • Said in the first post, strerror() returns "Too many open files." – Skid May 30 '13 at 09:32
  • your comment above should have been an answer. Are you developing for an embedded system with low memory? – BЈовић May 30 '13 at 09:57
  • My issue is sorted, my first comment was what resolved my issue. The reason I didn't put it as an answer was because I didn't have a high enough reputation to answer my own question until 8 hours after I posted the question. Since I was about to head home I didn't want people to waste there time to help with an issue I had solved, so I put it in the comments section. Now I'll have to wait till tomorrow to accept my own answer, but nvm, sorry for the confusion. – Skid May 30 '13 at 10:34
  • Does anyone know how to tell what the memory limit is for a set of message queues? I'm having a similar problem trying to go from 3 to 5 queues so I cut the maximum messages in half but still have the error. (If I don't figure out the problem by the time I get through all the similar questions I'll open a new question.) – Sinc Apr 30 '19 at 15:08

1 Answers1

3

I worked it out, the error message was misleading, it wasn't that I had too many mqueues open, it was that the mqueues had allocated for these-selves most of the memory assigned to the mqueue system. So when I tried to open a new mqueue it couldn't get enough memory for it and failed to open.

Looking at the code for the other processes I should be able to free up the space by just reducing the maxmsg value. Some are using queue sizes of 1000, the one above I copy pasted from another process is set to 512 messages, which seems very excessive. Did a quick test by halving that value in two processes and now I have my 6th queue running.

Skid
  • 95
  • 6