From: MengEn Sun <mengensun88@gmail.com>
To: mengensun88@gmail.com
Cc: akpm@linux-foundation.org, avagin@google.com,
joel.granados@kernel.org, linux-kernel@vger.kernel.org,
linux@weissschuh.net, mengensun@tencent.com,
yuehongwu@tencent.com
Subject: Re: [PATCH 1/2] ucounts: Move kfree() out of critical zone protected by ucounts_lock
Date: Fri, 6 Dec 2024 12:07:57 +0800 [thread overview]
Message-ID: <1733458077-11339-1-git-send-email-mengensun@tencent.com> (raw)
In-Reply-To: <1733453842-5773-1-git-send-email-mengensun@tencent.com>
I'm very sorry to disturb everyone. I wrote the subject incorrectly, so
this one is void; I will send a new one.
> Date: Fri, 6 Dec 2024 10:57:22 +0800 [thread overview]
> Message-ID: <1733453842-5773-1-git-send-email-mengensun@tencent.com> (raw)
>
> From: MengEn Sun <mengensun@tencent.com>
>
> Although kfree is a non-sleep function, it is possible to enter a
> long chain of calls probabilistically, so it looks better to move
> kfree from alloc_ucounts() out of the critical zone of ucounts_lock.
>
> Reviewed-by: YueHong Wu <yuehongwu@tencent.com>
> Signed-off-by: MengEn Sun <mengensun@tencent.com>
> ---
> kernel/ucount.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/ucount.c b/kernel/ucount.c
> index f950b5e5..86c5f1c 100644
> --- a/kernel/ucount.c
> +++ b/kernel/ucount.c
> @@ -164,8 +164,8 @@ struct ucounts *get_ucounts(struct ucounts *ucounts)
> struct ucounts *alloc_ucounts(struct user_namespace *ns, kuid_t uid)
> {
> struct hlist_head *hashent = ucounts_hashentry(ns, uid);
> - struct ucounts *ucounts, *new;
> bool wrapped;
> + struct ucounts *ucounts, *new = NULL;
>
> spin_lock_irq(&ucounts_lock);
> ucounts = find_ucounts(ns, uid, hashent);
> @@ -182,17 +182,17 @@ struct ucounts *alloc_ucounts(struct
> user_namespace *ns, kuid_t uid)
>
> spin_lock_irq(&ucounts_lock);
> ucounts = find_ucounts(ns, uid, hashent);
> - if (ucounts) {
> - kfree(new);
> - } else {
> + if (!ucounts) {
> hlist_add_head(&new->node, hashent);
> get_user_ns(new->ns);
> spin_unlock_irq(&ucounts_lock);
> return new;
> }
> }
> +
> wrapped = !get_ucounts_or_wrap(ucounts);
> spin_unlock_irq(&ucounts_lock);
> + kfree(new);
> if (wrapped) {
> put_ucounts(ucounts);
> return NULL;
> --
prev parent reply other threads:[~2024-12-06 4:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-06 2:57 mengensun88
2024-12-06 4:07 ` MengEn Sun [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=1733458077-11339-1-git-send-email-mengensun@tencent.com \
--to=mengensun88@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=avagin@google.com \
--cc=joel.granados@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=mengensun@tencent.com \
--cc=yuehongwu@tencent.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
all inboxes | Powered by JetHome®