This repository was archived by the owner on Mar 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathPreloaderThread.hpp
More file actions
110 lines (94 loc) · 3.68 KB
/
PreloaderThread.hpp
File metadata and controls
110 lines (94 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* Copyright 2011-2015 Quickstep Technologies LLC.
* Copyright 2015 Pivotal Software, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#ifndef QUICKSTEP_STORAGE_PRELOADER_THREAD_HPP_
#define QUICKSTEP_STORAGE_PRELOADER_THREAD_HPP_
#include <cstddef>
#include "storage/StorageConfig.h"
#include "threading/Thread.hpp"
#include "utility/Macros.hpp"
namespace quickstep {
class CatalogDatabase;
class CatalogRelation;
class StorageManager;
/** \addtogroup Storage
* @{
*/
/**
* @brief A thread that preloads all known blocks in a database into a
* StorageManager's buffer pool. A separate thread is used so that we
* can affinitize it like a worker and get allocations for buffer memory
* that are NUMA-local for at least some workers where possible.
**/
class PreloaderThread : public Thread {
public:
/**
* @brief Constructor.
*
* @param database All blocks in all non-temporary relations in this database
* will be loaded into the buffer pool.
* @param storage_manager Blocks will be loaded into this StorageManager's
* buffer pool. Note that if the total blocks in the database exceed
* the size of the StorageManager's buffer pool, some blocks will be
* evicted and the database will not be fully preloaded.
* @param cpu_id The ID of the CPU to affinitize this thread to, or -1 to
* indicate no affinity.
**/
PreloaderThread(const CatalogDatabase &database,
StorageManager *storage_manager,
const int cpu_id)
: database_(database),
storage_manager_(storage_manager),
cpu_id_(cpu_id) {
}
~PreloaderThread() override {
}
protected:
void run() override;
private:
#ifdef QUICKSTEP_HAVE_LIBNUMA
/**
* @brief Preload a relation which has a partition and a NUMA placement scheme.
*
* @param relation The relation to be preloaded.
* @param num_previously_loaded_blocks The number of blocks already preloaded.
* @param num_slots The maximum number of slots in the StorageManager.
*
* @warning This function may not detect skew on NUMA sockets, i.e. if a given
* NUMA socket has large number of blocks, preloading may cause the
* memory on that NUMA socket to be full. It is recommended to use
* this preloading when we are sure that each NUMA socket has been
* allocated sufficient amount of memory so as not to exceed that
* socket's memory limit.
*
* TODO(harshad) - Allow multiple preloader threads, each pinned to a NUMA
* socket in the system. Each thread should preload only its share of
* storage blocks.
*
* @return The number of blocks loaded during this function call.
**/
std::size_t preloadNUMAAware(const CatalogRelation &relation,
const std::size_t num_previously_loaded_blocks,
const std::size_t num_slots);
#endif
const CatalogDatabase &database_;
StorageManager *storage_manager_;
const int cpu_id_;
DISALLOW_COPY_AND_ASSIGN(PreloaderThread);
};
/** @} */
} // namespace quickstep
#endif // QUICKSTEP_STORAGE_PRELOADER_THREAD_HPP_