[PATCH 10/14] resource limits: track highwater mark of address space size

From: Topi Miettinen
Date: Fri Jul 15 2016 - 06:38:00 EST


Track maximum size of address space, to be able to configure
RLIMIT_AS resource limits. The information is available
with taskstats and cgroupstats netlink socket.

Signed-off-by: Topi Miettinen <toiwoton@xxxxxxxxx>
---
mm/mmap.c | 4 ++++
mm/mremap.c | 3 +++
2 files changed, 7 insertions(+)

diff --git a/mm/mmap.c b/mm/mmap.c
index c37f599..ded2f8d 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2707,6 +2707,9 @@ static int do_brk(unsigned long addr, unsigned long len)
out:
perf_event_mmap(vma);
mm->total_vm += len >> PAGE_SHIFT;
+
+ update_resource_highwatermark(RLIMIT_AS, mm->total_vm << PAGE_SHIFT);
+
mm->data_vm += len >> PAGE_SHIFT;
if (flags & VM_LOCKED)
mm->locked_vm += (len >> PAGE_SHIFT);
@@ -2927,6 +2930,7 @@ bool may_expand_vm(struct mm_struct *mm, vm_flags_t flags, unsigned long npages)
void vm_stat_account(struct mm_struct *mm, vm_flags_t flags, long npages)
{
mm->total_vm += npages;
+ update_resource_highwatermark(RLIMIT_AS, mm->total_vm << PAGE_SHIFT);

if (is_exec_mapping(flags))
mm->exec_vm += npages;
diff --git a/mm/mremap.c b/mm/mremap.c
index f1821335..aa717d0 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -398,6 +398,9 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
update_resource_highwatermark(RLIMIT_MEMLOCK,
(mm->locked_vm << PAGE_SHIFT) +
new_len - old_len);
+ update_resource_highwatermark(RLIMIT_AS, (mm->total_vm << PAGE_SHIFT) +
+ new_len - old_len);
+
return vma;
}

--
2.8.1