Loading...
Searching...
No Matches
XrdBuffXL Class Reference

`#include <XrdBuffXL.hh>`

Collaboration diagram for XrdBuffXL:

## Public Member Functions

| XrdBuffXL ()
| ~XrdBuffXL ()
void | Init (int maxMSZ)
int | MaxSize ()
XrdBuffer * | Obtain (int bsz)
int | Recalc (int bsz)
void | Release (XrdBuffer *bp)
int | Stats (char *buff, int blen, int do_sync=0)
void | Trim ()

## Detailed Description

Definition at line 37 of file XrdBuffXL.hh.

## Constructor & Destructor Documentation

## XrdBuffXL()

XrdBuffXL::XrdBuffXL | ( |  | ) |

Definition at line 56 of file XrdBuffXL.cc.

: bucket(0), totalo(0), pagsz(getpagesize()), slots(0),
maxsz(1<<(XRD_BUSHIFT+XRD_BUCKETS-1)), totreq(0)
{ }
XRD_BUSHIFT
#define XRD_BUSHIFT
Definition XrdBuffer.hh:67
XRD_BUCKETS
#define XRD_BUCKETS
Definition XrdBuffer.hh:66

References XRD_BUCKETS, and XRD_BUSHIFT.

## ~XrdBuffXL()

XrdBuffXL::~XrdBuffXL | ( |  | ) |

inline

Definition at line 57 of file XrdBuffXL.hh.

{} // The buffmanager is never deleted

## Member Function Documentation

## Init()

void XrdBuffXL::Init | ( | int | maxMSZ | ) |

Definition at line 64 of file XrdBuffXL.cc.

{
unsigned int lg2;
int chunksz;
// If this is a duplicate call, delete the previous setup
//
if (bucket) {delete [] bucket; bucket = 0;}
// Check if this is too small for us
//
if (maxMSZ <= iniBuffSz) {maxsz = iniBuffSz; return;}
// Check if this is too large for us (1GB limit) and adjust
//
if (maxMSZ > maxBuffSz) maxMSZ = maxBuffSz;
// Calculate how many buckets we need to have (note we trim this down
//
chunksz = maxMSZ >> minBShift;
lg2 = XrdOucUtils::Log2(chunksz);
chunksz = 1<<(lg2+minBShift);
if (chunksz < maxMSZ) {lg2++; maxsz = chunksz << 1;}
else maxsz = chunksz;
// Allocate a bucket array
//
bucket = new BuckVec[lg2+1];
slots = lg2+1;
}
XrdOucUtils::Log2
static int Log2(unsigned long long n)
Definition XrdOucUtils.cc:895

References XrdOucUtils::Log2().

Here is the call graph for this function:

## MaxSize()

int XrdBuffXL::MaxSize | ( |  | ) |

inline

Definition at line 49 of file XrdBuffXL.hh.

{return maxsz;}

## Obtain()

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

Definition at line 99 of file XrdBuffXL.cc.

{
XrdBuffer *bp;
char *memp;
int mk, buffSz, bindex = 0;
// Make sure the request is within our limits
//
if (sz <= 0 || sz > maxsz) return 0;
// Calculate bucket index. This is log2(shifted size) rounded up if need be.
// If the shift results in zero we know the request fits in the slot 0 buffer.
//
mk = sz >> minBShift;
if (!mk) buffSz = minBuffSz;
else {bindex = XrdOucUtils::Log2(mk);
buffSz = (bindex ? minBuffSz << bindex : minBuffSz);
if (buffSz < sz) {bindex++; buffSz = buffSz << 1;}
}
if (bindex >= slots) return 0; // Should never happen!
// Obtain a lock on the bucket array and try to give away an existing buffer
//
slotXL.Lock();
totreq++;
bucket[bindex].numreq++;
if ((bp = bucket[bindex].bnext))
{bucket[bindex].bnext = bp->next; bucket[bindex].numbuf--;}
slotXL.UnLock();
// Check if we really allocated a buffer
//
if (bp) return bp;
// Allocate a chunk of aligned memory
//
if (posix_memalign((void **)&memp, pagsz, buffSz)) return 0;
// Wrap the memory with a buffer object
//
if (!(bp = new XrdBuffer(memp, buffSz, bindex|isBigBuff)))
{free(memp); return 0;}
// Update statistics
//
slotXL.Lock(); totalo += buffSz; totbuf++; slotXL.UnLock();
// Return the buffer
//
return bp;
}

References XrdOucUtils::Log2().

Here is the call graph for this function:

## Recalc()

int XrdBuffXL::Recalc | ( | int | bsz | ) |

Definition at line 155 of file XrdBuffXL.cc.

{
int buffSz, mk, bindex = 0;
// Make sure the request is within our limits
//
if (sz <= 0 || sz > maxsz) return 0;
// Calculate bucket size corresponding to the desired size
//
mk = sz >> minBShift;
if (!mk) buffSz = minBuffSz;
else {bindex = XrdOucUtils::Log2(mk);
buffSz = (bindex ? minBuffSz << bindex : minBuffSz);
if (buffSz < sz) {bindex++; buffSz = buffSz << 1;}
}
if (bindex >= slots) return 0; // Should never happen!
// All done, return the actual size we would have allocated
//
return buffSz;
}

References XrdOucUtils::Log2().

Here is the call graph for this function:

## Release()

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

Definition at line 182 of file XrdBuffXL.cc.

{
int bindex = bp->bindex & ~isBigBuff;
// Obtain a lock on the bucket array and reclaim the buffer
//
slotXL.Lock();
bp->next = bucket[bindex].bnext;
bucket[bindex].bnext = bp;
bucket[bindex].numbuf++;
slotXL.UnLock();
}

## Stats()

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

Definition at line 199 of file XrdBuffXL.cc.

{
static const char statfmt[] = "<xlreqs>%d</xlreqs>"
"<xlmem>%lld</xlmem><xlbuffs>%d</xlbuffs>";
int nlen;
// If only size wanted, return it
//
if (!buff) return sizeof(statfmt) + 16*3;
// Return formatted stats
//
if (do_sync) slotXL.Lock();
nlen = snprintf(buff, blen, statfmt, totreq, totalo, totbuf);
if (do_sync) slotXL.UnLock();
return nlen;
}

## Trim()

void XrdBuffXL::Trim | ( |  | ) |

Definition at line 221 of file XrdBuffXL.cc.

{
XrdBuffer *bP;
int n, m;
// Obtain the lock
//
slotXL.Lock();
// Run through all our slots looking for buffers to release
//
for (int i = 0; i < slots; i++)
{if (bucket[i].numbuf > 1 && bucket[i].numbuf > bucket[i].numreq)
{n = bucket[i].numbuf - bucket[i].numreq;
m = bucket[i].numbuf/2;
if (m < n) n = m;
while(n-- && (bP = bucket[i].bnext))
{bucket[i].bnext = bP->next;
bucket[i].numbuf--;
totalo -= bP->bsize; totbuf--;
delete bP;
}
}
bucket[i].numreq = 0;
}
// Release the lock
//
slotXL.UnLock();
}
XrdBuffer::bsize
int bsize
Definition XrdBuffer.hh:46

References XrdBuffer::bsize.

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

- XrdBuffXL.hh
- XrdBuffXL.cc