From: Chris Mason When memory registered with UFFD_FEATURE_EVENT_UNMAP is unmapped, userfaultfd_unmap_prep() allocates a small structure for each userfaultfd context that should be notified. These structures are usually freed only after the monitor reads the events, so userspace controls how many of them are allocated and how long they stay around. They are allocated with GFP_KERNEL, so this memory is not charged to any memory cgroup and memory cgroup limits don't apply to it. Use GFP_KERNEL_ACCOUNT to charge this memory to the memory cgroup of the task that does the unmap. When the memory cgroup reaches its limit, the allocation can now trigger reclaim or the OOM killer there. If the charge fails, it is handled in the same way as any other failure of this allocation. Fixes: 897ab3e0c49e ("userfaultfd: non-cooperative: add event for memory unmaps") Signed-off-by: Chris Mason Signed-off-by: David Hildenbrand (Arm) [rppt: rewrote the changelog] Signed-off-by: Mike Rapoport (Microsoft) --- mm/userfaultfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 15ad69ec2fc0..2ed520c36f71 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -3264,7 +3264,7 @@ int userfaultfd_unmap_prep(struct vm_area_struct *vma, unsigned long start, has_unmap_ctx(ctx, unmaps, start, end)) return 0; - unmap_ctx = kzalloc_obj(*unmap_ctx); + unmap_ctx = kzalloc_obj(*unmap_ctx, GFP_KERNEL_ACCOUNT); if (!unmap_ctx) return -ENOMEM; -- 2.53.0