[Devel] [PATCH RHEL7 COMMIT] ub: account memory overcommit failures in UB_PRIVVMPAGES.failcnt

Konstantin Khorenko khorenko at virtuozzo.com
Mon Jun 27 04:36:33 PDT 2016


The commit is pushed to "branch-rh7-3.10.0-327.18.2.vz7.14.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-327.18.2.vz7.14.21
------>
commit d72403517f67ba6f790178ce539e36b5bc5eebe8
Author: Andrey Ryabinin <aryabinin at virtuozzo.com>
Date:   Mon Jun 27 15:36:33 2016 +0400

    ub: account memory overcommit failures in UB_PRIVVMPAGES.failcnt
    
    If allocation failed due to memory overcommit failcounters doesn't change.
    This contradicts with userspace expectations.
    With this patch, such failures will be accounted in failconter of
    UB_PRIVVMPAGES.
    
    https://jira.sw.ru/browse/PSBM-48891
    
    Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
    Reviewed-by: Vladimir Davydov <vdavydov at virtuozzo.com>
---
 kernel/bc/vm_pages.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/kernel/bc/vm_pages.c b/kernel/bc/vm_pages.c
index 63b335d..0bc5dda 100644
--- a/kernel/bc/vm_pages.c
+++ b/kernel/bc/vm_pages.c
@@ -125,6 +125,7 @@ int ub_enough_memory(struct mm_struct *mm, long pages)
 {
 	struct user_beancounter *ub;
 	struct cgroup_subsys_state *css;
+	unsigned long flags;
 	int ret;
 
 	if (!mm)
@@ -133,8 +134,10 @@ int ub_enough_memory(struct mm_struct *mm, long pages)
 	ub = mm->mm_ub;
 
 	if (ub->ub_parms[UB_PRIVVMPAGES].held >
-	    ub->ub_parms[UB_PRIVVMPAGES].barrier)
-		return -ENOMEM;
+	    ub->ub_parms[UB_PRIVVMPAGES].barrier) {
+		ret = -ENOMEM;
+		goto out;
+	}
 
 	if (ub == get_ub0() || ub_overcommit_memory)
 		return 0;
@@ -142,6 +145,12 @@ int ub_enough_memory(struct mm_struct *mm, long pages)
 	css = ub_get_mem_css(ub);
 	ret = mem_cgroup_enough_memory(mem_cgroup_from_cont(css->cgroup), pages);
 	css_put(css);
+out:
+	if (unlikely(ret < 0)) {
+		spin_lock_irqsave(&ub->ub_lock, flags);
+		ub->ub_parms[UB_PRIVVMPAGES].failcnt++;
+		spin_unlock_irqrestore(&ub->ub_lock, flags);
+	}
 	return ret;
 }
 


More information about the Devel mailing list