Re: Lockless uidinfo.



* Pawel Jakub Dawidek <pjd@xxxxxxxxxxx> [070818 09:14] wrote:
On Sat, Aug 18, 2007 at 08:50:41AM -0700, Alfred Perlstein wrote:
* Pawel Jakub Dawidek <pjd@xxxxxxxxxxx> [070818 07:59] wrote:
Yes, to lookup uidinfo you need to hold uihashtbl_mtx mutex, so once you
hold it and ui_ref is 0, noone will be able to reference it, because it
has to wait to look it up.

And the field doesn't need to be volatile to prevent cached/opportunitic
reads?

The only chance of something like this will be the scenario below:

thread1 (uifind) thread2 (uifree)
---------------- ----------------
refcount_release(&uip->ui_ref))
/* ui_ref == 0 */
mtx_lock(&uihashtbl_mtx);
refcount_acquire(&uip->ui_ref);
/* ui_ref == 1 */
mtx_unlock(&uihashtbl_mtx);
mtx_lock(&uihashtbl_mtx);
if (uip->ui_ref > 0) {
mtx_unlock(&uihashtbl_mtx);
return;
}

Now, you suggest that ui_ref in 'if (uip->ui_ref > 0)' may still have
cached 0? I don't think it is possible, first refcount_acquire() uses
read memory bariers (but we may still need ui_ref to volatile for this
to make any difference) and second, think of ui_ref as a field protected
by uihashtbl_mtx mutex in this very case.

Is my thinking correct?

I don't know, that's why I was asking you. :)

--
- Alfred Perlstein
_______________________________________________
freebsd-arch@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-arch
To unsubscribe, send any mail to "freebsd-arch-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: Lockless uidinfo.
    ... hold it and ui_ref is 0, noone will be able to reference it, because it ... And the field doesn't need to be volatile to prevent cached/opportunitic ... Is my thinking correct? ...
    (freebsd-arch)
  • Re: Lockless uidinfo.
    ... hold it and ui_ref is 0, noone will be able to reference it, because it ... And the field doesn't need to be volatile to prevent cached/opportunitic ... Is my thinking correct? ...
    (freebsd-arch)
  • Re: [patch 3/9] Guest page hinting: volatile page cache.
    ... needs to be able to check the dirty state of the pages. ... the volatile and the stable state. ... The page map count is not equal to the page reference count - 1. ... Because I don't see how you can generate a discard fault otherwise unless you know where the page table entries of the guest are located, which you already said you don't. ...
    (Linux-Kernel)
  • Re: strange grammar about volatile and operator overload
    ... actually in the definition/declaration of the global object, ... not marked as volatile. ... it's not treated as volatile or const. ... x is accessed via vr reference, ...
    (microsoft.public.vc.language)
  • Re: When is "volatile" used instead of "lock" ?
    ... "lock" cannot not apply. ... > synchronized method) shall implicitly perform a volatile write ... reference used as the parameter for the lock. ... There can be no lock acquire semantics for value members. ...
    (microsoft.public.dotnet.languages.csharp)