* [PATCH] Remove some pointless conditionals before kfree() in kernel/cgroup.c
@ 2009-02-22 22:05 Jesper Juhl
2009-02-23 8:12 ` Paul Menage
2009-02-23 8:32 ` Li Zefan
0 siblings, 2 replies; 7+ messages in thread
From: Jesper Juhl @ 2009-02-22 22:05 UTC (permalink / raw)
To: linux-kernel
Cc: Stephen Hemminger, Paul Jackson, Simon Derr, Paul Menage,
Jesper Juhl
Hi,
Here's a small patch for kernel/cgroup.c
Removes a few pointless tests of pointer == 0 before kfree() in
kernel/cgroup.c.
If the pointer we hand to kfree() is 0, then kfree() is a noop, so there
is no need to test.
Reduces object file size a bit :
Before:
$ size kernel/cgroup.o
text data bss dec hex filename
21593 7804 4924 34321 8611 kernel/cgroup.o
After:
$ size kernel/cgroup.o
text data bss dec hex filename
21537 7744 4924 34205 859d kernel/cgroup.o
and source file size shrinks a bit too - always nice.
Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 9edb5c4..1c0a9b5 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -865,8 +865,7 @@ static int cgroup_remount(struct super_block *sb, int *flags, char *data)
if (opts.release_agent)
strcpy(root->release_agent_path, opts.release_agent);
out_unlock:
- if (opts.release_agent)
- kfree(opts.release_agent);
+ kfree(opts.release_agent);
mutex_unlock(&cgroup_mutex);
mutex_unlock(&cgrp->dentry->d_inode->i_mutex);
return ret;
@@ -969,15 +968,13 @@ static int cgroup_get_sb(struct file_system_type *fs_type,
/* First find the desired set of subsystems */
ret = parse_cgroupfs_options(data, &opts);
if (ret) {
- if (opts.release_agent)
- kfree(opts.release_agent);
+ kfree(opts.release_agent);
return ret;
}
root = kzalloc(sizeof(*root), GFP_KERNEL);
if (!root) {
- if (opts.release_agent)
- kfree(opts.release_agent);
+ kfree(opts.release_agent);
return -ENOMEM;
}
--
Jesper Juhl <jj@chaosbits.net> http://www.chaosbits.net/
Plain text mails only, please http://www.expita.com/nomime.html
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH] Remove some pointless conditionals before kfree() in kernel/cgroup.c
2009-02-22 22:05 [PATCH] Remove some pointless conditionals before kfree() in kernel/cgroup.c Jesper Juhl
@ 2009-02-23 8:12 ` Paul Menage
2009-02-23 8:17 ` Cyrill Gorcunov
` (2 more replies)
2009-02-23 8:32 ` Li Zefan
1 sibling, 3 replies; 7+ messages in thread
From: Paul Menage @ 2009-02-23 8:12 UTC (permalink / raw)
To: Jesper Juhl; +Cc: linux-kernel, Stephen Hemminger, Paul Jackson, Simon Derr
On Sun, Feb 22, 2009 at 2:05 PM, Jesper Juhl <jj@chaosbits.net> wrote:
> Hi,
>
> Here's a small patch for kernel/cgroup.c
>
> Removes a few pointless tests of pointer == 0 before kfree() in
> kernel/cgroup.c.
> If the pointer we hand to kfree() is 0, then kfree() is a noop, so there
> is no need to test.
>
> Reduces object file size a bit :
>
> Before:
> $ size kernel/cgroup.o
> text data bss dec hex filename
> 21593 7804 4924 34321 8611 kernel/cgroup.o
> After:
> $ size kernel/cgroup.o
> text data bss dec hex filename
> 21537 7744 4924 34205 859d kernel/cgroup.o
Thanks. I'm a bit surprised that it also shrunk the data segment size
(and in fact, by more than the text segment size). Any idea how that
came about?
>
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>
Acked-by: Paul Menage <menage@google.com>
Paul
> ---
>
> diff --git a/kernel/cgroup.c b/kernel/cgroup.c
> index 9edb5c4..1c0a9b5 100644
> --- a/kernel/cgroup.c
> +++ b/kernel/cgroup.c
> @@ -865,8 +865,7 @@ static int cgroup_remount(struct super_block *sb, int *flags, char *data)
> if (opts.release_agent)
> strcpy(root->release_agent_path, opts.release_agent);
> out_unlock:
> - if (opts.release_agent)
> - kfree(opts.release_agent);
> + kfree(opts.release_agent);
> mutex_unlock(&cgroup_mutex);
> mutex_unlock(&cgrp->dentry->d_inode->i_mutex);
> return ret;
> @@ -969,15 +968,13 @@ static int cgroup_get_sb(struct file_system_type *fs_type,
> /* First find the desired set of subsystems */
> ret = parse_cgroupfs_options(data, &opts);
> if (ret) {
> - if (opts.release_agent)
> - kfree(opts.release_agent);
> + kfree(opts.release_agent);
> return ret;
> }
>
> root = kzalloc(sizeof(*root), GFP_KERNEL);
> if (!root) {
> - if (opts.release_agent)
> - kfree(opts.release_agent);
> + kfree(opts.release_agent);
> return -ENOMEM;
> }
>
>
>
> --
> Jesper Juhl <jj@chaosbits.net> http://www.chaosbits.net/
> Plain text mails only, please http://www.expita.com/nomime.html
> Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] Remove some pointless conditionals before kfree() in kernel/cgroup.c
2009-02-23 8:12 ` Paul Menage
@ 2009-02-23 8:17 ` Cyrill Gorcunov
2009-02-23 8:19 ` Cyrill Gorcunov
2009-02-23 8:30 ` Li Zefan
2009-02-23 21:46 ` Jesper Juhl
2 siblings, 1 reply; 7+ messages in thread
From: Cyrill Gorcunov @ 2009-02-23 8:17 UTC (permalink / raw)
To: Paul Menage
Cc: Jesper Juhl, linux-kernel, Stephen Hemminger, Paul Jackson,
Simon Derr
[Paul Menage - Mon, Feb 23, 2009 at 12:12:51AM -0800]
| On Sun, Feb 22, 2009 at 2:05 PM, Jesper Juhl <jj@chaosbits.net> wrote:
| > Hi,
| >
| > Here's a small patch for kernel/cgroup.c
| >
| > Removes a few pointless tests of pointer == 0 before kfree() in
| > kernel/cgroup.c.
| > If the pointer we hand to kfree() is 0, then kfree() is a noop, so there
| > is no need to test.
| >
| > Reduces object file size a bit :
| >
| > Before:
| > $ size kernel/cgroup.o
| > text data bss dec hex filename
| > 21593 7804 4924 34321 8611 kernel/cgroup.o
| > After:
| > $ size kernel/cgroup.o
| > text data bss dec hex filename
| > 21537 7744 4924 34205 859d kernel/cgroup.o
|
| Thanks. I'm a bit surprised that it also shrunk the data segment size
| (and in fact, by more than the text segment size). Any idea how that
| came about?
Maybe kfree was inlined by gcc for some reason?
|
| >
| > Signed-off-by: Jesper Juhl <jj@chaosbits.net>
|
| Acked-by: Paul Menage <menage@google.com>
|
| Paul
|
| > ---
| >
| > diff --git a/kernel/cgroup.c b/kernel/cgroup.c
| > index 9edb5c4..1c0a9b5 100644
| > --- a/kernel/cgroup.c
| > +++ b/kernel/cgroup.c
| > @@ -865,8 +865,7 @@ static int cgroup_remount(struct super_block *sb, int *flags, char *data)
| > if (opts.release_agent)
| > strcpy(root->release_agent_path, opts.release_agent);
| > out_unlock:
| > - if (opts.release_agent)
| > - kfree(opts.release_agent);
| > + kfree(opts.release_agent);
| > mutex_unlock(&cgroup_mutex);
| > mutex_unlock(&cgrp->dentry->d_inode->i_mutex);
| > return ret;
| > @@ -969,15 +968,13 @@ static int cgroup_get_sb(struct file_system_type *fs_type,
| > /* First find the desired set of subsystems */
| > ret = parse_cgroupfs_options(data, &opts);
| > if (ret) {
| > - if (opts.release_agent)
| > - kfree(opts.release_agent);
| > + kfree(opts.release_agent);
| > return ret;
| > }
| >
| > root = kzalloc(sizeof(*root), GFP_KERNEL);
| > if (!root) {
| > - if (opts.release_agent)
| > - kfree(opts.release_agent);
| > + kfree(opts.release_agent);
| > return -ENOMEM;
| > }
| >
| >
| >
| > --
| > Jesper Juhl <jj@chaosbits.net> http://www.chaosbits.net/
| > Plain text mails only, please http://www.expita.com/nomime.html
| > Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
| >
| >
|
- Cyrill -
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] Remove some pointless conditionals before kfree() in kernel/cgroup.c
2009-02-23 8:17 ` Cyrill Gorcunov
@ 2009-02-23 8:19 ` Cyrill Gorcunov
0 siblings, 0 replies; 7+ messages in thread
From: Cyrill Gorcunov @ 2009-02-23 8:19 UTC (permalink / raw)
To: Paul Menage, Jesper Juhl, linux-kernel, Stephen Hemminger,
Paul Jackson, Simon Derr
[Cyrill Gorcunov - Mon, Feb 23, 2009 at 11:17:57AM +0300]
...
| | Thanks. I'm a bit surprised that it also shrunk the data segment size
| | (and in fact, by more than the text segment size). Any idea how that
| | came about?
|
| Maybe kfree was inlined by gcc for some reason?
What I'm talking about? :)
Sorry for noise.
- Cyrill -
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Remove some pointless conditionals before kfree() in kernel/cgroup.c
2009-02-23 8:12 ` Paul Menage
2009-02-23 8:17 ` Cyrill Gorcunov
@ 2009-02-23 8:30 ` Li Zefan
2009-02-23 21:46 ` Jesper Juhl
2 siblings, 0 replies; 7+ messages in thread
From: Li Zefan @ 2009-02-23 8:30 UTC (permalink / raw)
To: Paul Menage
Cc: Jesper Juhl, linux-kernel, Stephen Hemminger, Paul Jackson,
Simon Derr
>> Reduces object file size a bit :
>>
>> Before:
>> $ size kernel/cgroup.o
>> text data bss dec hex filename
>> 21593 7804 4924 34321 8611 kernel/cgroup.o
>> After:
>> $ size kernel/cgroup.o
>> text data bss dec hex filename
>> 21537 7744 4924 34205 859d kernel/cgroup.o
>
> Thanks. I'm a bit surprised that it also shrunk the data segment size
> (and in fact, by more than the text segment size). Any idea how that
> came about?
>
A bit odd..
Here is the result on my x86_32:
text data bss dec hex filename
14118 1804 4960 20882 5192 kernel/cgroup.o.orig
text data bss dec hex filename
14114 1804 4960 20878 518e kernel/cgroup.o
And on IA64:
text data bss dec hex filename
42399 2712 5616 50727 c627 kernel/cgroup.o.orig
text data bss dec hex filename
42367 2712 5616 50695 c607 kernel/cgroup.o
No change in data segment.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Remove some pointless conditionals before kfree() in kernel/cgroup.c
2009-02-23 8:12 ` Paul Menage
2009-02-23 8:17 ` Cyrill Gorcunov
2009-02-23 8:30 ` Li Zefan
@ 2009-02-23 21:46 ` Jesper Juhl
2 siblings, 0 replies; 7+ messages in thread
From: Jesper Juhl @ 2009-02-23 21:46 UTC (permalink / raw)
To: Paul Menage; +Cc: linux-kernel, Stephen Hemminger, Paul Jackson, Simon Derr
On Mon, 23 Feb 2009, Paul Menage wrote:
> On Sun, Feb 22, 2009 at 2:05 PM, Jesper Juhl <jj@chaosbits.net> wrote:
> > Hi,
> >
> > Here's a small patch for kernel/cgroup.c
> >
> > Removes a few pointless tests of pointer == 0 before kfree() in
> > kernel/cgroup.c.
> > If the pointer we hand to kfree() is 0, then kfree() is a noop, so there
> > is no need to test.
> >
> > Reduces object file size a bit :
> >
> > Before:
> > $ size kernel/cgroup.o
> > text data bss dec hex filename
> > 21593 7804 4924 34321 8611 kernel/cgroup.o
> > After:
> > $ size kernel/cgroup.o
> > text data bss dec hex filename
> > 21537 7744 4924 34205 859d kernel/cgroup.o
>
> Thanks. I'm a bit surprised that it also shrunk the data segment size
> (and in fact, by more than the text segment size). Any idea how that
> came about?
>
Can't say I've got a good explanation for that, no.
--
Jesper Juhl <jj@chaosbits.net> http://www.chaosbits.net/
Plain text mails only, please http://www.expita.com/nomime.html
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Remove some pointless conditionals before kfree() in kernel/cgroup.c
2009-02-22 22:05 [PATCH] Remove some pointless conditionals before kfree() in kernel/cgroup.c Jesper Juhl
2009-02-23 8:12 ` Paul Menage
@ 2009-02-23 8:32 ` Li Zefan
1 sibling, 0 replies; 7+ messages in thread
From: Li Zefan @ 2009-02-23 8:32 UTC (permalink / raw)
To: Jesper Juhl
Cc: linux-kernel, Stephen Hemminger, Paul Jackson, Simon Derr,
Paul Menage
Jesper Juhl wrote:
> Hi,
>
> Here's a small patch for kernel/cgroup.c
>
> Removes a few pointless tests of pointer == 0 before kfree() in
> kernel/cgroup.c.
> If the pointer we hand to kfree() is 0, then kfree() is a noop, so there
> is no need to test.
>
> Reduces object file size a bit :
>
> Before:
> $ size kernel/cgroup.o
> text data bss dec hex filename
> 21593 7804 4924 34321 8611 kernel/cgroup.o
> After:
> $ size kernel/cgroup.o
> text data bss dec hex filename
> 21537 7744 4924 34205 859d kernel/cgroup.o
>
> and source file size shrinks a bit too - always nice.
>
>
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>
Reviewed-by: Li Zefan <lizf@cn.fujitsu.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-02-23 21:47 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-22 22:05 [PATCH] Remove some pointless conditionals before kfree() in kernel/cgroup.c Jesper Juhl
2009-02-23 8:12 ` Paul Menage
2009-02-23 8:17 ` Cyrill Gorcunov
2009-02-23 8:19 ` Cyrill Gorcunov
2009-02-23 8:30 ` Li Zefan
2009-02-23 21:46 ` Jesper Juhl
2009-02-23 8:32 ` Li Zefan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox