XRootD
Loading...
Searching...
No Matches
XrdRmcReal Class Reference

#include <XrdRmcReal.hh>

+ Inheritance diagram for XrdRmcReal:
+ Collaboration diagram for XrdRmcReal:

Public Member Functions

 XrdRmcReal (int &rc, XrdRmc::Parms &Parms, XrdOucCacheIO::aprParms *aprP=0)
 
 ~XrdRmcReal ()
 
XrdOucCacheIOAttach (XrdOucCacheIO *ioP, int Options=0)
 
void PreRead ()
 
- Public Member Functions inherited from XrdOucCache
 XrdOucCache (const char *ctype)
 
virtual ~XrdOucCache ()
 Destructor.
 
virtual int LocalFilePath (const char *url, char *buff=0, int blen=0, LFP_Reason why=ForAccess, bool forall=false)
 
virtual int Prepare (const char *url, int oflags, mode_t mode)
 
virtual int Rename (const char *oldp, const char *newp)
 
virtual int Rmdir (const char *dirp)
 
virtual int Stat (const char *url, struct stat &sbuff)
 
virtual int Truncate (const char *path, off_t size)
 
virtual int Unlink (const char *path)
 
virtual int Xeq (XeqCmd cmd, char *arg, int arglen)
 

Friends

class XrdRmcData
 

Additional Inherited Members

- Public Types inherited from XrdOucCache
enum  LFP_Reason {
  ForAccess =0 ,
  ForInfo ,
  ForPath
}
 
enum  XeqCmd { xeqNoop = 0 }
 
- Public Attributes inherited from XrdOucCache
const char CacheType [8]
 A 1-to-7 character cache type identifier (usually pfc or rmc).
 
XrdOucCacheStats Statistics
 
- Static Public Attributes inherited from XrdOucCache
static const int optFIS = 0x0001
 File is structured (e.g. root file)
 
static const int optNEW = 0x0014
 File is new -> optRW (o/w read or write)
 
static const int optRW = 0x0004
 File is read/write (o/w read/only)
 
static const int optWIN = 0x0024
 File is new -> optRW use write-in cache.
 

Detailed Description

Definition at line 39 of file XrdRmcReal.hh.

Constructor & Destructor Documentation

◆ XrdRmcReal()

XrdRmcReal::XrdRmcReal ( int & rc,
XrdRmc::Parms & Parms,
XrdOucCacheIO::aprParms * aprP = 0 )

Definition at line 58 of file XrdRmcReal.cc.

60 : XrdOucCache("rmc"),
61 Slots(0), Slash(0), Base((char *)MAP_FAILED), Dbg(0), Lgs(0),
62 AZero(0), Attached(0), prFirst(0), prLast(0),
63 prReady(0), prStop(0), prNum(0)
64{
65 size_t Bytes;
66 int n, minPag, isServ = ParmV.Options & XrdRmc::isServer;
67
68// Copy over options
69//
70 rc = ENOMEM;
71 Options = ParmV.Options;
72 if (Options & XrdRmc::Debug) Lgs = Dbg = (Options & XrdRmc::Debug);
73 if (Options & XrdRmc::logStats) Lgs = 1;
74 minPag = (ParmV.minPages <= 0 ? 256 : ParmV.minPages);
75
76// Establish maximum number of attached files
77//
78 if (ParmV.MaxFiles <= 0) maxFiles = (isServ ? 16384 : 256);
79 else {maxFiles = (ParmV.MaxFiles > 32764 ? 32764 : ParmV.MaxFiles);
80 maxFiles = maxFiles/sizeof(int)*sizeof(int);
81 if (!maxFiles) maxFiles = 256;
82 }
83
84// Adjust segment size to be a power of two and atleast 4k.
85//
86 if (ParmV.PageSize <= 0) SegSize = 32768;
87 else if (!(SegSize = ParmV.PageSize & ~0xfff)) SegSize = 4096;
88// else if (SegSize > 16*1024*1024) SegSize = 16*1024*1024;
89 SegShft = 0; n = SegSize-1;
90 while(n) {SegShft++; n = n >> 1;}
91 SegSize = 1<<SegShft;
92
93// The max to cache is also adjusted accrodingly based on segment size.
94//
95 OffMask = SegSize-1;
96 SegCnt = (ParmV.CacheSize > 0 ? ParmV.CacheSize : 104857600)/SegSize;
97 if (SegCnt < minPag) SegCnt = minPag;
98 if (ParmV.Max2Cache < SegSize) maxCache = SegSize;
99 else maxCache = ParmV.Max2Cache/SegSize*SegSize;
100 SegFull = (Options & XrdRmc::isServer ? XrdRmcSlot::lenMask : SegSize);
101
102// Allocate the cache plus the cache hash table
103//
104 Bytes = static_cast<size_t>(SegSize)*SegCnt;
105 Base = (char *)mmap(0, Bytes + SegCnt*sizeof(int), PROT_READ|PROT_WRITE,
106 MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
107 if (Base == MAP_FAILED) {rc = errno; return;}
108 Slash = (int *)(Base + Bytes); HNum = SegCnt/2*2-1;
109
110// Now allocate the actual slots. We add additional slots to map files. These
111// do not have any memory backing but serve as anchors for memory mappings.
112//
113 if (!(Slots = new XrdRmcSlot[SegCnt+maxFiles])) return;
114 XrdRmcSlot::Init(Slots, SegCnt);
115
116// Set pointers to be able to keep track of CacheIO objects and map them to
117// CacheData objects. The hash table will be the first page of slot memory.
118//
119 hTab = (int *)Base;
120 hMax = SegSize/sizeof(int);
121 sBeg = sFree = SegCnt;
122 sEnd = SegCnt + maxFiles;
123
124// Now iniialize the slots to be used for the CacheIO objects
125//
126 for (n = sBeg; n < sEnd; n++)
127 {Slots[n].Own.Next = Slots[n].Own.Prev = n;
128 Slots[n].HLink = n+1;
129 }
130 Slots[sEnd-1].HLink = 0;
131
132// Setup the pre-readers if pre-read is enabled
133//
134 if (Options & XrdRmc::canPreRead)
135 {pthread_t tid;
136 n = (Options & XrdRmc::isServer ? 9 : 3);
137 while(n--)
138 {if (XrdSysThread::Run(&tid, XrdRmcRealPRXeq, (void *)this,
139 0, "Prereader")) break;
140 prNum++;
141 }
142 if (aprP && prNum) XrdRmcData::setAPR(aprDefault, *aprP, SegSize);
143 }
144
145// All done
146//
147 rc = 0;
148}
void * XrdRmcRealPRXeq(void *parg)
Definition XrdRmcReal.cc:52
XrdOucCache(const char *ctype)
static int setAPR(aprParms &Dest, aprParms &Src, int pSize)
static const int lenMask
static void Init(XrdRmcSlot *Base, int Num)
Definition XrdRmcSlot.hh:63
static const int Debug
Produce some debug messages (levels 0, 1, 2, or 3)
Definition XrdRmc.hh:136
static const int logStats
Display statistics upon detach.
Definition XrdRmc.hh:127
static const int isServer
This is server application; not a user application.
Definition XrdRmc.hh:118
static const int canPreRead
Enable pre-read operations (o/w ignored)
Definition XrdRmc.hh:124
static int Run(pthread_t *, void *(*proc)(void *), void *arg, int opts=0, const char *desc=0)

References XrdOucCache::XrdOucCache(), XrdRmc::Parms::CacheSize, XrdRmc::canPreRead, XrdRmc::Debug, if(), XrdRmcSlot::Init(), XrdRmc::isServer, XrdRmcSlot::lenMask, XrdRmc::logStats, XrdRmc::Parms::Max2Cache, XrdRmc::Parms::MaxFiles, XrdRmc::Parms::minPages, XrdRmc::Parms::Options, XrdRmc::Parms::PageSize, XrdSysThread::Run(), XrdRmcData::setAPR(), and XrdRmcRealPRXeq().

+ Here is the call graph for this function:

◆ ~XrdRmcReal()

XrdRmcReal::~XrdRmcReal ( )

Definition at line 154 of file XrdRmcReal.cc.

155{
156// Wait for all attachers to go away
157//
158 CMutex.Lock();
159 if (Attached)
160 {XrdSysSemaphore aZero(0);
161 AZero = &aZero;
162 CMutex.UnLock();
163 aZero.Wait();
164 CMutex.Lock();
165 }
166
167// If any preread threads exist, then stop them now
168//
169 prMutex.Lock();
170 if (prNum)
171 {XrdSysSemaphore prDone(0);
172 prStop = &prDone;
173 prReady.Post();
174 prMutex.UnLock();
175 prDone.Wait();
176 prMutex.Lock();
177 }
178
179// Delete the slots
180//
181 delete Slots; Slots = 0;
182
183// Unmap cache memory and associated hash table
184//
185 if (Base != MAP_FAILED)
186 {munmap(Base, static_cast<size_t>(SegSize)*SegCnt);
187 Base = (char *)(MAP_FAILED);
188 }
189
190// Release all locks, we are done
191//
192 prMutex.UnLock();
193 CMutex.UnLock();
194}

References XrdSysSemaphore::Post(), and XrdSysSemaphore::Wait().

+ Here is the call graph for this function:

Member Function Documentation

◆ Attach()

XrdOucCacheIO * XrdRmcReal::Attach ( XrdOucCacheIO * ioP,
int Options = 0 )
virtual

Implements XrdOucCache.

Definition at line 200 of file XrdRmcReal.cc.

201{
202 static int Inst = 0;
203 XrdSysMutexHelper Monitor(CMutex);
204 XrdRmcData *dP;
205 int Cnt, Fnum = 0, theOpts = Opts & optRW;
206
207// Check if we are being deleted
208//
209 if (AZero) {errno = ECANCELED; return ioP;}
210
211// Setup structured/unstructured option
212//
213 if ((Opts & optFIS) || (Options & XrdRmc::isStructured)) theOpts |= optFIS;
214
215// Get an entry in the filename table.
216//
217 if (!(Cnt = ioAdd(ioP, Fnum)))
218 {errno = EMFILE;
219 return ioP;
220 }
221
222// If this is the first addition then we need to get a new CacheData object.
223// Otherwise, simply reuse the previous cache data object.
224//
225 if (Cnt != 1) dP = Slots[Fnum].Status.Data;
226 else {long long vNum = static_cast<long long>(Fnum-SegCnt) << Shift
227 | (static_cast<long long>(Inst) << (Shift - 16));
228 Inst = (Inst+1) & 0xffff;
229 if ((dP = new XrdRmcData(this, ioP, vNum, theOpts)))
230 {Attached++; Slots[Fnum].Status.Data = dP;}
231 }
232
233// Some debugging
234//
235 if (Dbg) std::cerr <<"Cache: Attached " <<Cnt <<'/' <<Attached <<' '
236 <<std::hex << Fnum <<std::dec <<' ' <<ioP->Path() <<std::endl;
237
238// All done
239//
240 if (!dP) {errno = ENOMEM; return ioP;}
241 return (XrdOucCacheIO *)dP;
242}
virtual const char * Path()=0
static const int optRW
File is read/write (o/w read/only)
static const int optFIS
File is structured (e.g. root file)
friend class XrdRmcData
Definition XrdRmcReal.hh:41
static const int isStructured
Definition XrdRmc.hh:121

References XrdRmc::isStructured, XrdOucCache::optFIS, XrdOucCache::optRW, XrdOucCacheIO::Path(), and XrdRmcData.

+ Here is the call graph for this function:

◆ PreRead()

void XrdRmcReal::PreRead ( )

Definition at line 456 of file XrdRmcReal.cc.

457{
458 prTask *prP;
459
460// Simply wait and dispatch elements
461//
462 if (Dbg) std::cerr <<"Cache: preread thread started; now " <<prNum <<std::endl;
463 while(1)
464 {prReady.Wait();
465 prMutex.Lock();
466 if (prStop) break;
467 if ((prP = prFirst))
468 {if (!(prFirst = prP->Next)) prLast = 0;
469 prMutex.UnLock();
470 prP->Data->Preread();
471 } else prMutex.UnLock();
472 }
473
474// The cache is being deleted, wind down the prereads
475//
476 prNum--;
477 if (prNum > 0) prReady.Post();
478 else prStop->Post();
479 if (Dbg) std::cerr <<"Cache: preread thread exited; left " <<prNum <<std::endl;
480 prMutex.UnLock();
481}

References XrdRmcData::Preread().

Referenced by XrdRmcRealPRXeq().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ XrdRmcData

friend class XrdRmcData
friend

Definition at line 41 of file XrdRmcReal.hh.

References ec, Path, and XrdRmcData.

Referenced by Attach(), and XrdRmcData.


The documentation for this class was generated from the following files: