XRootD
Loading...
Searching...
No Matches
XrdXrootdAioBuff.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d A i o B u f f . c c */
4/* */
5/* (c) 2021 by the Board of Trustees of the Leland Stanford, Jr., University */
6/* All Rights Reserved */
7/* Produced by Andrew Hanushevsky for Stanford University under contract */
8/* DE-AC02-76-SFO0515 with the Department of Energy */
9/* */
10/* This file is part of the XRootD software suite. */
11/* */
12/* XRootD is free software: you can redistribute it and/or modify it under */
13/* the terms of the GNU Lesser General Public License as published by the */
14/* Free Software Foundation, either version 3 of the License, or (at your */
15/* option) any later version. */
16/* */
17/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20/* License for more details. */
21/* */
22/* You should have received a copy of the GNU Lesser General Public License */
23/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25/* */
26/* The copyright holder's institutional names and contributor's names may not */
27/* be used to endorse or promote products derived from this software without */
28/* specific prior written permission of the institution or contributor. */
29/******************************************************************************/
30
31#include "Xrd/XrdBuffer.hh"
36
37#define TRACELINK reqP
38#define ID ID()
39
40/******************************************************************************/
41/* G l o b a l S t a t i c s */
42/******************************************************************************/
43
45
46const char *XrdXrootdAioBuff::TraceID = "AioBuff";
47
48namespace XrdXrootd
49{
50extern XrdBuffManager *BPool;
51}
52
53using namespace XrdXrootd;
54
55/******************************************************************************/
56/* L o c a l S t a t i c s */
57/******************************************************************************/
58
59namespace
60{
61XrdSysMutex fqMutex;
62XrdXrootdAioBuff *fqFirst = 0;
63int numFree = 0;
64
65static const int maxKeep =128; // Number of objects to keep sans buffer
66}
67
68/******************************************************************************/
69/* A l l o c */
70/******************************************************************************/
71
73{
74 XrdXrootdAioBuff *aiobuff;
75 XrdBuffer *bP;
76
77// Obtain a buffer as we never hold on to them (unlike pgaio)
78//
79 if (!(bP = BPool->Obtain(XrdXrootdProtocol::as_segsize))) return 0;
80
81// Obtain a preallocated aio object
82//
83 fqMutex.Lock();
84 if ((aiobuff = fqFirst))
85 {fqFirst = aiobuff->next;
86 numFree--;
87 }
88 fqMutex.UnLock();
89
90// If we have no object, create a new one.
91//
92 if (!aiobuff) aiobuff = new XrdXrootdAioBuff(arp, bP);
93 else {aiobuff->reqP = arp;
94 aiobuff->buffP = bP;
95 }
96 aiobuff->cksVec = 0;
97 aiobuff->sfsAio.aio_buf = bP->buff;
98 aiobuff->sfsAio.aio_nbytes = bP->bsize;
99
100// Update aio counters
101//
102 arp->urProtocol()->aioUpdate(1);
103
104// All done
105//
106 return aiobuff;
107}
108
109/******************************************************************************/
110/* d o n e R e a d */
111/******************************************************************************/
112
114{
115// Tell the request this data is available to be sent to the client
116//
117 reqP->Completed(this);
118}
119
120/******************************************************************************/
121/* d o n e W r i t e */
122/******************************************************************************/
123
125{
126// Tell the request this data is has been dealth with
127//
128 reqP->Completed(this);
129}
130
131/******************************************************************************/
132/* R e c y c l e */
133/******************************************************************************/
134
136{
137
138// Do some tracing
139//
140 TRACEI(FSAIO, "Recycle " <<sfsAio.aio_nbytes<<'@'
141 <<sfsAio.aio_offset<<" numF="<<numFree);
142
143// Update aio counters
144//
145 reqP->urProtocol()->aioUpdate(-1);
146
147// Recycle the buffer as we don't want to hold on to it
148//
149 if (buffP) {BPool->Release(buffP); buffP = 0;}
150
151// Place the object on the free queue if possible
152//
153 fqMutex.Lock();
154 if (numFree >= maxKeep)
155 {fqMutex.UnLock();
156 delete this;
157 } else {
158 next = fqFirst;
159 fqFirst = this;
160 numFree++;
161 fqMutex.UnLock();
162 }
163}
off_t aio_offset
Definition XrdSfsAio.hh:49
size_t aio_nbytes
Definition XrdSfsAio.hh:48
void * aio_buf
Definition XrdSfsAio.hh:47
#define TRACEI(act, x)
Definition XrdTrace.hh:66
XrdSysTrace XrdXrootdTrace
void Release(XrdBuffer *bp)
Definition XrdBuffer.cc:221
XrdBuffer * Obtain(int bsz)
Definition XrdBuffer.cc:140
char * buff
Definition XrdBuffer.hh:45
uint32_t * cksVec
Definition XrdSfsAio.hh:63
struct aiocb sfsAio
Definition XrdSfsAio.hh:62
void doneWrite() override
XrdXrootdAioBuff * next
virtual void Recycle() override
static XrdXrootdAioBuff * Alloc(XrdXrootdAioTask *arp)
XrdXrootdAioTask * reqP
static const char * TraceID
void doneRead() override
void Completed(XrdXrootdAioBuff *aioP)
XrdXrootdProtocol * urProtocol()
XrdBuffManager * BPool