[Devel] [PATCH RHEL8 COMMIT] ms/memcg: account security cred as well to kmemcg

Konstantin Khorenko khorenko at virtuozzo.com
Mon Sep 28 13:05:53 MSK 2020


The commit is pushed to "branch-rh8-4.18.0-193.6.3.vz8.4.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-193.6.3.vz8.4.9
------>
commit 60ab735e5b098212df0c2c944bac4fad0254b375
Author: Shakeel Butt <shakeelb at google.com>
Date:   Sat Jan 4 12:59:43 2020 -0800

    ms/memcg: account security cred as well to kmemcg
    
    The cred_jar kmem_cache is already memcg accounted in the current kernel
    but cred->security is not.  Account cred->security to kmemcg.
    
    Recently we saw high root slab usage on our production and on further
    inspection, we found a buggy application leaking processes.  Though that
    buggy application was contained within its memcg but we observe much
    more system memory overhead, couple of GiBs, during that period.  This
    overhead can adversely impact the isolation on the system.
    
    One source of high overhead we found was cred->security objects, which
    have a lifetime of at least the life of the process which allocated
    them.
    
    Link: http://lkml.kernel.org/r/20191205223721.40034-1-shakeelb@google.com
    Signed-off-by: Shakeel Butt <shakeelb at google.com>
    Acked-by: Chris Down <chris at chrisdown.name>
    Reviewed-by: Roman Gushchin <guro at fb.com>
    Acked-by: Michal Hocko <mhocko at suse.com>
    Cc: Johannes Weiner <hannes at cmpxchg.org>
    Cc: <stable at vger.kernel.org>
    Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
    
    (cherry picked from commit 84029fd04c201a4c7e0b07ba262664900f47c6f5)
    Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
    Found and suggested by Vasily Averin <vvs at virtuozzo.com>
---
 kernel/cred.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/cred.c b/kernel/cred.c
index 45d77284aed0..463a52f66c18 100644
--- a/kernel/cred.c
+++ b/kernel/cred.c
@@ -219,7 +219,7 @@ struct cred *cred_alloc_blank(void)
 	new->magic = CRED_MAGIC;
 #endif
 
-	if (security_cred_alloc_blank(new, GFP_KERNEL) < 0)
+	if (security_cred_alloc_blank(new, GFP_KERNEL_ACCOUNT) < 0)
 		goto error;
 
 	return new;
@@ -277,7 +277,7 @@ struct cred *prepare_creds(void)
 	new->security = NULL;
 #endif
 
-	if (security_prepare_creds(new, old, GFP_KERNEL) < 0)
+	if (security_prepare_creds(new, old, GFP_KERNEL_ACCOUNT) < 0)
 		goto error;
 	validate_creds(new);
 	return new;
@@ -684,7 +684,7 @@ struct cred *prepare_kernel_cred(struct task_struct *daemon)
 #ifdef CONFIG_SECURITY
 	new->security = NULL;
 #endif
-	if (security_prepare_creds(new, old, GFP_KERNEL) < 0)
+	if (security_prepare_creds(new, old, GFP_KERNEL_ACCOUNT) < 0)
 		goto error;
 
 	put_cred(old);


More information about the Devel mailing list