Skip to content

Commit 84029fd

Browse files
shakeelbtorvalds
authored andcommitted
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/[email protected] Signed-off-by: Shakeel Butt <[email protected]> Acked-by: Chris Down <[email protected]> Reviewed-by: Roman Gushchin <[email protected]> Acked-by: Michal Hocko <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent a69b83e commit 84029fd

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

kernel/cred.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ struct cred *cred_alloc_blank(void)
223223
new->magic = CRED_MAGIC;
224224
#endif
225225

226-
if (security_cred_alloc_blank(new, GFP_KERNEL) < 0)
226+
if (security_cred_alloc_blank(new, GFP_KERNEL_ACCOUNT) < 0)
227227
goto error;
228228

229229
return new;
@@ -282,7 +282,7 @@ struct cred *prepare_creds(void)
282282
new->security = NULL;
283283
#endif
284284

285-
if (security_prepare_creds(new, old, GFP_KERNEL) < 0)
285+
if (security_prepare_creds(new, old, GFP_KERNEL_ACCOUNT) < 0)
286286
goto error;
287287
validate_creds(new);
288288
return new;
@@ -715,7 +715,7 @@ struct cred *prepare_kernel_cred(struct task_struct *daemon)
715715
#ifdef CONFIG_SECURITY
716716
new->security = NULL;
717717
#endif
718-
if (security_prepare_creds(new, old, GFP_KERNEL) < 0)
718+
if (security_prepare_creds(new, old, GFP_KERNEL_ACCOUNT) < 0)
719719
goto error;
720720

721721
put_cred(old);

0 commit comments

Comments
 (0)