From: Andi Kleen <andi@firstfloor.org>
To: Andrew Grover <andy.grover@gmail.com>
Cc: netdev@vger.kernel.org
Subject: Re: how expensive are mallocs?
Date: Thu, 26 Nov 2009 23:25:27 +0100 [thread overview]
Message-ID: <877htc6i08.fsf@basil.nowhere.org> (raw)
In-Reply-To: <c0a09e5c0911240957x45abfb26k1611e53f435e5179@mail.gmail.com> (Andrew Grover's message of "Tue, 24 Nov 2009 09:57:34 -0800")
Andrew Grover <andy.grover@gmail.com> writes:
> How much effort generally makes sense to avoid mallocs? For example,
The slab allocators are very optimized, with a fast path for
allocation and freeing that's essentially "disable interrupts ;
unlink object from a list ; reenable". That's not expensive
(unless you're running on a CPU where disabling interrupts is)
The main costs in them come when you free objects on a different CPU
(or worse node) than where you allocate them. In that case you can end
up with some bounced cache lines, which are slow. If you can avoid
that you're good. If you can't even then you would need to make major
effort to do better.
> Also, RDS has its own per-cpu page remainder allocator (see
> net/rds/page.c) for kernel send buffers. Would cutting this code and
> just using kmalloc be recommended? Doesn't SL?B already do per-cpu
> pools?
Slab is all per cpu in the fast path, but see above.
> Does this stuff even matter enough to rise above the noise in benchmarks?
Yes it does in some circumstances, but it's hard to do better.
One example of doing better for special circumstances would be Eric's
rps work, but doing these things is not easy and only worth it
for really critical cases.
-Andi
--
ak@linux.intel.com -- Speaking for myself only.
prev parent reply other threads:[~2009-11-26 22:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-24 17:57 how expensive are mallocs? Andrew Grover
2009-11-25 23:18 ` David Miller
2009-11-26 22:25 ` Andi Kleen [this message]
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=877htc6i08.fsf@basil.nowhere.org \
--to=andi@firstfloor.org \
--cc=andy.grover@gmail.com \
--cc=netdev@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).