MMU and SMMU (Linux) notes

MMU:

1. Each process has a MMU page table--including user space entries and kernel space entries.

2. All processes share one global kernel MMU page table--init_mm, all kernel space entries are on it.

3. When a new process trap into kernel, page fault handler will copy global kernel MMU page table, kernel space entries, to process's MMU page table.

4.When page fault happens, kernel will update process's user space entries on it's page table or the kernel space entries on both its page table and init_mm. -- Need confirm by reading kernel code.

 

5. All page tables in the system for different EL(exception levels)

MMU and SMMU (Linux) notes_第1张图片

6. vmalloc() will 1)allocate continuous vitrual address 2)allocate seperate physical pages 3)mapping virtual address to physical pages in MMU page table. map_vm_area() is the step 3 function -- it will change the MMU page table.

MMU and SMMU (Linux) notes_第2张图片  

7. kmalloc() will allocate continuous virtual address which actually is continuous physical pages. And the mapping of virtual address to physical pages are fixed and already in the MMU page table as paging_init() -> kernel_physical_mapping_init() initialized them.

MMU and SMMU (Linux) notes_第3张图片

8. struct page presents the physical page. In kernel, zone->pages structure manages all the physical pages.  alloc_pages() or __get_free_pages() are all search free pages on this 'zone->pages' structure. 

MMU and SMMU (Linux) notes_第4张图片

To read zone information, we can "cat /proc/zoneinfo" .

MMU and SMMU (Linux) notes_第5张图片

Zone is initialized at zone_sizes_init().

9. HIGHMEM -- 32bits system

HIGHMEM is exist in 32bits system. As user space uses 3GB virtual address and kernel uses 1GB virtual address by default configuration, Kernel can't access the memory which is higher than 1GB address. For example, the hardware has 1.2GB memory, Kernel can't access higher 200MB memory as Kernel has only 1GB virtual address. So HIGHMEM was introduced to help Kernel to access these 200MB memory.

As HIGHMEM defined, Kernel just use about 900MB virtual address to fix mapping lower about 900MB physical memory. The about 100MB higher virtual address was dynamically mapping the left higher about 100MB+200MB physical memory. One task allocate it, use it then free it. Then next one can reuse the virtual address again.

So this could cause virtual address is continuous, but physical pages are seperate. Yes, vmalloc() is for HIGHMEM allocation.

In 64bits system, both user space and kernel has big enough virtual address, compared to current memory installed in the machine. So no HIGHMEM issue.

 

SMMU:

1. SMMU has different page table to MMU's page table. And SMMU use bus_address as virtual address. MMU use virtual_address as virtual address.

2. DMA API dma_alloc_coherent() can allocate physical page and map it to both MMU's page table by virtual_address@physical_address and SMMU's page table by bus_address@physical_address.

3. If you have a virtual_address and want to let master device(DMA) use, you need map the virtual_address to bus_address. This will add the entry on SMMU.

4. DMA-API-HOTO.txt on kernel/Documentations/ is a good doc to understand SMMU linux usage.

5. streamid, substream_id, VA is pair to master device, process, virtual_address.

6. SMMU driver is low level driver of DMA driver in Linux.

 

 

你可能感兴趣的:(linux)