MiRemoveUnusedSegments

VOID __stdcall MiRemoveUnusedSegments(_MI_PARTITION *Partition){
  unsigned __int64 v1; 
  unsigned int v2; 
  unsigned __int64 v3; 
  unsigned __int64 v5; 
  int v6; 
  unsigned __int64 v7; 
  unsigned __int64 UnusedSegmentPagedPool; 
  unsigned __int64 v9; 
  unsigned __int64 v10; 
  int v11; 
  UINT64 v12; 
  UINT64 v13; 
  int v14; 

  v2 = 0;
  v3 = v1;
  if( v1 )
  {
    if( v1 >= *(&stru_140C50B28 + 920) )
      v5 = 0i64;
    else
      v5 = *(&stru_140C50B28 + 920) - v1;
    v6 = 0;
  }
  else
  {
    v6 = 32;
    v5 = 0i64;
  }
  v7 = 1000 * Partition->Vp.NumberOfPhysicalPages / *(&stru_140C50B28 + 853);
  if( v7 )
  {
    UnusedSegmentPagedPool = Partition->Segments.UnusedSegmentPagedPool;
    v9 = UnusedSegmentPagedPool;
    if( v7 * (qword_140C4C6D8 / 0x3E8ui64) <= UnusedSegmentPagedPool )
      v9 = v7 * (qword_140C4C6D8 / 0x3E8ui64);
    if( v9 )
    {
      v10 = UnusedSegmentPagedPool - v9;
      if( v10 < 0x100000 )
        v10 = 0x100000i64;
      while( 1 )
      {
        if( v3 )
        {
          if( *(&stru_140C50B28 + 920) <= v5 )
            return;
        }
        else
        {
          if( !v6 || *(&stru_140C50B28 + 920) < 9 * (*(&stru_140C50B28 + 936) / 0xAui64) )
            return;
          --v6;
        }
        LOBYTE(v11) = MiShouldTrimUnusedSegments();
        if( !v11 || Partition->Segments.UnusedSegmentPagedPool <= v10 )
          return;
        if( (++v2 & 0x3F) == 0 )
        {
          MiProcessDereferenceList(Partition);
          if( v2 >= 0x80 )
            CcUnmapInactiveViews(0i64, v13, 0i64);
          KeDelayExecutionThread(0, 0, (_LARGE_INTEGER *)&Interval);
        }
        if( Partition->Segments.UnusedSegmentList.Flink == &Partition->Segments.UnusedSegmentList )
        {
          if( Partition->Segments.UnusedSubsectionList.Flink == &Partition->Segments.UnusedSubsectionList )
          {
            if( *(_DWORD *)&Partition->Core.gap68[4] )
              return;
            CcUnmapInactiveViews(0i64, v12, 0i64);
            if( !v14 )
              return;
          }
          else
          {
            MiDeleteCachedSubsection(Partition);
          }
        }
        else
        {
          MiDeleteCachedSegment(Partition);
        }
      }
    }
  }
}

Referenced by:

MiDereferenceSegmentThread
MiProcessDereferenceList