Re: [Patch 1/4] ipc/mqueue: improve performance of send/recv

From: Dan Carpenter
Date: Thu May 03 2012 - 05:17:59 EST


On Tue, May 01, 2012 at 01:50:52PM -0400, Doug Ledford wrote:
> @@ -150,16 +241,25 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
> info->attr.mq_maxmsg = attr->mq_maxmsg;
> info->attr.mq_msgsize = attr->mq_msgsize;
> }
> - mq_msg_tblsz = info->attr.mq_maxmsg * sizeof(struct msg_msg *);
> - if (mq_msg_tblsz > PAGE_SIZE)
> - info->messages = vmalloc(mq_msg_tblsz);
> - else
> - info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
> - if (!info->messages)
> - goto out_inode;
> + /*
> + * We used to allocate a static array of pointers and account
> + * the size of that array as well as one msg_msg struct per
> + * possible message into the queue size. That's no longer
> + * accurate as the queue is now an rbtree and will grow and
> + * shrink depending on usage patterns. We can, however, still
> + * account one msg_msg struct per message, but the nodes are
> + * allocated depending on priority usage, and most programs
> + * only use one, or a handful, of priorities. However, since
> + * this is pinned memory, we need to assume worst case, so
> + * that means the min(mq_maxmsg, max_priorities) * struct
> + * posix_msg_tree_node.
> + */
> + mq_treesize = info->attr.mq_maxmsg * sizeof(struct msg_msg) +
> + min_t(unsigned int, info->attr.mq_maxmsg, MQ_PRIO_MAX) *
> + sizeof(struct posix_msg_tree_node);

"info->attr.mq_maxmsg" is a long, but the min_t() truncates it to an
unsigned int. I'm not familiar with this code so I don't know if
that's a problem...

We do the same thing in mqueue_evict_inode() and mq_attr_ok().

regards,
dan carpenter

--
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/