当前位置:网站首页>[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 .
边栏推荐
- [flax high frequency question] leetcode 426 Convert binary search tree to sorted double linked list
- Pandaoxi's video
- [sg function]split game (2020 Jiangxi university student programming competition)
- Shell script three swordsman awk
- Pyqt5 sensitive word detection tool production, operator's Gospel
- Weekly leetcode - nc9/nc56/nc89/nc126/nc69/nc120
- C3p0 connection MySQL 8.0.11 configuration problem
- How to connect a laptop to a projector
- To rotate 90 degrees clockwise and modify the video format
- LeetCode 540. A single element in an ordered array
猜你喜欢

Summary of fluent systemchrome

Go Technology Daily (2022-02-13) - Summary of experience in database storage selection

Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?

Sort merge sort

Unsafe and CAS principle

Buuctf, misc: n solutions

Unique in China! Alibaba cloud container service enters the Forrester leader quadrant

1068. Consolidation of ring stones (ring, interval DP)
Creation of the template of the password management software keepassdx

Hcip day 16 notes
随机推荐
Text replacement demo
[15th issue] Tencent PCG background development internship I, II and III (OC)
Gorilla/mux framework (RK boot): add tracing Middleware
Redis single thread and multi thread
How to quickly build high availability of service discovery
How to connect a laptop to a projector
Ansible common usage scenarios
IO flow review
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
320. Energy Necklace (ring, interval DP)
Creation of the template of the password management software keepassdx
Pointer concept & character pointer & pointer array yyds dry inventory
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
Flutter internationalized Intl
3 environment construction -standalone
Teach you to easily learn the type of data stored in the database (a must see for getting started with the database)
finalize finalization finally final
在恒泰证券开户怎么样?安全吗?
The difference between SRAM and DRAM
A preliminary study on the middleware of script Downloader