增加内存页计数

This commit is contained in:
pointer-to-bios 2024-02-18 02:29:40 +08:00
parent 197c50ff5d
commit 073e50029a
3 changed files with 28 additions and 10 deletions

View File

@ -110,7 +110,6 @@ bool memm_map_pageframes_to(
return false;
while (size != 0)
{
// 这是当前需要映射的页的内存对齐(或者说是当前映射的页的大小)
memm_page_size align = memm_get_page_align(physical);
if (align == MEMM_PAGE_SIZE_1G)
{
@ -123,6 +122,20 @@ bool memm_map_pageframes_to(
align = MEMM_4K_ALIGN_MASK + 1;
}
align /= MEMM_PAGE_SIZE;
memory_manager_t *mm = memm_get_manager();
switch (align)
{
case MEMM_PAGE_SIZE_4K:
mm->mapped_4k_page++;
case MEMM_PAGE_SIZE_2M:
mm->mapped_2m_page++;
case MEMM_PAGE_SIZE_1G:
mm->mapped_1g_page++;
}
for (usize i = physical / MEMM_PAGE_SIZE; i < physical / MEMM_PAGE_SIZE + align; i++)
{
bitmap_set(mm->page_map, i);
}
map_pageframe_to(target, physical, user, write, align);

View File

@ -35,7 +35,7 @@ void kmain(void *mb2_bootinfo)
}
// 初始化内存管理模块
mem_manager_t *memm = memm_new(mem_size);
memory_manager_t *memm = memm_new(mem_size);
// 初始化tty模块
tty_controller_t *tty_controler = tty_controller_new();

View File

@ -5,9 +5,9 @@
#include <libk/string.h>
#include <libk/bits.h>
mem_manager_t memory_manager;
memory_manager_t memory_manager;
mem_manager_t *memm_new(usize mem_size)
memory_manager_t *memm_new(usize mem_size)
{
memset(&memory_manager, 0, sizeof(memory_manager));
memory_manager.memory_size = mem_size;
@ -47,20 +47,20 @@ mem_manager_t *memm_new(usize mem_size)
}
// 配置分配器页地图
memory_manager.map_with_allocator =
memory_manager.allocator_map =
allocator0->allocate(&allocator0->allocator_instance, pmc_size);
memset(memory_manager.map_with_allocator, 0, pmc_size);
memset(memory_manager.allocator_map, 0, pmc_size);
for (usize i = kernel_initial_size / MEMM_PAGE_SIZE;
i < MEMM_ALLOC_ONLY_MEMORY / MEMM_PAGE_SIZE;
i += MEMM_PAGE_SIZE)
{
bitmap_set(memory_manager.map_with_allocator, i);
bitmap_set(memory_manager.allocator_map, i);
}
// 分配器释放页地图
memory_manager.map_with_destructed_allocator =
memory_manager.destructed_allocator_map =
allocator0->allocate(&allocator0->allocator_instance, pmc_size);
memset(memory_manager.map_with_destructed_allocator, 0, pmc_size);
memset(memory_manager.destructed_allocator_map, 0, pmc_size);
// 配置空闲页线段搜索表
memory_manager.available_pages_table = lst_new(0, memory_manager.page_amount);
@ -69,6 +69,11 @@ mem_manager_t *memm_new(usize mem_size)
return &memory_manager;
}
memory_manager_t *memm_get_manager()
{
return &memory_manager;
}
allocator_t *memm_allocator_new(void *start, usize length, usize type, usize pid)
{
allocator_t *allocator = start;
@ -177,7 +182,7 @@ void *memm_allocate(usize size, usize pid)
return nullptr; // 内存中已经没有可分配的页了
for (usize i = allocator_start; i < allocator_start + size; i++)
{
bitmap_set(memory_manager.map_with_allocator, i);
bitmap_set(memory_manager.allocator_map, i);
}
memm_map_pageframes_to(
allocator_start * MEMM_PAGE_SIZE, allocator_start * MEMM_PAGE_SIZE,