]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/3.10.87/ipc-modify-message-queue-accounting-to-not-take-kernel-data-structures-into-account.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 3.10.87 / ipc-modify-message-queue-accounting-to-not-take-kernel-data-structures-into-account.patch
1 From de54b9ac253787c366bbfb28d901a31954eb3511 Mon Sep 17 00:00:00 2001
2 From: Marcus Gelderie <redmnic@gmail.com>
3 Date: Thu, 6 Aug 2015 15:46:10 -0700
4 Subject: ipc: modify message queue accounting to not take kernel data structures into account
5
6 From: Marcus Gelderie <redmnic@gmail.com>
7
8 commit de54b9ac253787c366bbfb28d901a31954eb3511 upstream.
9
10 A while back, the message queue implementation in the kernel was
11 improved to use btrees to speed up retrieval of messages, in commit
12 d6629859b36d ("ipc/mqueue: improve performance of send/recv").
13
14 That patch introducing the improved kernel handling of message queues
15 (using btrees) has, as a by-product, changed the meaning of the QSIZE
16 field in the pseudo-file created for the queue. Before, this field
17 reflected the size of the user-data in the queue. Since, it also takes
18 kernel data structures into account. For example, if 13 bytes of user
19 data are in the queue, on my machine the file reports a size of 61
20 bytes.
21
22 There was some discussion on this topic before (for example
23 https://lkml.org/lkml/2014/10/1/115). Commenting on a th lkml, Michael
24 Kerrisk gave the following background
25 (https://lkml.org/lkml/2015/6/16/74):
26
27 The pseudofiles in the mqueue filesystem (usually mounted at
28 /dev/mqueue) expose fields with metadata describing a message
29 queue. One of these fields, QSIZE, as originally implemented,
30 showed the total number of bytes of user data in all messages in
31 the message queue, and this feature was documented from the
32 beginning in the mq_overview(7) page. In 3.5, some other (useful)
33 work happened to break the user-space API in a couple of places,
34 including the value exposed via QSIZE, which now includes a measure
35 of kernel overhead bytes for the queue, a figure that renders QSIZE
36 useless for its original purpose, since there's no way to deduce
37 the number of overhead bytes consumed by the implementation.
38 (The other user-space breakage was subsequently fixed.)
39
40 This patch removes the accounting of kernel data structures in the
41 queue. Reporting the size of these data-structures in the QSIZE field
42 was a breaking change (see Michael's comment above). Without the QSIZE
43 field reporting the total size of user-data in the queue, there is no
44 way to deduce this number.
45
46 It should be noted that the resource limit RLIMIT_MSGQUEUE is counted
47 against the worst-case size of the queue (in both the old and the new
48 implementation). Therefore, the kernel overhead accounting in QSIZE is
49 not necessary to help the user understand the limitations RLIMIT imposes
50 on the processes.
51
52 Signed-off-by: Marcus Gelderie <redmnic@gmail.com>
53 Acked-by: Doug Ledford <dledford@redhat.com>
54 Acked-by: Michael Kerrisk <mtk.manpages@gmail.com>
55 Acked-by: Davidlohr Bueso <dbueso@suse.de>
56 Cc: David Howells <dhowells@redhat.com>
57 Cc: Alexander Viro <viro@zeniv.linux.org.uk>
58 Cc: John Duffy <jb_duffy@btinternet.com>
59 Cc: Arto Bendiken <arto@bendiken.net>
60 Cc: Manfred Spraul <manfred@colorfullife.com>
61 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
62 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
63 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
64
65 ---
66 ipc/mqueue.c | 5 -----
67 1 file changed, 5 deletions(-)
68
69 --- a/ipc/mqueue.c
70 +++ b/ipc/mqueue.c
71 @@ -143,7 +143,6 @@ static int msg_insert(struct msg_msg *ms
72 if (!leaf)
73 return -ENOMEM;
74 INIT_LIST_HEAD(&leaf->msg_list);
75 - info->qsize += sizeof(*leaf);
76 }
77 leaf->priority = msg->m_type;
78 rb_link_node(&leaf->rb_node, parent, p);
79 @@ -188,7 +187,6 @@ try_again:
80 "lazy leaf delete!\n");
81 rb_erase(&leaf->rb_node, &info->msg_tree);
82 if (info->node_cache) {
83 - info->qsize -= sizeof(*leaf);
84 kfree(leaf);
85 } else {
86 info->node_cache = leaf;
87 @@ -201,7 +199,6 @@ try_again:
88 if (list_empty(&leaf->msg_list)) {
89 rb_erase(&leaf->rb_node, &info->msg_tree);
90 if (info->node_cache) {
91 - info->qsize -= sizeof(*leaf);
92 kfree(leaf);
93 } else {
94 info->node_cache = leaf;
95 @@ -1026,7 +1023,6 @@ SYSCALL_DEFINE5(mq_timedsend, mqd_t, mqd
96 /* Save our speculative allocation into the cache */
97 INIT_LIST_HEAD(&new_leaf->msg_list);
98 info->node_cache = new_leaf;
99 - info->qsize += sizeof(*new_leaf);
100 new_leaf = NULL;
101 } else {
102 kfree(new_leaf);
103 @@ -1133,7 +1129,6 @@ SYSCALL_DEFINE5(mq_timedreceive, mqd_t,
104 /* Save our speculative allocation into the cache */
105 INIT_LIST_HEAD(&new_leaf->msg_list);
106 info->node_cache = new_leaf;
107 - info->qsize += sizeof(*new_leaf);
108 } else {
109 kfree(new_leaf);
110 }