编程知识 cdmana.com

30 questions about the Linux kernel for interviewers

Preface

The interview the other day was full of corpses , Because the interviewer asked linux kernel , Many students usually don't pay attention to this , So naturally there is no way to answer , Let's take a look at the problems that have baffled us , The answer has also been sorted out for you , But only a few , Because I don't know if anyone is watching , I'm lazy , The rest of the answers are available to interested friends

1. Linux What are the main types of kernel locks in ?

=============================

Linux The synchronization mechanism of 2.0 To 2.6 Since then, it has been continuously developed and perfected . From the initial atomic operation , Later The amount of signal , From big kernel locks to today's spinlocks . The development of these synchronization mechanisms is accompanied by Linux From a single place The transition from processors to symmetric multiprocessors ; With the transition from non preemptive kernel to preemptive kernel .Linux More and more effective locking mechanism , More and more

The more complicated it is . Spinlocks can only be held by one executable thread at most , If an execution thread attempts to request a request that has been contested and held ) The spin lock of , Then the thread will be busy looping all the time —— rotate —— wait for Lock is available again . If it's not disputed , The executing thread that requests it gets it immediately and continues . Spin lock can  

To prevent more than one execution thread from entering the critical section at any time . Sleep characteristics of semaphores , Make semaphores suitable for situations where locks will be held for a long time ; Only in the process The following is used , Because interrupt context cannot be scheduled ; In addition, when the code holds semaphores , No You can hold the spin lock again . Linux The synchronizer in the kernel

system : Atomic manipulation 、 Semaphore 、 Read and write semaphores and spinlocks API, another Other synchronization mechanisms , Including large kernel locks 、 Read-write lock 、 Big reader lock 、RCU (Read-Copy Update, As the name suggests, it means reading - Copy and modify ), And sequence lock .

2. Linux What is the meaning of user mode and kernel mode in ?  

=====================================

MS-DOS Wait for the operating system in a single CPU Run in mode , But some classes Unix The operating system makes With dual mode , Can effectively achieve time sharing . stay Linux On the machine ,CPU Or in trust Kernel mode of , Or in restricted user mode . Except that the kernel itself is in kernel mode , the Some user processes run

Line in user mode . Kernel mode code has unlimited access to all processor instruction sets as well as all memory and I/O Space . If user mode processes are to have this privilege , It must be sent to the device driver or other through a system call Kernel mode code makes a request . in addition , User mode code allows page faults to occur , And kernel mode

Code does not allow . stay 2.4 And earlier kernels , Only user mode processes can be context switched out , From others to Cheng grabs . Unless two things happen , Otherwise, kernel mode code can always be exclusive CPU:

(1) It gave up voluntarily CPU;

(2) An interrupt or exception has occurred .

2.6 Kernel introduces kernel preemption , Most kernel mode code can also be preempted .

3. How to apply for large kernel memory ?

========================

stay Linux In the kernel environment , The success rate of large memory application decreases with the increase of system running time , Although it can pass vmalloc Serial calls Request memory with physical discontinuity but continuous virtual address , But, after all,

Its use efficiency is not high and in 32 Bit system vmalloc Memory address space is limited . therefore , General The suggestion is to apply for large amount of memory in the system startup phase , But the probability of its success is only relatively high , and No 100%. If the program really cares about the success of the application , It can only be withdrawn “ Start inside save ”Boot Memory). Next is

Is the application and export of boot memory a sample code :

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 xn", x_bootmem_size, x_bootmem);
return 1;
}
__setup("x-bootmem=", x_bootmem_setup);

It can be seen that its application is relatively simple , But the pros and cons are always symbiotic , It inevitably has its own limitations

system :

Memory application code can only be connected to the kernel , Cannot be used in modules . The requested memory is not allocated by the page Utensils and slab Distributor usage and statistics , That is, it's outside the system's visible memory , Even in Somewhere in the future you let it go . The average user will only request a large amount of memory , If you need to put it into practice

Now complex memory management needs to be implemented by ourselves . Where memory allocation failure is not allowed , By starting inside Saving and reserving memory space will be our only choice .

4. What are the main ways of user process communication ?

===========================

  1. The Conduit Pipe): Pipes can be used for communication between processes with kinship , Allow one process and another Communication between processes with which it has a common ancestor
  2. name pipes named pipe): Named pipes overcome the limitation that pipes have no names , therefore , In addition to having Besides the functions of the pipeline , It also allows communication between unrelated processes . Named pipes in the file system There is a corresponding file name in . Named pipe through command mkfifo Or system call mkfifo To create .
  3. The signal Signal): Signal is a more complex way of communication , Used to notify the receiving process that something has happened raw , Except for interprocess communication , The process can also signal the process itself ;linux In addition to supporting Unix Early signal semantic function sigal Outside , Semantic compliance is also supported Posix.1 Standard signal function sigaction actually , This function is based on BSD Of ,BSD In order to realize reliable signal mechanism , And be able to Unified external interface , use sigaction Function re implemented signal function ).
  4. news Message) queue : Message queues are linked tables of messages , Include Posix Message queue system V Message queue . Processes with sufficient privileges can add messages to the queue , Processes that are given read permission are You can read messages in the queue . Message queuing overcomes the lack of signal carrying information , The pipe can only carry no grid There are some shortcomings such as byte stream and limited buffer size
  5. Semaphore semaphore): Mainly as a means of synchronization between processes and between different threads of the same process .
  6. Socket Socket): More general interprocess communication mechanism , It can be used between processes between different machines signal communication . At first it was by Unix Systematic BSD Branch developed , But now it can be transplanted to other class Unix On the system :Linux and System V Socket is supported in all variants of .

5、 call schedule() There are several ways to switch processes ?

=============================================

1. system call do_fork();

2. Timed interrupt do_timer();

3. Wake-up process wake_up_process

4. Change the scheduling policy of the process setscheduler();

5. System call comity sys_sched_yield();


6、 What are the functions that apply kernel memory through the partner system ?

7、 adopt slab The functions used by allocator to request kernel memory are ?

8、Linux How is the kernel space and user space divided ( With 32 For example, bit system )?

9、vmalloc() What are the characteristics of the requested memory ?

10、 User program use malloc() What is the range of memory space applied for ?

11、 Support and enable MMU In the system ,Linux The kernel and user program run in physical address mode or virtual address mode respectively ?

12、ARM The processor maps storage space through several levels of tables ?

13、Linux What components are used to support multiple file binding ?

14、Linux What are the key data structures of virtual file system ?( At least write four )

15、 The operation function of a file or device is stored in that data structure ?

16、 What are the system calls to create a process ?

17、Linux The scheduler schedules processes according to their dynamic or static priorities ?

18、 What is the core data structure of process scheduling ?

19、 How to load 、 Uninstall a module ?

20、Linux Is floating-point operation implemented by application or kernel ?

21、 Can module programs use linkable library functions ?

22、TLB What is cached in ?

23、Linux What kinds of equipment are there ?

24、 Which is the key data structure of character device driver ?

25、 What functions does the device driver include ?

26、 How to uniquely identify a device ?

27、Linux How to implement system call ?

28、Linux What is the role of soft interrupts and work queues ?


Okay , That's all for the article , You ask me why there is no answer in the back ? Because I'm too lazy to type , If you can't do it yourself or you want to prove it right , You can join the group 973961276 Talk to people , If anyone is watching it, I'll give you another explanation linux Video of the kernel , The meeting broke up !

版权声明
本文为[Bald brother]所创,转载请带上原文链接,感谢

Scroll to Top