Subject: Re: percpu storage allocator
To: None <ad@netbsd.org>
From: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
List: tech-kern
Date: 12/22/2007 09:37:48
> On Mon, Nov 12, 2007 at 09:38:02PM +0000, Andrew Doran wrote:
> 
> > I think you could get away with not taking the rwlock in the cross call
> > thread by deferring the lock to percpu_cpu_enlarge():
> > 
> > 	if (pcc.pcc_data != NULL) {
> > 		rw_enter(&percpu_swap_lock, RW_WRITER);
> > 		/* Ensures old value of pcc_data is no longer used. */
> > 		rw_exit(&percpu_swap_lock);
> > 		kmem_free(pcc.pcc_data, pcc.pcc_size);
> > 	}
> > 
> > Threads traversing will see either old or new values, but in either case the
> > pointer dereference will be safe. It may not be worth it; if so we should
> > probably document that threads doing a traversal should be careful not to
> > delay the xcall thread.
> 
> It occurred to me that won't work if setting an initial value for a new object.
> 
> Thanks,
> Andrew

good point.

i tend to think a xcall is a better solution for initialization.
(kmem_zalloc in percpu_cpu_enlarge doesn't work for re-used offsets.)
how do you think?

YAMAMOTO Takashi