XRootD
XrdOucBuffPool Class Reference

#include <XrdOucBuffer.hh>

+ Collaboration diagram for XrdOucBuffPool:

Public Member Functions

 XrdOucBuffPool (int minsz=4096, int maxsz=65536, int minh=1, int maxh=16, int rate=1)
 
 ~XrdOucBuffPool ()
 
XrdOucBufferAlloc (int sz)
 
int MaxSize () const
 

Friends

class XrdOucBuffer
 

Detailed Description

These classes allow for buffer management to minimize data copying. They are typically used in conjunction with the XrdOucErrInfo class. The XrdOucBuffPool class defines a pool of buffers and one such object must exist for each buffer pool (there can be many such pools). This object manufactures XrdOucBuffer objects. You can also create XrdOucBuffers without using a buffer pool (i.e. one time buffers). See the XrdOucBuffer constructor for details on how to do this and the associated caveats.

Definition at line 54 of file XrdOucBuffer.hh.

Constructor & Destructor Documentation

◆ XrdOucBuffPool()

XrdOucBuffPool::XrdOucBuffPool ( int  minsz = 4096,
int  maxsz = 65536,
int  minh = 1,
int  maxh = 16,
int  rate = 1 
)

Constructor

Parameters
minsz- the minimum size a buffer can have. If it is smaller than 1024 it is set to 1024. The minsz is also adjusted to be equal to the closest smaller value of 1024*(2**n) (i.e. 1K, 2k, 4K, etc). If it's greater than 16MB, it is set to 16MB.
maxsz- the maximum size a buffer can have and must be >= minsz. If it's >minsz it is rounded up to the next minsz increment. Buffer sizes are always allocated in minsz increments.
minh- the minimum number of buffers that should be held in reserve when a buffer is recycled.
maxh- the maximum number of buffers that should be held in reserve when a buffer is recycled. The value applies to the smallest buffer size and is progessively reduced as the buffer size increases. If maxh < minh it is set to minh.
rate- specifies how quickly the hold vale is to be reduced as buffer sizes increase. A rate of 0 specifies a purely linear decrease. Higher values logrithmically decrease the hold.

Definition at line 53 of file XrdOucBuffer.cc.

55 {
56  int keep, pct, i, n = 0;
57 
58 // Adjust the minsz
59 //
60  while(minsz > 1024*(1<<n)) n++;
61  if (n > 14) n = 14;
62  else if (n && minsz < 1024*(1<<n)) n--;
63  incBsz = 1024*(1<<n);
64  shfBsz = 10 + n;
65  rndBsz = incBsz - 1;
66  if (maxh < 0) maxh = 0;
67  if (minh < 0) minh = 0;
68  if (maxh < minh) maxh = minh;
69  if (rate < 0) rate = 0;
70 
71 // Round up the maxsz and make it a multiple of 4k
72 //
73  if (!(slots = maxsz / incBsz)) slots = 1;
74  else if (maxsz % incBsz) slots++;
75  maxBsz = slots << shfBsz;
76 
77 // Allocate a slot vector for this
78 //
79  bSlot = new BuffSlot[(unsigned int)slots];
80 
81 // Complete initializing the slot vector
82 //
83  n = incBsz;
84  for (i = 0; i < slots; i++)
85  {bSlot[i].size = n; n += incBsz;
86  pct = (slots - i + 1)*100/slots;
87  if (pct >= 100) keep = maxh;
88  else {keep = ((maxh * pct) + 55)/100 - i*rate;
89  if (keep > maxh) keep = maxh;
90  else if (keep < minh) keep = minh;
91  }
92  bSlot[i].maxbuff = keep;
93  }
94 }

◆ ~XrdOucBuffPool()

XrdOucBuffPool::~XrdOucBuffPool ( )
inline

Destructor - You must not destroy this object prior to recycling all oustanding buffers allocated out of this pool.

Definition at line 109 of file XrdOucBuffer.hh.

109 {delete [] bSlot;}

Member Function Documentation

◆ Alloc()

XrdOucBuffer * XrdOucBuffPool::Alloc ( int  sz)

Allocate a buffer object.

Parameters
sz- the desired size. It os rounded up to be a multiple of incBsz but cannot exceed maxBsz.
Returns
!0 - pointer to usable buffer object of suitable size.
=0 - insufficient memort ro allocate a buffer.

Definition at line 100 of file XrdOucBuffer.cc.

101 {
102  XrdOucBuffPool::BuffSlot *sP;
103  XrdOucBuffer *bP;
104  int snum;
105 
106 // Compute buffer slot
107 //
108  snum = (bsz <= incBsz ? 0 : (bsz + rndBsz) >> shfBsz);
109  if (snum >= slots) return 0;
110  sP = &bSlot[snum];
111 
112 // Lock the data area
113 //
114  sP->SlotMutex.Lock();
115 
116 // Either return a new buffer or an old one
117 //
118  if ((bP = sP->buffFree))
119  {sP->buffFree = bP->buffNext;
120  bP->buffPool = this;
121  sP->numbuff--;
122  } else {
123  if ((bP = new XrdOucBuffer(this, snum)))
124  {int mema;
125  if (sP->size >= alignit) mema = alignit;
126  else if (sP->size > 2048) mema = 4096;
127  else if (sP->size > 1024) mema = 2048;
128  else mema = 1024;
129  if (posix_memalign((void **)&(bP->data), mema, sP->size))
130  {delete bP; bP = 0;}
131  }
132  }
133 
134 // Unlock the data area
135 //
136  sP->SlotMutex.UnLock();
137 
138 // Return the buffer
139 //
140  return bP;
141 }
friend class XrdOucBuffer
Definition: XrdOucBuffer.hh:56

References XrdOucBuffer.

Referenced by XrdCmsClientMan::XrdCmsClientMan(), XrdOfsPrepGPIReal::PrepGPI::query(), and XrdSsiFileSess::write().

+ Here is the caller graph for this function:

◆ MaxSize()

int XrdOucBuffPool::MaxSize ( ) const
inline

Obtain the maximum size a buffer can have.

Returns
The maximum size a buffer can be.

Definition at line 77 of file XrdOucBuffer.hh.

77 {return maxBsz;}

Friends And Related Function Documentation

◆ XrdOucBuffer

friend class XrdOucBuffer
friend

Definition at line 56 of file XrdOucBuffer.hh.

Referenced by Alloc().


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