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

acl: Avoid allocations when checking implied ops #12079

Merged

Conversation

StephanDollberg
Copy link
Member

acl_implied_ops was quite visible (~3%) in the callchains leading to operator new() in the LRC profile.

It's called for every partition so this is not entirely surprising when using larger partition counts.

Avoid the allocations by "inlining" the check into the function so that no vector has to be allocated.

Backports Required

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v23.1.x
  • v22.3.x
  • v22.2.x

Release Notes

  • none

@StephanDollberg
Copy link
Member Author

image

dotnwat
dotnwat previously approved these changes Jul 13, 2023

switch (operation) {
case acl_operation::describe: {
std::array ops = {
Copy link
Contributor

Choose a reason for hiding this comment

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

why not mark static?

Copy link
Contributor

Choose a reason for hiding this comment

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

i suppose it may get inline anyway?

Copy link
Member Author

@StephanDollberg StephanDollberg Jul 13, 2023

Choose a reason for hiding this comment

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

That's what I assumed yes.

Codegen is actually quite interesting: https://gcc.godbolt.org/z/vfd6Mfasn

Depending on the numbers clang actually generates some bithacks to shortcut. Also codegen can be different dependent on the numbers between using static and not.

However, looking at llvm-mca (you need to comment out the functions you are not interested in or copy to https://uica.uops.info/) it seems the non-static version generates more efficient code. This is obviously not a microbenchmark as it also depends on what we search but it gives a good idea I think.

Copy link
Member

@travisdowns travisdowns Jul 13, 2023

Choose a reason for hiding this comment

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

A local static constexpr usually seems the best to me, if it's possible: keeps the table local to the scope it is used, doesn't pose any chance of stack allocations a non-static array might, or the "lazy init" that a non-constexpr static might cause (i.e., when you start see guard variable for XYZ like this though there has to be something that doesn't let the compiler do static init in the .data or .rodata sections for that to happen).

H/e oddly here static non-constexpr has different codegen from the other options as Stephan points odd. Pretty odd and inexplicable (which is itself not really odd weird when talking about compiler opts).

Copy link
Member Author

Choose a reason for hiding this comment

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

Switched to static constexpr

Copy link
Member

@travisdowns travisdowns left a comment

Choose a reason for hiding this comment

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

obligatory finish my review comment


switch (operation) {
case acl_operation::describe: {
std::array ops = {
Copy link
Member

@travisdowns travisdowns Jul 13, 2023

Choose a reason for hiding this comment

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

A local static constexpr usually seems the best to me, if it's possible: keeps the table local to the scope it is used, doesn't pose any chance of stack allocations a non-static array might, or the "lazy init" that a non-constexpr static might cause (i.e., when you start see guard variable for XYZ like this though there has to be something that doesn't let the compiler do static init in the .data or .rodata sections for that to happen).

H/e oddly here static non-constexpr has different codegen from the other options as Stephan points odd. Pretty odd and inexplicable (which is itself not really odd weird when talking about compiler opts).

@@ -131,6 +124,42 @@ class authorizer final {
}

private:
/*
* Compute whether the implied operations are allowed based on the specified
Copy link
Member

Choose a reason for hiding this comment

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

I think maybe the comment is backwards, or I'm not parsing it correctly?

Isn't it:

Determine whether the given operation is allowed based on the implied allowed operations in acl_matches.

?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes you are right - fixing.

travisdowns
travisdowns previously approved these changes Jul 13, 2023
`acl_implied_ops` was quite visible (~3%) in the callchains leading to
`operator new()` in the LRC profile.

It's called for every partition so this is not entirely surprising when
using larger partition counts.

Avoid the allocations by "inlining" the check into the function so that
no vector has to be allocated.
Copy link
Member

@travisdowns travisdowns left a comment

Choose a reason for hiding this comment

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

LGTM

@piyushredpanda piyushredpanda merged commit ebe34d6 into redpanda-data:dev Jul 14, 2023
@vbotbuildovich
Copy link
Collaborator

/backport v23.1.x

@vbotbuildovich
Copy link
Collaborator

/backport v22.3.x

@vbotbuildovich
Copy link
Collaborator

Failed to run cherry-pick command. I executed the commands below:

git checkout -b backport-pr-12079-v22.3.x-367 remotes/upstream/v22.3.x
git cherry-pick -x 74ea2372fd749c18ce7a63dc67790d20c8ad25df

Workflow run logs.

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

Successfully merging this pull request may close these issues.

6 participants