On Sun, Dec 24, 2017 at 03:42:02PM +0800, Wei Wang wrote: > On 12/24/2017 12:45 PM, Tetsuo Handa wrote: > > Matthew Wilcox wrote: > > > If you can't preload with anything better than that, I think that > > > xb_set_bit() should attempt an allocation with GFP_NOWAIT | __GFP_NOWARN, > > > and then you can skip the preload; it has no value for you. > > Yes, that's why I suggest directly using kzalloc() at xb_set_bit(). > > It has some possibilities to remove that preload if we also do the bitmap > allocation in the xb_set_bit(): > > bitmap = rcu_dereference_raw(*slot); > if (!bitmap) { > bitmap = this_cpu_xchg(ida_bitmap, NULL); > if (!bitmap) { > bitmap = kmalloc(sizeof(*bitmap), gfp); > if (!bitmap) > return -ENOMEM; > } > } > > But why not just follow the radix tree implementation style that puts the > allocation in preload, which would be invoked with a more relaxed gfp in > other use cases? Actually, the radix tree does attempt allocation, and falls back to the preload. The IDA was the odd one out that doesn't attempt allocation, and that was where I copied the code from. For other users, the preload API is beneficial, so I will leave it in. > Its usage in virtio_balloon is just a little special that we need to put the > allocation within the balloon_lock, which doesn't give us the benefit of > using a relaxed gfp in preload, but it doesn't prevent us from living with > the current APIs (i.e. the preload + xb_set pattern). > On the other side, if we do it as above, we have more things that need to > consider. For example, what if the a use case just want the radix tree > implementation style, which means it doesn't want allocation within > xb_set(), then would we be troubled with how to avoid the allocation path in > that case? > > So, I think it is better to stick with the convention by putting the > allocation in preload. Breaking the convention should show obvious > advantages, IMHO. The radix tree convention is objectively awful, which is why I'm working to change it. Specifying the GFP flags at radix tree initialisation time rather than allocation time leads to all kinds of confusion. The preload API is a pretty awful workaround, and it will go away once the XArray is working correctly. That said, there's no alternative to it without making XBitmap depend on XArray, and I don't want to hold you up there. So there's an xb_preload for the moment.