2002-10-03 14:46:09

by Cedric Roux

[permalink] [raw]
Subject: ipc - msg : memory usage too big ?

Hi kernel hackers,

While looking into msg.c, I noticed that in
sys_msgsnd, there is the test :

if(msgsz + msq->q_cbytes > msq->q_qbytes ||
1 + msq->q_qnum > msq->q_qbytes) {

so that you can send a message only if ressources won't
be exhausted.

The second case means I can send at most MSGMNB messages
to a queue, which is by default 16384.

Now suppose we send messages of length 0 (only type is used).

Knowing that load_msg calls :

msg = (struct msg_msg *) kmalloc (sizeof(*msg) + alen, GFP_KERNEL);

it will result in allocating 36 bytes of memory (suppose we
are on a ia32) per message.

We have 16 queues by default, so if we use the 16 queues this way,
we have :
16 * 36 * 16384 = 9437184, more than 9 MB used.

I hope I am right :-)

Don't you think it is far beyond the 256 KB someone is
expected to be used at maximum for the msg stuff ?

If it is seen as a problem, a solution might be to add
the memory overhead usage into the queue size, or add a
variable that counts the real memory used, and limits it
to a reasonable amount.

C?dric.

PS: I am not on the kernel mailing list, so CC is welcome. (I know it is
bad practice.)
--
main(){int i,j;{printf("\n Who did you say ? Sierpinski ? \n");}
for(i=0;i<80;i++){for(j=0;j<80;j++)printf("%c",i&j?'.':' ');printf("\n");}
printf("\n Life is a beach - George Sand (1804-1876) \n\n"); return 0;}