Re: [PATCH RFC v2 07/10] slab: determine barn status racily outside of lock

From: Vlastimil Babka
Date: Wed Mar 12 2025 - 14:23:34 EST


On 2/25/25 09:54, Harry Yoo wrote:
> On Fri, Feb 14, 2025 at 05:27:43PM +0100, Vlastimil Babka wrote:
>> The possibility of many barn operations is determined by the current
>> number of full or empty sheaves. Taking the barn->lock just to find out
>> that e.g. there are no empty sheaves results in unnecessary overhead and
>> lock contention. Thus perform these checks outside of the lock with a
>> data_race() annotated variable read and fail quickly without taking the
>> lock.
>>
>> Checks for sheaf availability that racily succeed have to be obviously
>> repeated under the lock for correctness, but we can skip repeating
>> checks if there are too many sheaves on the given list as the limits
>> don't need to be strict.
>>
>> Signed-off-by: Vlastimil Babka <vbabka@xxxxxxx>
>
> Looks good to me,
> Reviewed-by: Harry Yoo <harry.yoo@xxxxxxxxxx>
>
> in kmem_cache_return_sheaf:
>> if (!pcs->spare) {
>> pcs->spare = sheaf;
>> sheaf = NULL;
>> } else if (pcs->barn->nr_full >= MAX_FULL_SHEAVES) {
>> /* racy check */
>> barn = pcs->barn;
>> keep = true;
>> }
>
> By the way this code also needs data_race()?

Right, will add, thanks.