Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libbpf-tools: fix readahead, support v5.10+ kernel #3253

Merged
merged 1 commit into from
Feb 6, 2021

Conversation

ethercflow
Copy link
Contributor

Fix readahead, support 5.10+ kernel, mentioned in #3224

Signed-off-by: Wenbo Zhang ethercflow@gmail.com

Copy link
Contributor

@anakryiko anakryiko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would probably be cleaner (and less code churn) to leave single BPF_KPROBE and BPF_KRETPROBE program in BPF code (say for the latest variant of function name: do_page_cache_ra), but in runtime using explicit bpf_program__attach_kprobe() call to attach it. At that point, you can override the actual kernel function to attach to. WDYT?

Also, did the readahead start-up time become significantly slower due to ksyms index building? I was wondering if we should provide a simple way to find a single kernel symbol without parsing and remembering all symbols. That should speed up use cases like this, because you'll be parse /proc/kallsyms one line at a time and discarding lines that don't match. And once you found a match, you can finish early. Can you please give it a try?

@ethercflow
Copy link
Contributor Author

It would probably be cleaner (and less code churn) to leave single BPF_KPROBE and BPF_KRETPROBE program in BPF code (say for the latest variant of function name: do_page_cache_ra), but in runtime using explicit bpf_program__attach_kprobe() call to attach it. At that point, you can override the actual kernel function to attach to. WDYT?

That sounds cool, the current way of writing is really frustrating. I'll look at bpf_program__attach_kprobe then give it a try. Thanks!

Also, did the readahead start-up time become significantly slower due to ksyms index building? I was wondering if we should provide a simple way to find a single kernel symbol without parsing and remembering all symbols. That should speed up use cases like this, because you'll be parse /proc/kallsyms one line at a time and discarding lines that don't match. And once you found a match, you can finish early. Can you please give it a try?

Sure, I was wondering whether fallback can be achieved through the error code of bpf_program__attach_kprobe, such as (ENOENT)? If possible, we don’t need to resolve symbols. I'll look at it, if it cann't I'll try speed up way of symbol then.

@anakryiko
Copy link
Contributor

Sure, I was wondering whether fallback can be achieved through the error code of bpf_program__attach_kprobe, such as (ENOENT)? If possible, we don’t need to resolve symbols. I'll look at it, if it cann't I'll try speed up way of symbol then.

I don't know if hard-coding ENOENT is specific enough. But I guess you can just try attaching one, if that fails (with any error), try to attach another one. If that one fails, then report error. It's not as user-friendly as checking existence of ksymbol, but would work and would be pretty fast.

@ethercflow
Copy link
Contributor Author

Sure, I was wondering whether fallback can be achieved through the error code of bpf_program__attach_kprobe, such as (ENOENT)? If possible, we don’t need to resolve symbols. I'll look at it, if it cann't I'll try speed up way of symbol then.

I don't know if hard-coding ENOENT is specific enough. But I guess you can just try attaching one, if that fails (with any error), try to attach another one. If that one fails, then report error. It's not as user-friendly as checking existence of ksymbol, but would work and would be pretty fast.

@anakryiko Fixed, PTAL, thanks!

@anakryiko
Copy link
Contributor

Sure, I was wondering whether fallback can be achieved through the error code of bpf_program__attach_kprobe, such as (ENOENT)? If possible, we don’t need to resolve symbols. I'll look at it, if it cann't I'll try speed up way of symbol then.

I don't know if hard-coding ENOENT is specific enough. But I guess you can just try attaching one, if that fails (with any error), try to attach another one. If that one fails, then report error. It's not as user-friendly as checking existence of ksymbol, but would work and would be pretty fast.

@anakryiko Fixed, PTAL, thanks!

Hm.. sorry, I didn't realize that we were using fentry/fexit, not kprobe/kretprobe. It would be nice to stick fentry/fexit throughout. Let's use the same approach, but instead of doing bpf_program__attach_kprobe() and falling back to attach for another function, we can do bpf_program__set_attach_target() for one function, and if that fails, we can try bpf_program__set_attach_target() for another one. If both fail -- we are screwed and kernel doesn't support BTF or neither function is present.

I think it's actually even cleaner overall, because you can still use skeleton's attach method. You'll just have separate skeleton_open, set_attach_target with fallback, skeleton_load, and then skeleton_attach. How about that?

@ethercflow
Copy link
Contributor Author

Sure, I was wondering whether fallback can be achieved through the error code of bpf_program__attach_kprobe, such as (ENOENT)? If possible, we don’t need to resolve symbols. I'll look at it, if it cann't I'll try speed up way of symbol then.

I don't know if hard-coding ENOENT is specific enough. But I guess you can just try attaching one, if that fails (with any error), try to attach another one. If that one fails, then report error. It's not as user-friendly as checking existence of ksymbol, but would work and would be pretty fast.

@anakryiko Fixed, PTAL, thanks!

Hm.. sorry, I didn't realize that we were using fentry/fexit, not kprobe/kretprobe. It would be nice to stick fentry/fexit throughout. Let's use the same approach, but instead of doing bpf_program__attach_kprobe() and falling back to attach for another function, we can do bpf_program__set_attach_target() for one function, and if that fails, we can try bpf_program__set_attach_target() for another one. If both fail -- we are screwed and kernel doesn't support BTF or neither function is present.

I think it's actually even cleaner overall, because you can still use skeleton's attach method. You'll just have separate skeleton_open, set_attach_target with fallback, skeleton_load, and then skeleton_attach. How about that?

Yeah, I like this suggestion, it looks clear and natural with skeletion, I'll changed to that. Thanks! :)

Signed-off-by: Wenbo Zhang <ethercflow@gmail.com>
@ethercflow
Copy link
Contributor Author

Sure, I was wondering whether fallback can be achieved through the error code of bpf_program__attach_kprobe, such as (ENOENT)? If possible, we don’t need to resolve symbols. I'll look at it, if it cann't I'll try speed up way of symbol then.

I don't know if hard-coding ENOENT is specific enough. But I guess you can just try attaching one, if that fails (with any error), try to attach another one. If that one fails, then report error. It's not as user-friendly as checking existence of ksymbol, but would work and would be pretty fast.

@anakryiko Fixed, PTAL, thanks!

Hm.. sorry, I didn't realize that we were using fentry/fexit, not kprobe/kretprobe. It would be nice to stick fentry/fexit throughout. Let's use the same approach, but instead of doing bpf_program__attach_kprobe() and falling back to attach for another function, we can do bpf_program__set_attach_target() for one function, and if that fails, we can try bpf_program__set_attach_target() for another one. If both fail -- we are screwed and kernel doesn't support BTF or neither function is present.
I think it's actually even cleaner overall, because you can still use skeleton's attach method. You'll just have separate skeleton_open, set_attach_target with fallback, skeleton_load, and then skeleton_attach. How about that?

Yeah, I like this suggestion, it looks clear and natural with skeletion, I'll changed to that. Thanks! :)

@anakryiko Update, PTAL, thanks!

if (!err)
return 0;

fprintf(stderr, "failed to set attach target to %s: %s\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: to -> for

return 0;

fprintf(stderr, "failed to set attach target to %s: %s\n",
bpf_program__section_name(prog), strerror(-err));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use bpf_program__name() instead of bpf_program__section_name()

Comment on lines +126 to +131
err = readahead__set_attach_target(obj->progs.do_page_cache_ra);
if (err)
goto cleanup;
err = readahead__set_attach_target(obj->progs.do_page_cache_ra_ret);
if (err)
goto cleanup;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks pretty clean, I like it!

@yonghong-song
Copy link
Collaborator

[buildbot, test this please]

1 similar comment
@yonghong-song
Copy link
Collaborator

[buildbot, test this please]

@yonghong-song yonghong-song merged commit a976940 into iovisor:master Feb 6, 2021
@yonghong-song
Copy link
Collaborator

@ethercflow I missed that there are some minor changes required. Please do a followup. Thanks!

@ethercflow
Copy link
Contributor Author

@ethercflow I missed that there are some minor changes required. Please do a followup. Thanks!

@yonghong-song Fixed, PTAL, thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants