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
"
32
#include "
XrdXrootd/XrdXrootdAioBuff.hh
"
33
#include "
XrdXrootd/XrdXrootdAioTask.hh
"
34
#include "
XrdXrootd/XrdXrootdProtocol.hh
"
35
#include "
XrdXrootd/XrdXrootdTrace.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
44
extern
XrdSysTrace
XrdXrootdTrace
;
45
46
const
char
*
XrdXrootdAioBuff::TraceID
=
"AioBuff"
;
47
48
namespace
XrdXrootd
49
{
50
extern
XrdBuffManager
*
BPool
;
51
}
52
53
using namespace
XrdXrootd
;
54
55
/******************************************************************************/
56
/* L o c a l S t a t i c s */
57
/******************************************************************************/
58
59
namespace
60
{
61
XrdSysMutex
fqMutex;
62
XrdXrootdAioBuff
*fqFirst = 0;
63
int
numFree = 0;
64
65
static
const
int
maxKeep =128;
// Number of objects to keep sans buffer
66
}
67
68
/******************************************************************************/
69
/* A l l o c */
70
/******************************************************************************/
71
72
XrdXrootdAioBuff
*
XrdXrootdAioBuff::Alloc
(
XrdXrootdAioTask
* arp)
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
113
void
XrdXrootdAioBuff::doneRead
()
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
124
void
XrdXrootdAioBuff::doneWrite
()
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
135
void
XrdXrootdAioBuff::Recycle
()
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
}
XrdBuffer.hh
XrdXrootdTrace
XrdOucTrace * XrdXrootdTrace
Definition
XrdFrmAdminMain.cc:96
aiocb::aio_nbytes
size_t aio_nbytes
Definition
XrdSfsAio.hh:48
aiocb::aio_buf
void * aio_buf
Definition
XrdSfsAio.hh:47
TRACEI
#define TRACEI(act, x)
Definition
XrdTrace.hh:66
XrdXrootdAioBuff.hh
XrdXrootdAioTask.hh
XrdXrootdProtocol.hh
XrdXrootdTrace.hh
XrdBuffManager
Definition
XrdBuffer.hh:72
XrdBuffer
Definition
XrdBuffer.hh:42
XrdBuffer::bsize
int bsize
Definition
XrdBuffer.hh:46
XrdBuffer::buff
char * buff
Definition
XrdBuffer.hh:45
XrdSfsAio::cksVec
uint32_t * cksVec
Definition
XrdSfsAio.hh:63
XrdSfsAio::sfsAio
struct aiocb sfsAio
Definition
XrdSfsAio.hh:62
XrdSysMutex
Definition
XrdSysPthread.hh:165
XrdSysTrace
Definition
XrdSysTrace.hh:49
XrdXrootdAioBuff
Definition
XrdXrootdAioBuff.hh:41
XrdXrootdAioBuff::doneWrite
void doneWrite() override
Definition
XrdXrootdAioBuff.cc:124
XrdXrootdAioBuff::next
XrdXrootdAioBuff * next
Definition
XrdXrootdAioBuff.hh:53
XrdXrootdAioBuff::buffP
XrdBuffer * buffP
Definition
XrdXrootdAioBuff.hh:67
XrdXrootdAioBuff::Recycle
virtual void Recycle() override
Definition
XrdXrootdAioBuff.cc:135
XrdXrootdAioBuff::Alloc
static XrdXrootdAioBuff * Alloc(XrdXrootdAioTask *arp)
Definition
XrdXrootdAioBuff.cc:72
XrdXrootdAioBuff::reqP
XrdXrootdAioTask * reqP
Definition
XrdXrootdAioBuff.hh:66
XrdXrootdAioBuff::TraceID
static const char * TraceID
Definition
XrdXrootdAioBuff.hh:65
XrdXrootdAioBuff::XrdXrootdAioBuff
XrdXrootdAioBuff(XrdXrootdAioTask *tP, XrdBuffer *bP)
Definition
XrdXrootdAioBuff.hh:57
XrdXrootdAioBuff::doneRead
void doneRead() override
Definition
XrdXrootdAioBuff.cc:113
XrdXrootdAioTask
Definition
XrdXrootdAioTask.hh:47
XrdXrootdAioTask::urProtocol
XrdXrootdProtocol * urProtocol()
Definition
XrdXrootdAioTask.hh:63
XrdXrootdProtocol::aioUpdate
void aioUpdate(int val)
Definition
XrdXrootdProtocol.hh:160
XrdXrootdProtocol::as_segsize
static int as_segsize
Definition
XrdXrootdProtocol.hh:224
XrdXrootd
Definition
XrdXrootdAioBuff.cc:49
XrdXrootd::BPool
XrdBuffManager * BPool
Definition
XrdXrootdAioPgrw.cc:54
XrdXrootd
XrdXrootdAioBuff.cc
Generated by
1.14.0