* Re: [PATCH v3 08/10] IPC: message queue copy feature introduced
[not found] ` <20120810142602.12411.63440.stgit@localhost6.localdomain6>
@ 2012-08-11 11:20 ` Manfred Spraul
2012-08-11 13:31 ` Stanislav Kinsbursky
0 siblings, 1 reply; 4+ messages in thread
From: Manfred Spraul @ 2012-08-11 11:20 UTC (permalink / raw)
To: Stanislav Kinsbursky
Cc: akpm, eparis, a.p.zijlstra, arnd, hughd, linux-kernel, cmetcalf,
yeohc, linux-security-module, viro, kosaki.motohiro, hpa, casey,
sds, devel
Hi Stanislav,
2012/8/10 Stanislav Kinsbursky <skinsbursky@parallels.com>:
> This patch is required for checkpoint/restore in userspace.
> IOW, c/r requires some way to get all pending IPC messages without deleting
> them from the queue (checkpoint can fail and in this case tasks will be resumed,
> so queue have to be valid).
> To achive this, new operation flag MSG_COPY for sys_msgrcv() system call was
> introduced. Also, copy counter was added to msg_queue structure. It's set to
> zero by default and increases by one on each copy operation and decreased by
> one on each receive operation until reaches zero.
Is msq->q_copy_cnt really necessary?
As far as I can see user space needs the ability to read the n-th message.
The implementation adds a state variable to the kernel, adds two
automatic updates of the state into msgrcv() (an increase during
MSG_COPY, a decrease during normal receives) and adds a msgctl() to
set the state to a certain value.
a) What about the simpler approach:
- if MSG_COPY is set, then @mtype is interpreted as the number of the
message that should be copied.
If there are less than @mtype messages, then -ENOMSG is returned.
b) I do not understand the purpose of the decrease of msq->q_copy_cnt:
Do you want to handle normal msgrcv() calls in parallel with
msgrcv(|MSG_COPY) calls?
I don't think that this will work:
What if msq->q_copy_cnt is 1 and and msgrcv() call receives the 20th
message in the queue?
--
Manfred
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3 08/10] IPC: message queue copy feature introduced
2012-08-11 11:20 ` [PATCH v3 08/10] IPC: message queue copy feature introduced Manfred Spraul
@ 2012-08-11 13:31 ` Stanislav Kinsbursky
2012-08-12 9:48 ` Manfred Spraul
0 siblings, 1 reply; 4+ messages in thread
From: Stanislav Kinsbursky @ 2012-08-11 13:31 UTC (permalink / raw)
To: Manfred Spraul
Cc: akpm@linux-foundation.org, eparis@parisplace.org,
a.p.zijlstra@chello.nl, arnd@arndb.de, hughd@google.com,
linux-kernel@vger.kernel.org, cmetcalf@tilera.com,
yeohc@au1.ibm.com, linux-security-module@vger.kernel.org,
viro@zeniv.linux.org.uk, kosaki.motohiro@jp.fujitsu.com,
hpa@zytor.com, casey@schaufler-ca.com,
sds@tycho.nsa.govjames.l.morris, devel@openvz.org
11.08.2012 15:20, Manfred Spraul пишет:
> Hi Stanislav,
>
> 2012/8/10 Stanislav Kinsbursky <skinsbursky@parallels.com>:
>> This patch is required for checkpoint/restore in userspace.
>> IOW, c/r requires some way to get all pending IPC messages without deleting
>> them from the queue (checkpoint can fail and in this case tasks will be resumed,
>> so queue have to be valid).
>> To achive this, new operation flag MSG_COPY for sys_msgrcv() system call was
>> introduced. Also, copy counter was added to msg_queue structure. It's set to
>> zero by default and increases by one on each copy operation and decreased by
>> one on each receive operation until reaches zero.
> Is msq->q_copy_cnt really necessary?
> As far as I can see user space needs the ability to read the n-th message.
>
> The implementation adds a state variable to the kernel, adds two
> automatic updates of the state into msgrcv() (an increase during
> MSG_COPY, a decrease during normal receives) and adds a msgctl() to
> set the state to a certain value.
>
> a) What about the simpler approach:
> - if MSG_COPY is set, then @mtype is interpreted as the number of the
> message that should be copied.
> If there are less than @mtype messages, then -ENOMSG is returned.
Hi, Manfred.
Your approach is simplier, but makes the call less generic and adds
limitations.
I.e. sys_msgrcv() allows you to receive message by type. And from my pow
this logic have to be preserved - you can specify type and then copy all
the messages of specified type.
> b) I do not understand the purpose of the decrease of msq->q_copy_cnt:
> Do you want to handle normal msgrcv() calls in parallel with
> msgrcv(|MSG_COPY) calls?
Actually, I'm not going to copy a message from a queue, when somebody is
reading from it. But better to handle this case by decreasing
msq->q_copy_cnt, because otherwise this counter becomes invalid in case
of somebody is reading from queue. And this logic is similar to new
"peek" logic for sockets (introduced in 3.4 or 3.5).
But I understand, that in case of queue with messages with different
types this approach works only if mtype is not specified for copy
operation. Otherwise result is unpredictable.
> I don't think that this will work:
> What if msq->q_copy_cnt is 1 and and msgrcv() call receives the 20th
> message in the queue?
By "receives" you mean "copied"? If so, then it can happen only if mtype
was specified. And this logic is a part of current implementation.
>
> --
> Manfred
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3 08/10] IPC: message queue copy feature introduced
2012-08-11 13:31 ` Stanislav Kinsbursky
@ 2012-08-12 9:48 ` Manfred Spraul
2012-08-13 10:35 ` Stanislav Kinsbursky
0 siblings, 1 reply; 4+ messages in thread
From: Manfred Spraul @ 2012-08-12 9:48 UTC (permalink / raw)
To: Stanislav Kinsbursky
Cc: akpm@linux-foundation.org, eparis@parisplace.org,
a.p.zijlstra@chello.nl, arnd@arndb.de, hughd@google.com,
linux-kernel@vger.kernel.org, cmetcalf@tilera.com,
yeohc@au1.ibm.com, linux-security-module@vger.kernel.org,
viro@zeniv.linux.org.uk, kosaki.motohiro@jp.fujitsu.com,
hpa@zytor.com, casey@schaufler-ca.com, sds@tycho.nsa.gov,
devel@openvz.org, james.l.morris
Hi Stanislav,
2012/8/11 Stanislav Kinsbursky <skinsbursky@parallels.com>:
> 11.08.2012 15:20, Manfred Spraul пишет:
>> a) What about the simpler approach:
>> - if MSG_COPY is set, then @mtype is interpreted as the number of the
>> message that should be copied.
>> If there are less than @mtype messages, then -ENOMSG is returned.
>
>
> Hi, Manfred.
> Your approach is simplier, but makes the call less generic and adds
> limitations.
> I.e. sys_msgrcv() allows you to receive message by type. And from my pow
> this logic have to be preserved - you can specify type and then copy all the
> messages of specified type.
>
Your implementation adds the ability to select a message for MSG_COPY by id.
But I think the price is way too high:
a) added complexity
b) I didn't notice it immediately:
The implementation means that MSG_COPY cannot be used at all by
multiple processes:
task 1: msgrcv(id,buf,len,0,MSG_COPY).
task 2: msgrcv(id,buf,len,0,MSG_COPY).
It is unpredictable if a task receives the first or the 2nd message
from the queue.
task 1: int msgnr=0;
msgctl(id,MSG_SET_COPY,&msgnr)
msgrcv(id,buf,len,0,MSG_COPY).
task 2: int msgnr=0;
msgctl(id,MSG_SET_COPY,&msgnr)
msgrcv(id,buf,len,0,MSG_COPY).
Doesn't work either, it's a race condition.
>
>> b) I do not understand the purpose of the decrease of msq->q_copy_cnt:
>> Do you want to handle normal msgrcv() calls in parallel with
>> msgrcv(|MSG_COPY) calls?
>
>
> Actually, I'm not going to copy a message from a queue, when somebody is
> reading from it. But better to handle this case by decreasing
> msq->q_copy_cnt, because otherwise this counter becomes invalid in case of
> somebody is reading from queue. And this logic is similar to new "peek"
> logic for sockets (introduced in 3.4 or 3.5).
> But I understand, that in case of queue with messages with different types
> this approach works only if mtype is not specified for copy operation.
> Otherwise result is unpredictable.
>
a) If the result is unpredictable when mtype is used, does it make
sense to implement msgcrl(id,buf,len,id=<x>,MSG_COPY)?
b) The result is also unpredictable if mtype is used for the "normal"
msgrcv() (i.e. without MSG_COPY) call.
>
>> I don't think that this will work:
>> What if msq->q_copy_cnt is 1 and and msgrcv() call receives the 20th
>> message in the queue?
>
>
> By "receives" you mean "copied"? If so, then it can happen only if mtype was
> specified. And this logic is a part of current implementation.
>
I was thinking about the following case:
task 1: /* copy all entries */
errno=0;
for (i=0;errno<>0;i++)
msgrcv(msgid,buf[i],buflen,0,MSG_COPY);
task 2: /* receive a message with a given ID */
msgrcv(msqid,buf,buflen,123,0);
Now suppose that task 1 has read 5 messages from the queue and then
task 2 tries to receive the message with the id=123. Suppose this is
the 20th message in the queue.
Result: task 1 will copy the message 5 twice.
I would keep it simple - unless there is a clear use case where "peek
by id" is useful.
Or - since MSG_COPY is linux specific anyway:
What about storing the number of the message that should be returned in *msgp?
Store it as "int64", just to avoid any 32/64 bit issues.
--
Manfred
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3 08/10] IPC: message queue copy feature introduced
2012-08-12 9:48 ` Manfred Spraul
@ 2012-08-13 10:35 ` Stanislav Kinsbursky
0 siblings, 0 replies; 4+ messages in thread
From: Stanislav Kinsbursky @ 2012-08-13 10:35 UTC (permalink / raw)
To: Manfred Spraul
Cc: akpm@linux-foundation.org, eparis@parisplace.org,
a.p.zijlstra@chello.nl, arnd@arndb.de, hughd@google.com,
linux-kernel@vger.kernel.org, cmetcalf@tilera.com,
yeohc@au1.ibm.com, linux-security-module@vger.kernel.org,
kosaki.motohiro@jp.fujitsu.com, hpa@zytor.com,
casey@schaufler-ca.com, devel@openvz.org,
james.l.morris@oracle.com
12.08.2012 13:48, Manfred Spraul пишет:
> I would keep it simple - unless there is a clear use case where "peek
> by id" is useful.
>
> Or - since MSG_COPY is linux specific anyway:
> What about storing the number of the message that should be returned in *msgp?
> Store it as "int64", just to avoid any 32/64 bit issues.
Sounds reasonable. But, probably, mtype suit better for message number.
I'll update.
--
Best regards,
Stanislav Kinsbursky
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-08-13 10:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20120810141517.12411.83398.stgit@localhost6.localdomain6>
[not found] ` <20120810142602.12411.63440.stgit@localhost6.localdomain6>
2012-08-11 11:20 ` [PATCH v3 08/10] IPC: message queue copy feature introduced Manfred Spraul
2012-08-11 13:31 ` Stanislav Kinsbursky
2012-08-12 9:48 ` Manfred Spraul
2012-08-13 10:35 ` Stanislav Kinsbursky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox