|
AquilaOS documentation
How it works, and its code
|
Go to the source code of this file.
Macros | |
| #define | PAGE_ALIGN(ptr) |
| #define | PAGE_ROUND(ptr) |
| #define | PF_PRESENT 0x001 |
| #define | PF_READ 0x002 |
| #define | PF_WRITE 0x004 |
| #define | PF_EXEC 0x008 |
| #define | PF_USER 0x010 |
Functions | |
| void | mm_setup (struct boot *boot) |
| Sets up physical memory at boot, from the boot loader's memory map: the page structures, the buddy allocator, and what isn't free (the kernel, the modules, the reserved regions, page 0). | |
| struct vm_page * | mm_page_alloc (void) |
| Allocates a free page of physical memory. | |
| void | mm_page_incref (paddr_t paddr) |
| Adds a reference to a page of RAM. | |
| void | mm_page_decref (paddr_t paddr) |
| Drops a reference to a page of RAM. | |
| size_t | mm_page_ref (paddr_t paddr) |
| Returns how many references a page of RAM has. | |
| void | mm_page_dealloc (paddr_t paddr) |
| Frees a page of physical memory, back to the zone it came from. | |
| int | mm_page_map (struct pmap *pmap, vaddr_t vaddr, paddr_t paddr, int flags) |
| Maps a page into an address space. | |
| int | mm_map (struct pmap *pmap, paddr_t paddr, vaddr_t vaddr, size_t size, int flags) |
| Maps a range of an address space, page by page. | |
| void | mm_unmap_full (struct pmap *pmap, vaddr_t vaddr, size_t size) |
| Unmaps every page of a range of an address space. | |
| int | mm_page_fault (vaddr_t vaddr, int flags) |
| Handles a page fault in the current process's address space. | |
| #define PAGE_ALIGN | ( | ptr | ) |
Definition at line 9 of file mm.h.
Referenced by acpi_map(), binfmt_elf_load_segments(), mm_map(), mm_page_fault(), mm_unmap_full(), phys_window_map(), prefault(), slab_free(), vm_space_find(), vnode_page_in(), vnode_pages_update(), window_map(), and window_map().
| #define PAGE_ROUND | ( | ptr | ) |
Definition at line 10 of file mm.h.
Referenced by acpi_map(), binfmt_elf_load_segments(), binfmt_fmt_load(), boot_mem_place(), fbdev_vesa_map(), kvmem_alloc(), kvmem_guardtest(), kvmem_selftest_run(), mm_map(), mm_setup(), mm_unmap_full(), phys_window_map(), sys_mmap(), sys_munmap(), sys_sbrk(), window_map(), and window_map().
| #define PF_EXEC 0x008 |
Definition at line 19 of file mm.h.
Referenced by abort(), arch_mm_page_fault(), and check_violation().
| #define PF_PRESENT 0x001 |
Definition at line 16 of file mm.h.
Referenced by abort(), arch_mm_page_fault(), and mm_page_fault().
| #define PF_READ 0x002 |
Definition at line 17 of file mm.h.
Referenced by abort(), arch_mm_page_fault(), and check_violation().
| #define PF_USER 0x010 |
Definition at line 20 of file mm.h.
Referenced by abort(), and arch_mm_page_fault().
| #define PF_WRITE 0x004 |
Definition at line 18 of file mm.h.
Referenced by abort(), arch_mm_page_fault(), check_violation(), and pf_anon().
Maps a range of an address space, page by page.
Pages that are mapped already are left as they are.
| pmap | the address space's page tables |
| paddr | the physical address to map, or 0 to map new pages of memory |
| vaddr | the virtual address |
| size | the size of the range, in bytes (rounded to whole pages) |
| flags | the mappings' permissions (VM_*) |
Definition at line 161 of file mm.c.
References arch_page_get_mapping(), mm_map(), mm_page_alloc(), mm_page_dealloc(), mm_page_map(), vm_page::paddr, PAGE_ALIGN, PAGE_ROUND, and PAGE_SIZE.
| struct vm_page * mm_page_alloc | ( | void | ) |
Allocates a free page of physical memory.
Running out of memory is an error that the caller handles like any other, not a panic: a process's page fault kills it, a system call returns ENOMEM, a network frame is dropped. Only what the kernel can't boot without panics.
Definition at line 78 of file mm.c.
References buddy_alloc(), BUDDY_ZONE_DMA, BUDDY_ZONE_NORMAL, memset(), mm_page_alloc(), NULL, vm_page::paddr, PAGE, and PAGE_SIZE.
Referenced by kvmem_alloc(), mm_map(), mm_page_alloc(), netbuf_alloc(), page_get(), pf_anon(), pf_object(), pf_present(), pf_zero(), sigcode_in(), slab_page_alloc(), table_alloc(), table_alloc(), table_alloc(), and vnode_page_in().
| void mm_page_dealloc | ( | paddr_t | paddr | ) |
Frees a page of physical memory, back to the zone it came from.
| paddr | the page's physical address |
Definition at line 103 of file mm.c.
References buddy_free(), BUDDY_ZONE_DMA, BUDDY_ZONE_NORMAL, buddy_zone_offset, mm_page_dealloc(), vm_page::paddr, and PAGE_SIZE.
Referenced by kvmem_alloc(), kvmem_unmap(), mm_map(), mm_page_dealloc(), netbuf_alloc(), netbuf_free(), pf_object(), pf_zero(), sigcode_in(), slab_page_alloc(), slab_page_free(), table_free(), table_free(), table_free(), vm_anon_destroy(), vnode_page_in(), and vnode_pages_free().
| void mm_page_decref | ( | paddr_t | paddr | ) |
Drops a reference to a page of RAM.
A page past RAM is left alone.
| paddr | the page's physical address |
Definition at line 50 of file mm.c.
References mm_page_decref(), vm_page::paddr, PAGE, and TRACKED.
Referenced by mm_page_decref(), netbuf_free(), pf_present(), pmap_remove_all(), tables_free(), and tables_free().
| int mm_page_fault | ( | vaddr_t | vaddr, |
| int | flags ) |
Handles a page fault in the current process's address space.
The architecture calls it from its page fault handler.
If the address isn't mapped, or the mapping doesn't allow the access, the fault can't be resolved, and the architecture decides what follows: a SIGSEGV, a failed copy (EFAULT) for a system call, or a panic for the kernel's own access. If there's no memory to resolve it, the process is also killed (SIGKILL): it couldn't go on.
| vaddr | the address that faulted |
| flags | the kind of access (PF_READ, PF_WRITE, PF_EXEC, and PF_PRESENT if a page was mapped there) |
Definition at line 395 of file fault.c.
References pf::addr, vm_entry::base, check_violation(), curproc, curthread, pf::flags, vm_entry::flags, pf::hash, mm_page_fault(), NULL, pf::off, vm_entry::off, PAGE_ALIGN, pf_anon(), pf_object(), PF_PRESENT, pf_present(), pf_zero(), vm_space::pmap, printk(), signal_proc_send(), vm_entry::vm_anon, vm_entry::vm_object, and vm_space_find().
Referenced by abort(), arch_mm_page_fault(), and mm_page_fault().
| void mm_page_incref | ( | paddr_t | paddr | ) |
Adds a reference to a page of RAM.
A page past RAM (device memory, such as a framebuffer) has no reference count, and is left alone.
| paddr | the page's physical address |
Definition at line 39 of file mm.c.
References mm_page_incref(), vm_page::paddr, PAGE, and TRACKED.
Referenced by mm_page_incref(), netbuf_alloc(), pf_anon(), and pf_object().
Maps a page into an address space.
The page's references are the vm objects' that hold it, not the mappings', so this doesn't add one.
| pmap | the address space's page tables |
| vaddr | the virtual address, page-aligned |
| paddr | the page's physical address, page-aligned |
| flags | the mapping's permissions (VM_*) |
Definition at line 122 of file mm.c.
References mm_page_map(), vm_page::paddr, and pmap_add().
Referenced by mm_map(), mm_page_map(), pf_anon(), pf_object(), pf_present(), and pf_zero().
Returns how many references a page of RAM has.
| paddr | the page's physical address |
Definition at line 62 of file mm.c.
References mm_page_ref(), vm_page::paddr, PAGE, and TRACKED.
Referenced by mm_page_ref(), and netbuf_free().
| void mm_setup | ( | struct boot * | boot | ) |
Sets up physical memory at boot, from the boot loader's memory map: the page structures, the buddy allocator, and what isn't free (the kernel, the modules, the reserved regions, page 0).
Then the architecture sets up its page tables (arch_mm_setup()).
| boot | what the boot loader passed (see boot/boot.h) |
Definition at line 365 of file mm.c.
References arch_mm_setup(), boot_mem_next, boot_mem_place(), boot_mem_start, BUDDY_MAX_BS, buddy_set_unusable(), buddy_setup(), mmap_t::end, k_total_mem, MAX, MIN, mm_boot_alloc(), mm_mark_unusable(), mm_setup(), boot::mmap, boot::mmap_count, MMAP_USABLE, boot::modules, boot::modules_count, module_t::paddr, PAGE_ROUND, PAGE_SIZE, pages, pages_nr, printk(), ram_end(), module_t::size, mmap_t::start, boot::total_mem, and mmap_t::type.
Referenced by aarch64_init(), mm_setup(), and x86_cpu_init().
Unmaps every page of a range of an address space.
| pmap | the address space's page tables |
| vaddr | the range's start |
| size | its size, in bytes (rounded to whole pages) |
Definition at line 208 of file mm.c.
References mm_page_unmap(), mm_unmap_full(), PAGE_ALIGN, PAGE_ROUND, and PAGE_SIZE.
Referenced by mm_unmap_full(), and vm_unmap_full().