2 +----------------------------------------------------------------------+
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_APC_FILE_STORAGE_H_
18 #define incl_HPHP_APC_FILE_STORAGE_H_
25 #include "hphp/util/hash.h"
29 //////////////////////////////////////////////////////////////////////
32 * To save memory, hhvm puts portions of primed APC data in a file-backed mmap
33 * that we can madvise away after an initial warmup period.
35 struct APCFileStorage
{
36 enum class StorageState
{
43 APCFileStorage() = default;
44 APCFileStorage(const APCFileStorage
&) = delete;
45 APCFileStorage
& operator=(const APCFileStorage
&) = delete;
47 void enable(const std::string
& prefix
, size_t chunkSize
);
48 char *put(const char *data
, uint32_t len
);
53 StorageState
getState() { return m_state
; }
59 // [32-bit chunk index]:[32-bit offset]
60 std::atomic_uint_fast64_t m_current
{0};
61 size_t m_chunkSize
{0};
62 StorageState m_state
{StorageState::Invalid
};
63 std::vector
<char*> m_chunks
;
64 std::vector
<std::string
> m_fileNames
;
65 std::vector
<int> m_fds
;
68 // This lock is needed when manipulating chunks.
70 static constexpr strhash_t TombHash
= 0xdeadbeef;
71 static constexpr uint32_t PaddingSize
= sizeof(strhash_t
) + // hash
72 sizeof(int32_t) + // len
76 extern APCFileStorage s_apc_file_storage
;
78 //////////////////////////////////////////////////////////////////////