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>
20 #include <ROOT/RPageAllocator.hxx>
21 #include <ROOT/RNTupleUtil.hxx>
22 
23 #include <cstddef>
24 #include <mutex>
25 #include <vector>
26 
27 namespace ROOT {
28 namespace Experimental {
29 
30 namespace 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 
38 The page pool provides memory tracking for data written into an ntuple or read from an ntuple. Adding and removing
39 pages is thread-safe. The page pool does not allocate the memory -- allocation and deallocation is performed by the
40 page storage, which might do it in a way optimized to the backing store (e.g., mmap()).
41 Multiple page caches can coexist.
42 
43 TODO(jblomer): it should be possible to register pages and to find them by column and index; this would
44 facilitate pre-filling a cache, e.g. by read-ahead.
45 */
46 // clang-format on
47 class RPagePool {
48 private:
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 
59 public:
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
ROOT::Experimental::Detail::RPagePool::RPagePool
RPagePool(const RPagePool &)=delete
ROOT::Experimental::Detail::RPage
A page is a slice of a column that is mapped into memory.
Definition: RPage.hxx:41
RPage.hxx
ROOT::Experimental::Detail::RPagePool::RegisterPage
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
ROOT::Experimental::Detail::RPagePool::~RPagePool
~RPagePool()=default
ROOT::Experimental::Detail::RPagePool::fLock
std::mutex fLock
Definition: RPagePool.hxx:57
ROOT::Experimental::NTupleSize_t
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
Definition: RNTupleUtil.hxx:55
ROOT::Experimental::Detail::RPagePool::GetPage
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
ROOT::Experimental::Detail::RPagePool::ReturnPage
void ReturnPage(const RPage &page)
Give back a page to the pool and decrease the reference counter.
Definition: RPagePool.cxx:39
ROOT::Experimental::Detail::RPagePool::operator=
RPagePool & operator=(const RPagePool &)=delete
ROOT::Experimental::Detail::RPagePool::fPages
std::vector< RPage > fPages
TODO(jblomer): should be an efficient index structure that allows.
Definition: RPagePool.hxx:54
ROOT::Experimental::Detail::RPagePool::RPagePool
RPagePool()=default
ROOT::Experimental::Detail::RPageDeleter
A closure that can free the memory associated with a mapped page.
Definition: RPageAllocator.hxx:39
ROOT::Experimental::Detail::RPagePool::fReferences
std::vector< std::int32_t > fReferences
Definition: RPagePool.hxx:55
ROOT::Experimental::Detail::RPagePool
A thread-safe cache of column pages.
Definition: RPagePool.hxx:47
RNTupleUtil.hxx
ROOT::Experimental::RClusterIndex
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
Definition: RNTupleUtil.hxx:95
ROOT::Experimental::Detail::RPagePool::fDeleters
std::vector< RPageDeleter > fDeleters
Definition: RPagePool.hxx:56
RPageAllocator.hxx
ROOT::Experimental::Detail::RPagePool::PreloadPage
void PreloadPage(const RPage &page, const RPageDeleter &deleter)
Like RegisterPage() but the reference counter is initialized to 0.
Definition: RPagePool.cxx:31
ROOT::Experimental::ColumnId_t
std::int64_t ColumnId_t
Uniquely identifies a physical column within the scope of the current process, used to tag pages.
Definition: RNTupleUtil.hxx:87
ROOT
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: EExecutionPolicy.hxx:4