SpiecsEngine
 
Loading...
Searching...
No Matches
PageCache.h
Go to the documentation of this file.
1/**
2* @file PageCache.cpp.
3* @brief The PageCache Class Definitions.
4* @author tcmalloc.
5*/
6
7#pragma once
8#include "Core/Core.h"
9#include "MemoryPool.h"
10#include "Core/Container/SpanList.h"
11#include "Core/Container/RadixTrie.h"
12#include "ObjectPool.h"
13
14namespace Spices {
15
16 /**
17 * @brief Page memory cache.
18 * Third level of memory allocator.
19 */
21 {
22 public:
23
24 /**
25 * @brief Constructor Function.
26 */
27 PageCache() = default;
28
29 /**
30 * @brief Destructor Function.
31 */
32 virtual ~PageCache() = default;
33
34 /**
35 * @brief Copy Constructor Function.
36 * @note This Class not allowed copy behaves.
37 */
38 PageCache(const PageCache&) = delete;
39
40 /**
41 * @brief Copy Assignment Operation.
42 * @note This Class not allowed copy behaves.
43 */
44 PageCache& operator= (const PageCache&) = delete;
45
46 /**
47 * @brief Get this single instance.
48 * @return Returns this single instance.
49 */
50 static PageCache* Get() { return &m_PageCache; }
51
52 /**
53 * @brief Fetch pages span.
54 * @param[in] k pages count.
55 * @reurn Returns a new span.
56 */
57 scl::span* NewSpan(size_t k);
58
59 /**
60 * @brief Find span by memory pointer.
61 * @param[in] obj object memory pointer.
62 * @return Returns span.
63 */
64 scl::span* MapObjectToSpan(void* obj) const;
65
66 /**
67 * @brief Release span from cc to pc,
68 * @param[in] s span.
69 */
71
72 private:
73
74 /**
75 * @brief Fetch pages span(internal call).
76 * @param[in] k pages count.
77 * @reurn Returns a new span.
78 */
79 scl::span* InternalNewSpan(size_t k);
80
81 private:
82
83 /**
84 * @brief this single instance.
85 */
87
88 /**
89 * @brief FreeList Array.
90 */
92
93 /**
94 * @brief ObjectPool for span.
95 */
97
98 /**
99 * @brief mutex for pc.
100 */
102
103 /**
104 * @brief radix trie for [pageId - span]
105 */
107 };
108}
CentralCache()=default
Constructor Function.
static scl::span * GetOneSpan(scl::span_list &list, size_t size)
Get a not empty span.
size_t FetchRange(void *&start, void *&end, size_t batchNum, size_t size)
Fetch range memory to tc.
static CentralCache m_CentralCache
Single instance of this.
CentralCache & operator=(const CentralCache &)=delete
Copy Assignment Operation.
virtual ~CentralCache()=default
Destructor Function.
void ReleaseListToSpans(void *start, size_t size)
Release memory to pc.
std::array< scl::span_list, MemoryPool::FREE_LIST_NUM > m_SpanLists
FreeList Array.
CentralCache(const CentralCache &)=delete
Copy Constructor Function.
static CentralCache * Get()
Get this single Instance.
Central memory cache. Second level of memory allocator.
static void *& PointerSpace(void *obj)
Get object first 4/8 bytes as a pointer.
MemoryPool Class.
Definition MemoryPool.h:22
ObjectPool Class. Specific situation(Fixed size of block) of MemoryPool.
Definition ObjectPool.h:31
scl::radix_trie< 64 - MemoryPool::PAGE_SHIFT, 3 > m_IdSpanMap
radix trie for [pageId - span]
Definition PageCache.h:106
virtual ~PageCache()=default
Destructor Function.
PageCache & operator=(const PageCache &)=delete
Copy Assignment Operation.
static PageCache m_PageCache
this single instance.
Definition PageCache.h:86
PageCache()=default
Constructor Function.
scl::span * MapObjectToSpan(void *obj) const
Find span by memory pointer.
Definition PageCache.cpp:21
scl::span * InternalNewSpan(size_t k)
Fetch pages span(internal call).
static PageCache * Get()
Get this single instance.
Definition PageCache.h:50
void ReleaseSpanToPageCache(scl::span *s)
Release span from cc to pc,.
Definition PageCache.cpp:43
std::mutex m_Mutex
mutex for pc.
Definition PageCache.h:101
scl::span * NewSpan(size_t k)
Fetch pages span.
Definition PageCache.cpp:14
ObjectPool< scl::span > m_SpanPool
ObjectPool for span.
Definition PageCache.h:96
PageCache(const PageCache &)=delete
Copy Constructor Function.
std::array< scl::span_list, MemoryPool::PAGE_NUM > m_SpanLists
FreeList Array.
Definition PageCache.h:91
Page memory cache. Third level of memory allocator.
Definition PageCache.h:21
void PushFront(span *s)
Push a span to this list.
Definition SpanList.cpp:40
span * Begin() const
Get begin pointer.
Definition SpanList.cpp:59
span * End() const
Get end pointer.
Definition SpanList.cpp:64
Bidirectional cyclic linked list for span.
Definition SpanList.h:73
span * m_Next
next span.
Definition SpanList.h:41
void * m_FreeList
current pointer.
Definition SpanList.h:51
bool m_IsUse
True if in use.
Definition SpanList.h:61
Used for manage multiple page memory.
Definition SpanList.h:15