Working on allocator
This commit is contained in:
parent
6a498c2d08
commit
ded1e99fb9
|
@ -33,7 +33,7 @@
|
|||
|
||||
#define KPAGESIZE (4 * KB)
|
||||
#define UPAGESIZE (4 * KB)
|
||||
#define USERSPACE 0x100000000
|
||||
#define USERSPACE 0x200000000
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
|
|
|
@ -201,6 +201,10 @@ void MmInitPaging(void)
|
|||
MmPT[index] = (ulong)curAddrPT | PRESENT | READWRITE;
|
||||
MmPhysicalPageTable[xedni] = (ulong)curAddrPT;
|
||||
}
|
||||
else {
|
||||
MmPT[index] = (ulong)0;
|
||||
MmPhysicalPageTable[xedni] = (ulong)0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -292,7 +296,12 @@ void MmMapPage(void* virtualAddr, void* physicalAddr, ulong flags)
|
|||
{
|
||||
pte_t *page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
||||
|
||||
*page = ((ulong)physicalAddr & ~((KPAGESIZE - 1) | NX)) | flags;
|
||||
DebugLog("Request %p:%p with %lu\n", virtualAddr, physicalAddr, flags);
|
||||
DebugLog("Page (at %p) %p : was %p\n", &page, page, *page);
|
||||
|
||||
*page = (ulong)physicalAddr | flags;
|
||||
|
||||
DebugLog("Page (at %p) %p : is %p\n", &page, page, *page);
|
||||
|
||||
MmPhysicalPageTable[(ulong)physicalAddr
|
||||
/ ((ulong)KPAGESIZE)
|
||||
|
|
|
@ -158,7 +158,7 @@ ulong MmAllocPageFrameEx(void ***frameListPtr, size_t *pageNumber, size_t size,
|
|||
ulong phRamSize = memoryMap.freeRamSize + memoryMap.nonfreeRamSize;
|
||||
|
||||
//DebugLog("Allocating %d pages...\n", *pageNumber);
|
||||
|
||||
if (contiguous) {
|
||||
for (void *curPage = (void*)(MmPhysLastKernAddress + KPAGESIZE); curPage < (void*)phRamSize; curPage += KPAGESIZE) {
|
||||
if (!isPageBusy(curPage)) {
|
||||
(*frameListPtr)[curNumber] = curPage;
|
||||
|
@ -174,6 +174,17 @@ ulong MmAllocPageFrameEx(void ***frameListPtr, size_t *pageNumber, size_t size,
|
|||
if (!inBlock)
|
||||
curNumber = 0;
|
||||
}
|
||||
} else {
|
||||
for (void *curPage = (void*)(MmPhysLastKernAddress + KPAGESIZE); curPage < (void*)phRamSize; curPage += KPAGESIZE) {
|
||||
if (!isPageBusy(curPage)) {
|
||||
(*frameListPtr)[curNumber] = curPage;
|
||||
//DebugLog("Select page : %p\n", curPage);
|
||||
if (++curNumber >= *pageNumber) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (curNumber != *pageNumber) {
|
||||
KeStartPanic("MmAllocPageFrameEx() : No more free pages to allocate");
|
||||
|
@ -236,8 +247,8 @@ error_t MmMapPageFrame(ulong id, void *virtAddr, ulong flags)
|
|||
}
|
||||
|
||||
if (id == busyPage->id) {
|
||||
DebugLog("Map %p at %p\n", busyPage->phyAddress, virtAddr + offset);
|
||||
MmMapPage((void*)((ulong)virtAddr + offset), busyPage->phyAddress, flags);
|
||||
//DebugLog("Map %p at %p\n", busyPage->phyAddress, virtAddr + offset);
|
||||
offset += KPAGESIZE;
|
||||
}
|
||||
}
|
||||
|
@ -285,18 +296,39 @@ error_t MmTestBusyPage(void)
|
|||
/* } */
|
||||
|
||||
ulong a = KeGetTicks();
|
||||
tab[j++] = MmAllocPageFrame(50*MB, NORMAL);
|
||||
tab[j++] = MmAllocPageFrame(50*MB, NORMAL);
|
||||
tab[j++] = MmAllocPageFrame(50*MB, NORMAL);
|
||||
tab[j++] = MmAllocPageFrame(50*MB, NORMAL);
|
||||
tab[j++] = MmAllocPageFrame(50*MB, NORMAL);
|
||||
DebugLog("Start alloc : %lu s\n", a/1000);
|
||||
tab[j++] = MmAllocPageFrame(30*MB, NORMAL);
|
||||
ulong b = KeGetTicks();
|
||||
|
||||
DebugLog("Alloc time per MB : %lu\n", (b-a)/5/5);
|
||||
|
||||
//printBusyPages();
|
||||
DebugLog("End alloc : %lu s\n", b/1000);
|
||||
DebugLog("Alloc time : %lu s\n", (b-a)/1000);
|
||||
DebugLog("Alloc : %d; Free : %d; Count : %lu Mo\n", NSuccessfulAlloc, NSuccessfulFree, MmBusyPagesSpace() / MB);
|
||||
|
||||
a = KeGetTicks();
|
||||
DebugLog("Start alloc : %lu s\n", a/1000);
|
||||
tab[j++] = MmAllocPageFrame(20*MB, NORMAL);
|
||||
b = KeGetTicks();
|
||||
DebugLog("End alloc : %lu s\n", b/1000);
|
||||
DebugLog("Alloc time : %lu s\n", (b-a)/1000);
|
||||
DebugLog("Alloc : %d; Free : %d; Count : %lu Mo\n", NSuccessfulAlloc, NSuccessfulFree, MmBusyPagesSpace() / MB);
|
||||
|
||||
j = 0;
|
||||
|
||||
a = KeGetTicks();
|
||||
DebugLog("Start free : %lu ms\n", a);
|
||||
MmFreePageFrame(tab[j++]);
|
||||
b = KeGetTicks();
|
||||
DebugLog("End free : %lu ms\n", b);
|
||||
DebugLog("Free time : %lu ms\n", (b-a));
|
||||
DebugLog("Alloc : %d; Free : %d; Count : %lu Mo\n", NSuccessfulAlloc, NSuccessfulFree, MmBusyPagesSpace() / MB);
|
||||
|
||||
a = KeGetTicks();
|
||||
DebugLog("Start map : %lu ms\n", a);
|
||||
MmMapPageFrame(tab[1], (void*)USERSPACE, PRESENT | USERMODE | READWRITE);
|
||||
b = KeGetTicks();
|
||||
DebugLog("End map : %lu ms\n", b);
|
||||
DebugLog("Map time : %lu ms\n", (b-a));
|
||||
//printBusyPages();
|
||||
|
||||
DebugLog("Finished !\n");
|
||||
|
||||
return EOK;
|
||||
|
|
Loading…
Reference in New Issue