During this period of time when I looked at the Linux kernel source code, I often encountered vdso (for example, in Feature-fixup, getting the time and so on). I searched the internet to find out the meaning, it turns out that this is a rare trick for Linux to solve glibc compatibility. The following is a list of Chinese emails from Fedora...
During this period of time when I looked at the Linux kernel source code, I often encountered vdso (for example, in Feature-fixup, getting the time and so on). I searched the internet to find out the meaning, it turns out that this is a rare trick for Linux to solve glibc compatibility. The following is a conversion from the Ora Chinese email list.
Generally, a function is added to the kernel. glibc takes a long time to use. It had been a long time since linux had entered the kernel for this feature, and glibc had to argue about whether to use this new kernel feature for a long time (glibc was not proprietary to Linux, we also need to consider BSD (although people do not need glibc), SysV Windows (you can't do it), sun's dying solaris, and their own Hurd. Then, in short, the new features are acceptable... It's too slow.
In terms of closeness, fnotify glibc does not have a corresponding packaging function. it takes a long time for futex and NPTL to enter the mainstream. Libc is a bridge between the app and the kernel. libc should be able to quickly keep up with the kernel interface changes, but glibc and the kernel are not developed in one way. Therefore, this is just an ideal solution. Glibc must be compatible with different versions of the kernel!
The kernel is also compatible with glibc of different versions. both Sides carry too much historical burden. Glibc retains Linux Threads compatible with the old 2.4 kernel. Linux is useless, and even system calls with bugs (interface problems make some bugs necessary) must be retained. who knows which version of glibc the user will use? Although the new glibc uses new calls, it provides the same APIs as the old ones for compatibility. However, it is common for users to upgrade only the kernel without upgrading glibc. Even if glibc is upgraded, will your new version of glibc use the new kernel interface? Wait a few more years until the quarrel between glibc developers is over.
As a result, the Linux Giants once again made a trick: turning libc into VDSO and entering the kernel.
Here we will popularize the VDSO knowledge. people who know it will skip it. people who don't know it will read it: VDSO is a Virtual Dynamic Shared Object, or Virtual provided by the kernel. so, this. so files are not on the disk, but in the kernel. The kernel maps the memory page containing a. so file into its memory space when the program starts. the corresponding program can use the function as a common. so file. For example, the syscall () function is in the linux-vdso.so.1, but there is no corresponding file on the disk. you can look at it through ldd/bin/bash.
In this way, the libc released with the kernel is bound to a specific version of the kernel. Note that VDSO is only released with the kernel and does not run in the kernel space. this will not cause kernel expansion. In this way, both the kernel and libc do not need to write too much code and introduce too many bugs for compatibility with different versions of each other.
Of course, libc not only has kernel interfaces, but also has many common functions. these functions do not need to be carefully written for different versions of the kernel. therefore, I guess there will be two libc in Linux. one libc is in the kernel, but it is only a package called by the system. The other libc is still a common libc, it's just that libc no longer needs to work with so many kernel resources.
For example, one is kernellibc and the other is glibc: printf. Open (), read (), write (), socket (), but these are no longer glibc, they are in kernellibc.
In Linux, traditional system calls are implemented through soft interruptions (0x80). in a Kernel.org mail list, an email discussed "Intel P6 vs P7 system call performance". The final conclusion is that using the traditional int 0x80 system call wastes a lot of time, sysenter/sysexit can make up for this shortcoming, so it is decided to replace the former in the Linux kernel (this function is added to the kernel of version 2.6, that is, sysenter/sysexit ).
How can I replace the previous int 0x80 with sysenter/sysexit? Linux kenerl needs to take this into consideration: some machines do not support sysenter/sysexit, so it makes a good decision with glibc: "You will call the system call from the address I gave you later, the content pointed to by this address is either int 0x80 or sysenter/sysexit. I will select one of them based on the machine "(the cooperation between kernel and glibc is so tacit ), this is the first address of vsyscall.
You can think of vdso as a shared objdect file (this file does not actually exist). The Kernel maps it to an address space and is shared by all programs. (I think one technology is used here: multiple virtual pages are mapped to the same physical page. That is, the kernel maps vdso to a physical page, and all programs will have a page table entry pointing to it for sharing, so that the vdso address of each program can be different)
Compared with the interrupted command, the "quick system invocation command" consumes less time, but with the development of the CPU design, there should be no disparity like Intel Pentium4 in the future. Compared with the interrupt method, the "quick system call command" still has some limitations, for example, other system calls cannot be called through "quick system call command" during a system call process. Therefore, not every system call must be implemented through "quick system call Command. For example, for complex system calls such as fork, the time difference between the two system call methods is negligible compared with the time consumed by system calls, there is no need to use the "quick system call command" method. However, the "quick system call command" method should be used for system calls that require a short running time and high time accuracy, such as getuid and gettimeofday. Therefore, only by taking flexible measures and taking different methods for different system calls can we get the optimal performance and achieve the most perfect functions.
From JuanA1's column