Linux's synchronization mechanism has evolved from 2.0 to 2.6. From the initial atomic operations, to the later semaphores, from large kernel locks to today's spinlocks. The development of these synchronization mechanisms has been accompanied by the transition of Linux from uniprocessor to symmetric multiprocessor.
With the transition from non-preemptive kernels to preemption of the kernel. The lock mechanism of Linux is more and more effective and more and more complicated.
1) Linux kernel locks are mainly spin locks and semaphores.
A spin lock can only be held by at most one executable thread. If an execution thread tries to request a spin lock that has been contended (has already been held), then the thread will continue busy looping - rotation - Wait for the lock to be available again. If the lock is not contention, the thread that requested it can get it immediately and continue. Spin locks can prevent more than one execution thread from entering the critical section at any time.
The semaphore in Linux is a type of sleep lock. If there is a task trying to get a semaphore that has been held, the semaphore will push it into the waiting queue and then let it sleep. At this point the processor is free to execute other code. When the process holding the semaphore releases the semaphore, a task in the waiting queue will be woken up so that this semaphore can be obtained.
The semaphore's sleep characteristic makes the semaphore suitable for situations where the lock will be held for a long time; it can only be used in the process context because the interrupt context cannot be scheduled; otherwise when the code holds semaphores, it cannot Then hold the spin lock.
Synchronization mechanisms in the Linux kernel: Atomic operations, semaphores, APIs for reading and writing semaphores and spin locks, and other synchronization mechanisms, including large kernel locks, read-write locks, large reader locks, RCU (Read-Copy Update, as the name suggests) Is read-copy modification, and sequential locking.
2) What is the meaning of user mode and kernel mode in Linux?
Operating systems such as MS-DOS run in a single CPU mode, but some Unix-like operating systems use dual mode, which can effectively achieve time sharing. On Linux machines, the CPU is either in a trusted kernel mode or in a restricted user mode. In addition to the kernel itself being in kernel mode, all user processes run in user mode.
Kernel-mode code has unlimited access to all processor instruction sets and all memory and I/O space. If a user-mode process wants to enjoy this privilege, it must make a request to the device driver or other kernel-mode code through a system call. In addition, user-mode code allows missing pages, while kernel-mode code does not.
In 2.4 and earlier kernels, only user-mode processes can be switched out of context and preempted by other processes. Kernel mode code can monopolize the CPU until both of the following occur:
(1) It voluntarily gave up the CPU;
(2) An interruption or abnormality occurred.
The 2.6 kernel introduces kernel preemption, and most kernel-mode code can also be preempted.
3) How to apply for large kernel memory?
In the Linux kernel environment, the success rate of applying for large blocks of memory decreases with the increase of system running time. Although physical memory can be requested through the vmalloc series calls but the virtual address is continuous, it is not efficient and it is used in 32. The memory address space of vmalloc on the bit system is limited. Therefore, the general recommendation is to apply for large blocks of memory during the system startup phase, but the probability of success is only relatively high, not 100%. If the program really cares about the success of this application, only Boot Memory can be used. Here is a sample code for requesting and exporting boot memory:
Void* x_bootmem = NULL;
EXPORT_SYMBOL(x_bootmem);
Unsigned long x_bootmem_size = 0;
EXPORT_SYMBOL(x_bootmem_size);
staTIc int __init x_bootmem_setup(char *str)
{
X_bootmem_size = memparse(str, &str);
X_bootmem = alloc_bootmem(x_bootmem_size);
Printk("Reserved %lu bytes from %p for x", x_bootmem_size, x_bootmem);
Return 1;
}
__setup("x-bootmem=", x_bootmem_setup);
It can be seen that its application is still relatively simple, but the pros and cons are always symbiotic, and it inevitably has its own limitations:
The memory request code can only be connected to the kernel and cannot be used in the module.
The requested memory is not used and counted by the page allocator and the slab allocator, which means that it is outside of the system's visible memory, even if you release it somewhere in the future.
The average user will only apply for a large block of memory. If you need to implement complex memory management on it, you need to implement it yourself.
When memory allocation is not allowed to fail, it is our only choice to reserve memory space by starting memory.
4) What are the main methods of communication between user processes?
(1) Pipes: Pipes can be used to communicate between affiliated processes, allowing one process to communicate with another process that has a common ancestor with it.
(2) named pipe: Named pipe overcomes the restriction that pipes have no name. Therefore, in addition to having the function of the pipe, it also allows communication between unrelated processes. Named pipes have corresponding file names in the file system. Named pipes are created by the command mkfifo or the system call mkfifo.
(3)Signal:Signal is a more complex communication method used to notify the receiving process that there is some kind of event. In addition to being used for inter-process communication, the process can also send signals to the process itself; linux supports Unix early signal in addition to In addition to the semantic function sigal, the signal function sigacTIon whose semantics conforms to the Posix.1 standard is also supported (actually, this function is based on BSD. BSD can re-implement the signal function by using the sigacTIon function in order to implement a reliable signal mechanism and to unify the external interface). .
(4) Message queue: The message queue is a linked list of messages, including the Posix message queue system V message queue. A process with sufficient privileges can add messages to the queue, and a process with read privileges can read the messages in the queue. Message queuing overcomes the lack of signal-bearing information, pipelines can only carry unformatted byte streams, and buffer sizes are limited
(5) shared memory: making multiple processes can access the same memory space, is the fastest available IPC form. It is designed for the lower operating efficiency of other communication mechanisms. It is often used in conjunction with other communication mechanisms such as semaphores to achieve synchronization and mutual exclusion between processes.
(6) Semaphore: It is mainly used as a synchronization method between processes and between different threads of the same process.
(7) Socket: A more general inter-process communication mechanism that can be used for inter-process communication between different machines. Originally developed by the BSD branch of the Unix system, it is now generally portable to other Unix-like systems: Both Linux and System V variants support sockets.
5) What are the functions of applying kernel memory through partner system?
A zone based buddy system (zone based buddy system) is implemented in physical page management. A separate buddy system is used for the memory in different zones, and free pages are independently monitored. The corresponding interface alloc_pages (gfp_mask, order), _ _get_free_pages (gfp_mask, order) and so on.
6) Is there a function for applying kernel memory through the slab allocator?
7) How does Linux's kernel space and user space are divided (taking a 32-bit system as an example)?
8) What are the characteristics of the memory requested by vmalloc()?
9) What is the memory space that the user program applies to using malloc()?
10) In a system that supports and enables MMU, does the Linux kernel and user program run in physical address mode or virtual address mode, respectively?
11) Does the ARM processor perform storage space mapping through several levels?
12) What component does Linux implement to support multiple file systems?
13) What are the key data structures of Linux virtual file system? (at least four)
14) Is the operating function for the file or device stored in that data structure?
15) Which files are included in Linux?
16) What are the system calls for creating the process?
17) There are several ways to call schedule() to switch processes?
18) Does the Linux scheduler schedule processes based on the process's dynamic or static priority?
19) Which is the core data structure of process scheduling?
20) How to load and unload a module?
21) What space does the module and application run in?
22) Does floating point arithmetic in Linux be implemented by an application or a kernel?
23) Can the module program use linkable library functions?
24) What is cached in the TLB?
25) What kind of devices does Linux have?
26) Which is the key data structure of the character device driver?
27) Which function functions are included in the device driver?
28) How to uniquely identify a device?
29) How does Linux implement system calls?
30) What is the role of Linux soft interrupts and work queues?
The utility model discloses an Electronic Cigarette with atomizer oil core separation structure, which comprises a atomizer assembly and a battery assembly; The utility model has the advantages of reasonable structure design and high practicability. During operation, because the oil storage tank of the atomizer is completely sealed and the oil guide material is completely isolated from the oil guide material, the oil guide material will never contact with the oil guide material in the storage process
Advantages:
Oil core separation, Mesh removable heating core, Ultra quiet design,100% oil leakage free, Excellent taste, Cost far less than the industry price.
A variety of colors and finishing are available, can be adjusted according to your market needs.
Oil Coil Separation Pod Patent,Oil Coil Separetion Vape Pod Oem,Innovated Vape Products Oem,Oil Coil Separation Vape Products Oem
Shenzhen MASON VAP Technology Co., Ltd. , https://www.masonvap.com