Skip to content

Commit

Permalink
libbpf-tools: Fix cachestat with kernel 5.15
Browse files Browse the repository at this point in the history
The tool cachestat is broken on kernel 5.15 due to kernel function
renaming. Fix the tool by detecting symbol existence. See #3687 and

Signed-off-by: Hengqi Chen <chenhengqi@outlook.com>
  • Loading branch information
chenhengqi authored and serverlessplus committed Feb 16, 2022
1 parent 8db99af commit f4bdc26
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion libbpf-tools/cachestat.c
Expand Up @@ -144,10 +144,29 @@ int main(int argc, char **argv)

obj = cachestat_bpf__open_and_load();
if (!obj) {
fprintf(stderr, "failed to open and/or load BPF object\n");
fprintf(stderr, "failed to open BPF object\n");
return 1;
}

/**
* account_page_dirtied was renamed to folio_account_dirtied
* in kernel commit 203a31516616 ("mm/writeback: Add __folio_mark_dirty()")
*/
if (fentry_exists("folio_account_dirtied", NULL)) {
err = bpf_program__set_attach_target(obj->progs.account_page_dirtied, 0,
"folio_account_dirtied");
if (err) {
fprintf(stderr, "failed to set attach target\n");
goto cleanup;
}
}

err = cachestat_bpf__load(obj);
if (err) {
fprintf(stderr, "failed to load BPF object\n");
goto cleanup;
}

if (!obj->bss) {
fprintf(stderr, "Memory-mapping BPF maps is supported starting from Linux 5.7, please upgrade.\n");
goto cleanup;
Expand Down

0 comments on commit f4bdc26

Please sign in to comment.