Loading...
Searching...
No Matches
XrdBuffManager Class Reference

`#include <XrdBuffer.hh>`

Collaboration diagram for XrdBuffManager:

## Public Member Functions

| XrdBuffManager (int minrst=20 *60)
| ~XrdBuffManager ()
void | Init ()
int | MaxSize ()
XrdBuffer * | Obtain (int bsz)
int | Recalc (int bsz)
void | Release (XrdBuffer *bp)
void | Reshape ()
void | Set (int maxmem=-1, int minw=-1)
int | Stats (char *buff, int blen, int do_sync=0)

## Detailed Description

Definition at line 71 of file XrdBuffer.hh.

## Constructor & Destructor Documentation

## XrdBuffManager()

XrdBuffManager::XrdBuffManager | ( | int | minrst = 20*60 | ) |

Definition at line 78 of file XrdBuffer.cc.

:
slots(XRD_BUCKETS),
shift(XRD_BUSHIFT),
pagsz(getpagesize()),
maxsz(1<<(XRD_BUSHIFT+XRD_BUCKETS-1)),
Reshaper(0, "buff reshaper")
{
// Clear everything to zero
//
totbuf = 0;
totreq = 0;
totalo = 0;
totadj = 0;
#ifdef _SC_PHYS_PAGES
maxalo = static_cast<long long>(pagsz)/8
* static_cast<long long>(sysconf(_SC_PHYS_PAGES));
#else
maxalo = 0x7ffffff;
#endif
rsinprog = 0;
minrsw = minrst;
memset(static_cast<void *>(bucket), 0, sizeof(bucket));
}
XRD_BUSHIFT
#define XRD_BUSHIFT
Definition XrdBuffer.hh:67
XRD_BUCKETS
#define XRD_BUCKETS
Definition XrdBuffer.hh:66

References XRD_BUCKETS, and XRD_BUSHIFT.

## ~XrdBuffManager()

XrdBuffManager::~XrdBuffManager | ( |  | ) |

Definition at line 107 of file XrdBuffer.cc.

{
XrdBuffer *bP;
for (int i = 0; i < XRD_BUCKETS; i++)
{while((bP = bucket[i].bnext))
{bucket[i].bnext = bP->next;
delete bP;
}
bucket[i].numbuf = 0;
}
}

References XRD_BUCKETS.

## Member Function Documentation

## Init()

void XrdBuffManager::Init | ( |  | ) |

Definition at line 124 of file XrdBuffer.cc.

{
pthread_t tid;
int rc;
// Start the reshaper thread
//
if ((rc = XrdSysThread::Run(&tid, XrdReshaper, static_cast<void *>(this), 0,
"Buffer Manager reshaper")))
Log.Emsg("BuffManager", rc, "create reshaper thread");
}
XrdReshaper
void * XrdReshaper(void *pp)
Definition XrdBuffer.cc:48
XrdSysError::Emsg
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition XrdSysError.cc:95
XrdSysThread::Run
static int Run(pthread_t *, void *(*proc)(void *), void *arg, int opts=0, const char *desc=0)
Definition XrdSysPthread.cc:307
XrdGlobal::Log
XrdSysError Log
Definition XrdConfig.cc:113

References XrdGlobal::Log, XrdSysThread::Run(), and XrdReshaper().

Here is the call graph for this function:

## MaxSize()

int XrdBuffManager::MaxSize | ( |  | ) |

inline

Definition at line 83 of file XrdBuffer.hh.

{return maxsz;}

## Obtain()

XrdBuffer * XrdBuffManager::Obtain | ( | int | bsz | ) |

Definition at line 140 of file XrdBuffer.cc.

{
XrdBuffer *bp;
char *memp;
int mk, pk, bindex;
// Make sure the request is within our limits
//
if (sz <= 0) return 0;
if (sz > maxsz) return xlBuff.Obtain(sz);
// Calculate bucket index
//
mk = sz >> shift;
bindex = XrdOucUtils::Log2(mk);
mk = minBuffSz << bindex;
if (mk < sz) {bindex++; mk = mk << 1;}
if (bindex >= slots) return 0; // Should never happen!
// Obtain a lock on the bucket array and try to give away an existing buffer
//
Reshaper.Lock();
totreq++;
bucket[bindex].numreq++;
if ((bp = bucket[bindex].bnext))
{bucket[bindex].bnext = bp->next; bucket[bindex].numbuf--;}
Reshaper.UnLock();
// Check if we really allocated a buffer
//
if (bp) return bp;
// Allocate a chunk of aligned memory
//
pk = (mk < pagsz ? mk : pagsz);
if (posix_memalign((void **)&memp, pk, mk)) return 0;
// Wrap the memory with a buffer object
//
if (!(bp = new XrdBuffer(memp, mk, bindex))) {free(memp); return 0;}
// Update statistics
//
Reshaper.Lock();
totbuf++;
if ((totalo += mk) > maxalo && !rsinprog)
{rsinprog = 1; Reshaper.Signal();}
Reshaper.UnLock();
return bp;
}
XrdBuffXL::Obtain
XrdBuffer * Obtain(int bsz)
Definition XrdBuffXL.cc:99
XrdOucUtils::Log2
static int Log2(unsigned long long n)
Definition XrdOucUtils.cc:895
XrdGlobal::xlBuff
XrdBuffXL xlBuff
Definition XrdBuffer.cc:68

References XrdOucUtils::Log2(), and XrdGlobal::xlBuff.

Here is the call graph for this function:

## Recalc()

int XrdBuffManager::Recalc | ( | int | bsz | ) |

Definition at line 195 of file XrdBuffer.cc.

{
int mk, bindex;
// Make sure the request is within our limits
//
if (sz <= 0) return 0;
if (sz > maxsz) return xlBuff.Recalc(sz);
// Calculate bucket index
//
mk = sz >> shift;
bindex = XrdOucUtils::Log2(mk);
mk = minBuffSz << bindex;
if (mk < sz) {bindex++; mk = mk << 1;}
if (bindex >= slots) return 0; // Should never happen!
// All done, return the actual size we would have allocated
//
return mk;
}
XrdBuffXL::Recalc
int Recalc(int bsz)
Definition XrdBuffXL.cc:155

References XrdOucUtils::Log2(), and XrdGlobal::xlBuff.

Here is the call graph for this function:

## Release()

void XrdBuffManager::Release | ( | XrdBuffer * | bp | ) |

Definition at line 221 of file XrdBuffer.cc.

{
int bindex = bp->bindex;
// Check if we should release this via the big buffer object
//
if (bindex >= slots) {xlBuff.Release(bp); return;}
// Obtain a lock on the bucket array and reclaim the buffer
//
Reshaper.Lock();
bp->next = bucket[bp->bindex].bnext;
bucket[bp->bindex].bnext = bp;
bucket[bindex].numbuf++;
Reshaper.UnLock();
}
XrdBuffXL::Release
void Release(XrdBuffer *bp)
Definition XrdBuffXL.cc:182

References XrdGlobal::xlBuff.

## Reshape()

void XrdBuffManager::Reshape | ( |  | ) |

Definition at line 242 of file XrdBuffer.cc.

{
int i, bufprof[XRD_BUCKETS], numfreed;
time_t delta, lastshape = time(0);
long long memslot, memhave, memtarget = (long long)(.80*(float)maxalo);
XrdSysTimer Timer;
float requests, buffers;
XrdBuffer *bp;
// This is an endless loop to periodically reshape the buffer pool
//
while(1)
{Reshaper.Lock();
while(Reshaper.Wait(minrsw) && totalo <= maxalo)
{TRACE(MEM, "Reshaper has " <<(totalo>>10) <<"K; target " <<(memtarget>>10) <<"K");}
if ((delta = (time(0) - lastshape)) < minrsw)
{Reshaper.UnLock();
Timer.Wait((minrsw-delta)*1000);
Reshaper.Lock();
}
// We have the lock so compute the request profile
//
if (totreq > slots)
{requests = (float)totreq;
buffers = (float)totbuf;
for (i = 0; i < slots; i++)
{bufprof[i] = (int)(buffers*(((float)bucket[i].numreq)/requests));
bucket[i].numreq = 0;
}
totreq = 0; memhave = totalo;
} else memhave = 0;
Reshaper.UnLock();
// Reshape the buffer pool to agree with the request profile
//
memslot = maxsz; numfreed = 0;
for (i = slots-1; i >= 0 && memhave > memtarget; i--)
{Reshaper.Lock();
while(bucket[i].numbuf > bufprof[i])
if ((bp = bucket[i].bnext))
{bucket[i].bnext = bp->next;
delete bp;
bucket[i].numbuf--; numfreed++;
memhave -= memslot; totalo -= memslot;
totbuf--;
} else {bucket[i].numbuf = 0; break;}
Reshaper.UnLock();
memslot = memslot>>1;
}
// All done
//
totadj += numfreed;
TRACE(MEM, "Pool reshaped; " <<numfreed <<" freed; have " <<(memhave>>10) <<"K; target " <<(memtarget>>10) <<"K");
lastshape = time(0);
rsinprog = 0; // No need to lock, we're the only ones now setting it
xlBuff.Trim(); // Trim big buffers
}
}
TRACE
#define TRACE(act, x)
Definition XrdTrace.hh:63
XrdBuffXL::Trim
void Trim()
Definition XrdBuffXL.cc:221
XrdSysTimer::Wait
static void Wait(int milliseconds)
Definition XrdSysTimer.cc:227

References TRACE, XrdSysTimer::Wait(), XrdGlobal::xlBuff, and XRD_BUCKETS.

Referenced by XrdReshaper().

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

## Set()

void XrdBuffManager::Set | ( | int | maxmem = -1,
|  | int | minw = -1 )

Definition at line 308 of file XrdBuffer.cc.

{
// Obtain a lock and set the values
//
Reshaper.Lock();
if (maxmem > 0) maxalo = (long long)maxmem;
if (minw > 0) minrsw = minw;
Reshaper.UnLock();
}

## Stats()

int XrdBuffManager::Stats | ( | char * | buff,
|  | int | blen,
|  | int | do_sync = 0 )

Definition at line 323 of file XrdBuffer.cc.

{
static const char statfmt[] = "<stats id=\"buff\"><reqs>%d</reqs>"
"<mem>%lld</mem><buffs>%d</buffs><adj>%d</adj>%s</stats>";
char xlStats[1024];
int nlen;
// If only size wanted, return it
//
if (!buff) return sizeof(statfmt) + 16*4 + xlBuff.Stats(0,0);
// Return formatted stats
//
if (do_sync) Reshaper.Lock();
xlBuff.Stats(xlStats, sizeof(xlStats), do_sync);
nlen = snprintf(buff,blen,statfmt,totreq,totalo,totbuf,totadj,xlStats);
if (do_sync) Reshaper.UnLock();
return nlen;
}
XrdBuffXL::Stats
int Stats(char *buff, int blen, int do_sync=0)
Definition XrdBuffXL.cc:199

References XrdGlobal::xlBuff.

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

- XrdBuffer.hh
- XrdBuffer.cc