From: Andrew Morton <akpm@linux-foundation.org>
To: Alexey Dobriyan <adobriyan@sw.ru>
Cc: linux-kernel@vger.kernel.org, devel@openvz.org
Subject: Re: [PATCH 2/3] user.c: use kmem_cache_zalloc()
Date: Fri, 21 Sep 2007 12:34:25 -0700 [thread overview]
Message-ID: <20070921123425.54436b17.akpm@linux-foundation.org> (raw)
In-Reply-To: <20070921093906.GB6812@localhost.sw.ru>
On Fri, 21 Sep 2007 13:39:06 +0400
Alexey Dobriyan <adobriyan@sw.ru> wrote:
> Quite a few fields are zeroed during user_struct creation, so use
> kmem_cache_zalloc() -- save a few lines and #ifdef. Also will help avoid
> #ifdef CONFIG_POSIX_MQUEUE in next patch.
>
> Signed-off-by: Alexey Dobriyan <adobriyan@sw.ru>
> ---
>
> kernel/user.c | 13 +------------
> 1 file changed, 1 insertion(+), 12 deletions(-)
>
> --- a/kernel/user.c
> +++ b/kernel/user.c
> @@ -129,21 +129,11 @@ struct user_struct * alloc_uid(struct user_namespace *ns, uid_t uid)
> if (!up) {
> struct user_struct *new;
>
> - new = kmem_cache_alloc(uid_cachep, GFP_KERNEL);
> + new = kmem_cache_zalloc(uid_cachep, GFP_KERNEL);
> if (!new)
> return NULL;
> new->uid = uid;
> atomic_set(&new->__count, 1);
> - atomic_set(&new->processes, 0);
> - atomic_set(&new->files, 0);
> - atomic_set(&new->sigpending, 0);
> -#ifdef CONFIG_INOTIFY_USER
> - atomic_set(&new->inotify_watches, 0);
> - atomic_set(&new->inotify_devs, 0);
> -#endif
> -
> - new->mq_bytes = 0;
> - new->locked_shm = 0;
This assumes that setting an atomic_t to the all-zeroes pattern is
equivalent to atomic_set(v, 0).
This happens to be true for all present architectures, afaik. But an
architecture which has crappy primitives could quite legitimately implement
its atomic_t as:
typedef struct {
int counter;
spinlock_t lock;
} atomic_t;
in which case your assumption breaks.
So it's all a bit theoretical and a bit anal, and I'm sure we're making the
same mistake in other places, but it's not a change I particularly like..
next prev parent reply other threads:[~2007-09-21 19:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-21 9:39 Alexey Dobriyan
2007-09-21 19:34 ` Andrew Morton [this message]
2007-09-22 4:33 ` Satyam Sharma
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=20070921123425.54436b17.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=adobriyan@sw.ru \
--cc=devel@openvz.org \
--cc=linux-kernel@vger.kernel.org \
/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®