Recently developed with the fuse file system, the file system is implemented in the user-state, but its filesystem operation interface must be registered in the kernel state, so it is necessary to study the kernel state to the user state overhead.
The following example is seen on StackOverflow, which basically reflects the difference in overhead:
In Linux testing this test program, GETUID is a system call that returns the ID of the current user
1 #include <unistd.h>23#define MAX 1000000004int Main () {5 int II; 6 for (ii=0; ii<max; ii++) getuid (); 7 return 0 ; 8 }
The result shows that the loop is 100 million times more than 8 seconds.
Real 0m8.438s
User 0m3.952s
SYS 0m4.485s
When testing with the following program,
1#include <unistd.h>2 #defineMAX 1000000003 4 int_getid ()5 {6 return 1;7 }8 9 intMain () {Ten intII; One for(ii=0; ii<max; ii++) _getid (); A return 0; -}
The results of the operation are as follows:
Real 0m0.305s
User 0m0.304s
SYS 0m0.000s
The time consumption is significantly reduced.
The two program time consumption mainly lies in the kernel state and the user state switch, each cycle involves the user state and so on the user state and so on the switch, therefore consumes the time to be many.
It also means that I have to modify the functionality of the various file interfaces of fuse to make it no longer repeatedly switch the user's kernel state.
Test for kernel state and user-state switching overhead