I want my driver to work with a big amount of memory, which is very fast (not paged out). What is the best way to allocate this memory? It can be 500 Mb for Windows XP x32. Using of paged or nonpaged pool under x32-versions is not good, because both are limited to ~256 MB and other drivers need them too. Ok, under x64 I can just use ExAllocatePoolWithTag. I read another thread and wrote this test function:
bool AllocateAndLock(char*& Allocated, SIZE_T MEM_SIZE)
{
PMDL mdl;
Allocated = (char*)MmAllocateNonCachedMemory(MEM_SIZE);
//Allocated = (char*)ExAllocatePoolWithTag(PagedPool, MEM_SIZE, 0x44564D20);
if (Allocated == NULL)
{
DBG_TL(“MmAllocateNonCachedMemory failed \n”);
return false;
}
mdl = IoAllocateMdl(Allocated, (ULONG)MEM_SIZE, FALSE, FALSE, 0);
if (mdl == 0)
{
DBG_TL(“IoAllocateMdl failed \n”);
MmFreeNonCachedMemory(Allocated, MEM_SIZE);
//ExFreePoolWithTag(Allocated, 0x44564D20);
Allocated = NULL;
return false;
}
//ULONG ull = MmGetMdlByteCount(mdl);
//DBG_TVL("MEM_SIZE == ", (u64)MEM_SIZE);
//DBG_TVL("ull == ", (u64)ull);
//MmBuildMdlForNonPagedPool(mdl);
MmProbeAndLockPages(mdl, KernelMode, IoWriteAccess);
return true;
}
I hoped, MmProbeAndLockPages() would make the allocated buffer unoupageable and fast, but it is actually slower as a buffer in paged pool allocated with ExAllocatePoolWithTag even without MmProbeAndLockPages(). How can I reserve a big amount of memory not from paged or nonpaged pool in kernel mode and make it unoutpageable?
Or is it easier to allocate it in user mode and give an adress to the driver for locking?