Skip to content

Commit f9cce23

Browse files
beaubelgraverostedt
authored andcommitted
tracing/user_events: Charge event allocs to cgroups
Operators need a way to limit how much memory cgroups use. User events need to be included into that accounting. Fix this by using GFP_KERNEL_ACCOUNT for allocations generated by user programs for user_event tracing. Link: https://lkml.kernel.org/r/20230328235219.203-11-beaub@linux.microsoft.com Signed-off-by: Beau Belgrave <beaub@linux.microsoft.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 27dc2ae commit f9cce23

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

kernel/trace/trace_events_user.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ static bool user_event_enabler_dup(struct user_event_enabler *orig,
442442
if (unlikely(test_bit(ENABLE_VAL_FREEING_BIT, ENABLE_BITOPS(orig))))
443443
return true;
444444

445-
enabler = kzalloc(sizeof(*enabler), GFP_NOWAIT);
445+
enabler = kzalloc(sizeof(*enabler), GFP_NOWAIT | __GFP_ACCOUNT);
446446

447447
if (!enabler)
448448
return false;
@@ -502,7 +502,7 @@ static struct user_event_mm *user_event_mm_create(struct task_struct *t)
502502
struct user_event_mm *user_mm;
503503
unsigned long flags;
504504

505-
user_mm = kzalloc(sizeof(*user_mm), GFP_KERNEL);
505+
user_mm = kzalloc(sizeof(*user_mm), GFP_KERNEL_ACCOUNT);
506506

507507
if (!user_mm)
508508
return NULL;
@@ -662,7 +662,7 @@ static struct user_event_enabler
662662
if (!user_mm)
663663
return NULL;
664664

665-
enabler = kzalloc(sizeof(*enabler), GFP_KERNEL);
665+
enabler = kzalloc(sizeof(*enabler), GFP_KERNEL_ACCOUNT);
666666

667667
if (!enabler)
668668
goto out;
@@ -870,7 +870,7 @@ static int user_event_add_field(struct user_event *user, const char *type,
870870
struct ftrace_event_field *field;
871871
int validator_flags = 0;
872872

873-
field = kmalloc(sizeof(*field), GFP_KERNEL);
873+
field = kmalloc(sizeof(*field), GFP_KERNEL_ACCOUNT);
874874

875875
if (!field)
876876
return -ENOMEM;
@@ -889,7 +889,7 @@ static int user_event_add_field(struct user_event *user, const char *type,
889889
if (strstr(type, "char") != NULL)
890890
validator_flags |= VALIDATOR_ENSURE_NULL;
891891

892-
validator = kmalloc(sizeof(*validator), GFP_KERNEL);
892+
validator = kmalloc(sizeof(*validator), GFP_KERNEL_ACCOUNT);
893893

894894
if (!validator) {
895895
kfree(field);
@@ -1175,7 +1175,7 @@ static int user_event_create_print_fmt(struct user_event *user)
11751175

11761176
len = user_event_set_print_fmt(user, NULL, 0);
11771177

1178-
print_fmt = kmalloc(len, GFP_KERNEL);
1178+
print_fmt = kmalloc(len, GFP_KERNEL_ACCOUNT);
11791179

11801180
if (!print_fmt)
11811181
return -ENOMEM;
@@ -1508,7 +1508,7 @@ static int user_event_create(const char *raw_command)
15081508
raw_command += USER_EVENTS_PREFIX_LEN;
15091509
raw_command = skip_spaces(raw_command);
15101510

1511-
name = kstrdup(raw_command, GFP_KERNEL);
1511+
name = kstrdup(raw_command, GFP_KERNEL_ACCOUNT);
15121512

15131513
if (!name)
15141514
return -ENOMEM;
@@ -1704,7 +1704,7 @@ static int user_event_parse(struct user_event_group *group, char *name,
17041704
return 0;
17051705
}
17061706

1707-
user = kzalloc(sizeof(*user), GFP_KERNEL);
1707+
user = kzalloc(sizeof(*user), GFP_KERNEL_ACCOUNT);
17081708

17091709
if (!user)
17101710
return -ENOMEM;
@@ -1874,7 +1874,7 @@ static int user_events_open(struct inode *node, struct file *file)
18741874
if (!group)
18751875
return -ENOENT;
18761876

1877-
info = kzalloc(sizeof(*info), GFP_KERNEL);
1877+
info = kzalloc(sizeof(*info), GFP_KERNEL_ACCOUNT);
18781878

18791879
if (!info)
18801880
return -ENOMEM;
@@ -1927,7 +1927,7 @@ static int user_events_ref_add(struct user_event_file_info *info,
19271927

19281928
size = struct_size(refs, events, count + 1);
19291929

1930-
new_refs = kzalloc(size, GFP_KERNEL);
1930+
new_refs = kzalloc(size, GFP_KERNEL_ACCOUNT);
19311931

19321932
if (!new_refs)
19331933
return -ENOMEM;

0 commit comments

Comments
 (0)