struct msg_queue {

struct kern_ipc_perm q perm; time_t q_stime; time_t q_rtime; time_t q_ctime; unsigned long q_cbytes; unsigned long q_qnum; unsigned long q_qbytes; pid_t q_lspid; pid_t q_lrpid;

struct list_head q_messages; struct list_head q_receivers; struct list_head q_senders;

The structure includes status information as well as queue access permissions.

□ q_stime, q_rtime and q_ctime specify the last send, receive, and change time (if queue properties are changed).

□ q_cbytes specifies the number of bytes currently used by the messages in the queue.

/* current number of bytes on queue */

/* number of messages in queue */

□ q_qbytes specifies the maximum number of bytes that may be used by the messages in the queue.

□ q_num specifies the number of messages in the queue.

□ q_lspid is the PID of the last sender process; q_lrpid is the PID of the last receiver process.

Three standard lists of the kernel are used to manage sleeping senders (q_senders), sleeping receivers (q_receivers), and the messages themselves (q_messages). Each uses its own separate data structures as list elements.

Each message in q_messages is encapsulated in an instance of msg_msg. ipc/msg.c struct msg_msg {

struct list_head m_list; long m_type;

struct msg_msgseg* next;

/* the actual message follows immediately */

m_list is used as a list element to link the individual messages; the other elements are used to manage the message itself.

□ m_type specifies the message type and is used as described to support several types per queue.

□ m_ts specifies the message text size in bytes.

□ next is needed to hold long messages requiring more than one memory page.

There is no explicit field in which the message itself is stored. Because (at least) one page is always reserved for each message and the msg_msg instance is held at the beginning of this page, the remaining space can be used to store the message text, as shown in Figure 5-5.

struct msg_msg

next w

struct msg_msg_seq

next w

struct msg_msg_seq

Page frame Message text

Page frame Message text

Figure 5-5: Managing an IPC message in memory.

The maximum number of bytes available for the message text in a msg_msg page is calculated by subtracting the size of the structure from the size of a memory page.

Continue reading here: Ipcmsgutilsc

Was this article helpful?

0 0