From: Paul Moore <paul@paul-moore.com>
To: Gaosheng Cui <cuigaosheng1@huawei.com>
Cc: eparis@redhat.com, audit@vger.kernel.org
Subject: Re: [PATCH -next] audit: refactor audit_log_cap to improve performance
Date: Wed, 8 Mar 2023 12:14:07 -0500 [thread overview]
Message-ID: <CAHC9VhR55ygtwzV758j3B7JCMUD2ya-imKdxawZNb3mTMOKYuQ@mail.gmail.com> (raw)
In-Reply-To: <20230307122524.2341659-1-cuigaosheng1@huawei.com>
On Tue, Mar 7, 2023 at 7:25 AM Gaosheng Cui <cuigaosheng1@huawei.com> wrote:
>
> By testing the performance of snprintf on qemu, I found that
> snprintf("%s", str) performed much better than snprintf("xx%s", str),
> the former takes 2ns while the latter takes 60ns.
>
> Based on the test results, using audit_log_format(ab, "%s", prefix)
> instead of audit_log_format(ab, " %s=0", prefix) will get better
> performance, so refactor the audit_log_cap() to improve performance.
>
> Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
> ---
> kernel/auditsc.c | 37 +++++++++++++++++++------------------
> 1 file changed, 19 insertions(+), 18 deletions(-)
>
> diff --git a/kernel/auditsc.c b/kernel/auditsc.c
> index addeed3df15d..d04d0a57a603 100644
> --- a/kernel/auditsc.c
> +++ b/kernel/auditsc.c
> @@ -1295,11 +1295,12 @@ static void audit_log_execve_info(struct audit_context *context,
> static void audit_log_cap(struct audit_buffer *ab, char *prefix,
> kernel_cap_t *cap)
> {
> + audit_log_format(ab, "%s", prefix);
> if (cap_isclear(*cap)) {
> - audit_log_format(ab, " %s=0", prefix);
> + audit_log_format(ab, "0");
> return;
> }
> - audit_log_format(ab, " %s=%016llx", prefix, cap->val);
> + audit_log_format(ab, "%016llx", cap->val);
> }
Have you specifically measured the impact to audit? I worry that any
improvements gained by using snprintf() differently will be lost by
the additional audit_log_format() call for every capability logged.
--
paul-moore.com
prev parent reply other threads:[~2023-03-08 17:16 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-07 12:25 [PATCH -next] audit: refactor audit_log_cap to improve performance Gaosheng Cui
2023-03-08 17:14 ` Paul Moore [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAHC9VhR55ygtwzV758j3B7JCMUD2ya-imKdxawZNb3mTMOKYuQ@mail.gmail.com \
--to=paul@paul-moore.com \
--cc=audit@vger.kernel.org \
--cc=cuigaosheng1@huawei.com \
--cc=eparis@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).