Zero copy can avoid redundant memory copy (CPU copy) and context switches between user space and kernel space. But the "truly zero copy" requires hardware DMA (Direct Memory Access) with scatter-gather capability. In the process of ordinary DMA transferring data, the source physical address and the target physical address must be continuous. Scatter-gather DMA is different, it can transfer the data from a discrete physical address to a continuous physical address.
$ git [email protected]:Chen-Kuan-Chung/zero-copy.git
$ cd zero-copy
$ make
- File copy from disk to disk
./file_copy -h
Usage
file_copy -m <mode> -b <buffer size>
Mode:
1: read/write
2: mmap/write
3: sendfile
Buffer size: bytes, default is 64
Example: use mmap/write with a buffer size of 128 bytes to copy file
$ ./file_copy -m 2 -b 128
- File copy from disk to network
[Server]
./file_copy_server -h
Usage
file_copy_server -b <buffer size>
Buffer size: bytes, default is 64
-------------------------------------------------
[Client]
./file_copy_client -h
Usage
file_copy -i <ip> -m <mode> -b <buffer size>
IP: Server IP address, default is 127.0.0.1
Mode:
1: read/write
2: mmap/write
3: sendfile
Buffer size: bytes, default is 64
Example: use mmap/write with a buffer size of 128 bytes to copy file from client to server (192.168.127.256)
[Server]
$ ./file_copy_server -b 128
-------------------------------------------------
[Client]
$ file_copy -i 192.168.127.256 -m 2 -b 128
- File copy from disk to disk
- Buffer size: 32, 64, 128, 256, 512
- Test iteration: 10
$ cd zero-copy
$ ./analysis.sh
Note: sendfile has no buffer parameter