History

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

Beau Belgrave committed 3 years ago

Commit f9cce231 parent 27dc2ae1 file · +10 −10Browse files

Unified · Split

kernel/trace/trace_events_user.c+10−10
@@ -442,7 +442,7 @@ static bool user_event_enabler_dup(struct user_event_enabler *orig, · 441 unmodified lines
442 if (unlikely(test_bit(ENABLE_VAL_FREEING_BIT, ENABLE_BITOPS(orig))))442 if (unlikely(test_bit(ENABLE_VAL_FREEING_BIT, ENABLE_BITOPS(orig))))
443 return true;443 return true;
444 444
445 enabler = kzalloc(sizeof(*enabler), GFP_NOWAIT);445 enabler = kzalloc(sizeof(*enabler), GFP_NOWAIT | __GFP_ACCOUNT);
446 446
447 if (!enabler)447 if (!enabler)
448 return false;448 return false;
@@ -502,7 +502,7 @@ static struct user_event_mm *user_event_mm_create(struct task_struct *t) · 53 unmodified lines
502 struct user_event_mm *user_mm;502 struct user_event_mm *user_mm;
503 unsigned long flags;503 unsigned long flags;
504 504
505 user_mm = kzalloc(sizeof(*user_mm), GFP_KERNEL);505 user_mm = kzalloc(sizeof(*user_mm), GFP_KERNEL_ACCOUNT);
506 506
507 if (!user_mm)507 if (!user_mm)
508 return NULL;508 return NULL;
@@ -662,7 +662,7 @@ static struct user_event_enabler · 153 unmodified lines
662 if (!user_mm)662 if (!user_mm)
663 return NULL;663 return NULL;
664 664
665 enabler = kzalloc(sizeof(*enabler), GFP_KERNEL);665 enabler = kzalloc(sizeof(*enabler), GFP_KERNEL_ACCOUNT);
666 666
667 if (!enabler)667 if (!enabler)
668 goto out;668 goto out;
@@ -870,7 +870,7 @@ static int user_event_add_field(struct user_event *user, const char *type, · 201 unmodified lines
870 struct ftrace_event_field *field;870 struct ftrace_event_field *field;
871 int validator_flags = 0;871 int validator_flags = 0;
872 872
873 field = kmalloc(sizeof(*field), GFP_KERNEL);873 field = kmalloc(sizeof(*field), GFP_KERNEL_ACCOUNT);
874 874
875 if (!field)875 if (!field)
876 return -ENOMEM;876 return -ENOMEM;
@@ -889,7 +889,7 @@ add_validator: · 12 unmodified lines
889 if (strstr(type, "char") != NULL)889 if (strstr(type, "char") != NULL)
890 validator_flags |= VALIDATOR_ENSURE_NULL;890 validator_flags |= VALIDATOR_ENSURE_NULL;
891 891
892 validator = kmalloc(sizeof(*validator), GFP_KERNEL);892 validator = kmalloc(sizeof(*validator), GFP_KERNEL_ACCOUNT);
893 893
894 if (!validator) {894 if (!validator) {
895 kfree(field);895 kfree(field);
@@ -1175,7 +1175,7 @@ static int user_event_create_print_fmt(struct user_event *user) · 279 unmodified lines
1175 1175
1176 len = user_event_set_print_fmt(user, NULL, 0);1176 len = user_event_set_print_fmt(user, NULL, 0);
1177 1177
1178 print_fmt = kmalloc(len, GFP_KERNEL);1178 print_fmt = kmalloc(len, GFP_KERNEL_ACCOUNT);
1179 1179
1180 if (!print_fmt)1180 if (!print_fmt)
1181 return -ENOMEM;1181 return -ENOMEM;
@@ -1508,7 +1508,7 @@ static int user_event_create(const char *raw_command) · 326 unmodified lines
1508 raw_command += USER_EVENTS_PREFIX_LEN;1508 raw_command += USER_EVENTS_PREFIX_LEN;
1509 raw_command = skip_spaces(raw_command);1509 raw_command = skip_spaces(raw_command);
1510 1510
1511 name = kstrdup(raw_command, GFP_KERNEL);1511 name = kstrdup(raw_command, GFP_KERNEL_ACCOUNT);
1512 1512
1513 if (!name)1513 if (!name)
1514 return -ENOMEM;1514 return -ENOMEM;
@@ -1704,7 +1704,7 @@ static int user_event_parse(struct user_event_group *group, char *name, · 189 unmodified lines
1704 return 0;1704 return 0;
1705 }1705 }
1706 1706
1707 user = kzalloc(sizeof(*user), GFP_KERNEL);1707 user = kzalloc(sizeof(*user), GFP_KERNEL_ACCOUNT);
1708 1708
1709 if (!user)1709 if (!user)
1710 return -ENOMEM;1710 return -ENOMEM;
@@ -1874,7 +1874,7 @@ static int user_events_open(struct inode *node, struct file *file) · 163 unmodified lines
1874 if (!group)1874 if (!group)
1875 return -ENOENT;1875 return -ENOENT;
1876 1876
1877 info = kzalloc(sizeof(*info), GFP_KERNEL);1877 info = kzalloc(sizeof(*info), GFP_KERNEL_ACCOUNT);
1878 1878
1879 if (!info)1879 if (!info)
1880 return -ENOMEM;1880 return -ENOMEM;
@@ -1927,7 +1927,7 @@ static int user_events_ref_add(struct user_event_file_info *info, · 46 unmodified lines
1927 1927
1928 size = struct_size(refs, events, count + 1);1928 size = struct_size(refs, events, count + 1);
1929 1929
1930 new_refs = kzalloc(size, GFP_KERNEL);1930 new_refs = kzalloc(size, GFP_KERNEL_ACCOUNT);
1931 1931
1932 if (!new_refs)1932 if (!new_refs)
1933 return -ENOMEM;1933 return -ENOMEM;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t