Use mmap(MAP_ANONYMOUS) to allocate queue buffers

Internal buffers for QPs, CQs, SRQs etc. are allocated with
mthca_alloc_buf(), which rounds the buffer's size to the page size and
then allocates page aligned memory using posix_memalign().

However, this allocation is quite wasteful on architectures using 64K
pages (ia64 for example) because we then hit glibc's MMAP_THRESHOLD
malloc parameter and chunks are allocated using mmap.  Thus we end up

  (requested size rounded to the page size) + (page size) + (malloc overhead)

rounded internally to the page size.

So for example, if we request a buffer of page_size bytes, we end up
consuming 3 pages.  In short, for each buffer we allocate, there is an
overhead of 2 pages.  This is quite visible on large clusters where
the number of QPs can reach several thousands.

This patch replaces the call to posix_memalign() in mthca_alloc_buf()
with a direct call to mmap().

Signed-off-by: Sebastien Dugue <>
Signed-off-by: Roland Dreier <>
1 file changed