All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] afs: afs_alloc_inode: use kmem_cache_zalloc
@ 2014-02-20 13:16 Fabian Frederick
  2014-02-20 21:30 ` Joe Perches
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Fabian Frederick @ 2014-02-20 13:16 UTC (permalink / raw)
  To: linux-kernel; +Cc: dhowells, akpm

afs_vnode is currently cleared with 2 memsets after allocation and 
1 in constructor (afs_i_init_once).
	-This patch calls zalloc for explicit zero fill.
	-Fix some typos.

Signed-off-by: Fabian Frederick <fabf@skynet.be>
---
 fs/afs/super.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/fs/afs/super.c b/fs/afs/super.c
index c486155..e1fc569 100644
--- a/fs/afs/super.c
+++ b/fs/afs/super.c
@@ -76,7 +76,7 @@ static const match_table_t afs_options_list = {
 };
 
 /*
- * initialise the filesystem
+ * Initialize the filesystem
  */
 int __init afs_fs_init(void)
 {
@@ -448,19 +448,19 @@ error:
 static void afs_kill_super(struct super_block *sb)
 {
 	struct afs_super_info *as = sb->s_fs_info;
+
 	kill_anon_super(sb);
 	afs_put_volume(as->volume);
 	kfree(as);
 }
 
 /*
- * initialise an inode cache slab element prior to any use
+ * Initialize an inode cache slab element prior to any use
  */
 static void afs_i_init_once(void *_vnode)
 {
 	struct afs_vnode *vnode = _vnode;
 
-	memset(vnode, 0, sizeof(*vnode));
 	inode_init_once(&vnode->vfs_inode);
 	init_waitqueue_head(&vnode->update_waitq);
 	mutex_init(&vnode->permits_lock);
@@ -481,15 +481,12 @@ static struct inode *afs_alloc_inode(struct super_block *sb)
 {
 	struct afs_vnode *vnode;
 
-	vnode = kmem_cache_alloc(afs_inode_cachep, GFP_KERNEL);
+	vnode = kmem_cache_zalloc(afs_inode_cachep, GFP_KERNEL);
 	if (!vnode)
 		return NULL;
 
 	atomic_inc(&afs_count_active_inodes);
 
-	memset(&vnode->fid, 0, sizeof(vnode->fid));
-	memset(&vnode->status, 0, sizeof(vnode->status));
-
 	vnode->volume		= NULL;
 	vnode->update_cnt	= 0;
 	vnode->flags		= 1 << AFS_VNODE_UNSET;
@@ -503,6 +500,7 @@ static void afs_i_callback(struct rcu_head *head)
 {
 	struct inode *inode = container_of(head, struct inode, i_rcu);
 	struct afs_vnode *vnode = AFS_FS_I(inode);
+
 	kmem_cache_free(afs_inode_cachep, vnode);
 }
 
-- 
1.8.1.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/1] afs: afs_alloc_inode: use kmem_cache_zalloc
  2014-02-20 13:16 [PATCH 1/1] afs: afs_alloc_inode: use kmem_cache_zalloc Fabian Frederick
@ 2014-02-20 21:30 ` Joe Perches
  2014-02-20 22:03 ` David Howells
  2014-02-20 22:23 ` Has slab ctor operation changed? -- was " David Howells
  2 siblings, 0 replies; 7+ messages in thread
From: Joe Perches @ 2014-02-20 21:30 UTC (permalink / raw)
  To: Fabian Frederick; +Cc: linux-kernel, dhowells, akpm

On Thu, 2014-02-20 at 21:16 +0800, Fabian Frederick wrote:
> afs_vnode is currently cleared with 2 memsets after allocation and 
> 1 in constructor (afs_i_init_once).

Trivial comments:

> 	-This patch calls zalloc for explicit zero fill.

OK, but see below.

> 	-Fix some typos.

Well...

> diff --git a/fs/afs/super.c b/fs/afs/super.c
[]
> @@ -76,7 +76,7 @@ static const match_table_t afs_options_list = {
[]
> - * initialise the filesystem
> + * Initialize the filesystem
> @@ -448,19 +448,19 @@ error:
[]
> - * initialise an inode cache slab element prior to any use
> + * Initialize an inode cache slab element prior to any use

English spellings don't need to be changed to American.

> @@ -481,15 +481,12 @@ static struct inode *afs_alloc_inode(struct super_block *sb)
[]
> -	vnode = kmem_cache_alloc(afs_inode_cachep, GFP_KERNEL);
> +	vnode = kmem_cache_zalloc(afs_inode_cachep, GFP_KERNEL);
[]
> -	memset(&vnode->fid, 0, sizeof(vnode->fid));
> -	memset(&vnode->status, 0, sizeof(vnode->status));
> -
>  	vnode->volume		= NULL;
>  	vnode->update_cnt	= 0;

These could be removed too.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Has slab ctor operation changed? -- was [PATCH 1/1] afs: afs_alloc_inode: use kmem_cache_zalloc
  2014-02-20 22:23 ` Has slab ctor operation changed? -- was " David Howells
@ 2014-02-20 21:47   ` Fabian Frederick
  2014-02-21  0:19   ` Dave Chinner
  2014-02-24 19:52   ` Christoph Lameter
  2 siblings, 0 replies; 7+ messages in thread
From: Fabian Frederick @ 2014-02-20 21:47 UTC (permalink / raw)
  To: David Howells; +Cc: linux-kernel, akpm, cl

On Thu, 20 Feb 2014 22:23:15 +0000
David Howells <dhowells@redhat.com> wrote:

> Fabian Frederick <fabf@skynet.be> wrote:
> 
> > afs_vnode is currently cleared with 2 memsets after allocation and 
> > 1 in constructor (afs_i_init_once).
> > 	-This patch calls zalloc for explicit zero fill.
> 
> Ummm...  This patch isn't necessarily correct in the substantiative portions.
> 
> Since afs_i_init_once() is called by the slab allocator during the course of
> kmem_cache_alloc(), how does kmem_cache_zalloc() interact with that?

Object of this patch was to replace any kmem_cache_alloc by kmem_cache_zalloc
so I guess what is done in the patch v2 in afs_alloc_inode below zalloc
would be ok (leaving ctor how it is) ?

> 
> IIRC, it used to be that the ctor() function was called when the pages were
> allocated to the slab - and it wasn't called again, even if the object was
> allocated, deallocated and reallocated.  This means that things like locks and
> lists don't need reinitialising after allocation.
> 
> So afs_i_init_once() theoretically constructs the stuff that can be reused,
> and afs_alloc_inode() therefore has to clear the non-reusable state.
> 
> Of course, it's possible that the slab allocator no longer works like this...
> 
> David

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/1] afs: afs_alloc_inode: use kmem_cache_zalloc
  2014-02-20 13:16 [PATCH 1/1] afs: afs_alloc_inode: use kmem_cache_zalloc Fabian Frederick
  2014-02-20 21:30 ` Joe Perches
@ 2014-02-20 22:03 ` David Howells
  2014-02-20 22:23 ` Has slab ctor operation changed? -- was " David Howells
  2 siblings, 0 replies; 7+ messages in thread
From: David Howells @ 2014-02-20 22:03 UTC (permalink / raw)
  To: Joe Perches; +Cc: dhowells, Fabian Frederick, linux-kernel, akpm

Joe Perches <joe@perches.com> wrote:

> > - * initialise an inode cache slab element prior to any use
> > + * Initialize an inode cache slab element prior to any use
> 
> English spellings don't need to be changed to American.

Indeed! :-)

David

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Has slab ctor operation changed? -- was [PATCH 1/1] afs: afs_alloc_inode: use kmem_cache_zalloc
  2014-02-20 13:16 [PATCH 1/1] afs: afs_alloc_inode: use kmem_cache_zalloc Fabian Frederick
  2014-02-20 21:30 ` Joe Perches
  2014-02-20 22:03 ` David Howells
@ 2014-02-20 22:23 ` David Howells
  2014-02-20 21:47   ` Fabian Frederick
                     ` (2 more replies)
  2 siblings, 3 replies; 7+ messages in thread
From: David Howells @ 2014-02-20 22:23 UTC (permalink / raw)
  To: Fabian Frederick; +Cc: dhowells, linux-kernel, akpm, cl

Fabian Frederick <fabf@skynet.be> wrote:

> afs_vnode is currently cleared with 2 memsets after allocation and 
> 1 in constructor (afs_i_init_once).
> 	-This patch calls zalloc for explicit zero fill.

Ummm...  This patch isn't necessarily correct in the substantiative portions.

Since afs_i_init_once() is called by the slab allocator during the course of
kmem_cache_alloc(), how does kmem_cache_zalloc() interact with that?

IIRC, it used to be that the ctor() function was called when the pages were
allocated to the slab - and it wasn't called again, even if the object was
allocated, deallocated and reallocated.  This means that things like locks and
lists don't need reinitialising after allocation.

So afs_i_init_once() theoretically constructs the stuff that can be reused,
and afs_alloc_inode() therefore has to clear the non-reusable state.

Of course, it's possible that the slab allocator no longer works like this...

David

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Has slab ctor operation changed? -- was [PATCH 1/1] afs: afs_alloc_inode: use kmem_cache_zalloc
  2014-02-20 22:23 ` Has slab ctor operation changed? -- was " David Howells
  2014-02-20 21:47   ` Fabian Frederick
@ 2014-02-21  0:19   ` Dave Chinner
  2014-02-24 19:52   ` Christoph Lameter
  2 siblings, 0 replies; 7+ messages in thread
From: Dave Chinner @ 2014-02-21  0:19 UTC (permalink / raw)
  To: David Howells; +Cc: Fabian Frederick, linux-kernel, akpm, cl

On Thu, Feb 20, 2014 at 10:23:15PM +0000, David Howells wrote:
> Fabian Frederick <fabf@skynet.be> wrote:
> 
> > afs_vnode is currently cleared with 2 memsets after allocation and 
> > 1 in constructor (afs_i_init_once).
> > 	-This patch calls zalloc for explicit zero fill.
> 
> Ummm...  This patch isn't necessarily correct in the substantiative portions.
> 
> Since afs_i_init_once() is called by the slab allocator during the course of
> kmem_cache_alloc(), how does kmem_cache_zalloc() interact with that?

It breaks it. ;)

> IIRC, it used to be that the ctor() function was called when the pages were
> allocated to the slab - and it wasn't called again, even if the object was
> allocated, deallocated and reallocated.  This means that things like locks and
> lists don't need reinitialising after allocation.
> 
> So afs_i_init_once() theoretically constructs the stuff that can be reused,
> and afs_alloc_inode() therefore has to clear the non-reusable state.
> 
> Of course, it's possible that the slab allocator no longer works like this...

AFAIA the slab constructor behaviour has not changed. If it did, I'm
pretty sure most filesystems would end up with inode cache problems
because most of them rely on this ctor behaviour to avoid
unnecessary reinitialisation of inode state....

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Has slab ctor operation changed? -- was [PATCH 1/1] afs: afs_alloc_inode: use kmem_cache_zalloc
  2014-02-20 22:23 ` Has slab ctor operation changed? -- was " David Howells
  2014-02-20 21:47   ` Fabian Frederick
  2014-02-21  0:19   ` Dave Chinner
@ 2014-02-24 19:52   ` Christoph Lameter
  2 siblings, 0 replies; 7+ messages in thread
From: Christoph Lameter @ 2014-02-24 19:52 UTC (permalink / raw)
  To: David Howells; +Cc: Fabian Frederick, linux-kernel, akpm

On Thu, 20 Feb 2014, David Howells wrote:

> Of course, it's possible that the slab allocator no longer works like this...

They still work like that (aside from SLOB that calls the ctor on each
alloc but that also has never changed).


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-02-24 19:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-20 13:16 [PATCH 1/1] afs: afs_alloc_inode: use kmem_cache_zalloc Fabian Frederick
2014-02-20 21:30 ` Joe Perches
2014-02-20 22:03 ` David Howells
2014-02-20 22:23 ` Has slab ctor operation changed? -- was " David Howells
2014-02-20 21:47   ` Fabian Frederick
2014-02-21  0:19   ` Dave Chinner
2014-02-24 19:52   ` Christoph Lameter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.