What I know about kernel locks didn't amount to
a hill of beans. Here's a list of the kernel locking types
I've found over the last hours or so, where they live, and
when to use them. When this is reasonably complete for 2.2.x,
I'll send it to Alan as a patch, then begin work on the 2.3.x
Lock List.
Bring on the documentation bug reports!!!
----------------- Lock List v0.0.0 -------------------------------
Copyright 2000, Jason McMullan <jmcmullan@linuxcare.com>
Types of Kernel Locks
---------------------
Big Kernel Lock
When to use: You don't know what fine-grain lock to call,
or a fine-grained lock doesn't exists.
Lock: lock_kernel();
Unlock: unlock_kernel();
spinlock
When to use: SMP, # writers == # readers
Initialize: spinlock_t my_lock = SPIN_LOCK_UNLOCKED;
Lock: spin_lock(&my_lock);
Unlock: spin_unlock(&my_lock);
irq spinlock
When to use: SMP, sending signals or in an IRQ back-half
Initialize: spinlock_t my_lock = SPIN_LOCK_UNLOCKED;
Lock: spin_lock_irq(&my_lock);
Unlock: spin_unlock_irq(&my_lock);
rwlock:
When to use: # writers < # readers
Initialize: rwlock_t my_lock = RW_LOCK_UNLOCKED;
Read Lock: read_lock(&my_lock);
Read Unlock: read_unlock(&my_lock);
Write Lock: write_lock(&my_lock);
Write Unlock: write_unlock(&my_lock);
bitlocks:
When to use: Never?
Initialize: unsigned long my_lock=0;
Spin Lock: while (test_and_set_bit(bit,&my_lock))
schedule();
Unlock: clear_bit(bit,&my_lock);
2.2.x System Lock Map
----------------------
The Big Kernel Lock
-------------------
Wrapped around most syscalls (NOTE: Make a list of exceptions),
primarily needs to be held in interrupt backhandlers,
scheduled timers, kernel threads, and other kernel-initiated
tasks. The big safety net if you don't know what you're doing.
Other Locks
----------
Global:
EXPORTED inode_lock:
Type: spinlock, UP & SMP
Protects: in-memory inode cache structure
Users: Quota, Reiserfs
Wrappers:
mark_inode_dirty();
sync_inodes();
write_inode_now();
invalidate_inodes();
free_inode_memory();
get_empty_inode();
iunique();
igrab();
iget();
insert_inode_hash();
remove_inode_hash();
iput();
iget_in_use();
IN-KERNEL tasklist_lock: Type: rwlock, UP & SMP
Protects: System list of tasks
init_task.next_task structure
find_task_by_pid() inline
hash_pid() inline
unhash_pid() inline
for_each_task() macro
SET_LINKS() macro
REMOVE_LINKS() macro
Wrappers:
schedule();
IN-KERNEL runqueue_lock:
Type: IRQ spinlock
Protects: run-queues
(lock for access to task's
has_cpu and processor members)
Users: kernel/exit.c, kernel/signal.c
Wrappers:
wake_up_process();
schedule();
IN-KERNEL waitqueue_lock:
Type: rwlock, UP & SMP
Protects: struct wait_queue
Users: Implicit with wrappers
Wrappers:
add_wait_queue();
remove_wait_queue();
wait_event();
wait_event_interruptible();
wake_up();
wake_up_interruptible();
interruptible_sleep_on();
interruptible_sleep_on_timeout();
sleep_on();
sleep_on_timeout();
IN-KERNEL timerlist_lock:
Type: IRQ spinlock, UP & SMP
Protects: struct timer_list
Users: Implicit with wrappers
Wrappers:
add_timer();
mod_timer();
del_timer();
Current Task:
current->
EXPORTED sigmask_lock: Type: IRQ spinlock
Protects: Process signal mask
sigismember();
siginitsetinv();
recalc_sigpending();
-------------------- Cut Here ---------------------------------
-- Jason McMullan, Senior Linux Consultant, Linuxcare, Inc. 412.422.8077 tel, 412.656.3519 cell, 415.701.0792 fax jmcmullan@linuxcare.com, http://www.linuxcare.com/ Linuxcare. Support for the revolution.- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
This archive was generated by hypermail 2b29 : Tue May 23 2000 - 21:00:13 EST