-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Support big strings #3228
Merged
Merged
Support big strings #3228
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In another window:
@tyroguru you'll be happy to know I woke up this morning with the approach fully formed in my head. But perhaps also sad to know it blew up my sunday :) |
Related but not done: #2853 |
danobi
force-pushed
the
big_str
branch
2 times, most recently
from
June 10, 2024 03:02
bf0893f
to
c919a83
Compare
danobi
force-pushed
the
big_str
branch
2 times, most recently
from
June 10, 2024 17:16
1fd35fa
to
d026d58
Compare
jordalgo
reviewed
Jun 11, 2024
jordalgo
reviewed
Jun 11, 2024
This all looks great and surprisingly straightforward. |
jordalgo
reviewed
Jun 11, 2024
Order the ids in the order they were defined in codegen_llvm.h. This makes it easier to spot missing ids.
We were missing cgroup_path_id and watchpoint_id. Without this, there would be bugs for cgroupid() if it is used inside a loop or in an expanded probe. Similarly, if watchpoint probes are expanded, there would have been bugs.
There is no need to keep the strlen value explicitly on stack. We can leave it up to LLVM whether or not to spill onto stack or keep in a register.
Before, strncmp codegen assumed that caller was passing in two alloca'd strings. This assumption was fine but overly narrow now that we are implementing big strings. Big strings are not an array type (alloca), but rather a proper pointer. Relax assumption by using a more general pointer to i8.
Previously, all strings needed to be stored on the stack. Given that BPF has a 512B stack limit, this put serious limits on strings. In practice, it was limited to about 200B. This commit raises the limit much higher to around 1024. The new limit we hit is from the LLVM memset() builtin. It only supports up to 1K. To go above this, we need to create our own memset() routine in BPF. This is quite easy to do and will be attempted in a later commit. The way big strings work is by assigning each str() call in the script a unique ID. Then we create a percpu array map such that for each CPU, there is a percpu entry that can accomodate each str() callsite. This makes it so scripts can keep as many strings "on the stack" as they'd like, with the tradeoff being the amount of memory we need to preallocate. As long as the kernel never allows BPF programs to nest (eg execute prog A while prog A is already on the call stack), this approach is robust to self-corruption. Note we do not yet remove or change default value of BPFTRACE_MAX_STRLEN. That is b/c a few other helpers (buf(), path(), maybe more) also read the value and allocate space on stack accordingly. We need to decouple or convert those helpers to scratch maps as well. This closes bpftrace#305.
jordalgo
approved these changes
Jun 12, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, all strings needed to be stored on the stack. Given that BPF
has a 512B stack limit, this put serious limits on strings. In practice,
it was limited to about 200B.
This PR raises the limit much higher to around 1024. The new limit
we hit is from the LLVM memset() builtin. It only supports up to 1K. To
go above this, we need to create our own memset() routine in BPF. This
is quite easy to do and will be attempted in a later commit.
The way big strings work is by assigning each str() call in the script a
unique ID. Then we create a percpu array map such that for each CPU,
there is a percpu entry that can accomodate each str() callsite. This
makes it so scripts can keep as many strings "on the stack" as they'd
like, with the tradeoff being the amount of memory we need to
preallocate.
As long as the kernel never allows BPF programs to nest (eg execute prog
A while prog A is already on the call stack), this approach is robust to
self-corruption.
This closes #305.
Checklist
man/adoc/bpftrace.adoc
CHANGELOG.md