Professional Documents
Culture Documents
http://www.linuxjournal.com/article/6345?page=0,0
Username/Email:
Password:
Login
www.lightcms.com
Ads by Google
By now almost everyone has heard of so-called zero-copy functionality under Linux, but I often run into people who don't have a full understanding of the subject. Because of this, I decided to write a few articles that dig into the matter a bit deeper, in the hope of unraveling this useful feature. In this article, we take a look at zero copy from a user-mode application point of view, so gory kernel-level details are omitted intentionally. What Is Zero-Copy?
(/issue/105)
To better understand the solution to a problem, we first need to understand the problem itself. Let's look at what is involved in the simple procedure of a network server dmon serving data stored in a file to a client over the network. Here's some sample code:
read(file, tmp_buf, len); write(socket, tmp_buf, len);
Looks simple enough; you would think there is not much overhead with only those two system calls. In reality, this couldn't be further from the truth. Behind those two calls, the data has been copied at least four times, and almost as many user/kernel context switches have been performed. (Actually this process is much more complicated, but I wanted to keep it simple). To get a better idea of the process involved, take a look at Figure 1. The top side shows context switches, and the bottom side shows copy operations.
Figure 1. Copying in Two Sample System Calls Step one: the read system call causes a context switch from user mode
1 of 4