Re: [PATCH 06/11] super: Use acquire for SB_BORN check in super_cache_count()
From: Jinjie Ruan
Date: Mon Aug 31 2026 - 08:52:10 EST
在 2026/8/31 20:29, Jan Kara 写道:
> On Tue 25-08-26 17:54:17, Jinjie Ruan wrote:
>> The active SB_BORN check in super_cache_count() pairs with the
>> smp_store_release() in super_wake() when publishing a newly initialized
>> superblock.
>>
>> Replace the historical independent smp_rmb() barrier with an acquire load
>> on sb->s_flags. This expresses the publish-subscribe pattern more clearly
>> and allows weakly-ordered architectures like arm64 to utilize efficient
>> native instructions (e.g., LDAR) instead of a full one-way barrier.
>>
>> Also update the outdated comment to correctly point to super_wake().
>>
>> Assisted-by: Gemini:Gemini-3.1
>> Assisted-by: DeepSeek:DeepSeek-V3
>> Signed-off-by: Jinjie Ruan <ruanjinjie@xxxxxxxxxx>
>
> Looks good. Just one nit below. With that addressed feel free to add:
>
> Reviewed-by: Jan Kara <jack@xxxxxxx>
>
>> diff --git a/fs/super.c b/fs/super.c
>> index 05e443173038..5860daea6d40 100644
>> --- a/fs/super.c
>> +++ b/fs/super.c
>> @@ -267,12 +267,11 @@ static unsigned long super_cache_count(struct shrinker *shrink,
>> * However, if we are currently mounting the superblock, the underlying
>> * filesystem might be in a state of partial construction and hence it
>> * is dangerous to access it. super_trylock_shared() uses a SB_BORN check
>> - * to avoid this situation, so do the same here. The memory barrier is
>> - * matched with the one in mount_fs() as we don't hold locks here.
>> + * to avoid this situation, so do the same here. The acquire is matched
>> + * with the smp_store_release() in super_wake() as we don't hold locks here.
>> */
>> - if (!(sb->s_flags & SB_BORN))
>> + if (!(smp_load_acquire(&sb->s_flags) & SB_BORN))
>> return 0;
>
> We have super_flags() helper exactly for checks like this so it would be
> good to use it here.
Right! And we can just remove the outdated memory barrier comment, as
the underlying super_flags() implementation already has a self-document.
>
> Honza
>
>> - smp_rmb();
>>
>> if (sb->s_op && sb->s_op->nr_cached_objects &&
>> super_fs_objects_eligible(sc))
>> --
>> 2.34.1
>>