diff options
author | Conrad Pankoff <deoxxa@fknsrs.biz> | 2019-06-11 21:13:02 +1000 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-06-12 15:38:17 +0200 |
commit | aee9317d86c9d8976d943a84dfd69a67da55a161 (patch) | |
tree | f1746f6771f059d23b331687e73292c71f040df3 /Kernel/VM/PhysicalRegion.h | |
parent | 1a77dfed236c988f03e0c93eef296f22e044e272 (diff) | |
download | serenity-aee9317d86c9d8976d943a84dfd69a67da55a161.zip |
Kernel: Refactor MemoryManager to use a Bitmap rather than a Vector
This significantly reduces the pressure on the kernel heap when
allocating a lot of pages.
Previously at about 250MB allocated, the free page list would outgrow
the kernel's heap. Given that there is no longer a page list, this does
not happen.
The next barrier will be the kernel memory used by the page records for
in-use memory. This kicks in at about 1GB.
Diffstat (limited to 'Kernel/VM/PhysicalRegion.h')
-rw-r--r-- | Kernel/VM/PhysicalRegion.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Kernel/VM/PhysicalRegion.h b/Kernel/VM/PhysicalRegion.h new file mode 100644 index 0000000000..d4f4fb1934 --- /dev/null +++ b/Kernel/VM/PhysicalRegion.h @@ -0,0 +1,39 @@ +#pragma once + +#include <AK/Bitmap.h> +#include <AK/Retainable.h> +#include <AK/Retained.h> +#include <Kernel/PhysicalAddress.h> +#include <Kernel/VM/PhysicalPage.h> + +class PhysicalRegion : public Retainable<PhysicalRegion> { + AK_MAKE_ETERNAL + +public: + static Retained<PhysicalRegion> create(PhysicalAddress lower, PhysicalAddress upper); + ~PhysicalRegion() {} + + void expand(PhysicalAddress lower, PhysicalAddress upper); + unsigned finalize_capacity(); + + PhysicalAddress lower() const { return m_lower; } + PhysicalAddress upper() const { return m_upper; } + unsigned size() const { return m_pages; } + unsigned used() const { return m_used; } + unsigned free() const { return m_pages - m_used; } + bool contains(PhysicalPage& page) const { return page.paddr() >= m_lower && page.paddr() <= m_upper; } + + RetainPtr<PhysicalPage> take_free_page(bool supervisor); + void return_page_at(PhysicalAddress addr); + void return_page(PhysicalPage& page) { return_page_at(page.paddr()); } + +private: + PhysicalRegion(PhysicalAddress lower, PhysicalAddress upper); + + PhysicalAddress m_lower; + PhysicalAddress m_upper; + unsigned m_pages { 0 }; + unsigned m_used { 0 }; + unsigned m_last { 0 }; + Bitmap m_bitmap; +}; |