From: Doug Ledford <dledford@redhat.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org,
sfr@canb.auug.org.au
Subject: Re: [Patch 1/4] ipc/mqueue: improve performance of send/recv
Date: Thu, 03 May 2012 09:03:44 -0400 [thread overview]
Message-ID: <4FA28230.5080507@redhat.com> (raw)
In-Reply-To: <20120503092105.GA6603@mwanda>
[-- Attachment #1: Type: text/plain, Size: 2576 bytes --]
On 5/3/2012 5:21 AM, Dan Carpenter wrote:
> 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...
It's fine. We currently cap mq_maxmsg at a hard limit of 65536, and
MQ_PRIO_MAX is 32768, so both well within the limits of truncating a
long to unsigned int. In order for this to ever be a problem, we would
first have to change the accounting of mq bytes in the user struct from
a 32bit type to a 64bit type. As long as it's still 32 bits, and as
long as mq_maxmsg * (sizeof(struct msg_msg) + mq_msgsize) must fit
within that 32bit struct, we will never have an mq_maxmsg large enough
to truncate in this situation.
> We do the same thing in mqueue_evict_inode() and mq_attr_ok().
All of the math in here would need an audit if we increased the maximum
mq bytes from 32bit to 64bit.
--
Doug Ledford <dledford@redhat.com>
GPG KeyID: 0E572FDD
http://people.redhat.com/dledford
Infiniband specific RPMs available at
http://people.redhat.com/dledford/Infiniband
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 898 bytes --]
next prev parent reply other threads:[~2012-05-03 13:03 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-01 17:50 [Patch 0/4] ipc/mqueue improvements Doug Ledford
2012-05-01 17:50 ` [Patch 1/4] ipc/mqueue: improve performance of send/recv Doug Ledford
2012-05-01 17:50 ` [Patch 2/4] ipc/mqueue: correct mq_attr_ok test Doug Ledford
2012-05-01 19:34 ` Andrew Morton
2012-05-01 19:38 ` Doug Ledford
2012-05-01 17:50 ` [Patch 3/4] ipc/mqueue: strengthen checks on mqueue creation Doug Ledford
2012-05-01 20:01 ` KOSAKI Motohiro
2012-05-01 20:11 ` Doug Ledford
2012-05-01 20:18 ` KOSAKI Motohiro
2012-05-01 23:02 ` Doug Ledford
2012-05-01 23:04 ` KOSAKI Motohiro
2012-05-01 23:11 ` Andrew Morton
2012-05-01 17:50 ` [Patch 4/4] tools/selftests: add mq_perf_tests Doug Ledford
2012-05-01 19:53 ` Andrew Morton
2012-05-01 20:14 ` Doug Ledford
2012-05-03 9:21 ` [Patch 1/4] ipc/mqueue: improve performance of send/recv Dan Carpenter
2012-05-03 13:03 ` Doug Ledford [this message]
2012-05-03 10:05 ` Nick Piggin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4FA28230.5080507@redhat.com \
--to=dledford@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=dan.carpenter@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sfr@canb.auug.org.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox