All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/mprotect: reduce Committed_AS if memory protection is changed to PROT_NONE
@ 2022-04-26 11:27 liusongtang
  2022-04-26 20:34 ` Andrew Morton
  2022-04-30 15:41   ` kernel test robot
  0 siblings, 2 replies; 6+ messages in thread
From: liusongtang @ 2022-04-26 11:27 UTC (permalink / raw)
  To: akpm
  Cc: liusongtang, linux-mm, linux-kernel, nixiaoming, young.liuyang,
	wangkefeng

If PROT_WRITE is set, the size of vm area will be added to Committed_AS.
However, if memory protection is changed to PROT_NONE,
the corresponding physical memory will not be used, but Committed_AS still
count the size of the PROT_NONE memory.

This patch reduce Committed_AS and free the corresponding memory if
memory protection is changed to PROT_NONE.

Signed-off-by: liusongtang <liusongtang@huawei.com>
---
 mm/mprotect.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/mm/mprotect.c b/mm/mprotect.c
index b69ce7a..c3121e6 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -497,6 +497,12 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
 	}
 
 success:
+	if ((newflags & (VM_READ | VM_WRITE | VM_EXEC | VM_LOCKED | VM_ACCOUNT)) == VM_ACCOUNT) {
+		zap_page_range(vma, start, end - start);
+		newflags &= ~VM_ACCOUNT;
+		vm_unacct_memory((end - start) >> PAGE_SHIFT);
+	}
+
 	/*
 	 * vm_flags and vm_page_prot are protected by the mmap_lock
 	 * held in write mode.
-- 
2.12.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-05-03 18:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-26 11:27 [PATCH] mm/mprotect: reduce Committed_AS if memory protection is changed to PROT_NONE liusongtang
2022-04-26 20:34 ` Andrew Morton
2022-04-27  6:34   ` liusongtang
2022-05-03 18:35   ` David Hildenbrand
2022-04-30 15:41 ` [mm/mprotect] 5e1e18b334: kvm-unit-tests.eventinj.fail kernel test robot
2022-04-30 15:41   ` kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.