1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 15:35:08 +00:00

Kernel: Reorganize memory layout a bit

Move the kernel image to the 1 MB physical mark. This prevents it from
colliding with stuff like the VGA memory. This was causing us to end
up with the BIOS screen contents sneaking into kernel memory sometimes.

This patch also bumps the kmalloc heap size from 1 MB to 3 MB. It's not
the perfect permanent solution (obviously) but it should get the OOM
monkey off our backs for a while.
This commit is contained in:
Andreas Kling 2019-11-04 12:00:29 +01:00
parent ea4e02ed86
commit 19398cd7d5
4 changed files with 26 additions and 21 deletions

View file

@ -20,15 +20,13 @@ struct [[gnu::packed]] allocation_t
size_t nchunk; size_t nchunk;
}; };
#define BASE_PHYSICAL (4 * MB)
#define CHUNK_SIZE 8 #define CHUNK_SIZE 8
#define POOL_SIZE (1024 * 1024) #define POOL_SIZE (3 * MB)
#define ETERNAL_BASE_PHYSICAL (1 * MB) #define ETERNAL_BASE_PHYSICAL (2 * MB)
#define ETERNAL_RANGE_SIZE (2 * MB) #define ETERNAL_RANGE_SIZE (2 * MB)
#define BASE_PHYSICAL (3 * MB)
#define RANGE_SIZE (1 * MB)
static u8 alloc_map[POOL_SIZE / CHUNK_SIZE / 8]; static u8 alloc_map[POOL_SIZE / CHUNK_SIZE / 8];
volatile size_t sum_alloc = 0; volatile size_t sum_alloc = 0;

View file

@ -113,7 +113,7 @@ CXXFLAGS += -nostdlib -nostdinc -nostdinc++
CXXFLAGS += -I../Toolchain/Local/i686-pc-serenity/include/c++/8.3.0/ CXXFLAGS += -I../Toolchain/Local/i686-pc-serenity/include/c++/8.3.0/
CXXFLAGS += -I../Toolchain/Local/i686-pc-serenity/include/c++/8.3.0/i686-pc-serenity/ CXXFLAGS += -I../Toolchain/Local/i686-pc-serenity/include/c++/8.3.0/i686-pc-serenity/
DEFINES += -DKERNEL DEFINES += -DKERNEL
LDFLAGS += -Ttext 0x10000 -Wl,-T linker.ld -nostdlib LDFLAGS += -Ttext 0x100000 -Wl,-T linker.ld -nostdlib
all: $(KERNEL) kernel.map all: $(KERNEL) kernel.map

View file

@ -22,6 +22,7 @@ MemoryManager& MM
MemoryManager::MemoryManager() MemoryManager::MemoryManager()
{ {
// FIXME: Hard-coding these is stupid. Find a better way.
m_kernel_page_directory = PageDirectory::create_at_fixed_address(PhysicalAddress(0x4000)); m_kernel_page_directory = PageDirectory::create_at_fixed_address(PhysicalAddress(0x4000));
m_page_table_zero = (PageTableEntry*)0x6000; m_page_table_zero = (PageTableEntry*)0x6000;
m_page_table_one = (PageTableEntry*)0x7000; m_page_table_one = (PageTableEntry*)0x7000;
@ -61,25 +62,31 @@ void MemoryManager::initialize_paging()
map_protected(VirtualAddress(0), PAGE_SIZE); map_protected(VirtualAddress(0), PAGE_SIZE);
#ifdef MM_DEBUG #ifdef MM_DEBUG
dbgprintf("MM: Identity map bottom 5MB\n"); dbgprintf("MM: Identity map bottom 8MB\n");
#endif #endif
// The bottom 5 MB (except for the null page) are identity mapped & supervisor only. // The bottom 8 MB (except for the null page) are identity mapped & supervisor only.
// Every process shares these mappings. // Every process shares these mappings.
create_identity_mapping(kernel_page_directory(), VirtualAddress(PAGE_SIZE), (5 * MB) - PAGE_SIZE); create_identity_mapping(kernel_page_directory(), VirtualAddress(PAGE_SIZE), (8 * MB) - PAGE_SIZE);
// Basic memory map: // FIXME: We should move everything kernel-related above the 0xc0000000 virtual mark.
// 0 -> 512 kB Kernel code. Root page directory & PDE 0.
// (last page before 1MB) Used by quickmap_page(). // Basic physical memory map:
// 1 MB -> 3 MB kmalloc_eternal() space. // 0 -> 1 MB We're just leaving this alone for now.
// 3 MB -> 4 MB kmalloc() space. // 1 -> 3 MB Kernel image.
// 4 MB -> 5 MB Supervisor physical pages (available for allocation!) // (last page before 2MB) Used by quickmap_page().
// 5 MB -> 0xc0000000 Userspace physical pages (available for allocation!) // 2 MB -> 4 MB kmalloc_eternal() space.
// 0xc0000000-0xffffffff Kernel-only virtual address space // 4 MB -> 7 MB kmalloc() space.
// 7 MB -> 8 MB Supervisor physical pages (available for allocation!)
// 8 MB -> MAX Userspace physical pages (available for allocation!)
// Basic virtual memory map:
// 0 MB -> 8MB Identity mapped.
// 0xc0000000-0xffffffff Kernel-only virtual address space.
#ifdef MM_DEBUG #ifdef MM_DEBUG
dbgprintf("MM: Quickmap will use %p\n", m_quickmap_addr.get()); dbgprintf("MM: Quickmap will use %p\n", m_quickmap_addr.get());
#endif #endif
m_quickmap_addr = VirtualAddress((1 * MB) - PAGE_SIZE); m_quickmap_addr = VirtualAddress((2 * MB) - PAGE_SIZE);
RefPtr<PhysicalRegion> region; RefPtr<PhysicalRegion> region;
bool region_is_super = false; bool region_is_super = false;
@ -126,9 +133,9 @@ void MemoryManager::initialize_paging()
for (size_t page_base = mmap->addr; page_base < (mmap->addr + mmap->len); page_base += PAGE_SIZE) { for (size_t page_base = mmap->addr; page_base < (mmap->addr + mmap->len); page_base += PAGE_SIZE) {
auto addr = PhysicalAddress(page_base); auto addr = PhysicalAddress(page_base);
if (page_base < 4 * MB) { if (page_base < 7 * MB) {
// nothing // nothing
} else if (page_base >= 4 * MB && page_base < 5 * MB) { } else if (page_base >= 7 * MB && page_base < 8 * MB) {
if (region.is_null() || !region_is_super || region->upper().offset(PAGE_SIZE) != addr) { if (region.is_null() || !region_is_super || region->upper().offset(PAGE_SIZE) != addr) {
m_super_physical_regions.append(PhysicalRegion::create(addr, addr)); m_super_physical_regions.append(PhysicalRegion::create(addr, addr));
region = m_super_physical_regions.last(); region = m_super_physical_regions.last();

View file

@ -2,7 +2,7 @@ ENTRY(start)
SECTIONS SECTIONS
{ {
. = 0x10000; . = 0x100000;
.text BLOCK(4K) : ALIGN(4K) .text BLOCK(4K) : ALIGN(4K)
{ {