Linux Memory allocation Learning __linux

Source: Internet
Author: User

The collection and collation of some concepts:


Writethough vs Writeback

1. Writethough
Write-through means that the write operation does not use caching at all. Data is always written directly to the disk. Turns off write caching, which frees the cache for read operations. Write caching, which is shared by read and write operations,
can improve the performance of writes. The data is not written directly to the disk, but is written to the cache. From an application's point of view, it is much faster than waiting to complete a disk write operation. Therefore, you can improve write performance. The
controller writes data that is not written to disk in the cache to disk. On the surface, write cache is better than Write-through read and write performance, but also depends on the disk access mode and disk load.

2. Writeback
write-back (write cache) is usually faster when the disk load is lighter. When the load is heavy, every time the data is written to the cache, it is written to the disk immediately to release the cache to save the new data that will be written, and the
controller will run faster if the data is written directly to the disk. Therefore, when the load is heavy, writing the data to the cache first reduces throughput.


cacheable vs buferfable

1. For Write-though write strategy, cacheable is writeback data refers to whether to put the cache (of course, for some I/O operations such as nature can not cacheable),
Bufferable refers to the writeback data can be put into the writebuffer, slowly back to write only main memory (some cases for some data is required to write back immediately, can not first buffer)
2. The same is true for Write-back's writing strategy, but one exception is cacheable/unbufferable, because since it's all cache,
for write-back strategy it means waiting for the cache When line is replaced, it is written to main memory, which means that writing back main memory time is destined to be delay,
so generally it will be translated into Write-though cached/buffered behavior.

starting && stopping cache flushing levels

These two settings affect how the controller handles cached data that is not written to disk and takes effect only in Write-back cache mode. Data written to disk in cache is called Flushing. You can configure the
starting and stopping cache flushing levels value, which represents the percentage of the total cache size. When data that is not written to disk in the cache reaches starting flushing value, the
controller begins flushing (written to disk by cache). The flushing process stops when the amount of disk data not written in the cache is lower than the stop flush value. The controller always flush the old cached data first. The
data in the cache is not written for more than 20 seconds and is automatically flushing.
The typical start flushing level is 80%. Typically, the stop flushing level is also set to 80%. That is, the controller does not allow more than 80% of the cache to be used for Write-back cache,
but remains as far as possible. If you use this setting, you can write more data in the cache memory. This helps to improve the performance of write operations, but at the expense of data protection. If you want to get data protection,
you can use the lower start and stop values. By setting these two parameters, you can adjust the read and write performance of the cache. The test shows that the performance is better when using close start and stop flushing levels
. If stop level value is far below the start value, it can cause disk congestion when flushing.

Cache block Size
This value refers to the size of the cache allocation unit, which can be 4 K or 16K. Choosing the right values can significantly improve cache usage performance.
if the application accesses more than 8K of data, the cache block size is set to 16K, with only a subset of cache blocks per access.
8 k or smaller data is always stored in the cache block of 16K, meaning that only 50% of the cache capacity is used effectively, which can degrade performance. 4K is appropriate for random I/O and small block of data transfer
. On the other hand, if it is continuous I/O and uses large segment size, it is best to choose 16K. The large cache block size means that the number of cache blocks is small and can shorten caching consumption latency.
In addition, for the same size of data, cache block size is larger, the need for less cache data transfer.

dma_alloc_coherent vs Dma_alloc_writecombine
is to allocate contiguous physical memory, returning the virtual address
1.dma_alloc_coherent
#define PGPROT_NONCACHED (Prot) __pgprot (Pgprot_val (Prot) & ~ (L_ pte_cacheable | l_pte_bufferable))
disables cahceable and bufferable

2.dma_alloc_writecombine
#define Pgprot_writecombine ( Prot) __pgprot (Pgprot_val (Prot) & ~l_pte_cacheable)

CMA vs UMP


CMA: Manages contiguous memory, can be reserved, and can be used when allocated. Reserved in 4412BSP.

Ump:mali use memory, dynamic distribution when used (Alloc_page)

NEON

Multi-media and accelerated instruction set, enhanced arm for multimedia processing capabilities, some scenarios can replace the hardware processing unit.
ARM? NEON? The universal SIMD engine can effectively handle current and future multimedia formats, thereby improving the user experience.
NEON Technology accelerates multimedia and signal processing algorithms (such as video encoding/decoding, 2d/3d graphics, gaming, audio and speech processing, image processing technology, telephony, and voice synthesis)
at least 3 times times the performance of ARMV5, twice times ARMv6 SIMD performance.

NEON Technology is built in a clean way and can be used seamlessly for its own independent piping and register files. The
NEON Technology is a 128-bit SIMD (single instruction multiple data) architecture extension for ARM CORTEX?-A series processors, designed to provide flexible and powerful acceleration for consumer multimedia applications,
thus significantly improving the user experience. It has 32 registers, 64-bit width (16 registers, 128-bit width double view). )


request_mem_region && ioremap && phys_to_virt ()

Linux defines three macros in the header file include/linux/ioport.h that operate on I/O memory resources: (1) request_mem_region () macros, requesting the allocation of the specified I/O memory resource.
(2) Check_mem_region () macro to check if the specified I/O memory resource is occupied.
 (3) Release_mem_region () macros to free the specified I/O memory resources. These three macros are defined as follows: #define REQUEST_MEM_REGION (Start,n,name) __request_region (&iomem_resource, (start), (n), (name)) #defi Ne check_mem_region (start,n) __check_region (&iomem_resource, (start), (n)) #define Release_mem_region (St Art,n) __release_region (&iomem_resource, (start), (n)) where parameter start is the starting physical address of the I/O memory resource (the physical address of the CPU in the physical address space of the RAM), parameter n The size of a fixed I/O memory resource.

   
When the IO memory resource was requested to succeed, the mapping operation was started with Ioremap.
void * __IOREMAP (unsigned long phys_addr, unsigned long size, unsigned long flags) maps an IO address space to the virtual address space of the kernel for easy access. Entry: PHYS_ADDR is the starting IO address to map, the size is the amount of space to map, and the flag is the namespace-related flag to map; implementation: To determine the IO address space to map, the low Pci/isa address does not need remapping, Also do not allow users to map the IO address space to the RAM in use, and finally apply for a VM_AREA_STRUCT structure, call Remap_area_pages fill out the page table, if the completion process is not successful release the application vm_area_struct space
To modify the page table based on the virtual address and the physical address you want to map, and then the kernel can use this virtual address to access the physical address of the map. Ioremap do nothing for directly mapped I/O addresses (such as Uclin without MMU)The UX directly returns the physical address). With Ioremap (and Iounmap), the device can access any I/O memory space, regardless of whether it maps directly to the virtual address space.


However, these addresses can never be used directly (as with the address returned by Kmalloc), but with the READB function. The same is true from the physical address assigned to the virtual address, as well as the following function: Phys_to_virt () The actual address translated into a virtual address, the two are different.
The conversion of physical address to virtual address with Ioremap and Phys_to_virt is found: addr = (unsigned int volatile *) Ioremap (0x56000088,12);
PRINTK (Kern_alert "%x\n", addr);
addr = (unsigned int volatile *) Phys_to_virt (0x56000088);
PRINTK (Kern_alert "%x\n", addr); Two functions return a different addr value. The reason is: (1) in the kernel, Phys_to_virt simply subtracts a fixed offset from the address: #ifndef __virt_to_phys #define __virt_to_phys (x) ((x)-Page_offset + phys_offs ET) #define __PHYS_TO_VIRT (x) (x)-Phys_offset + page_offset) #endif Note: Phys_offset =0x50000000, in the MMU kernel, Page_
OFFSET is 0xc0000000, with phys_offset in the kernel without MMU. (2) The principle of ioremap () is that the kernel creates a new Map page table based on the specified physical address, and the relationship between the physical address and the virtual address is set by these page tables. : This can be seen from the Ioremap function body.


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.