当前位置:网站首页>[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 .
边栏推荐
- Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
- Exness: the Central Bank of England will raise interest rates again in March, and inflation is coming
- Hcip 13th day notes
- Leetcode week 4: maximum sum of arrays (shape pressing DP bit operation)
- Overview of Yunxi database executor
- Pooling idea: string constant pool, thread pool, database connection pool
- Runtime. getRuntime(). totalMemory/maxMemory()
- Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
- Buuctf, misc: n solutions
- Meta metauniverse female safety problems occur frequently, how to solve the relevant problems in the metauniverse?
猜你喜欢

Qtoolbutton available signal

Buuctf, misc: n solutions

Teach you how to run two or more MySQL databases at the same time in one system

Hcip day 15 notes

4 environment construction -standalone ha

Data consistency between redis and database

Pyqt5 sensitive word detection tool production, operator's Gospel

Esp-idf turns off serial port log output.

How can enterprises and developers take advantage of the explosion of cloud native landing?
![Buuctf, web:[geek challenge 2019] buyflag](/img/02/d3add04f8145621bff35d46b82ba53.jpg)
Buuctf, web:[geek challenge 2019] buyflag
随机推荐
[issue 16] golang's one-year experience in developing Purdue Technology
User login function: simple but difficult
LeetCode 540. A single element in an ordered array
Leetcode week 4: maximum sum of arrays (shape pressing DP bit operation)
Programming language (2)
在恒泰证券开户怎么样?安全吗?
Mongoose the table associated with the primary key, and automatically bring out the data of another table
Ansible common usage scenarios
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
JarPath
Quick one click batch adding video text watermark and modifying video size simple tutorial
Weekly leetcode - nc9/nc56/nc89/nc126/nc69/nc120
Redis single thread and multi thread
SDMU OJ#P19. Stock trading
In 2022, 6G development has indeed warmed up
MLX90614 driver, function introduction and PEC verification
How to obtain opensea data through opensea JS
Recursive least square adjustment
[15th issue] Tencent PCG background development internship I, II and III (OC)
33 restrict the input of qlineedit control (verifier)