Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 04d771f

Browse files
T.J. MercierTreehugger Robot
authored andcommitted
FROMGIT: dma-buf: heaps: Don't track CMA dma-buf pages under RssFile
DMA buffers allocated from the CMA dma-buf heap get counted under RssFile for processes that map them and trigger page faults. In addition to the incorrect accounting reported to userspace, reclaim behavior was influenced by the MM_FILEPAGES counter until linux 6.8, but this memory is not reclaimable. [1] Change the CMA dma-buf heap to set VM_PFNMAP on the VMA so MM does not poke at the memory managed by this dma-buf heap, and use vmf_insert_pfn to correct the RSS accounting. The system dma-buf heap does not suffer from this issue since remap_pfn_range is used during the mmap of the buffer, which also sets VM_PFNMAP on the VMA. [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/mm/vmscan.c?id=fb46e22a9e3863e08aef8815df9f17d0f4b9aede Fixes: b61614e ("dma-buf: heaps: Add CMA heap to dmabuf heaps") Change-Id: Id0d82b529e3456374c27387c6d5038b73132c874 Signed-off-by: T.J. Mercier <tjmercier@google.com> Acked-by: Christian König <christian.koenig@amd.com> Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org> Link: https://patchwork.freedesktop.org/patch/msgid/20240117181141.286383-1-tjmercier@google.com (cherry picked from commit 1c1914d https://anongit.freedesktop.org/git/drm/drm-misc.git drm-misc-fixes) Link: https://lore.kernel.org/all/20240117181141.286383-1-tjmercier@google.com/ Signed-off-by: T.J. Mercier <tjmercier@google.com>
1 parent 51cb9a2 commit 04d771f

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

drivers/dma-buf/heaps/cma_heap.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,7 @@ static vm_fault_t cma_heap_vm_fault(struct vm_fault *vmf)
170170
if (vmf->pgoff > buffer->pagecount)
171171
return VM_FAULT_SIGBUS;
172172

173-
vmf->page = buffer->pages[vmf->pgoff];
174-
get_page(vmf->page);
175-
176-
return 0;
173+
return vmf_insert_pfn(vma, vmf->address, page_to_pfn(buffer->pages[vmf->pgoff]));
177174
}
178175

179176
static const struct vm_operations_struct dma_heap_vm_ops = {
@@ -187,6 +184,8 @@ static int cma_heap_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma)
187184
if ((vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) == 0)
188185
return -EINVAL;
189186

187+
vm_flags_set(vma, VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP);
188+
190189
vma->vm_ops = &dma_heap_vm_ops;
191190
vma->vm_private_data = buffer;
192191

0 commit comments

Comments
 (0)