summaryrefslogtreecommitdiff
path: root/Kernel/Memory
AgeCommit message (Collapse)Author
2022-03-17Kernel: Use default constructors/destructorsLenny Maiorani
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules "The compiler is more likely to get the default semantics right and you cannot implement these functions better than the compiler."
2022-02-14Kernel: Make Inode::set_shared_vmobject() OOM-fallibleIdan Horowitz
Allocating a WeakPtr can fail, so this let's us properly propagate said failure.
2022-02-11Kernel: Stop trying to write unmapped Process regions into CoreDumpsIdan Horowitz
If we crashed in the middle of mapping in Regions, some of the regions may not have a page directory yet, and will result in a crash when Region::remap() is called.
2022-02-11Kernel: Set up Regions before adding them to a Process's AddressSpaceIdan Horowitz
This reduces the amount of time in which not fully-initialized Regions are present inside an AddressSpace's region tree.
2022-02-11Kernel: Make SharedInodeVMObject pages Bitmap allocation OOM-fallibleIdan Horowitz
2022-02-11Kernel: Make AnonymousVMObject COW-Bitmap allocation OOM-fallibleIdan Horowitz
2022-02-11AK: Make Bitmap construction OOM-fallibleIdan Horowitz
2022-02-11Kernel: Make contiguous VM objects use "user physical pages" by defaultAndreas Kling
If someone specifically wants contiguous memory in the low-physical- address-for-DMA range ("super pages"), they can use the allocate_dma_buffer_pages() helper.
2022-02-09Kernel: Change static constexpr variables to constexpr where possibleLenny Maiorani
Function-local `static constexpr` variables can be `constexpr`. This can reduce memory consumption, binary size, and offer additional compiler optimizations. These changes result in a stripped x86_64 kernel binary size reduction of 592 bytes.
2022-02-03Kernel: Stop using the make<T> factory method in the KernelIdan Horowitz
As make<T> is infallible, it really should not be used anywhere in the Kernel. Instead replace with fallible `new (nothrow)` calls, that will eventually be error-propagated.
2022-02-02Revert "Kernel: Only update page tables for faulting region"Andreas Kling
This reverts commit 1c5ffaae41be4e67f81b46c3bfdce7f54a1dc8e0. This broke shared memory as used by OutOfProcessWebView. Let's do a revert until we can figure out what went wrong.
2022-02-02Kernel: Only update page tables for faulting regionAndreas Kling
When a page fault led to the mapping of a new physical page, we were updating the page tables for *every* region that shared the same underlying VMObject. Let's just not do that, avoiding a bunch of unnecessary page table updates and TLB invalidations.
2022-01-30Kernel: Release page directory and MM locks sooner in space finalizationAndreas Kling
We don't need to hold these locks when tearing down the region tree. Release them as soon as unmapping is finished.
2022-01-30Kernel: Remove unnecessary includes from Thread.hAndreas Kling
...and deal with the fallout by adding missing includes everywhere.
2022-01-29Everywhere: Remove redundant inline keywordLenny Maiorani
`constexpr` implies `inline` so when both are used it is redundant.
2022-01-28Kernel: Move kernel region checks from x86 page fault handler to MMAndreas Kling
Ideally the x86 fault handler would only do x86 specific things and delegate the rest of the work to MemoryManager. This patch moves some of the address checks to a more generic place.
2022-01-28Kernel: Quickly reject userspace addresses in kernel_region_from_vaddr()Andreas Kling
This avoids taking and releasing the MM lock just to reject an address that we can tell from just looking at it that it won't ever be in the kernel regions tree.
2022-01-28Kernel: Convert MemoryManager::allocate_user_physical_page to ErrorOrIdan Horowitz
This allows is to use the TRY macro at the call sites, instead of using clunky null checks.
2022-01-28Kernel: Make allocate_supervisor_physical_page OOM-fallibleIdan Horowitz
2022-01-28Kernel: Make allocate_contiguous_supervisor_physical_pages OOM-fallibleIdan Horowitz
2022-01-28Kernel: Use memset instead of fast_u32_fill in MemoryManager zero fillsIdan Horowitz
When the values we're setting are not actually u32s and the size of the area we're setting is PAGE_SIZE-aligned and a multiple of PAGE_SIZE in size, there's no point in using fast_u32_fill, as that forces us to use STOSDs instead of STOSQs.
2022-01-26Kernel: Make VirtualRangeAllocator::carve_from_region OOM-fallibleIdan Horowitz
2022-01-26Kernel: Implement Page Attribute Table (PAT) support and Write-CombineTom
This allows us to enable Write-Combine on e.g. framebuffers, significantly improving performance on bare metal. To keep things simple we right now only use one of up to three bits (bit 7 in the PTE), which maps to the PA4 entry in the PAT MSR, which we set to the Write-Combine mode on each CPU at boot time.
2022-01-26Kernel: Make AddressSpace::find_regions_intersecting OOM-fallibleIdan Horowitz
2022-01-26Kernel: Make AddressSpace::amount_clean_inode() OOM-fallibleIdan Horowitz
2022-01-23Kernel: Add missing #include <AK/Badge.h> to MemoryManager.hMarco Cutecchia
This missing header broke the aarch64 build
2022-01-21Kernel: Make Memory::RingBuffer construction fallibleIdan Horowitz
2022-01-16Kernel: Use an IntrusiveRedBlackTree for kernel regionsAndreas Kling
We were already using a non-intrusive RedBlackTree, and since the kernel regions tree is non-owning, this is a trivial conversion that makes a bunch of the tree operations infallible (by being allocation-free.) :^)
2022-01-16Kernel: Don't access directory table of uninitialized PageDirectorycreator1creeper1
PageDirectory gets initialized step-by-step in PageDirectory::try_create_for_userspace(). This initialization may fail anywhere in this function - for example, we may not be able to allocate a directory table, in which case PageDirectory::try_create_for_userspace() will return a null pointer. We recognize this condition and early-return ENOMEM. However, at this point, we need to correctly destruct the only partially initialized PageDirectory. Previously, PageDirectory::~PageDirectory() would assume that the object it was destructing was always fully initialized. It now uses the new helper PageDirectory::is_cr3_initialized() to correctly recognize when the directory table was not yet initialized. This helper checks if the pointer to the directory table is null. Only if it is not null does the destructor try to fetch the directory table using PageDirectory::cr3().
2022-01-15Kernel: Remove infallible VMObject resource factory functionscreator1creeper1
These infallible resource factory functions were only there to ease the conversion to the new factory functions. Since all child classes of VMObject now use the fallible resource factory functions, we don't need the infallible versions anymore.
2022-01-15Kernel: Make SharedInodeVMObject construction OOM-awarecreator1creeper1
This commit moves the allocation of the resources required for SharedInodeVMObject from its constructors to its factory functions. We're making this change to expose the fallibility of the allocation.
2022-01-15Kernel: Make PrivateInodeVMObject construction OOM-awarecreator1creeper1
This commit moves the allocation of the resources required for PrivateInodeVMObject from its constructors to its factory functions. We're making this change to expose the fallibility of the allocation.
2022-01-15Kernel: Make InodeVMOBject construction OOM-awarecreator1creeper1
This commit moves the allocation of the resources required for InodeVMObject from its constructors to the constructors of its child classes. We're making this change to give the child classes the chance to expose the fallibility of the allocation.
2022-01-15Kernel: Make AnonymousVMObject construction OOM-awarecreator1creeper1
This commit moves the allocation of the resources required for AnonymousVMObject from its constructors to its factory functions. We're making this change to expose the fallibility of the allocation.
2022-01-15Kernel: Make VMOBject construction OOM-awarecreator1creeper1
This commit moves the allocation of the resources required for VMObject from its constructors to the constructors of its child classes. We're making this change to give the child classes the chance to expose the fallibility of the allocation.
2022-01-15Kernel: Don't remap already non-writable regions when they become CoWAndreas Kling
The only purpose of the remap() in Region::try_clone() is to ensure non-writable page table entries for CoW regions. If a region is already non-writable, there's no need to waste time updating the page tables.
2022-01-15Kernel: Don't bother with page tables for PROT_NONE mappingsAndreas Kling
When mapping or unmapping completely inaccessible memory regions, we don't need to update the page tables at all. This saves a bunch of time in some situations, most notably during dynamic linking, where we make a large VM reservation and immediately throw it away. :^)
2022-01-15Kernel: Use move() in Region::try_clone() to avoid a VMObject::unref()Andreas Kling
2022-01-15Kernel: Only register kernel regions with MemoryManagerAndreas Kling
We were already only tracking kernel regions, this patch just makes it more clear by having it reflected in the name of the registration helpers. We also stop calling them for userspace regions, avoiding some spinlock action in such cases.
2022-01-15Kernel: Remove old "region lookup cache" optimizationAndreas Kling
This optimization was added when region lookup was O(n), before we had the O(log n) RedBlackTree. Let's remove it to simplify the code, as we have no evidence that it remains valuable.
2022-01-15Kernel: Always remove PageDirectories from the cr3 map on destructionIdan Horowitz
Previously we would only remove them from the map if they were attached to an AddressSpace, even though we would always add them to the map on construction. This results in an assertion failure on destruction if the page directory was never attached to an AddressSpace. (for example, on an allocation failure of said AddressSpace)
2022-01-13Kernel: Make map_typed() & map_typed_writable() fallible using ErrorOrIdan Horowitz
This mostly just moved the problem, as a lot of the callers are not capable of propagating the errors themselves, but it's a step in the right direction.
2022-01-13Kernel: Don't flush TLB after creating brand-new mappingsAndreas Kling
The CPU will not cache TLB entries for non-present mappings, so we can simply skip flushing the TLB after creating entirely new mappings.
2022-01-13Kernel: Use StringView instead of String in RingBuffer's constructorIdan Horowitz
This String was being copied into a KString internally anyways.
2022-01-12Kernel: Actually clear page slots in Region::clear_to_zero()Andreas Kling
We were copying the RefPtr<PhysicalPage> and zeroing the copy instead of zeroing the slot itself.
2022-01-12Kernel: Don't release/relock spinlocks repeatedly during space teardownAndreas Kling
Grab the page directory and MM locks once at the start of address space teardown, then hold onto them across all the region unmapping work.
2022-01-12Kernel: Do less unnecessary work when tearing down process address spaceAndreas Kling
When deleting an entire AddressSpace, we don't need to do TLB flushes at all (since the entire page directory is going away anyway). We also don't need to deallocate VM ranges one by one, since the entire VM range allocator will be deleted anyway.
2022-01-10Kernel: Remove redundant hash map of page tables in PageDirectoryAndreas Kling
The purpose of the PageDirectory::m_page_tables map was really just to act as ref-counting storage for PhysicalPage objects that were being used for the directory's page tables. However, this was basically redundant, since we can find the physical address of each page table from the page directory, and we can find the PhysicalPage object from MemoryManager::get_physical_page_entry(). So if we just manually ref() and unref() the pages when they go in and out of the directory, we no longer need PageDirectory::m_page_tables! Not only does this remove a bunch of kmalloc() traffic, it also solves a race condition that would occur when lazily adding a new page table to a directory: Previously, when MemoryManager::ensure_pte() would call HashMap::set() to insert the new page table into m_page_tables, if the HashMap had to grow its internal storage, it would call kmalloc(). If that kmalloc() would need to perform heap expansion, it would end up calling ensure_pte() again, which would clobber the page directory mapping used by the outer invocation of ensure_pte(). The net result of the above bug would be that any invocation of MemoryManager::ensure_pte() could erroneously return a pointer into a kernel page table instead of the correct one! This whole problem goes away when we remove the HashMap, as ensure_pte() no longer does anything that allocates from the heap.
2022-01-10Kernel: Don't relock MM lock for every page when remapping regionAndreas Kling
Make sure that callers already hold the MM lock, and we don't have to worry about reacquiring it every time.
2022-01-09Kernel: Add implied auto qualifiers in MemoryHendiadyoin1