This repository has been archived by the owner on Sep 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from memN0ps/dev
Optimize Stack and Memory Management
- Loading branch information
Showing
7 changed files
with
66 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,15 @@ | ||
/// The default number of logical processors for a high-end desktop system. | ||
/// | ||
/// This value is set to 1 for testing purposes but can be adjusted up to 64 or more based on the system. | ||
/// Adjusting this value will increase the total heap size accordingly. | ||
const DEFAULT_LOGICAL_PROCESSORS: usize = 16; | ||
|
||
/// The number of pages for the stack per processor/core. | ||
/// | ||
/// Each processor/core gets its own stack. The default stack size per processor is calculated as: | ||
/// STACK_PAGES_PER_PROCESSOR * BASE_PAGE_SIZE (4096 bytes per page) | ||
/// 0x4000 * 4096 = 67,108,864 bytes (64 MB) | ||
/// | ||
/// This stack size is allocated individually for each processor. | ||
pub const STACK_PAGES_PER_PROCESSOR: usize = 0x2000; | ||
|
||
/// The size of a page table in bytes. | ||
const PAGE_TABLE_SIZE: usize = 2 * 1024 * 1024; // 2 MB | ||
|
||
/// The total number of page tables needed per processor to split the stack. | ||
/// | ||
/// This is calculated as: | ||
/// STACK_SIZE / PAGE_TABLE_SIZE | ||
/// 64 MB / 2 MB = 32 page tables | ||
const PAGE_TABLES_PER_PROCESSOR: usize = 32; | ||
|
||
/// The padding added to the heap size for other allocations (e.g., vectors, boxes). | ||
/// | ||
/// This is an additional memory buffer to ensure there's enough space for other dynamic allocations. | ||
const HEAP_PADDING: usize = 8 * 1024 * 1024; // 8 MB | ||
|
||
/// The total size of the heap in bytes, shared among all processors. | ||
/// | ||
/// This base heap size is for 1 processor, calculated as: | ||
/// 32 * 2 * 1024 * 1024 + 8 * 1024 * 1024 = 72,237,568 bytes (68 MB) | ||
/// | ||
/// For 4 processors, the heap size would be: | ||
/// (32 * 2 * 1024 * 1024 * 4) + 8 * 1024 * 1024 = 288,957,440 bytes (276 MB) | ||
/// | ||
/// For 8 processors, the heap size would be: | ||
/// (32 * 2 * 1024 * 1024 * 8) + 8 * 1024 * 1024 = 577,874,944 bytes (552 MB) | ||
/// | ||
/// For 16 processors, the heap size would be: | ||
/// (32 * 2 * 1024 * 1024 * 16) + 8 * 1024 * 1024 = 1,155,685,888 bytes (1.08 GB) | ||
/// | ||
/// For 32 processors, the heap size would be: | ||
/// (32 * 2 * 1024 * 1024 * 32) + 8 * 1024 * 1024 = 2,311,371,776 bytes (2.16 GB) | ||
/// | ||
/// For 64 processors, the heap size would be: | ||
/// (32 * 2 * 1024 * 1024 * 64) + 8 * 1024 * 1024 = 4,622,743,552 bytes (4.32 GB) | ||
/// | ||
/// By adjusting the number of logical processors, the heap size will scale accordingly. | ||
pub const TOTAL_HEAP_SIZE: usize = (PAGE_TABLES_PER_PROCESSOR * PAGE_TABLE_SIZE * DEFAULT_LOGICAL_PROCESSORS) + HEAP_PADDING; | ||
use {crate::intel::vm::Vm, core::mem::size_of}; | ||
|
||
/// Number of stack pages per logical processor. | ||
/// Includes size of `Vm` in pages plus 0x1000 (4096) pages for padding. | ||
/// - Size of `Vm`: 1027 pages (0x403 pages). | ||
/// - Padding: 4096 pages (0x1000 pages). | ||
/// - Total: 1027 + 4096 pages = 5123 pages (0x1403 pages). | ||
/// - Total size in bytes: 5123 * 4096 = 20,971,520 bytes (20 MB). | ||
pub const STACK_PAGES_PER_PROCESSOR: usize = (size_of::<Vm>() / 0x1000) + 0x1000; | ||
|
||
/// Total heap size (64 MB) shared across all logical processors. | ||
/// - Total size in bytes: 64 * 1024 * 1024 = 67,108,864 bytes (64 MB). | ||
/// - Total size in hexadecimal: 0x4000000 bytes. | ||
/// Increase this value if additional heap memory is needed or if more hooks are required. | ||
pub const TOTAL_HEAP_SIZE: usize = 0x4000000; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters