X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Farch%2Fx86_64%2Fmm_phys.c;h=5d9f2ef307c51b9402f5bbc08ef04cb5ddcf51bd;hb=e6d539f85a06fb3d25b985d1a27d8648d23736f0;hp=77ca92e7eac625b399e3579e69eda124032c6b65;hpb=e71a426f7cc3cd98e43ca8f529ee8e1e13395885;p=tpg%2Facess2.git diff --git a/Kernel/arch/x86_64/mm_phys.c b/Kernel/arch/x86_64/mm_phys.c index 77ca92e7..5d9f2ef3 100644 --- a/Kernel/arch/x86_64/mm_phys.c +++ b/Kernel/arch/x86_64/mm_phys.c @@ -368,15 +368,15 @@ tPAddr MM_AllocPhysRange(int Num, int Bits) LOG("nFree = %i = 0 (super) (0x%x)", nFree, addr); nFree = 0; addr += 1 << (6+6); - addr &= (1 << (6+6)) - 1; + addr &= ~( (1 << (6+6)) - 1 ); continue; } // Check page block (64 pages) - if( gaSuperBitmap[addr >> (6+6)] & (1 << (addr>>6)&63)) { + if( gaMainBitmap[addr >> 6] == -1) { LOG("nFree = %i = 0 (main) (0x%x)", nFree, addr); nFree = 0; - addr += 1 << (12+6); - addr &= (1 << (12+6)) - 1; + addr += 1 << (6); + addr &= ~( (1 << (6)) - 1 ); continue; } // Check individual page @@ -423,8 +423,10 @@ tPAddr MM_AllocPhysRange(int Num, int Bits) for( i = 0; i < Num; i++, addr++ ) { gaMainBitmap[addr >> 6] |= 1 << (addr & 63); - rangeID = MM_int_GetRangeID(addr); + rangeID = MM_int_GetRangeID(addr << 12); giPhysRangeFree[ rangeID ] --; + if(addr == giPhysRangeFirst[ rangeID ]) + giPhysRangeFirst[ rangeID ] += 1; } ret = addr; // Save the return address @@ -507,15 +509,20 @@ void MM_DerefPhys(tPAddr PAddr) else gaMainBitmap[ page >> 6 ] &= ~(1 << (page&63)); - // TODO: Update free counts + // Update the free counts if the page was freed if( !(gaMainBitmap[ page >> 6 ] & (1 << (page&63))) ) { int rangeID; rangeID = MM_int_GetRangeID( PAddr ); giPhysRangeFree[ rangeID ] ++; + if( giPhysRangeFirst[rangeID] > page ) + giPhysRangeFirst[rangeID] = page; + if( giPhysRangeLast[rangeID] < page ) + giPhysRangeLast[rangeID] = page; } - if(gaMainBitmap[ page >> 6 ] == 0) { + // If the bitmap entry is not -1, unset the bit in the super bitmap + if(gaMainBitmap[ page >> 6 ] != -1 ) { gaSuperBitmap[page >> 12] &= ~(1 << ((page >> 6) & 63)); } }