memcg: account the remaining uncharged kernel allocations
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest7 patches 15 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/7 | scsi: sg and st: account the command buffer memory to memcgdrivers/ drivers/ | +24 | 1 reply | |
| 2/7 | dma-buf/udmabuf: account the page array metadata to memcgdrivers/ | +4 | 5 replies | |
| 3/7 | vhost: account the per-device kernel allocations to memcgdrivers/ drivers/ drivers/ | +21 | 2 replies | |
| 4/7 | tracing: account ring buffer pages and trace_array metadata to memcgkernel/ kernel/ | +10 | 4 replies | |
| 5/7 | iommufd: account the hw_queue page array to memcgdrivers/ | +2 | 2 replies | |
| 6/7 | io_uring: account the ring context and SQPOLL thread data to memcgio_uring/ io_uring/ io_uring/ +1 more | +6 | 1 reply | |
| 7/7 | io_uring: account the remaining per-object allocations to memcgio_uring/ io_uring/ io_uring/ +1 more | +6 | 0 replies |
Reviews trailers per patch
3 of 7 patches have a Reviewed-by or Acked-by.
| Patch | T.J. Mercier | Jason Gunthorpe | Michael S. Tsirkin |
|---|---|---|---|
| 1/7 | |||
| 2/7 | R-b | ||
| 3/7 | A-b | ||
| 4/7 | |||
| 5/7 | R-b | ||
| 6/7 | |||
| 7/7 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.
Cover letter [PATCH 0/7] memcg: account the remaining uncharged kernel allocations
From: Tao Cui <[email protected]>
Kernel memory that scales with user controlled input is supposed to be charged to the memcg of the task that induces it, so that memory.max contains the damage and the accounting is honest. Sweeping the interfaces that let unprivileged or delegated users drive kernel allocations turned up seven more places where the charge is missing. Every fix is one flag; the interesting part is who can pull the lever and how much a pull buys.
An open sg fd reserves up to max_sectors worth of buffer, SG_MAX_QUEUE
(16) commands can be in flight per fd, and the fd count is bounded only by RLIMIT_NOFILE. udmabuf metadata costs about 4MB of SUnreclaim per GB of buffer with size_limit_mb defaulting to INT_MAX. vhost holds roughly 150KB of resident kernel memory per SET_OWNER, and /dev/vhost-net is handed to containers by device plugins. A ftrace instance allocates two full sets of per-cpu ring buffers the moment it is created, about 1.375MB per cpu per set, gated by tracefs permissions alone. iommufd's hw_queue contiguity check allocates an array sized by a u64 from userspace, frees it when the check fails, and can be repeated in a tight loop. io_uring still leaves the ring context, the SQPOLL thread data, io-wq, the alloc cache arrays, the kbuf iovecs and the registered eventfds uncharged. The rsrc and tctx surfaces are already charged by commit 075d5837bafc ("io_uring/rsrc: charge buffer arrays and nodes to memcg") and commit 0b34e7b20a48 ("io_uring: charge tctx nodes and personalities"); patches 6-7 pick up what those did not.
Verified on next-20261104 under qemu, same config with and without the series, everything builtin: eight sg fds with 1MB reserved buffers charge 8MB with the series and nothing without; resizing the global trace buffer to 16MB per cpu charges 67MB against 0 before; four 512MB udmabuf buffers charge around 8MB of metadata; sixteen vhost SET_OWNER calls charge 4MB; 1000 io_uring rings charge 7.6MB on top of what the in-tree charging already accounts. All slab allocations in the series are served by kmalloc caches, so they keep charging under the SLAB_MAY_ACCOUNT opt-in rule queued in slab/for-next; the tracing patch accounts page allocations, which are not affected by it.
Two in-flight series overlap but do not collide. The dma-heap explicit memcg charging series moves dma-buf data page charging to an explicit path and removes __GFP_ACCOUNT from the system heap, while patch 2 here accounts udmabuf metadata only, which that series does not see; if it lands first, the system heap reference in patch 2 wants dropping. The io_uring patches sit on top of the charging Mason and Jens already merged, and cite those commits as the in-tree predecessors.
I am sending these in one thread so the class is visible in one place. If any of you would rather take your piece through your own tree, an ack is all I need and I will split the series.
Tao Cui (7):
scsi: sg and st: account the command buffer memory to memcg dma-buf/udmabuf: account the page array metadata to memcg
vhost: account the per-device kernel allocations to memcg
tracing: account ring buffer pages and trace_array metadata to memcg
iommufd: account the hw_queue page array to memcg
io_uring: account the ring context and SQPOLL thread data to memcg
io_uring: account the remaining per-object allocations to memcg
drivers/dma-buf/udmabuf.c | 7 ++++--- drivers/iommu/iommufd/viommu.c | 3 ++- drivers/scsi/sg.c | 23 ++++++++++++++++++++--- drivers/scsi/st.c | 7 ++++--- drivers/vhost/net.c | 14 ++++++++------ drivers/vhost/vhost.c | 16 ++++++++++------ drivers/vhost/vsock.c | 5 +++-- io_uring/alloc_cache.c | 3 ++- io_uring/eventfd.c | 2 +- io_uring/io-wq.c | 4 ++-- io_uring/io_uring.c | 2 +- io_uring/kbuf.c | 2 +- io_uring/rsrc.c | 3 ++- io_uring/sqpoll.c | 2 +- io_uring/tctx.c | 4 ++-- kernel/trace/ring_buffer.c | 8 +++++++- kernel/trace/trace.c | 6 +++--- 17 files changed, 73 insertions(+), 38 deletions(-)
Signature · 1 line
2.43.0