-
Notifications
You must be signed in to change notification settings - Fork 22
kdump-lib-initramfs: Fix performance regression in kdump_get_conf_val #137
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
Conversation
Summary of ChangesHello @prudo1, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical performance bottleneck in the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request effectively addresses a significant performance regression in kdump_get_conf_val by pre-filtering the configuration file using grep. The implementation is solid, including the correct handling of subshells in pipelines. My review includes a couple of suggestions for further micro-optimizations within the loop to enhance performance by replacing external process calls with shell built-ins, which is in line with the goal of this PR.
Rewriting kdump_get_conf_val in Bash lead to a massive performance regression. On my test system starting the kdump service took $ time kdumpctl start real 0m13.134s user 0m8.828s sys 0m7.450s which is ~20 times slower compared to kdump-utils-1.0.59-1.fc44 with $ time kdumpctl start real 0m0.641s user 0m0.208s sys 0m0.538s Looking at the traces shows that this is caused because Bash now has to handle the whole kdump.conf, including the extensive comment at the start, every time kdump_get_conf_val is called. This is done multiple times when starting the kdump service and is often cloaked by other functions, e.g. is_ssh_dump_target() or get_save_path(). To fix the issue remove comments and empty lines in a regex again so that the Bash code only has to handle valid config entries. With this change alone the performance is almost as good as the original version with $ time kdumpctl start real 0m0.780s user 0m0.330s sys 0m0.604s In the long run it would make sense to also reduce the number of calls to kdump_get_conf_val. This patch also fixes the issue that subsequent blanks are replaced by a single space. Usually this is not an issue but there are corner cases, e.g. in printf-like format strings passed as an argument, where the new behaviour is undesirable. Fixes: d81109c ("kdump-lib-initramfs: rewrite kdump_get_conf_val") Signed-off-by: Philipp Rudo <prudo@redhat.com>
9b887bd to
638c48a
Compare
|
Added first suggestion from Gemini. Even though the expected performance impact should be tiny (comments at the end of the line should be rare) it's better to use the shell build-in functionality if possible. The second suggestion of Gemini cannot be included as it is not POSIX compliant. |
licliu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @prudo1!
This patch looks good to me. Just a small nit: "\s" isn't strictly POSIX-compliant, though I don't think it's an issue here.
|
Hi @prudo1, I'm surprised to find that kdump_get_conf_val can be called so many times, Currently the patch only filters out the comment lines. If your test only covers the default case which mean there are only 3 non-comment lines in the default kdump.conf, maybe you can add more options to /etc/kdump.conf to see how it performs. One interesting thing I notice if I add Another issue with kdump_get_conf_val is it parses kdump.conf again and again whereas parse_config already parses the configs into the
So ideally we should achieve the goal of only parsing once and to achieve this goal bash associative array is necessary. Unfortunately associative array is not POSIX. Personally I think we can switch to bash for kdump-lib-initramfs.sh because Fedora defaults to bash and I notice even changing the root's shell to dash, the kdump initramfs still uses bash. But if we can't make a quick decision and we need better performance, maybe something as follows can be useful, --- a/kdump-lib-initramfs.sh
+++ b/kdump-lib-initramfs.sh
@@ -29,6 +29,11 @@ kdump_get_conf_val()
_to_find="$1"
_found=""
+ if ! $POSIX && ((${#OPT[@]})); then
+ echo -n "${OPT[$1]}"
+ return
+ fiBy the way I notice a problem (not caused by this patch) is cases like |
|
Hi @licliu,
true, |
|
Hi @coiby, thanks for taking a look! Let's start with the important things. I agree with you that more needs to be done. This patch isn't perfect though I deem it good enough for the moment. The only alternative I see is to revert d81109c ("kdump-lib-initramfs: rewrite kdump_get_conf_val") and re-add 1a73387 ("Strip surrounding quotes from configuration values"). But that will leave us with a rather nasty regex to maintain. So I'd prefer to keep this fix. Either way, we should decide quickly. The current state is almost unusable. Taking into account that we also need to backport the fix to RHEL and the merge window closes soon. It would be best when the backport is done before the Chinese New Year holidays. More below.
On my test system I even found 63 calls to I've tried enabling more options in
True, that's an inconsistency we should remove. No idea on what is the right behavior though...
That's not entirely true.
the spaces are squashed but in
the spaces are preserved.
I agree with you that we should aim for only parsing the config once. Although my idea to achieve this is different. I've opened issue #139 for this. As I believe this will be a larger task I suggest we move the discussion there. I've also opened #140 and #141, that should at least help us remove some calls to
True... I never thought about spaces in file names... This makes me think that the 'problem' that was fixed with 1a73387 ("Strip surrounding quotes from configuration values") is actually the desired behavior.... I need to think about this more... Thanks |
|
Hi @prudo1 Thanks for creating the new issues. Since the main problem is performance issue and I think PR fixes the issue without introducing any new problem, I'll merge the PR to give us enough time to come up with a long-term solution. |
Rewriting kdump_get_conf_val in Bash lead to a massive performance regression. On my test system starting the kdump service took
$ time kdumpctl start
real 0m13.134s
user 0m8.828s
sys 0m7.450s
which is ~20 times slower compared to kdump-utils-1.0.59-1.fc44 with
$ time kdumpctl start
real 0m0.641s
user 0m0.208s
sys 0m0.538s
Looking at the traces shows that this is caused because Bash now has to handle the whole kdump.conf, including the extensive comment at the start, every time kdump_get_conf_val is called. This is done multiple times when starting the kdump service and is often cloaked by other functions, e.g. is_ssh_dump_target() or get_save_path().
To fix the issue remove comments and empty lines in a regex again so that the Bash code only has to handle valid config entries. With this change alone the performance is almost as good as the original version with
$ time kdumpctl start
real 0m0.780s
user 0m0.330s
sys 0m0.604s
In the long run it would make sense to also reduce the number of calls to kdump_get_conf_val.
This patch also fixes the issue that subsequent blanks are replaced by a single space. Usually this is not an issue but there are corner cases, e.g. in printf-like format strings passed as an argument, where the new behaviour is undesirable.
Fixes: d81109c ("kdump-lib-initramfs: rewrite kdump_get_conf_val")