1
#pragma once
2

            
3
#include "envoy/event/dispatcher.h"
4
#include "envoy/server/overload/overload_manager.h"
5
#include "envoy/stats/scope.h"
6
#include "envoy/stats/stats.h"
7

            
8
namespace Envoy {
9
namespace Memory {
10

            
11
/**
12
 * A utility class to periodically attempt to shrink the heap by releasing free memory
13
 * to the system if the "shrink heap" overload action has been configured and triggered.
14
 */
15
class HeapShrinker {
16
public:
17
  HeapShrinker(Event::Dispatcher& dispatcher, Server::OverloadManager& overload_manager,
18
               Envoy::Stats::Scope& stats);
19

            
20
private:
21
  void shrinkHeap();
22

            
23
  bool active_{false};
24
  Envoy::Stats::Counter* shrink_counter_;
25
  Envoy::Event::TimerPtr timer_;
26
};
27

            
28
} // namespace Memory
29
} // namespace Envoy