Skip to content

Draft: [th/g-bit-lock-contention-classes] gbitlock: bump CONTENTION_CLASSES from 11 to 97

Thomas Haller requested to merge th/g-bit-lock-contention-classes into main

CONTENTION_CLASSES seems low. Bump it.

Unlock essentially does:

  g_atomic_int_and (address_nonvolatile, ~mask);
  guint class = ((gsize) address_nonvolatile) % G_N_ELEMENTS (g_bit_lock_contended);
  if (g_atomic_int_get (&g_bit_lock_contended[class]))
    g_futex_wake (address_nonvolatile);

that means, if "g_bit_lock_contended" indicates a lock, we wakes up a futex. Which can be expensive, if the wake up was unnecessary. By adding more classes, the idea is to hit false positives with lower probability.

The cost is that we now allocate extra 86 gint (344 bytes). Which seems very acceptable.

This is the simplest change which might make an impact in reducing unnecessary g_futex_wake() calls. GObject's "qdata" and object_bit_lock() use bit locks at prominent places.

This is not backed by bench marks. Just by reasoning, that 11 seems a very low number. 11 was used since the beginning ([1]), but I don't see any comment/justification why it would be a good number. It probably is not a good number (anymore).

[1] https://bugzilla.gnome.org/show_bug.cgi?id=548967#c1


Benchmarks still missing. I shoot this out first, for feedback/opinions.

Merge request reports