MiDecreaseAvailablePages

NTSTATUS __stdcall MiDecreaseAvailablePages(
        _MI_PARTITION *Partition,
        UINT64 NumberOfPages,
        UINT64 RemainderPages,
        UINT64 Flags){
  INT16 v4; 
  unsigned __int64 v7; 
  unsigned __int64 HighMemoryThreshold; 
  unsigned __int64 v9; 
  unsigned __int64 LowMemoryThreshold; 
  NTSTATUS result; 
  _BYTE *WorkingSetControl; 

  v4 = Flags;
  if( NumberOfPages == 1 )
  {
    v9 = _InterlockedDecrement64((volatile signed __int64 *)&Partition->Vp.AvailablePages);
    if( v9 == Partition->PageLists.LowMemoryThreshold || v9 == Partition->PageLists.HighMemoryThreshold )
      MiUpdateAvailableEvents(Partition);
    v7 = v9 + 1;
  }
  else
  {
    v7 = _InterlockedExchangeAdd64((volatile signed __int64 *)&Partition->Vp.AvailablePages, -(__int64)NumberOfPages);
    HighMemoryThreshold = Partition->PageLists.HighMemoryThreshold;
    v9 = v7 - NumberOfPages;
    if( v7 - NumberOfPages <= HighMemoryThreshold && v7 > HighMemoryThreshold
      || (LowMemoryThreshold = Partition->PageLists.LowMemoryThreshold, v9 <= LowMemoryThreshold)
      && v7 > LowMemoryThreshold )
    {
      MiUpdateAvailableEvents(Partition);
    }
  }
  if( v9 <= 0x420 )
  {
    WorkingSetControl = Partition->WorkingSetControl;
    if( !WorkingSetControl || !WorkingSetControl[52] )
      MiObtainFreePages(Partition);
    if( v9 < 0xA0 && v7 >= 0xA0 && Partition->Store.Registered )
      KeSetEvent((PRKEVENT)&Partition->Modwriter.gap236[2], 0, 0);
  }
  if( RemainderPages != -1i64 )
    return v9 >= RemainderPages;
  LOBYTE(result) = MiPageAvailableEx((INT64)Partition, v9, v4);
  return result;
}

Referenced by:

MiRemoveLowestPriorityStandbyPage
MiReplaceTransitionPage
MiReplenishPageSlist
MiUnlinkNodeLargePageHelper