当前位置:网站首页>[note] IPC traditional interprocess communication and binder interprocess communication principle
[note] IPC traditional interprocess communication and binder interprocess communication principle
2022-07-03 23:04:00 【Li Baoming】
Tradition IPC
Two copy process :

1. The message sender stores the message data to be sent into the memory buffer , Enter kernel state through system call .
2. Then kernel program allocates memory in kernel space , And open up a memory cache , call copy_from_user() Copy data from the user space memory cache to the kernel cache in kernel space .
3. When receiving data, the receiver process creates a memory buffer in its own user space .
4. Then the kernel program calls copy_to_user() Copy the data from the kernel cache to the memory cache of the receiver process .
This completes a data transmission between processes .
This traditional IPC There are two problems with communication :
1. Poor performance , A data transfer needs to go through : Memory cache --> Kernel cache --> Memory cache , need 2 Secondary data copy ;
2. The buffer for receiving data is provided by the data receiving process , But the receiving process doesn't know how much space is needed to store the data to be transferred , So we can only open up as much memory space as possible or call first API Receive the message header to get the small of the message body , These two methods are either a waste of space or a waste of time .
Binder IPC

Binder IPC The memory mapping involved in the mechanism is through mmap() To achieve .
mmap(): Is a memory mapping method in the operating system .
Memory mapping is simply to map a block of memory area of user space to kernel space . After the mapping relationship is established , The user's modification of this memory area can directly reflect the kernel space ; On the other hand, the kernel space modification of this area can also directly reflect the user space .
Memory mapping can reduce the number of data copies , Achieve efficient interaction between user space and kernel space .
The changes of the two spaces can be directly reflected in the mapped memory area , So as to be perceived by each other's space in time
Once complete Binder IPC The communication process is usually like this :
1. First Binder The driver creates a data receiving buffer in kernel space ;
2. And then open a kernel cache in kernel space , Establish the mapping relationship between the kernel cache and the data receiving cache in the kernel , And the mapping relationship between the data receiving buffer and the user space address of the receiving process in the kernel ;
3. Sender process through system call copy from user() Put the data copy To the inside
Kernel cache in the kernel , Due to the memory mapping between the kernel cache and the user space of the receiving process , Therefore, it is equivalent to sending data to the user space of the receiving process , This completes a communication between processes .
边栏推荐
- 1068. Consolidation of ring stones (ring, interval DP)
- pycuda._ driver. LogicError: explicit_ context_ dependent failed: invalid device context - no currently
- Mindmanager2022 serial number key decompression installer tutorial
- 2022.02.13
- Niuke winter vacation training camp 4 g (enumeration optimization, Euler power reduction)
- Codeforces Round #768 (Div. 1)(A-C)
- Hcip day 12 notes
- [15th issue] Tencent PCG background development internship I, II and III (OC)
- The overseas listing of Shangmei group received feedback, and brands such as Han Shu and Yiye have been notified for many times and received attention
- URLEncoder. Encode and urldecoder Decode processing URL
猜你喜欢

Leetcode: a single element in an ordered array

Flutter internationalized Intl

Weekly leetcode - nc9/nc56/nc89/nc126/nc69/nc120

Interpretation of corolla sub low configuration, three cylinder power configuration, CVT fuel saving and smooth, safety configuration is in place

Es6~es12 knowledge sorting and summary
![[flax high frequency question] leetcode 426 Convert binary search tree to sorted double linked list](/img/db/b992d2b461ca17652518a1511b4947.gif)
[flax high frequency question] leetcode 426 Convert binary search tree to sorted double linked list

Buuctf, misc: sniffed traffic

Some 5000+ likes, the development notes of a director of cosmic factory, leaked

1 Introduction to spark Foundation

Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
随机推荐
Buuctf, misc: n solutions
The difference between SRAM and DRAM
[issue 16] golang's one-year experience in developing Purdue Technology
Mindmanager2022 serial number key decompression installer tutorial
Flutter internationalized Intl
Subset enumeration method
Leetcode: a single element in an ordered array
Recursive least square adjustment
Opengauss database log management guide
320. Energy Necklace (ring, interval DP)
The reason why the computer runs slowly and how to solve it
[actual combat record] record the whole process of the server being attacked (redis vulnerability)
2.14 summary
Teach you to easily learn the type of data stored in the database (a must see for getting started with the database)
1068. Consolidation of ring stones (ring, interval DP)
Loop compensation - explanation and calculation of first-order, second-order and op amp compensation
How about opening an account at Hengtai securities? Is it safe?
In VS_ In 2019, scanf and other functions are used to prompt the error of unsafe functions
Format cluster and start cluster
File copy method