Skip to content

Commit 3ea2f2b

Browse files
oleg-nesterovIngo Molnar
authored andcommitted
perf: Do not waste PAGE_SIZE bytes for ALIGN(8) in perf_event_mmap_event()
perf_event_mmap_event() does kzalloc(PATH_MAX + sizeof(u64)) to ensure we can align the size later. However this means that we actually allocate PAGE_SIZE * 2 buffer, seems too much. Change this code to allocate PATH_MAX==PAGE_SIZE bytes, but tell d_path() to not use the last sizeof(u64) bytes. Note: it is not clear why do we need __GFP_ZERO, see the next patch. Signed-off-by: Oleg Nesterov <[email protected]> Signed-off-by: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 32c5fb7 commit 3ea2f2b

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

kernel/events/core.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5113,17 +5113,18 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
51135113
if (file) {
51145114
struct inode *inode;
51155115
dev_t dev;
5116-
/*
5117-
* d_path works from the end of the rb backwards, so we
5118-
* need to add enough zero bytes after the string to handle
5119-
* the 64bit alignment we do later.
5120-
*/
5121-
buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
5116+
5117+
buf = kzalloc(PATH_MAX, GFP_KERNEL);
51225118
if (!buf) {
51235119
name = strncpy(tmp, "//enomem", sizeof(tmp));
51245120
goto got_name;
51255121
}
5126-
name = d_path(&file->f_path, buf, PATH_MAX);
5122+
/*
5123+
* d_path() works from the end of the rb backwards, so we
5124+
* need to add enough zero bytes after the string to handle
5125+
* the 64bit alignment we do later.
5126+
*/
5127+
name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
51275128
if (IS_ERR(name)) {
51285129
name = strncpy(tmp, "//toolong", sizeof(tmp));
51295130
goto got_name;

0 commit comments

Comments
 (0)