提交 e8b19840 编写于 作者: R Robin Murphy 提交者: Joerg Roedel

iommu/iova: Try harder to allocate from rcache magazine

When devices with different DMA masks are using the same domain, or for
PCI devices where we usually try a speculative 32-bit allocation first,
there is a fair possibility that the top PFN of the rcache stack at any
given time may be unsuitable for the lower limit, prompting a fallback
to allocating anew from the rbtree. Consequently, we may end up
artifically increasing pressure on the 32-bit IOVA space as unused IOVAs
accumulate lower down in the rcache stacks, while callers with 32-bit
masks also impose unnecessary rbtree overhead.

In such cases, let's try a bit harder to satisfy the allocation locally
first - scanning the whole stack should still be relatively inexpensive.
Signed-off-by: NRobin Murphy <robin.murphy@arm.com>
Signed-off-by: NJoerg Roedel <jroedel@suse.de>
上级 b826ee9a
...@@ -821,12 +821,21 @@ static bool iova_magazine_empty(struct iova_magazine *mag) ...@@ -821,12 +821,21 @@ static bool iova_magazine_empty(struct iova_magazine *mag)
static unsigned long iova_magazine_pop(struct iova_magazine *mag, static unsigned long iova_magazine_pop(struct iova_magazine *mag,
unsigned long limit_pfn) unsigned long limit_pfn)
{ {
int i;
unsigned long pfn;
BUG_ON(iova_magazine_empty(mag)); BUG_ON(iova_magazine_empty(mag));
if (mag->pfns[mag->size - 1] > limit_pfn) /* Only fall back to the rbtree if we have no suitable pfns at all */
return 0; for (i = mag->size - 1; mag->pfns[i] > limit_pfn; i--)
if (i == 0)
return 0;
/* Swap it to pop it */
pfn = mag->pfns[i];
mag->pfns[i] = mag->pfns[--mag->size];
return mag->pfns[--mag->size]; return pfn;
} }
static void iova_magazine_push(struct iova_magazine *mag, unsigned long pfn) static void iova_magazine_push(struct iova_magazine *mag, unsigned long pfn)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册