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

#include <XrdOssMio.hh>

Collaboration diagram for XrdOssMio:

Static Public Member Functions

static void Display (XrdSysError &Eroute)
static char isAuto ()
static char isOn ()
static XrdOssMioFileMap (char *path, int fd, int opts)
static void * preLoad (void *arg)
static void Recycle (XrdOssMioFile *mp)
static void Set (int V_off, int V_preld, int V_check)
static void Set (long long V_max)

Detailed Description

Definition at line 44 of file XrdOssMio.hh.

Member Function Documentation

◆ Display()

void XrdOssMio::Display ( XrdSysError & Eroute)
static

Definition at line 80 of file XrdOssMio.cc.

81{
82 char buff[1080];
83 snprintf(buff, sizeof(buff), " oss.memfile %s%s%s max %lld",
84 (MM_on ? "" : "off "),
85 (MM_preld ? "preload" : ""),
86 (MM_chk ? "check xattr" : ""), MM_max);
87 Eroute.Say(buff);
88}
void Say(const char *text1, const char *text2=0, const char *txt3=0, const char *text4=0, const char *text5=0, const char *txt6=0)

References XrdSysError::Say().

Referenced by XrdOssSys::Config_Display().

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

◆ isAuto()

char XrdOssMio::isAuto ( )
inlinestatic

Definition at line 49 of file XrdOssMio.hh.

49{return MM_chk;}

Referenced by XrdOssSys::ConfigMio().

Here is the caller graph for this function:

◆ isOn()

char XrdOssMio::isOn ( )
inlinestatic

Definition at line 51 of file XrdOssMio.hh.

51{return MM_on;}

Referenced by XrdOssSys::ConfigMio().

Here is the caller graph for this function:

◆ Map()

XrdOssMioFile * XrdOssMio::Map ( char * path,
int fd,
int opts )
static

Definition at line 94 of file XrdOssMio.cc.

95{
96#if defined(_POSIX_MAPPED_FILES)
97 EPNAME("MioMap");
98 XrdSysMutexHelper mapMutex;
99 struct stat statb;
100 XrdOssMioFile *mp;
101 void *thefile;
102 char hashname[64];
103
104// Get the size of the file
105//
106 if (fstat(fd, &statb))
107 {OssEroute.Emsg("Mio", errno, "fstat file", path);
108 return 0;
109 }
110
111// Develop hash name for this file
112//
113 int st_devSZ = sizeof(statb.st_dev);
114 XrdOucUtils::bin2hex((char *)&statb.st_dev, st_devSZ,
115 hashname, sizeof(hashname), false);
116 st_devSZ <<= 1;
117 XrdOucUtils::bin2hex((char *)&statb.st_ino, int(sizeof(statb.st_ino)),
118 hashname+st_devSZ, sizeof(hashname) - st_devSZ, false);
119
120// Because of potntial race conditions, we must serialize execution
121//
122 mapMutex.Lock(&MM_Mutex);
123
124// Check if we already have this mapping
125//
126 if ((mp = MM_Hash.Find(hashname)))
127 {DEBUG("Reusing mmap; usecnt=" <<mp->inUse <<" path=" <<path);
128 if (!(mp->Status & OSSMIO_MPRM) && !mp->inUse) Reclaim(mp);
129 mp->inUse++;
130 return mp;
131 }
132
133// Check if memory will be over committed
134//
135 if (MM_inuse + statb.st_size > MM_max)
136 {if (!Reclaim(statb.st_size))
137 {OssEroute.Emsg("Mio", "Unable to reclaim enough storage to mmap",path);
138 return 0;
139 }
140 }
141 MM_inuse += statb.st_size;
142
143// Memory map the file
144//
145 if ((thefile = mmap(0,statb.st_size,PROT_READ,MAP_PRIVATE,fd,0))==MAP_FAILED)
146 {OssEroute.Emsg("Mio", errno, "mmap file", path);
147 return 0;
148 } else {DEBUG("mmap " <<statb.st_size <<" bytes for " <<path);}
149
150// Lock the file, if need be. Turn off locking if we don't have privs
151//
152 if (MM_okmlock && (opts & OSSMIO_MLOK))
153 {if (mlock((char *)thefile, statb.st_size))
154 { if (errno == ENOSYS || errno == ENOTSUP)
155 {OssEroute.Emsg("Mio","mlock() not supported; feature disabled.");
156 MM_okmlock = 0;
157 }
158 else if (errno == EPERM)
159 {OssEroute.Emsg("Mio","Not privileged for mlock(); feature disabled.");
160 MM_okmlock = 0;
161 }
162 else OssEroute.Emsg("Mio", errno, "mlock file", path);
163 } else {DEBUG("Locked " <<statb.st_size <<" bytes for " <<path);}
164 }
165
166// get a new file object
167//
168 if (!(mp = new XrdOssMioFile(hashname)))
169 {OssEroute.Emsg("Mio", "Unable to allocate mmap file object for", path);
170 munmap((char *)thefile, statb.st_size);
171 return 0;
172 }
173
174// Complete the object here
175//
176 mp->Base = thefile;
177 mp->Size = statb.st_size;
178 mp->Dev = statb.st_dev;
179 mp->Ino = statb.st_ino;
180 mp->Status = opts;
181
182// Add the mapping to our hash table
183//
184 if (MM_Hash.Add(hashname, mp))
185 {OssEroute.Emsg("Mio", "Hash add failed for", path);
186 munmap((char *)thefile, statb.st_size);
187 delete mp;
188 return 0;
189 }
190
191// If this is a permanent file, place it on the permanent queue
192//
193 if (opts & OSSMIO_MPRM)
194 {mp->Next = MM_Perm; MM_Perm = mp;
195 DEBUG("Placed file on permanent queue " <<path);
196 }
197
198// If this file is to be preloaded, start it now
199//
200 if (MM_preld && mp->inUse == 1)
201 {pthread_t tid;
202 int retc;
203 mp->inUse++;
204 if ((retc = XrdSysThread::Run(&tid, preLoad, (void *)mp)) < 0)
205 {OssEroute.Emsg("Mio", retc, "creating mmap preload thread");
206 mp->inUse--;
207 }
208 else DEBUG("started mmap preload thread; tid=" <<(unsigned long)tid);
209 }
210
211// All done
212//
213 return mp;
214#else
215 return 0;
216#endif
217}
#define DEBUG(x)
#define EPNAME(x)
XrdSysError OssEroute
#define OSSMIO_MLOK
Definition XrdOssMio.hh:40
#define OSSMIO_MPRM
Definition XrdOssMio.hh:42
#define fstat(a, b)
Definition XrdPosix.hh:57
#define stat(a, b)
Definition XrdPosix.hh:96
struct myOpts opts
static void * preLoad(void *arg)
Definition XrdOssMio.cc:223
static char * bin2hex(char *inbuff, int dlen, char *buff, int blen, bool sep=true)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
void Lock(XrdSysMutex *Mutex)
static int Run(pthread_t *, void *(*proc)(void *), void *arg, int opts=0, const char *desc=0)

References XrdOucUtils::bin2hex(), DEBUG, EPNAME, fstat, XrdSysMutexHelper::Lock(), opts, OssEroute, OSSMIO_MLOK, OSSMIO_MPRM, preLoad(), XrdSysThread::Run(), and stat.

Referenced by XrdOssFile::Open().

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

◆ preLoad()

void * XrdOssMio::preLoad ( void * arg)
static

Definition at line 223 of file XrdOssMio.cc.

224{
225 XrdOssMioFile *mp = (XrdOssMioFile *)arg;
226 char *Base = (char *)(mp->Base);
227 char *Bend = Base + mp->Size;
228 long long MY_pagsz = MM_pagsz;
229
230// Reference each page until we are done. This is somewhat obtuse but we
231// are trying to keep the compiler from optimizing out the code.
232//
233 while(Base < Bend) Base += (*Base ? MY_pagsz : MM_pagsz);
234
235// All done
236//
237 Recycle(mp);
238 return (void *)0;
239}
static void Recycle(XrdOssMioFile *mp)
Definition XrdOssMio.cc:294

References Recycle().

Referenced by Map().

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

◆ Recycle()

void XrdOssMio::Recycle ( XrdOssMioFile * mp)
static

Definition at line 294 of file XrdOssMio.cc.

295{
296 XrdSysMutexHelper mmMutex(&MM_Mutex);
297
298// Decrement the use count
299//
300 mp->inUse--;
301 if (mp->inUse < 0)
302 {OssEroute.Emsg("Mio", "MM usecount underflow for ", mp->HashName);
303 mp->inUse = 0;
304 } else if (mp->inUse > 0) return;
305
306// If this is not a kept mapping, put it on the reclaim list
307//
308 if (!(mp->Status & OSSMIO_MPRM))
309 {if (MM_IdleLast) MM_IdleLast->Next = mp;
310 else MM_Idle = mp;
311 MM_IdleLast = mp;
312 mp->Next = 0;
313 }
314}

References OssEroute, and OSSMIO_MPRM.

Referenced by XrdOssFile::Close(), and preLoad().

Here is the caller graph for this function:

◆ Set() [1/2]

void XrdOssMio::Set ( int V_off,
int V_preld,
int V_check )
static

Definition at line 320 of file XrdOssMio.cc.

321{
322 if (V_on >= 0) MM_on = (char)V_on;
323 if (V_preld >= 0) MM_preld = (char)V_preld;
324 if (V_check >= 0) MM_chk = (char)V_check;
325}

Referenced by XrdOssSys::ConfigMio(), and XrdOssSys::xmemf().

Here is the caller graph for this function:

◆ Set() [2/2]

void XrdOssMio::Set ( long long V_max)
static

Definition at line 327 of file XrdOssMio.cc.

328{
329 if (V_max > 0) MM_max = V_max;
330 else if (V_max < 0) MM_max = MM_pagsz*MM_pages*(-V_max)/100;
331}

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