Comments

Hi Lai,
Just a few comments about your v2 proposal. Hopefully you'll catch
these before you send out v3 :)
- I would prefer reader_refcnt to be unsigned int instead of unsigned long
- I would like some comment to indicate that lgrwlocks don't have
reader-writer fairness and are thus somewhat discouraged
(people could use plain lglock if they don't need reader preference,
though even that use (as brlock) is discouraged already :)
- I don't think FALLBACK_BASE is necessary (you already mentioned you'd
drop it)
- I prefer using the fallback_rwlock's dep_map for lockdep tracking.
I feel this is more natural since we want the lgrwlock to behave as
the rwlock, not as the lglock.
- I prefer to avoid return statements in the middle of functions when
it's easyto do so.
Attached is my current version (based on an earlier version of your code).
You don't have to take it as is but I feel it makes for a more concrete
suggestion :)
Thanks,
----------------------------8<-------------------------------------------
lglock: add read-preference lgrwlock
Current lglock may be used as a fair rwlock; however sometimes a
read-preference rwlock is preferred. One such use case recently came
up for get_cpu_online_atomic().
This change adds a new lgrwlock with the following properties:
- high performance read side, using only cpu-local structures when there
is no write side to contend with;
- correctness guarantees similar to rwlock_t: recursive readers are allowed
and the lock's read side is not ordered vs other locks;
- low performance write side (comparable to lglocks' global side).
The implementation relies on the following principles:
- reader_refcnt is a local lock count; it indicates how many recursive
read locks are taken using the local lglock;
- lglock is used by readers for local locking; it must be acquired
before reader_refcnt becomes nonzero and released after reader_refcnt
goes back to zero;
- fallback_rwlock is used by readers for global locking; it is acquired
when fallback_reader_refcnt is zero and the trylock fails on lglock.
- writers take both the lglock write side and the fallback_rwlock, thus
making sure to exclude both local and global readers.
Thanks to Srivatsa S. Bhat for proposing a lock with these requirements
and Lai Jiangshan for proposing this algorithm as an lglock extension.
Signed-off-by: Michel Lespinasse <walken@google.com>
---
include/linux/lglock.h | 46 +++++++++++++++++++++++++++++++++++++++
kernel/lglock.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 104 insertions(+)