Memory ing and DMA, memory ing DMA

Source: Internet
Author: User

Memory ing and DMA, memory ing DMA

1. the implementation process of mmap system calling. The system calling directly maps the device memory to the address space of the user process.

2. How to map the user space memory to the kernel (get_user_pages ).

3. Direct Memory Access (DMA), which enables peripherals to directly access the system memory.

 

Address type in linux: User Virtual Address, kernel virtual address, kernel logical address (linear relationship with physical address), physical address

 

User space and kernel space: the kernel divides 4G virtual address space into user space and kernel space, and uses the same ing in the context of the two. The kernel cannot operate the memory not mapped to the kernel address space. In the kernel address, there is an address space dedicated for virtual ing from the user space to the kernel.

 

Low-end memory: the logical memory address that exists in the kernel space.

High-end memory: memory that does not have a logical address.

 

The memory processing function in the kernel tends to use a pointer to the page structure, which is used to save all the physical memory information required by the kernel.

 

Page table: the processor uses a page table to convert a virtual address to a corresponding physical address.

 

Virtual Memory zone (VMA): used to manage the kernel data structures of different regions in the process address space. The image file generated by each process after compilation and linking has a code segment, data segment, and stack segment (as shown in 1). All memory mappings (at least) contain the following areas:

1) executable code area of the program

2) Multiple Data zones, including the initialized data zone, non-initialized data zone, and program stack.

3) The region corresponding to the memory ing of each activity

Figure 1 (Process Virtual Space Division)

Generally, the virtual memory space used by the process is not consecutive, And the access attributes of each part of the virtual memory space may be different. Therefore, the virtual storage space of a process needs to be described by multiple vm_area_struct structures.

When the number of vm_area_struct structures is small, each vm_area_struct is sorted in ascending order and organizes data in the form of a single-chain table (points to the next vm_area_struct structure through the vm_next pointer ). However, when there is a large amount of data in the vm_area_struct structure, the chain table is still organized, which will inevitably affect the search speed. To solve this problem, vm_area_struct also adds vm_avl_hight (tree height), vm_avl_left (left sub-node), and vm_avl_right (right sub-node) to implement AVL Tree to improve the search speed of vm_area_struct.

If vm_area_struct describes a file-mapped virtual storage space, the vm_file Member points to the file structure of the mapped file. vm_pgoff is the file offset of the starting address of the virtual storage space in the vm_file file, the Unit is physical page.

 

Figure 2 Process Virtual Address

The task of mmap system calling is to prepare such a virtual storage space, create a vm_area_struct struct, and pass it to a specific device driver. These are all completed by the kernel.

 

When a user space process calls mmap to map the device memory to its address space, the system creates a new VMA that indicates the ing as a response and supports mmap drivers, you need to help the process complete VMA initialization.


In linux, when the DMA data of the device is 0 x f0000000, mmap ing is used, and memcpy is used, the efficiency is quite low. 16 m Requires 400 ms. How can this problem be improved?

Where are the bottlenecks first?
1) device dma rate. Do not map the data directly in the memory of the memcpy device.

2) mmap efficiency. Do not use DMA memory for ing, use the memory requested by the kernel for ing, and then check the rate in the user control memcpy.

3) User memcpy efficiency. You have tested this, not a problem.
 
Memory ing and port ing

The former is correctly understood.

"A single physical address space for CPU" refers to RAM. As described above, "CPU (such as PowerPC and m68k) in some architectures generally only implement one physical address space (RAM) ". That is to say, the CPU of this type of structure (memory ing mode) is only mapped to RAM, and other objects such as I/O and ROM must be mapped to RAM for CPU access.

"Other architecture CPUs (typically X86) provide a dedicated address space for peripherals." (I/O ing mode) CPU is the CPU in our current PC. Isn't the addressing space of this type of CPU divided into regular memory, reserved memory, and extended memory? The reserved memory is used for direct addressing of I/O, ROM, etc. However, because the read Speed of I/O and ROM involved in direct addressing is not as fast as RAM, the motherboard provides the ing function. After the ing, the physical RAM involved in retaining the memory addressing is actually used, in this case, it is similar to the memory ing method.

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.