One: Kernel base layer data structure
1: Doubly linked list List
A): Definition of linked list
structstruct list_head *next,*pre; }
b): Container objects and List_entry
#define container_of(ptr,type,member){ \ const typeof(((type *)0->member) *_mptr = (ptr); (type*)((char*)_mptr-offset(type,member));})
#define list_entry(ptr,type,member) \ container_of(ptr,type,member)
For a more detailed description of the doubly linked list, please refer to my blog:
Learning from Linux kernel list.h
2:hash linked List
A): definition
struct hlist_head{ struct hlist_head *first;}
b): Hash link List Library
Same as List
Please refer to the following section of this article for the contents of the hash list:
Learning from Linux kernel list.h
3: Red and black trees
A): Essentially self-balancing binary tree
b): defined in the rbtree.c file (pending blog update, Introduction to Rbtree)
C): Application scenario
Mainly used in memory management, IO scheduling algorithm and other implementation of the red-black tree
4:radix Loss – Base tree
A): Defined in/lib/radix_tree.c
b): Radix tree is a space-time data structure that reduces time consumption through space redundancy
(Wait for the blog update, the introduction of Radix_tree)
c):page cache management uses radix tree
Second: synchronization mechanism of kernel base layer
1: Spin Lock
A): Role
(1): If the data is not locked, then get the lock and run, if the data is locked, then it must be rotated (in fact, repeated execution of an instruction)
(2): Spin lock does not work under a single processor environment (non-preemptive kernel)
(3): Single-processor, preemptive kernel environment, the role of spin lock is to prohibit preemption
b): Call of spin lock
(1): Spin_lock
(2): Spin_unlock
2: Kernel signal volume
A): defined in file Semaphore.h file
b): Semaphore and mutexes
(1): Sema_init: Count can be multiple
(2): Init_mutex: The semaphore with a count of 1
c): Operation of the semaphore
(1): Up: Releasing the semaphore
(2): down: Gets the semaphore and, if not, goes to sleep
(3): Down_trylock: Gets the semaphore, returns immediately if not available, the process does not go to sleep state
Attention:
the difference between spin locks and semaphores
1: Spin lock can be used in interrupt processing functions and Tasklet and other non-sleep scenes, and the semaphore is not
2: Sleep scenarios can use either semaphores or spin locks, and spin locks are often used in lightweight scenes
3: Synchronization mechanism – Atomic variable
A): Atomic variables provide an atomic data structure that is not broken down and broken down in the reading and writing of such data structures.
b): The invocation provided by the atomic variable
(1): Atomic_add: Add an integer to the atomic variable
(2): automic_sub: Subtract an integer from an atomic variable
(3): Automic_set: Set the numeric value of the atomic variable
(4): Automic_read: Read the value of the atomic variable
4: Synchronization mechanism –completion
A): completion provides a mechanism to wait for completion
b): The provided call
(1): wait_for_completion: Wait for operation to complete
(2): Complete: The completed signal
5: Other Kernel synchronization mechanisms
A): CPU variable Define_per_cpu
b): RCU lock
c): Sequential lock
Linux Kernel Base Layer Learning (1)