Remove empty from slow runtime tests
[hiphop-php.git] / hphp / runtime / base / purger.h
blob0ef5d473fc29424a53147b03b58378aee4f72ac1
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_PURGER_H_
18 #define incl_HPHP_PURGER_H_
20 #include <array>
21 #include <cstddef>
22 #include <cstdint>
24 namespace HPHP {
27 * Purger implements decay-based purging of unused dirty pages using a similar
28 * algorithm to jemalloc. we maintain a number of buckets, representing time
29 * slices over the decay time window. Each bucket tracks the max heap size
30 * observed in that time slice.
32 * Each time purge() is called, we apply the decay function to the heap size for
33 * each slice, to arrive at the number of unused dirty pages we would like to
34 * retain, then purge the rest by calling madvise(MADV_DONTNEED).
36 * There are a few tuning parameters in Purger:
37 * kNumBuckets: 16, the number of time slices over the decay time window
38 * RuntimeOption::HeapPurgeThreshold: (bytes) max retained dirty memory
39 * anything over this is eagerly purged. default 128MB.
40 * RuntimeOption::HeapPurgeWindowSize: (ns) decay time window. default 5s.
43 struct Purger {
44 Purger();
47 * Purge the memory from base to front, according to the decay curve
49 void purge(char* base, char* front);
52 * Purge all the dirty pages starting from base
54 void flush(char* base);
56 private:
57 static const int64_t kNumBuckets = 16;
58 struct Bucket {
59 int64_t time; // most recent timestamp for this bucket
60 size_t max; // max heap size in this bucket time slice
63 // Time window size for purge size calculation. The amount of memory that
64 // is allowed to be alive will be set to the maximum memory amount of the
65 // latest time window according to the decay curve.
66 int64_t const window_;
68 // the dirty_ memory threshold
69 size_t const threshold_;
70 int64_t const bucket_slice_;
71 size_t dirty_; // bytes of dirty memory
72 std::array<Bucket,kNumBuckets> buckets_; // buckets array for time window
73 int const id_;
78 #endif