Logo ROOT  
Reference Guide
RPagePool.hxx
Go to the documentation of this file.
1/// \file ROOT/RPagePool.hxx
2/// \ingroup NTuple ROOT7
3/// \author Jakob Blomer <jblomer@cern.ch>
4/// \date 2018-10-09
5/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6/// is welcome!
7
8/*************************************************************************
9 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
10 * All rights reserved. *
11 * *
12 * For the licensing terms see $ROOTSYS/LICENSE. *
13 * For the list of contributors see $ROOTSYS/README/CREDITS. *
14 *************************************************************************/
15
16#ifndef ROOT7_RPagePool
17#define ROOT7_RPagePool
18
19#include <ROOT/RPage.hxx>
21#include <ROOT/RNTupleUtil.hxx>
22
23#include <cstddef>
24#include <mutex>
25#include <vector>
26
27namespace ROOT {
28namespace Experimental {
29
30namespace Detail {
31
32// clang-format off
33/**
34\class ROOT::Experimental::Detail::RPagePool
35\ingroup NTuple
36\brief A thread-safe cache of column pages.
37
38The page pool provides memory tracking for data written into an ntuple or read from an ntuple. Adding and removing
39pages is thread-safe. The page pool does not allocate the memory -- allocation and deallocation is performed by the
40page storage, which might do it in a way optimized to the backing store (e.g., mmap()).
41Multiple page caches can coexist.
42
43TODO(jblomer): it should be possible to register pages and to find them by column and index; this would
44facilitate pre-filling a cache, e.g. by read-ahead.
45*/
46// clang-format on
47class RPagePool {
48private:
49 /// TODO(jblomer): should be an efficient index structure that allows
50 /// - random insert
51 /// - random delete
52 /// - searching by page
53 /// - searching by tree index
54 std::vector<RPage> fPages;
55 std::vector<std::int32_t> fReferences;
56 std::vector<RPageDeleter> fDeleters;
57 std::mutex fLock;
58
59public:
60 RPagePool() = default;
61 RPagePool(const RPagePool&) = delete;
62 RPagePool& operator =(const RPagePool&) = delete;
63 ~RPagePool() = default;
64
65 /// Adds a new page to the pool together with the function to free its space. Upon registration,
66 /// the page pool takes ownership of the page's memory. The new page has its reference counter set to 1.
67 void RegisterPage(const RPage &page, const RPageDeleter &deleter);
68 /// Like RegisterPage() but the reference counter is initialized to 0
69 void PreloadPage(const RPage &page, const RPageDeleter &deleter);
70 /// Tries to find the page corresponding to column and index in the cache. If the page is found, its reference
71 /// counter is increased
72 RPage GetPage(ColumnId_t columnId, NTupleSize_t globalIndex);
73 RPage GetPage(ColumnId_t columnId, const RClusterIndex &clusterIndex);
74 /// Give back a page to the pool and decrease the reference counter. There must not be any pointers anymore into
75 /// this page. If the reference counter drops to zero, the page pool might decide to call the deleter given in
76 /// during registration.
77 void ReturnPage(const RPage &page);
78};
79
80} // namespace Detail
81
82} // namespace Experimental
83} // namespace ROOT
84
85#endif
A closure that can free the memory associated with a mapped page.
A thread-safe cache of column pages.
Definition: RPagePool.hxx:47
std::vector< std::int32_t > fReferences
Definition: RPagePool.hxx:55
std::vector< RPageDeleter > fDeleters
Definition: RPagePool.hxx:56
void PreloadPage(const RPage &page, const RPageDeleter &deleter)
Like RegisterPage() but the reference counter is initialized to 0.
Definition: RPagePool.cxx:31
RPagePool & operator=(const RPagePool &)=delete
void ReturnPage(const RPage &page)
Give back a page to the pool and decrease the reference counter.
Definition: RPagePool.cxx:39
RPagePool(const RPagePool &)=delete
RPage GetPage(ColumnId_t columnId, NTupleSize_t globalIndex)
Tries to find the page corresponding to column and index in the cache.
Definition: RPagePool.cxx:62
std::vector< RPage > fPages
TODO(jblomer): should be an efficient index structure that allows.
Definition: RPagePool.hxx:54
void RegisterPage(const RPage &page, const RPageDeleter &deleter)
Adds a new page to the pool together with the function to free its space.
Definition: RPagePool.cxx:23
A page is a slice of a column that is mapped into memory.
Definition: RPage.hxx:41
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
Definition: RNTupleUtil.hxx:77
std::int64_t ColumnId_t
Uniquely identifies a physical column within the scope of the current process, used to tag pages.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...