From: "Christian König" <christian.koenig@amd.com>
To: "T.J. Mercier" <tjmercier@google.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>,
sumit.semwal@linaro.org, phasta@kernel.org,
benjamin.gaignard@collabora.com, jstultz@google.com,
linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 1/3] dma-buf: system_heap: add a 2MB allocation order for IOMMU superpages
Date: Tue, 15 Sep 2026 17:44:25 +0200 [thread overview]
Message-ID: <871b6fc6-e126-429f-881c-9cc517ee8dcc@amd.com> (raw)
In-Reply-To: <CABdmKX1ky3Jfr7B-Oqaz17aLJwo1SSh1huZ05NG7D44SMF=9fw@mail.gmail.com>
On 9/15/26 17:33, T.J. Mercier wrote:
> On Tue, Sep 15, 2026 at 1:41 AM Christian König
> <christian.koenig@amd.com> wrote:
>>
>> On 9/14/26 23:22, Davidlohr Bueso wrote:
>>> With 4KB base pages, the system heap allocates buffers in 1MB, 64KB
>>> and 4KB chunks. The conventional Intel VT-d second-stage and AMD-Vi v2
>>> page-table formats, and Arm SMMU's 64-bit long-descriptor format with
>>> a 4KB translation granule, define 4KB pages and 2MB/1GB large-page
>>> mappings, but no 1MB leaf. A 1MB chunk therefore requires 256 4KB leaf
>>> entries unless it can be combined with adjacent chunks into a
>>> suitably aligned larger mapping.
>>
>> Yes, it was an intentional design choice to *NOT* optimize for AMD nor Intels IOMMU here.
>>
>>> Adding a 2MB allocation order provides naturally aligned, physically
>>> contiguous chunks matching the 2MB leaf size, without relying on this
>>> being accidental for separate smaller allocations. The new cost
>>> is one failed order-9 attempt (keeping current large allocation semantics)
>>> per buffer when 2MB pages are exhausted.
>>
>> We have plenty of experience with this with TTM and the overhead this results in is usually not acceptable.
>
> Overhead from compaction and reclaim to get 2M pages? That is disabled
> for non-0 page orders here in HIGH_ORDER_GFP.
Ah! Thanks for pointing that out, I misread the code that __GFP_RECLAIM is ORed into the mask.
But the question is still why? Without reclaim that is pretty much an useless feature on most x86 boxes.
Regards,
Christian.
>
>>> Two benchmarks, measured on an AMD EPYC 7313P.
>>
>> Why in the world are you testing the system heap on an AMD EPYC system?
>>
>> AMD clearly doesn't recommend using the system heap on those boxes for ROCm, so I'm really wondering what combination of HW you have here?
>>
>> Regards,
>> Christian.
>>
>>>
>>> (i) Mapping, into an idle NVMe function's translated DMA-FQ domain,
>>> measuring map/unmap: with the v1 page table restricted to 4K/2M/1G
>>> (amd_iommu=v2_pgsizes_only), a 1GB buffer goes from 1024 1MB chunks,
>>> only one of whose 2MB windows was superpage-mappable in that run, to
>>> 512 2MB chunks with all 512 mappable. dma_buf_map_attachment() costs
>>> decrease by ~16x on average with ~32x for the worst cases. Unmapping
>>> that buffer drops from ~500 us to 1.25 us.
>>>
>>> (ii) A microbench that measures the cost of DMA_HEAP_IOCTL_ALLOC+close
>>> across various thread counts decreases by factors of ~3-7x alleviating
>>> allocator's zone->lock contention by being PMD order and therefore is
>>> pcpu list eligible. Once the buffer size is large enough then the cost
>>> of the zeroing takes over.
>>>
>>> Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
>>> ---
>>> drivers/dma-buf/heaps/system_heap.c | 13 +++++++------
>>> 1 file changed, 7 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c
>>> index c8959eadc71d..621cf238ef97 100644
>>> --- a/drivers/dma-buf/heaps/system_heap.c
>>> +++ b/drivers/dma-buf/heaps/system_heap.c
>>> @@ -55,14 +55,15 @@ struct dma_heap_attachment {
>>> #define HIGH_ORDER_GFP (((GFP_HIGHUSER | __GFP_ZERO | __GFP_NOWARN \
>>> | __GFP_NORETRY) & ~__GFP_RECLAIM) \
>>> | __GFP_COMP)
>>> -static gfp_t order_flags[] = {HIGH_ORDER_GFP, HIGH_ORDER_GFP, LOW_ORDER_GFP};
>>> +static gfp_t order_flags[] = {HIGH_ORDER_GFP, HIGH_ORDER_GFP,
>>> + HIGH_ORDER_GFP, LOW_ORDER_GFP};
>>> /*
>>> - * The selection of the orders used for allocation (1MB, 64K, 4K) is designed
>>> - * to match with the sizes often found in IOMMUs. Using order 4 pages instead
>>> - * of order 0 pages can significantly improve the performance of many IOMMUs
>>> - * by reducing TLB pressure and time spent updating page tables.
>>> + * The selection of the orders used for allocation (2MB, 1MB, 64K, 4K) is
>>> + * designed to match with the sizes often found in IOMMUs. Using larger order
>>> + * pages instead of order 0 pages can significantly improve the performance of
>>> + * many IOMMUs by reducing TLB pressure and time spent updating page tables.
>>> */
>>> -static const unsigned int orders[] = {8, 4, 0};
>>> +static const unsigned int orders[] = {9, 8, 4, 0};
>>> #define NUM_ORDERS ARRAY_SIZE(orders)
>>>
>>> static int system_heap_set_page_decrypted(struct page *page)
>>> --
>>> 2.39.5
>>>
>>
next prev parent reply other threads:[~2026-09-15 15:44 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-14 21:22 [PATCH 0/3] dma-buf: system_heap: 2MB system heap chunks Davidlohr Bueso
2026-09-14 21:22 ` [PATCH 1/3] dma-buf: system_heap: add a 2MB allocation order for IOMMU superpages Davidlohr Bueso
2026-09-14 23:23 ` T.J. Mercier
2026-09-15 8:41 ` Christian König
2026-09-15 15:33 ` T.J. Mercier
2026-09-15 15:44 ` Christian König [this message]
2026-09-15 16:26 ` T.J. Mercier
2026-09-15 17:26 ` T.J. Mercier
2026-09-16 8:41 ` Christian König
2026-09-16 16:03 ` T.J. Mercier
2026-09-16 16:22 ` Davidlohr Bueso
2026-09-17 8:11 ` Christian König
2026-09-24 14:01 ` Davidlohr Bueso
2026-09-14 21:22 ` [PATCH 2/3] dma-buf: system_heap: fix the allocation ladder on non-4K base pages Davidlohr Bueso
2026-09-14 23:24 ` T.J. Mercier
2026-09-15 8:45 ` Christian König
2026-09-14 21:22 ` [PATCH 3/3] dma-buf: validate the attachment before asserting its reservation lock Davidlohr Bueso
2026-09-14 21:48 ` sashiko-bot
2026-09-14 23:24 ` T.J. Mercier
2026-09-15 8:46 ` Christian König
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=871b6fc6-e126-429f-881c-9cc517ee8dcc@amd.com \
--to=christian.koenig@amd.com \
--cc=benjamin.gaignard@collabora.com \
--cc=dave@stgolabs.net \
--cc=dri-devel@lists.freedesktop.org \
--cc=jstultz@google.com \
--cc=linux-media@vger.kernel.org \
--cc=phasta@kernel.org \
--cc=sumit.semwal@linaro.org \
--cc=tjmercier@google.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.