[RFC] dma-buf: system_heap: add PTE_CONT for larger contiguous

From: gao xu
Date: Mon Dec 08 2025 - 04:50:31 EST


commit 04c7adb5871a ("dma-buf: system_heap: use larger contiguous mappings
instead of per-page mmap") facilitates the use of PTE_CONT. The system_heap
allocates pages of order 4 and 8 that meet the alignment requirements for
PTE_CONT. enabling PTE_CONT for larger contiguous mappings.

After applying this patch, TLB misses are reduced by approximately 5% when
opening the camera on Android systems.

Signed-off-by: gao xu <gaoxu2@xxxxxxxxx>
---
drivers/dma-buf/heaps/system_heap.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c
index 4c782fe33..103b06f89 100644
--- a/drivers/dma-buf/heaps/system_heap.c
+++ b/drivers/dma-buf/heaps/system_heap.c
@@ -202,12 +202,16 @@ static int system_heap_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma)
unsigned long n = (sg->length >> PAGE_SHIFT) - pgoff;
struct page *page = sg_page(sg) + pgoff;
unsigned long size = n << PAGE_SHIFT;
+ pgprot_t prot = vma->vm_page_prot;

if (addr + size > vma->vm_end)
size = vma->vm_end - addr;

+ if (((addr | size) & ~CONT_PTE_MASK) == 0)
+ prot = __pgprot(pgprot_val(prot) | PTE_CONT);
+
ret = remap_pfn_range(vma, addr, page_to_pfn(page),
- size, vma->vm_page_prot);
+ size, prot);
if (ret)
return ret;

--
2.42.0