Re: POSIX message queues should not allocate memory on send

From: Martijn Sipkema
Date: Sat Aug 14 2004 - 18:15:18 EST


From: "Jakub Jelinek" <jakub@xxxxxxxxxx>
> On Fri, May 14, 2004 at 12:09:46PM +0100, Martijn Sipkema wrote:
> > You are correct; defaults are indeed needed. The current default value
> > for mq_msgsize seems rather large considering that mq_msgsize*mq_maxmsg
> > bytes will have to be allocated on queue creation. If variable sized large
> > payload messages are needed one might consider using shared memory in
> > combination with a message queue.
> >
> > My main point was that mq_send()/mq_timedsend() may not return ENOMEM
> > and I am positive I did not misread the standard on that.
>
> Even that is not clear.
> http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_03.html#tag_02_03
> " Implementations may support additional errors not included in this list,
> may generate errors included in this list under circumstances other than
> those described here, or may contain extensions or limitations that
> prevent some errors from occurring. The ERRORS section on each
> reference page specifies whether an error shall be returned, or whether
> it may be returned. Implementations shall not generate a different error
> number from the ones described here for error conditions described in
> this volume of IEEE Std 1003.1-2001, but may generate additional errors
> unless explicitly disallowed for a particular function."
>
> Explicitely disallowed in the general section is only EINTR for the THR
> option functions unless explitely listed for that function and nothing else.
>
> I don't see ENOMEM explicitly forbidden for mq_send/mq_timedsend nor
> any wording in mq_open description which would require the buffers to
> be preallocated.

You are correct, but from the mq_send/mq_timedsend DESCRIPTION:

``If the specified message queue is not full, mq_send() shall behave as if the
message is inserted into the message queue at the position indicated by the
msg_prio argument.''

and from ERRORS:

``The mq_send() and mq_timedsend() functions shall fail if:
[EAGAIN] The O_NONBLOCK flag is set in the message queue description
associated with mqdes, and the specified message queue is full.''

Thus, if full could be interpreted as to also mean that there is no memory
to store the message, returning ENOMEM is not allowed and EAGAIN
would have to be used in stead since an implementation isn't allowed to
use a different error number for the same error condition.

If full is taken to mean that the queue contains its maximum number
of messages, which I think is the correct meaning, then returning ENOMEM
is not allowed, i.e. the queue has to be preallocated, I think, since the
description states that a message shall be added if the queue is not full.

--ms


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/