From: Serge Gautherie Date: Wed, 12 Apr 2017 15:57:00 +0200 Subject: [IOMGR] iomdl.c: *Create/Use a LOOKASIDE_MDL_FIXED_SIZE define for IoAllocateMdl(). *Fix a few comments, especially in IoFreeMdl(). CORE-13066 Index: reactos/ntoskrnl/io/iomgr/iomdl.c --- a/reactos/ntoskrnl/io/iomgr/iomdl.c +++ b/reactos/ntoskrnl/io/iomgr/iomdl.c @@ -14,6 +14,8 @@ /* FUNCTIONS *****************************************************************/ +/* Internal fixed size for MDLs in lookaside list. */ +#define LOOKASIDE_MDL_FIXED_SIZE 23 /* * @implemented */ @@ -37,9 +39,9 @@ /* Calculate the number of pages for the allocation */ Size = ADDRESS_AND_SIZE_TO_SPAN_PAGES(VirtualAddress, Length); - if (Size > 23) + if (Size > LOOKASIDE_MDL_FIXED_SIZE) { - /* This is bigger then our fixed-size MDLs. Calculate real size */ + /* This is bigger than our fixed size MDLs. Calculate real size. */ Size *= sizeof(PFN_NUMBER); Size += sizeof(MDL); if (Size > MAXUSHORT) return NULL; @@ -47,7 +49,7 @@ else { /* Use an internal fixed MDL size */ - Size = (23 * sizeof(PFN_NUMBER)) + sizeof(MDL); + Size = (LOOKASIDE_MDL_FIXED_SIZE * sizeof(PFN_NUMBER)) + sizeof(MDL); Flags |= MDL_ALLOCATED_FIXED_SIZE; /* Allocate one from the lookaside list */ @@ -87,6 +89,7 @@ /* Return the allocated mdl */ return Mdl; } +#undef LOOKASIDE_MDL_FIXED_SIZE /* * @implemented @@ -148,15 +151,15 @@ /* Tell Mm to reuse the MDL */ MmPrepareMdlForReuse(Mdl); - /* Check if this was a pool allocation */ + /* Always free fixed size allocations to the lookaside list. */ if (!(Mdl->MdlFlags & MDL_ALLOCATED_FIXED_SIZE)) { - /* Free it from the pool */ + /* Free it to the pool. */ ExFreePoolWithTag(Mdl, TAG_MDL); } else { - /* Free it from the lookaside */ + /* Free it to the lookaside list. */ IopFreeMdlFromLookaside(Mdl, LookasideMdlList); } }