mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
Kernel: Make contiguous VM objects use "user physical pages" by default
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.
This commit is contained in:
parent
5ff816abbf
commit
2ff9db0245
Notes:
sideshowbarker
2024-07-17 22:41:14 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/2ff9db0245
3 changed files with 24 additions and 1 deletions
|
@ -82,7 +82,7 @@ ErrorOr<NonnullRefPtr<AnonymousVMObject>> AnonymousVMObject::try_create_with_siz
|
|||
|
||||
ErrorOr<NonnullRefPtr<AnonymousVMObject>> AnonymousVMObject::try_create_physically_contiguous_with_size(size_t size)
|
||||
{
|
||||
auto contiguous_physical_pages = TRY(MM.allocate_contiguous_supervisor_physical_pages(size));
|
||||
auto contiguous_physical_pages = TRY(MM.allocate_contiguous_user_physical_pages(size));
|
||||
|
||||
auto new_physical_pages = TRY(FixedArray<RefPtr<PhysicalPage>>::try_create(contiguous_physical_pages.span()));
|
||||
|
||||
|
|
|
@ -954,6 +954,28 @@ ErrorOr<NonnullRefPtr<PhysicalPage>> MemoryManager::allocate_user_physical_page(
|
|||
return page.release_nonnull();
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtrVector<PhysicalPage>> MemoryManager::allocate_contiguous_user_physical_pages(size_t size)
|
||||
{
|
||||
VERIFY(!(size % PAGE_SIZE));
|
||||
SpinlockLocker lock(s_mm_lock);
|
||||
size_t page_count = ceil_div(size, static_cast<size_t>(PAGE_SIZE));
|
||||
|
||||
for (auto& physical_region : m_user_physical_regions) {
|
||||
auto physical_pages = physical_region.take_contiguous_free_pages(page_count);
|
||||
if (!physical_pages.is_empty()) {
|
||||
{
|
||||
auto cleanup_region = TRY(MM.allocate_kernel_region(physical_pages[0].paddr(), PAGE_SIZE * page_count, "MemoryManager Allocation Sanitization", Region::Access::Read | Region::Access::Write));
|
||||
memset(cleanup_region->vaddr().as_ptr(), 0, PAGE_SIZE * page_count);
|
||||
}
|
||||
m_system_memory_info.user_physical_pages_used += page_count;
|
||||
return physical_pages;
|
||||
}
|
||||
}
|
||||
|
||||
dmesgln("MM: no contiguous user physical pages available");
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtrVector<PhysicalPage>> MemoryManager::allocate_contiguous_supervisor_physical_pages(size_t size)
|
||||
{
|
||||
VERIFY(!(size % PAGE_SIZE));
|
||||
|
|
|
@ -174,6 +174,7 @@ public:
|
|||
ErrorOr<NonnullRefPtr<PhysicalPage>> allocate_user_physical_page(ShouldZeroFill = ShouldZeroFill::Yes, bool* did_purge = nullptr);
|
||||
ErrorOr<NonnullRefPtr<PhysicalPage>> allocate_supervisor_physical_page();
|
||||
ErrorOr<NonnullRefPtrVector<PhysicalPage>> allocate_contiguous_supervisor_physical_pages(size_t size);
|
||||
ErrorOr<NonnullRefPtrVector<PhysicalPage>> allocate_contiguous_user_physical_pages(size_t size);
|
||||
void deallocate_physical_page(PhysicalAddress);
|
||||
|
||||
ErrorOr<NonnullOwnPtr<Region>> allocate_contiguous_kernel_region(size_t, StringView name, Region::Access access, Region::Cacheable = Region::Cacheable::Yes);
|
||||
|
|
Loading…
Reference in a new issue