mirror of
https://github.com/tailix/kernel.git
synced 2024-11-20 11:16:10 -05:00
Allocate and free big pages
This commit is contained in:
parent
b981271c64
commit
9dcd21f42e
2 changed files with 39 additions and 0 deletions
|
@ -45,6 +45,32 @@ unsigned long memory_alloc_page()
|
|||
return 0;
|
||||
}
|
||||
|
||||
unsigned long memory_alloc_big_page()
|
||||
{
|
||||
unsigned int start = 0;
|
||||
|
||||
for (unsigned int i = 0; i < FRAMES_COUNT; ++i) {
|
||||
if (frames[i]) {
|
||||
start = i + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (start % (PAGE_BIG_SIZE / PAGE_SIZE)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i - start + 1 == PAGE_BIG_SIZE / PAGE_SIZE) {
|
||||
for (unsigned int j = start; j <= i; ++j) {
|
||||
frames[j] = 0xFF;
|
||||
}
|
||||
|
||||
return start * PAGE_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void memory_free_page(const unsigned long addr)
|
||||
{
|
||||
const unsigned long i = addr / PAGE_SIZE;
|
||||
|
@ -56,6 +82,16 @@ void memory_free_page(const unsigned long addr)
|
|||
frames[i] = 0;
|
||||
}
|
||||
|
||||
void memory_free_big_page(const unsigned long addr)
|
||||
{
|
||||
const unsigned long start = addr / PAGE_SIZE;
|
||||
const unsigned long end = start + PAGE_BIG_SIZE / PAGE_SIZE;
|
||||
|
||||
for (unsigned int i = start; i <= end && i < FRAMES_COUNT; ++i) {
|
||||
frames[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void mark_used(const unsigned long base, const unsigned long limit)
|
||||
{
|
||||
const unsigned int start = base / PAGE_SIZE;
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
void memory_initialize(const struct KernelMQ_Info *kinfo);
|
||||
|
||||
unsigned long memory_alloc_page();
|
||||
unsigned long memory_alloc_big_page();
|
||||
|
||||
void memory_free_page(unsigned long addr);
|
||||
void memory_free_big_page(unsigned long addr);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue