On Sun, Dec 14, 2025 at 08:43:18AM -0500, Mathieu Desnoyers wrote:
[...]
> > ... By the way I wanted to emphasize my PoV, that requiring storage
> > provided by the user seems to negate one of the big benefits of hazard

TBH, if users don't want to do the extra allocation, they probably want
to just use RCU ;-) and even we can hide the allocation behind the
API, the performance penalty is still there when the "allocation"
happens. For example, in Mathieu's proposal below, when this cpu's slot
is used (which should be normal if we allow preemptible hazptr readers)
every hazptr_try_protect() will become a mutex acquisition, that means
we are back to locking in common cases. I in general don't think
allocating or filling in the backup slot while _try_protect() is a
good idea, unless we can avoid the cost in common cases.

> > pointers I think. Unless there is a solid use case for it, we should
> > probably not require the user to provide separate storage IMHO (or make
> > allocation internal to the api as I mentioned).
> I think the solution I have in mind takes care of the negative aspects
> of preallocation requirement. Here is how it would be used (see
> [1] for the current prototype). The "backup slot" is within the

A few issues in the prototype:

* hazptr_load_try_protect_percpu() needs to either be called in
  preemption disabling context or disable preemption itself.

* In __hazptr_load_try_protect(), seems to me that we shouldn't return
  after hazptr_chain_backup_slot() being called, but rather continue,
  otherwise we would miss the updater changes.

* As I mentioned above, since we allow preemption during hazptr readers,
  then when we have multiple users, it's likely that the per-CPU slot is
  used at most of the time, and other try_protect()s would always go
  into the slow path, which downgrade us to normal locking.

Regards,
Boqun

> struct hazptr_ctx, so from a user perspective, it's under the hood.
> 
> The user just has to provide a context variable on its stack.
> 
> (untested example below)
> 
> void *ptr;
> 
> void fct(void)
> {
>       struct hazptr_ctx ctx;
>       void *addr;
> 
>       addr = hazptr_load_try_protect(&ctx, &ptr);
>       if (!addr)
>               return;
>       [critical section]
>       hazptr_release(&ctx, addr);
> }
> 
> Thanks,
> 
> Mathieu
> 
> [1] 
> https://github.com/compudj/linux-dev/commit/5e33fc13f950929e630a60ef44249e7b0978e80f
> 
> 
> -- 
> Mathieu Desnoyers
> EfficiOS Inc.
> https://www.efficios.com

Reply via email to