Improve the dma-buf tracking
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v5 Latest3 patches 2 repliesIn review
- v43 patches 2 repliesSuperseded
- v3 posting 3/33 patches 3 repliesSuperseded
Earlier versions · 4
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v3 posting 2/3 | 3 patches | 0 replies | Superseded | |
| v3 posting 1/3 | 3 patches | 0 replies | Superseded | |
| v2 RFC | 3 patches | 7 replies | Superseded | |
| v1 RFC | 3 patches | 4 replies | Superseded |
Changes in v5 from the cover letter
* Add the missing kfree for the dma-buf name ioctl.
Patches in v5 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | dma-buf: give each buffer a full-fledged inodedrivers/ include/ | +58 | 0 replies | |
| 2/3 | dma-buf: add DMA_BUF_SET_NAME ioctlsdrivers/ include/ include/ | +69 | 1 reply | |
| 3/3 | dma-buf: add show_fdinfo handlerdrivers/ | +15 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v5 yet.
Cover letter [PATCH v5 0/3] Improve the dma-buf tracking
Currently, all dma-bufs share the same anonymous inode. While we can count how many dma-buf fds or mappings a process has, we can't get the size of the backing buffers or tell if two entries point to the same dma-buf. And in debugfs, we can get a per-buffer breakdown of size and reference count, but can't tell which processes are actually holding the references to each buffer.
To resolve the issue above and provide better method for userspace to track the dma-buf usage across different processes, the following changes are proposed in dma-buf kernel side. First of all, replace the singleton inode inside the dma-buf subsystem with a mini-filesystem, and assign each dma-buf a unique inode out of this filesystem. With this change, calling stat(2) on each entry gives the caller a unique ID (st_ino), the buffer's size (st_size), and even the number of pages assigned to each dma-buffer. Secoundly, add the inode information to /sys/kernel/debug/dma_buf/bufinfo so in the case where a buffer is mmap()ed into a process’s address space but all remaining fds have been closed, we can still get the dma-buf information and try to accociate it with the process by searching the proc/pid/maps and looking for the corresponding inode number exposed in dma-buf debug fs. Thirdly, created an ioctl to assign names to dma-bufs which lets userspace assign short names (e.g., "CAMERA") to buffers. This information can be extremely helpful for tracking and accounting shared buffers based on their usage and original purpose. Last but not least, add dma-buf information to /proc/pid/fdinfo by adding a show_fdinfo() handler to dma_buf_file_operations. The handler will print the file_count and name of each buffer.
Change in v2:
* Add a check to prevent changing dma-buf name when it is attached to devices.
* Fixed some compile warnings
Change in v3:
* Removed the GET_DMA_BUF_NAME ioctls, add the dma_buf pointer to dentry d_fsdata so the name can be displayed in proc/pid/maps and proc/pid/map_files.
Change in v4:
* Updated the commit message and added some comments for the DMA_BUF_SET_NAME iotcl
Change in v5:
* Add the missing kfree for the dma-buf name ioctl.
Greg Hackmann (3):
dma-buf: give each buffer a full-fledged inode
dma-buf: add DMA_BUF_{GET,SET}_NAME ioctls
dma-buf: add show_fdinfo handler
drivers/dma-buf/dma-buf.c | 122 +++++++++++++++++++++++++++++++++-- include/linux/dma-buf.h | 5 +- include/uapi/linux/dma-buf.h | 3 + include/uapi/linux/magic.h | 1 + 4 files changed, 124 insertions(+), 7 deletions(-)
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog