0 Copy technology in Linux, part 1th

Source: Internet
Author: User

Overview

This series consists of two articles, which describe several 0 copy technologies currently used on the Linux operating system, and simply describes the implementation of various 0 copy technologies, as well as their characteristics and application scenarios. This article is the first part of this series, mainly to introduce some background knowledge of 0 copy technology, a brief overview of why Linux requires 0 copy technology and what kind of 0 copy technology is available in Linux.

1 reviews:

Huang, software engineer, IBM

Feng Rui, software engineer, IBM

January 27, 2011

    • Content

Develop and deploy your next application on the IBM Bluemix cloud platform.

Start your free trial now

Introduction

The standard I/O interface for traditional Linux operating systems is based on data copy operations, where I/O operations cause data to be transferred between the buffer of the operating system kernel address space and the buffer defined by the application address space. The biggest benefit is that you can reduce disk I/O operations, because if the requested data is already stored in the operating system's cache, then no actual physical disk I/O is required. However, the data copy operation in the process of transmission results in great CPU overhead, which restricts the ability of the operating system to carry out data transfer efficiently.

0 Copy (zero-copy) This technology can effectively improve the performance of data transmission, when the kernel driver (such as the network stack or disk storage driver) processing I/O data, 0 copy technology can to some extent reduce or even completely avoid unnecessary CPU data copy operation. Modern CPUs and storage architectures provide many features that can effectively implement 0 copy technology, but because of the complexity of the storage architecture and the fact that the network stack sometimes requires the necessary processing of the data, 0 copy technology can have a lot of negative effects, even leading to a complete loss of the benefits of the 0 copy technology itself.

Back to top of page

Why 0 Copy technology is required

Today, many Web servers are based on the client-server model. In this model, the client requests data or services from the server side, and the server needs to respond to requests made by the client and provide the client with the data it needs. With the gradual popularization of network services, video applications have developed rapidly. Today's computer systems already have the capacity to handle the heavy load on clients of applications such as video, but on the server side it is stretched to cope with the network traffic caused by such applications as video. Moreover, the number of clients is growing rapidly, so the server side is more likely to become a performance bottleneck. For heavily loaded servers, the operating system is often the culprit for performance bottlenecks. For example, when a system call for a data "write" Operation or data "send" operation is issued, the operating system typically copies the data from the buffer in the application's address space to the buffer of the operating system kernel. The benefit of the operating system is that the interface is simple, but the system performance is largely lost because this data copy operation requires not only CPU time slices but also additional memory bandwidth.

Generally, clients send requests to the server through a network interface card, which the operating system passes on to the server-side application, the server-side application processes the requests, and after the request is processed, the operating system also needs to pass the resulting processing back through the network adapter.

This section below will be a brief introduction to the reader how the traditional server is the data transfer, and the processing of such data transmission problems may cause server performance loss.

The process of transferring data to traditional servers in Linux

Traditional I/O operations in Linux are a buffer the data generated during the I/O,I/O process typically requires multiple copies in the buffer. In general, when transferring data, the user application needs to allocate a chunk of the appropriate size buffer to hold the data to be transmitted. The application reads a piece of data from the file and sends the data over the network to the receiving end. The user application simply needs to call both system calls read () and write () to complete this data transfer operation, and the application does not know the data copy operation that the operating system did during this data transfer. For Linux operating systems, the operating system kernel will perform multiple copies of the data transfer process, based on various factors such as sorting or checking. In some cases, these data copy operations can greatly reduce the performance of the transmission.

When an application needs to access a block of data, the operating system kernel checks to see if the data is stored in the buffer area of the operating system kernel address space for the previous access to the same file, and if the data is not found in the kernel buffer, the Linux The operating system kernel reads this piece of data from the disk and puts it into the buffer of the operating system kernel. If this data read operation is done by DMA, then in the process of data read DMA, the CPU just need to buffer management, and create and process DMA, in addition, the CPU does not need to do more things, DMA after the data read operation, will notify the operating system to do further processing. The Linux operating system will store this data in the address space of the application requesting the data according to the address of the application address space specified by the read () system, and in the following process, The operating system needs to copy the data again from the buffer of the user application's address space to the kernel buffer associated with the network stack, which is also CPU-intensive. After the data copy operation is finished, the data is packaged and sent to the network interface card. During the data transfer process, the application can go back and perform other operations. Then, when calling the write () system call, the data content in the user application buffer can be safely discarded or changed, because the operating system has retained a copy of the data in the kernel buffer, and the copy of the data can be discarded once the data has been successfully transmitted to the hardware.

As can be seen from the above description, in this traditional data transmission process, at least four copy operations, even if the use of DMA to communicate with the hardware, the CPU still needs to access data two times. In read () reading data, the data is not directly from the hard disk, but must first pass through the operating system's filesystem layer. In the process of writing the data, in order to match the size of the packet to be transmitted, the data must be divided into blocks first, but also to pre-consider the Baotou, and to perform data validation and operation.

Figure 1. Traditional data transfer using read and write system calls

Back to top of page

0 copy (zero copy) technology Overview What is a 0 copy?

In a nutshell, a 0 copy is a technique that avoids the CPU copying data from one piece of storage to another. The various 0-copy technologies that occur for device drivers, file systems, and network protocol stacks in the operating system greatly enhance the performance of specific applications and enable these applications to make more efficient use of system resources. This performance improvement is achieved by allowing the CPU to perform other tasks while the data is being copied. 0 Copy technology can reduce the number of data copy and shared bus operation, eliminate the unnecessary intermediate copy number between memory and transmit data, thus effectively improve the data transmission efficiency. Furthermore, 0 copy technology reduces the overhead of context switching between the user application address space and the operating system kernel address space. A lot of data copying is actually a simple task, from the operating system point of view, if the CPU has been occupied to perform this simple task, then this will be a waste of resources, if there are other relatively simple system parts can do this thing, so that the CPU freed up to do something else, Then the utilization of the system resources will be more effective. In summary, the goal of 0 copy technology can be summarized as follows:

Avoid data copying

    • Avoid data copy operations between operating system kernel buffers.
    • Avoid data copy operations between the operating system kernel and the user application address space.
    • User applications can bypass the operating system for direct access to hardware storage.
    • Data transfer as far as possible DMA to do.

Combine a variety of operations

    • Avoid unnecessary system calls and context switches.
    • The data that needs to be copied can be cached first.
    • The data is processed as much as possible by the hardware.

As mentioned earlier, 0 copy technology is very important for high-speed networks. This is because the network link capability of the high-speed network is close to the CPU's processing power, even exceeding the CPU's processing power. If this is the case, then the CPU may have to spend almost all of the time to copy the data to be transferred, but not the ability to do other things, which creates a performance bottleneck, limiting the communication rate, thereby reducing the ability of the network link. In general, a CPU clock cycle can process one bit of data. For example, a 1 GHz processor can perform traditional data copy operations on 1GBIT/S network links, but 0 copy technology becomes very important for the same processor if it is a network of ten gbit/s. For over 1 gbit/s of network links, 0 copy technology is used in supercomputer clusters and large commercial data centers. However, with the development of information technology, the network of 1 gbit/s,10 gbit/s and gbit/s is becoming more and more popular, so 0 copy technology will become more and more popular, because the processing power of the network link is much faster than the CPU processing power. Traditional data copying is limited by the traditional operating system or communication protocol, which limits the data transmission performance. 0 Copy technology reduces the number of copies of data, simplifies the level of protocol processing, and provides faster data transfer between applications and networks, thus effectively reducing communication latency and increasing network throughput. 0 Copy technology is one of the main technologies to realize high-speed network interface of equipment such as host or router.

Modern CPU and storage architectures provide a number of related functions to reduce or avoid unnecessary CPU data copy operations during I/O operations, but this advantage of CPU and storage architectures is often overestimated. The complexity of the storage architecture, as well as the data transfer required in the network protocol, can cause problems, and sometimes even the benefits of a 0 copy of the technology are completely lost. In the next chapter, we'll cover the 0 copy technologies that appear in several Linux operating systems, simply describe how they are implemented, and analyze their weaknesses.

0 Copy Technology classification

The development of 0 copy technology is very diverse, the existing 0 copy technology is also very large, and currently does not have a suitable for all scenarios of the emergence of 0 copy technology. For Linux, the existing 0 copy technology is also more, these 0 copy technology is mostly in different versions of the Linux kernel, some of the old technology in different versions of the Linux kernel has been greatly developed or has been gradually replaced by new technology. In this paper, the different scenarios for these 0 copy technologies are divided. In summary, the 0 copy technology in Linux mainly has the following kinds of:

    • Direct I/O: for this kind of data transmission, the application can directly access the hardware storage, the operating system core is only secondary data transfer: This kind of 0 copy technology is for the operating system kernel does not need to directly handle the data situation, The data can be transferred directly between the buffer and the disk in the application address space, without the support of the page cache provided by the Linux operating system kernel at all.
    • In the course of data transfer, avoid copying data between the buffer of the operating system kernel address space and the buffer of the user application address space. Sometimes, when the application does not need to access the data while it is being transferred, it is completely avoided by copying the data from the Linux page cache to the buffer of the user process, and the transmitted data is processed in the page cache. In some special cases, this 0-copy technology can achieve better performance. Similar system calls are available in Linux primarily with mmap (), Sendfile (), and Splice ().
    • Optimizes the transfer process between the data in the Linux page cache and the buffer of the user process. The 0 copy technology focuses on the flexibility to handle the copying of data between the buffer of the user process and the page cache of the operating system. This approach continues the traditional way of communication, but is more flexible. In Linux, this method mainly utilizes write-time replication techniques.

The first two types of methods are intended primarily to avoid buffer copy operations between the application address space and the operating system kernel address space. These two types of 0-copy technology are typically used in certain special situations, such as the data to be transferred that does not need to be processed by the operating system kernel or is not required to be processed by the application. The third method inherits the concept of the traditional application address space and the data transfer between the operating system kernel address space, and then optimizes the data transmission itself. We know that the data transfer between the hardware and software can be done by using DMA, and the DMA does not require CPU participation in the process of data transmission, so that the CPU can be freed up to do more things, but when the data needs to be in the buffer of the user address space and the Linux operating system kernel Page cache transfer between the time, and no similar to the DMA tool can be used, the CPU needs to participate in this data copy operation, so the purpose of this third kind of method is to effectively improve the data between the user address space and the operating system kernel address space transfer efficiency.

Back to top of page

Summarize

This article series describes the 0 copy technology in Linux, the first part of this article, introduces the basic concepts of 0 Copy technology, why Linux needs 0 copies of this technology, and a brief overview of what 0 copy technology in Linux has a basic background knowledge. We'll detail some of the 0 copy technologies in Linux described in this article in the second part of this series.

0 Copy technology in Linux, part 1th

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.