-
Notifications
You must be signed in to change notification settings - Fork 10
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
Performance impact measurement tool #24
Comments
I don't think that adding tracepoints is a good solution here. Possibly, it would be better to use kprobes. However, they have some issues compared to tracepoints:
What do you think? [1] https://lore.kernel.org/all/[email protected]/
|
I think kprobes/kretprobes would be fine from a performance point of view, but that may not be enough to identify requests to specific kernel objects (e.g. the performance impact of opening a specific file). That may not be an issue for benchmark if we can scope the probes to only the benchmarked process though. I think tracepoints are useful when we need to increment a counter or print variables according to code within a function or with a specific semantic (not necessarily passed as function argument). The kernel API change and especially the Landlock changes should not be a big issue because the benchmark tool would mostly live with the kernel source code and could be part of the Kselftests and be updated with the kernel code. |
Hello @sm1ling-knight -- just for coordination; did you start working on this bug already? |
Hello! Yep, I'm currently working on it. |
Good! We should explicit say when we started or want to work on a task to avoid duplicated work. 😉 |
@l0kod, do you have any cases of what events would be useful to trace in Landlock? I currently have an idea of tracing I also want to add CPU profiling to measure overhead of Landlock changes. What do you think? |
I expect On top of that, timing each LSM hook (including the Landlock hook implementations) called per syscall should give a good overview of Landlock's impact on the kernel's execution time.
That would be very useful! |
For reference, Flame Graphs are a visualization tool (relying on kernel features such as perf) useful to see a performance impact and to debug, but not to quickly compare two implementations nor to measure according to a context (e.g., depth of a file path) in an automatic (and deterministic as much as possible) way. |
In my mind, the percentage of time spent in Landlock would be an interesting metric to capture; In particular, the entry point functions are interesting, which are hit during program execution; that is: (a) the three syscalls, and (b) the LSM hooks which Landlock overrides. This is already recorded when doing
It might be wiser to replace /bin/ls with something more long running. With The result can then be plotted with Brendan Gregg's Flame graph scripts; I'm using this:
or it can be analyzed with This is just how far I got with the obvious part. I figured that
|
I don't think that perf is suitable for our case. Execution time of hooks may be too short for perf to provide sufficient accuracy. On my system execution of 'file_open' hook takes about 4e-5 seconds (in average) for sandboxed I got these values using bpftrace tool and implementing #define call_void_hook(FUNC, ...) \
do { \
struct security_hook_list *P; \
\
hlist_for_each_entry(P, &security_hook_heads.FUNC, list) { \
trace_lsm_hook_enter(P->lsmid->id, #FUNC); \
P->hook.FUNC(__VA_ARGS__); \
trace_lsm_hook_exit(P->lsmid->id, #FUNC); \
} \
} while (0) Tracepoints were used to gather total execution time and total number of calls for 'file_open' hook and openat syscall. You can see bpftrace script similar to the one I used for gathering at the end of the message It seems that sampling frequency should be at least on the order of 10^-5 seconds for adequate accuracy. From Brendan Gregg's blog: It turns out that the sampling frequency that does not involve overhead is on the order of 10^-2. Using perf would be unacceptable in order to measure time taken by hook accurately enough. Moreover, using perf involves problem with tracing static symbols in fs.c, net.c (such as hooks) and extracting CPU percentages (as you mentioned). I suggest using bpftrace tool for profiling. It seems like quite convenient way to measure execution time for our case with almost zero overhead. Bpftrace allows to add gathering instructions for every required tracing blob (tracepoint, kprobe, uprobe..). To measure time in this way, following steps are required:
|
Because we can change the Landlock/kernel code, I don't think we should be limited by any sampling frequency. Your bpftrace script looks good! I guess we should not need more dependency than this tool.
We indeed need all benchmarks to be simply run, eventually by a CI. However, it would help to also be able to create a flamegraph from these benchmarks, but that could be another iteration of the patches.
We should have both microbenchmarks and real-world benchmarks. It looks like bpftrace scripts should be good for both cases. The main intensive and real-world scenarios that come to mind are:
|
Hello! Can i send the implementation as landlock-test-tools pull request? (when it's ready) |
As for the seccomp benchmark tool, it would help to keep similar tools in the kernel source tree e.g., to easily run performance tests with a kernel CI, and to add reference to performance improvements in commit messages. Moreover, the benchmark scripts may need to evolve along with future kernel versions (e.g. if an LSM hooks change). I think higher level tooling (e.g. generate flame graphs, compare performance of two kernel versions) would make sense in landlock-test-tools though. |
Do you agree that adding tracepoints |
Yes, that looks reasonable to me. |
Btw, i decided to try bcc to solve this issue. It's a bit more verbose compared to bpftrace, but it makes it easier to work with command line arguments and custom output (for manual usage). I think it doesn't require a lot of dependencies, so I'll try to make the first patch using bcc. It should be easy to switch into bpftrace, if something goes wrong. |
FYI, patches fixing an issue in perf with Landlock and BTF: |
We need tooling to measure the performance impact of kernel changes. Until now, we used simple scripts to get an idea of the worse case scenarios, and manual profiling.
It would be useful to have a way to measure in a predictive way the overhead of sandboxing on a set of scenarios (e.g. path walk) with synthetic benchmarks. Several tracing kernel features might be interesting: tracepoints, eBPF...
We might need kernel changes such as tracepoints.
This measurement tool should be simple to use manually and by a CI (see landlock-test-tools). It would be useful to measure performance improvement changes (#1 and #9).
See seccomp_benchmark.c and other benchmark programs in tools/testing/selftests.
The text was updated successfully, but these errors were encountered: