* Re: [PATCH] iommu/sva: Charge IOPF allocations to the faulting mm's memcg
2026-10-12 20:08 [PATCH] iommu/sva: Charge IOPF allocations to the faulting mm's memcg Peizhe Liu
@ 2026-10-12 23:07 ` Shakeel Butt
2026-10-13 2:23 ` Muchun Song
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Shakeel Butt @ 2026-10-12 23:07 UTC (permalink / raw)
To: Peizhe Liu
Cc: Joerg Roedel, Will Deacon, Robin Murphy, Lu Baolu,
Jason Gunthorpe, Kevin Tian, Jean-Philippe Brucker,
Johannes Weiner, Michal Hocko, Roman Gushchin, Muchun Song, iommu,
linux-mm, cgroups, linux-kernel
On Mon, Oct 12, 2026 at 03:08:23PM -0500, Peizhe Liu wrote:
> iommu_sva_handle_mm() runs from the IOPF workqueue and calls
> handle_mm_fault() for the faulting mm, but does not set the active
> memcg. File-backed faults can allocate page cache through
> mem_cgroup_charge(folio, NULL, gfp), which falls back to the root memcg
> when the worker has neither an active memcg nor a current->mm. Page
> cache faulted in by a device is therefore charged to root and escapes
> the task's memory.max.
>
> Set the active memcg to the one associated with the faulting mm while
> handling the fault, and restore the previous value afterwards.
>
> Fixes: fc36479db74e ("iommu: Add a page fault handler")
> Signed-off-by: Peizhe Liu <peizheliu@utexas.edu>
This looks fine from memcg perspective.
Reviewed-by: Shakeel Butt <shakeel.butt@linux.dev>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] iommu/sva: Charge IOPF allocations to the faulting mm's memcg
2026-10-12 20:08 [PATCH] iommu/sva: Charge IOPF allocations to the faulting mm's memcg Peizhe Liu
2026-10-12 23:07 ` Shakeel Butt
@ 2026-10-13 2:23 ` Muchun Song
2026-10-13 12:22 ` Jason Gunthorpe
2026-10-16 4:46 ` Baolu Lu
3 siblings, 0 replies; 5+ messages in thread
From: Muchun Song @ 2026-10-13 2:23 UTC (permalink / raw)
To: Peizhe Liu
Cc: Joerg Roedel, Will Deacon, Robin Murphy, Lu Baolu,
Jason Gunthorpe, Kevin Tian, Jean-Philippe Brucker,
Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt,
iommu, linux-mm, cgroups, linux-kernel
> On Oct 13, 2026, at 04:08, Peizhe Liu <peizheliu@utexas.edu> wrote:
>
> iommu_sva_handle_mm() runs from the IOPF workqueue and calls
> handle_mm_fault() for the faulting mm, but does not set the active
> memcg. File-backed faults can allocate page cache through
> mem_cgroup_charge(folio, NULL, gfp), which falls back to the root memcg
> when the worker has neither an active memcg nor a current->mm. Page
> cache faulted in by a device is therefore charged to root and escapes
> the task's memory.max.
>
> Set the active memcg to the one associated with the faulting mm while
> handling the fault, and restore the previous value afterwards.
>
> Fixes: fc36479db74e ("iommu: Add a page fault handler")
> Signed-off-by: Peizhe Liu <peizheliu@utexas.edu>
Acked-by: Muchun Song <muchun.song@linux.dev>
Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] iommu/sva: Charge IOPF allocations to the faulting mm's memcg
2026-10-12 20:08 [PATCH] iommu/sva: Charge IOPF allocations to the faulting mm's memcg Peizhe Liu
2026-10-12 23:07 ` Shakeel Butt
2026-10-13 2:23 ` Muchun Song
@ 2026-10-13 12:22 ` Jason Gunthorpe
2026-10-16 4:46 ` Baolu Lu
3 siblings, 0 replies; 5+ messages in thread
From: Jason Gunthorpe @ 2026-10-13 12:22 UTC (permalink / raw)
To: Peizhe Liu
Cc: Joerg Roedel, Will Deacon, Robin Murphy, Lu Baolu, Kevin Tian,
Jean-Philippe Brucker, Johannes Weiner, Michal Hocko,
Roman Gushchin, Shakeel Butt, Muchun Song, iommu, linux-mm,
cgroups, linux-kernel
On Mon, Oct 12, 2026 at 03:08:23PM -0500, Peizhe Liu wrote:
> iommu_sva_handle_mm() runs from the IOPF workqueue and calls
> handle_mm_fault() for the faulting mm, but does not set the active
> memcg. File-backed faults can allocate page cache through
> mem_cgroup_charge(folio, NULL, gfp), which falls back to the root memcg
> when the worker has neither an active memcg nor a current->mm. Page
> cache faulted in by a device is therefore charged to root and escapes
> the task's memory.max.
>
> Set the active memcg to the one associated with the faulting mm while
> handling the fault, and restore the previous value afterwards.
>
> Fixes: fc36479db74e ("iommu: Add a page fault handler")
> Signed-off-by: Peizhe Liu <peizheliu@utexas.edu>
> ---
> Tested on a Xeon Gold 5512U with Intel DSA, based on iommu/next.
> Before/after testing confirmed that the block-on-fault case charges
> the page cache to the task's memcg after this change and is subject
> to memory.max.
>
> drivers/iommu/iommu-sva.c | 6 ++++++
> 1 file changed, 6 insertions(+)
It makes sense to me
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Jason
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] iommu/sva: Charge IOPF allocations to the faulting mm's memcg
2026-10-12 20:08 [PATCH] iommu/sva: Charge IOPF allocations to the faulting mm's memcg Peizhe Liu
` (2 preceding siblings ...)
2026-10-13 12:22 ` Jason Gunthorpe
@ 2026-10-16 4:46 ` Baolu Lu
3 siblings, 0 replies; 5+ messages in thread
From: Baolu Lu @ 2026-10-16 4:46 UTC (permalink / raw)
To: Peizhe Liu, Joerg Roedel, Will Deacon
Cc: baolu.lu, Robin Murphy, Jason Gunthorpe, Kevin Tian,
Jean-Philippe Brucker, Johannes Weiner, Michal Hocko,
Roman Gushchin, Shakeel Butt, Muchun Song, iommu, linux-mm,
cgroups, linux-kernel
On 10/13/2026 4:08 AM, Peizhe Liu wrote:
> iommu_sva_handle_mm() runs from the IOPF workqueue and calls
> handle_mm_fault() for the faulting mm, but does not set the active
> memcg. File-backed faults can allocate page cache through
> mem_cgroup_charge(folio, NULL, gfp), which falls back to the root memcg
> when the worker has neither an active memcg nor a current->mm. Page
> cache faulted in by a device is therefore charged to root and escapes
> the task's memory.max.
>
> Set the active memcg to the one associated with the faulting mm while
> handling the fault, and restore the previous value afterwards.
>
> Fixes: fc36479db74e ("iommu: Add a page fault handler")
> Signed-off-by: Peizhe Liu<peizheliu@utexas.edu>
> ---
> Tested on a Xeon Gold 5512U with Intel DSA, based on iommu/next.
> Before/after testing confirmed that the block-on-fault case charges
> the page cache to the task's memcg after this change and is subject
> to memory.max.
>
> drivers/iommu/iommu-sva.c | 6 ++++++
> 1 file changed, 6 insertions(+)
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
^ permalink raw reply [flat|nested] 5+ messages in thread