private void degradeLastFlushTime() {
    TreeSet<TimePartitionInfo> treeSet = new TreeSet<>(TimePartitionInfo::comparePriority);
    synchronized (timePartitionInfoMap) {
      for (Map.Entry<DataRegionId, Map<Long, TimePartitionInfo>> entry :
          timePartitionInfoMap.entrySet()) {
        treeSet.addAll(entry.getValue().values());
      }

      while (timePartitionInfoMemoryBlock.getUsedMemoryInBytes()
          > timePartitionInfoMemoryBlock.getTotalMemorySizeInBytes()) {
        TimePartitionInfo timePartitionInfo = treeSet.pollFirst();
        if (timePartitionInfo == null) {
          return;
        }
        timePartitionInfoMemoryBlock.release(timePartitionInfo.memSize);
        DataRegion dataRegion =
            StorageEngine.getInstance().getDataRegion(timePartitionInfo.dataRegionId);
        if (dataRegion != null) {
          dataRegion.degradeFlushTimeMap(timePartitionInfo.partitionId);
          logger.info(
              "[{}]degrade LastFlushTimeMap of old TimePartitionInfo-{}, mem size is {}, remaining mem cost is {}",
              timePartitionInfo.dataRegionId,
              timePartitionInfo.partitionId,
              timePartitionInfo.memSize,
              timePartitionInfoMemoryBlock.getUsedMemoryInBytes());
        }
        timePartitionInfoMap
            .get(timePartitionInfo.dataRegionId)
            .remove(timePartitionInfo.partitionId);
      }
    }
  }
Manage all the time partitions for all data regions and control the total memory of them
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/rescon/memory/TimePartitionManager.java