- Make Mm allocation strategy low->high by default.

- Clean up Mm APIs which are not needed anymore.
- Get rid of the LOADER_HIGH_ZONE definition, now the real LoaderPagesSpanned value is calculated and used. As a result, minimum memory requirement (which was >= LOADER_HIGH_ZONE) is gone, and a maximum amount of memory which could be allocated is also gone (previously, not more that the LOADER_HIGH_ZONE).
- IMPORTANT: The FAT filesystem caching is disabled by default now due strange problems in 3rd boot stage, after switching the cache to use heap routines. Cache can't use non-heap routines anymore, since the memory will overlap the contigious modules memory space which ReactOS needs.
- More cleanup and more usage of the heap routines for temporary buffers.
- Fix a bug in MmAllocateMemoryWithType, where result of MmFindAvailablePages was checked against -1 in error case, when in reality it's 0 (spotted by Alex). NB: 0 page is marked as a reserved in x86 arch, so it's never going to be returned as an available.

svn path=/trunk/; revision=32113
This commit is contained in:
Aleksey Bragin 2008-02-04 10:45:55 +00:00
parent f971658fb8
commit ac79d6ae4b
10 changed files with 874 additions and 875 deletions

View file

@ -582,7 +582,7 @@ FrLdrMapImage(IN FILE *Image,
FsSetFilePointer(Image, 0);
/* Allocate a temporary buffer for the read */
ReadBuffer = MmAllocateMemory(ImageSize);
ReadBuffer = MmHeapAlloc(ImageSize);
/* Load the file image */
FsReadFile(Image, ImageSize, NULL, ReadBuffer);
@ -591,7 +591,7 @@ FrLdrMapImage(IN FILE *Image,
ImageSize = FrLdrReMapImage(ReadBuffer, LoadBase);
/* Free the temporary buffer */
MmFreeMemory(ReadBuffer);
MmHeapFree(ReadBuffer);
/* Calculate Difference between Real Base and Compiled Base*/
Status = LdrRelocateImageWithBias(LoadBase,

View file

@ -108,7 +108,7 @@ PCACHE_BLOCK CacheInternalAddBlockToCache(PCACHE_DRIVE CacheDrive, ULONG BlockNu
// allocate room for the block data
RtlZeroMemory(CacheBlock, sizeof(CACHE_BLOCK));
CacheBlock->BlockNumber = BlockNumber;
CacheBlock->BlockData = MmAllocateMemory(CacheDrive->BlockSize * CacheDrive->BytesPerSector);
CacheBlock->BlockData = MmHeapAlloc(CacheDrive->BlockSize * CacheDrive->BytesPerSector);
if (CacheBlock->BlockData ==NULL)
{
MmHeapFree(CacheBlock);
@ -118,7 +118,7 @@ PCACHE_BLOCK CacheInternalAddBlockToCache(PCACHE_DRIVE CacheDrive, ULONG BlockNu
// Now try to read in the block
if (!MachDiskReadLogicalSectors(CacheDrive->DriveNumber, (BlockNumber * CacheDrive->BlockSize), CacheDrive->BlockSize, (PVOID)DISKREADBUFFER))
{
MmFreeMemory(CacheBlock->BlockData);
MmHeapFree(CacheBlock->BlockData);
MmHeapFree(CacheBlock);
return NULL;
}
@ -161,7 +161,7 @@ BOOLEAN CacheInternalFreeBlock(PCACHE_DRIVE CacheDrive)
RemoveEntryList(&CacheBlockToFree->ListEntry);
// Free the block memory and the block structure
MmFreeMemory(CacheBlockToFree->BlockData);
MmHeapFree(CacheBlockToFree->BlockData);
MmHeapFree(CacheBlockToFree);
// Update the cache data

View file

@ -70,7 +70,7 @@ BOOLEAN CacheInitializeDrive(ULONG DriveNumber)
CACHE_BLOCK,
ListEntry);
MmFreeMemory(NextCacheBlock->BlockData);
MmHeapFree(NextCacheBlock->BlockData);
MmHeapFree(NextCacheBlock);
}
}

View file

@ -22,7 +22,7 @@
#define NDEBUG
#include <debug.h>
BOOLEAN gCacheEnabled = TRUE;
BOOLEAN gCacheEnabled = FALSE;
ULONG BytesPerSector; /* Number of bytes per sector */
ULONG SectorsPerCluster; /* Number of sectors per cluster */

View file

@ -47,10 +47,6 @@ typedef struct
( ((a) >> MM_PAGE_SHIFT) + ((a) & MM_PAGE_MASK ? 1 : 0) )
#endif // defined __i386__ or _PPC_ or _MIPS_
//
// This is the zone which is used by the OS loader
//
#define LOADER_HIGH_ZONE ((24*1024*1024) >> MM_PAGE_SHIFT) // 24Mb
// HEAP and STACK size
#define HEAP_PAGES 0x400
@ -105,9 +101,6 @@ VOID MmInitializeHeap(PVOID PageLookupTable);
PVOID MmAllocateMemory(ULONG MemorySize);
PVOID MmAllocateMemoryWithType(ULONG MemorySize, TYPE_OF_MEMORY MemoryType);
VOID MmFreeMemory(PVOID MemoryPointer);
VOID MmChangeAllocationPolicy(BOOLEAN PolicyAllocatePagesFromEnd);
//PVOID MmAllocateLowMemory(ULONG MemorySize);
//VOID MmFreeLowMemory(PVOID MemoryPointer);
PVOID MmAllocateMemoryAtAddress(ULONG MemorySize, PVOID DesiredAddress, TYPE_OF_MEMORY MemoryType);
PVOID MmAllocateHighestMemoryBelowAddress(ULONG MemorySize, PVOID DesiredAddress, TYPE_OF_MEMORY MemoryType);

View file

@ -393,8 +393,7 @@ ULONG MmFindAvailablePages(PVOID PageLookupTable, ULONG TotalPageCount, ULONG Pa
if (FromEnd)
{
/* Allocate "high" (from end) pages */
for (Index=/*LastFreePageHint-1*/LOADER_HIGH_ZONE-1; Index>0; Index--)
//for (Index=LastFreePageHint-1; Index>0; Index--)
for (Index=LastFreePageHint-1; Index>0; Index--)
{
if (RealPageLookupTable[Index].PageAllocated != LoaderFree)
{

View file

@ -25,12 +25,7 @@ VOID DumpMemoryAllocMap(VOID);
VOID MemAllocTest(VOID);
#endif // DBG
BOOLEAN AllocateFromEnd = TRUE;
VOID MmChangeAllocationPolicy(BOOLEAN PolicyAllocatePagesFromEnd)
{
AllocateFromEnd = PolicyAllocatePagesFromEnd;
}
ULONG LoaderPagesSpanned = 0;
PVOID MmAllocateMemoryWithType(ULONG MemorySize, TYPE_OF_MEMORY MemoryType)
{
@ -60,9 +55,9 @@ PVOID MmAllocateMemoryWithType(ULONG MemorySize, TYPE_OF_MEMORY MemoryType)
return NULL;
}
FirstFreePageFromEnd = MmFindAvailablePages(PageLookupTableAddress, TotalPagesInLookupTable, PagesNeeded, AllocateFromEnd);
FirstFreePageFromEnd = MmFindAvailablePages(PageLookupTableAddress, TotalPagesInLookupTable, PagesNeeded, FALSE);
if (FirstFreePageFromEnd == (ULONG)-1)
if (FirstFreePageFromEnd == 0)
{
DbgPrint((DPRINT_MEMORY, "Memory allocation failed in MmAllocateMemory(). Not enough free memory to allocate %d bytes.\n", MemorySize));
UiMessageBoxCritical("Memory allocation failed: out of memory.");
@ -79,6 +74,10 @@ PVOID MmAllocateMemoryWithType(ULONG MemorySize, TYPE_OF_MEMORY MemoryType)
DbgPrint((DPRINT_MEMORY, "Memory allocation pointer: 0x%x\n", MemPointer));
#endif // DBG
// Update LoaderPagesSpanned count
if ((((ULONG_PTR)MemPointer + MemorySize) >> PAGE_SHIFT) > LoaderPagesSpanned)
LoaderPagesSpanned = (((ULONG_PTR)MemPointer + MemorySize) >> PAGE_SHIFT);
// Now return the pointer
return MemPointer;
}
@ -175,6 +174,10 @@ PVOID MmAllocateMemoryAtAddress(ULONG MemorySize, PVOID DesiredAddress, TYPE_OF_
DbgPrint((DPRINT_MEMORY, "Memory allocation pointer: 0x%x\n", MemPointer));
#endif // DBG
// Update LoaderPagesSpanned count
if ((((ULONG_PTR)MemPointer + MemorySize) >> PAGE_SHIFT) > LoaderPagesSpanned)
LoaderPagesSpanned = (((ULONG_PTR)MemPointer + MemorySize) >> PAGE_SHIFT);
// Now return the pointer
return MemPointer;
}
@ -228,6 +231,10 @@ PVOID MmAllocateHighestMemoryBelowAddress(ULONG MemorySize, PVOID DesiredAddress
DbgPrint((DPRINT_MEMORY, "Memory allocation pointer: 0x%x\n", MemPointer));
#endif // DBG
// Update LoaderPagesSpanned count
if ((((ULONG_PTR)MemPointer + MemorySize) >> PAGE_SHIFT) > LoaderPagesSpanned)
LoaderPagesSpanned = (((ULONG_PTR)MemPointer + MemorySize) >> PAGE_SHIFT);
// Now return the pointer
return MemPointer;
}

File diff suppressed because it is too large Load diff

View file

@ -30,6 +30,7 @@ extern ARC_DISK_SIGNATURE reactos_arc_disk_info[];
extern char reactos_arc_strings[32][256];
extern BOOLEAN UseRealHeap;
extern ULONG LoaderPagesSpanned;
BOOLEAN
WinLdrCheckForLoadedDll(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock,
@ -186,12 +187,11 @@ WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock,
}
RtlZeroMemory(Extension, sizeof(LOADER_PARAMETER_EXTENSION));
/* Save size and version information */
/* Fill LPB extension */
Extension->Size = sizeof(LOADER_PARAMETER_EXTENSION);
Extension->MajorVersion = (VersionToBoot & 0xFF00) >> 8;
Extension->MinorVersion = VersionToBoot & 0xFF;
Extension->LoaderPagesSpanned = LOADER_HIGH_ZONE;
Extension->Profile.Status = 2;
LoaderBlock->Extension = PaToVa(Extension);
}
@ -208,8 +208,8 @@ void WinLdrSetupForNt(PLOADER_PARAMETER_BLOCK LoaderBlock,
ULONG_PTR Tss = 0;
ULONG BlockSize, NumPages;
LoaderBlock->u.I386.CommonDataArea = NULL;//CommonDataArea;
//LoaderBlock->u.I386.MachineType = MachineType; //FIXME: MachineType?
LoaderBlock->u.I386.CommonDataArea = NULL; //CommonDataArea;
LoaderBlock->u.I386.MachineType = 0; // ntldr sets this to 0
/* Allocate 2 pages for PCR */
Pcr = (ULONG_PTR)MmAllocateMemoryWithType(2 * MM_PAGE_SIZE, LoaderStartupPcrPage);
@ -483,12 +483,12 @@ LoadAndBootWindows(PCSTR OperatingSystemName, WORD OperatingSystemVersion)
Status = WinLdrLoadBootDrivers(LoaderBlock, BootPath);
DbgPrint((DPRINT_WINDOWS, "Boot drivers loaded with status %d\n", Status));
/* Initialize Phase 1 - no drivers loading anymore */
WinLdrInitializePhase1(LoaderBlock, BootOptions, SystemPath, OperatingSystemVersion);
/* Alloc PCR, TSS, do magic things with the GDT/IDT */
WinLdrSetupForNt(LoaderBlock, &GdtIdt, &PcrBasePage, &TssBasePage);
/* Initialize Phase 1 - no drivers loading anymore */
WinLdrInitializePhase1(LoaderBlock, BootOptions, SystemPath, OperatingSystemVersion);
/* Save entry-point pointer and Loader block VAs */
KiSystemStartup = (KERNEL_ENTRY_POINT)KernelDTE->EntryPoint;
LoaderBlockVA = PaToVa(LoaderBlock);
@ -506,6 +506,9 @@ LoadAndBootWindows(PCSTR OperatingSystemName, WORD OperatingSystemVersion)
/* Turn on paging mode of CPU*/
WinLdrTurnOnPaging(LoaderBlock, PcrBasePage, TssBasePage, GdtIdt);
/* Save final value of LoaderPagesSpanned */
LoaderBlock->Extension->LoaderPagesSpanned = LoaderPagesSpanned;
DbgPrint((DPRINT_WINDOWS, "Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n",
KiSystemStartup, LoaderBlockVA));

View file

@ -14,6 +14,7 @@
#include <debug.h>
extern ULONG TotalNLSSize;
extern ULONG LoaderPagesSpanned;
// This is needed because headers define wrong one for ReactOS
#undef KIP0PCRADDRESS
@ -131,14 +132,14 @@ MempAllocatePageTables()
// PDE, HAL mapping page table, physical mapping, kernel mapping
TotalSize = (1+1+NumPageTables*2)*MM_PAGE_SIZE;
// Physical PTEs = FirmwareTemporary
PhysicalPageTablesBuffer = MmAllocateMemoryWithType(
NumPageTables*MM_PAGE_SIZE, LoaderFirmwareTemporary);
// PDE+HAL+KernelPTEs == MemoryData
Buffer = MmAllocateMemoryWithType(
TotalSize - NumPageTables*MM_PAGE_SIZE, LoaderMemoryData);
// Physical PTEs = FirmwareTemporary
PhysicalPageTablesBuffer = MmAllocateMemoryWithType(
NumPageTables*MM_PAGE_SIZE, LoaderFirmwareTemporary);
if (Buffer + (TotalSize - NumPageTables*MM_PAGE_SIZE) !=
PhysicalPageTablesBuffer)
{
@ -290,23 +291,22 @@ MempDisablePages()
if (Mad[i].MemoryType == LoaderFirmwarePermanent ||
Mad[i].MemoryType == LoaderSpecialMemory ||
Mad[i].MemoryType == LoaderFree ||
(Mad[i].MemoryType == LoaderFirmwareTemporary && EndPage <= LOADER_HIGH_ZONE) ||
(Mad[i].MemoryType == LoaderFirmwareTemporary && EndPage <= LoaderPagesSpanned) ||
Mad[i].MemoryType == LoaderOsloaderStack ||
Mad[i].MemoryType == LoaderLoadedProgram)
{
//
// But, the first megabyte of memory always stays!
// And, to tell the truth, we don't care about what's higher
// than LOADER_HIGH_ZONE
// than LoaderPagesSpanned
if (Mad[i].MemoryType == LoaderFirmwarePermanent ||
Mad[i].MemoryType == LoaderSpecialMemory)
{
if (StartPage < 0x100)
StartPage = 0x100;
if (EndPage > LOADER_HIGH_ZONE)
EndPage = LOADER_HIGH_ZONE;
if (EndPage > LoaderPagesSpanned)
EndPage = LoaderPagesSpanned;
}
for (Page = StartPage; Page < EndPage; Page++)
@ -330,7 +330,6 @@ MempDisablePages()
}
}
VOID
MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
ULONG BasePage,
@ -361,7 +360,7 @@ MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
// Check if it's more than the allowed for OS loader
// if yes - don't map the pages, just add as FirmwareTemporary
//
if (BasePage + PageCount > LOADER_HIGH_ZONE)
if (BasePage + PageCount > LoaderPagesSpanned)
{
if (Mad[MadCount].MemoryType != LoaderSpecialMemory &&
Mad[MadCount].MemoryType != LoaderFirmwarePermanent &&