DiskThreadsIOStrategy.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9/* DEBUG: section 79 Squid-side Disk I/O functions. */
10
11#include "squid.h"
12#include "DiskThreadsDiskFile.h"
14#include "fde.h"
15#include "mgr/Registration.h"
16#include "SquidConfig.h"
17#include "StatCounters.h"
18#include "Store.h"
19
20/* squidaio_ctrl_t uses explicit alloc()/freeOne().
21 * XXX: convert to MEMPROXY_CLASS() API
22 */
23#include "mem/Pool.h"
24
25void
27{
28 if (initialised)
29 return;
30
31 initialised = true;
32
33 /*
34 * We'd like to call squidaio_init() here, but the configuration
35 * hasn't been parsed yet and we don't know how many cache_dirs
36 * there are, which means we don't know how many threads to start.
37 */
38
40}
41
42void
44{
45 Mgr::RegisterAction("squidaio_counts", "Async IO Function Counters",
46 aioStats, 0, 1);
47}
48
49void
51{
52 if (!initialised)
53 return;
54
56
57 initialised = false;
58}
59
60int
62{
63 squidaio_result_t *resultp;
64 squidaio_ctrl_t *ctrlp;
65 int retval = 0;
66
69
70 for (;;) {
71 if ((resultp = squidaio_poll_done()) == nullptr)
72 break;
73
74 ctrlp = (squidaio_ctrl_t *) resultp->data;
75
76 switch (resultp->result_type) {
77
78 case _AIO_OP_NONE:
79
80 case _AIO_OP_OPENDIR:
81 break;
82
83 case _AIO_OP_OPEN:
85 break;
86
87 case _AIO_OP_READ:
89 break;
90
91 case _AIO_OP_WRITE:
93 break;
94
95 case _AIO_OP_CLOSE:
97 break;
98
99 case _AIO_OP_UNLINK:
101 break;
102
103 case _AIO_OP_STAT:
105 break;
106 }
107
108 if (ctrlp == nullptr)
109 continue; /* XXX Should not happen */
110
111 dlinkDelete(&ctrlp->node, &used_list);
112
113 if (ctrlp->done_handler) {
114 AIOCB *done_callback = ctrlp->done_handler;
115 void *cbdata;
116 ctrlp->done_handler = nullptr;
117
119 retval = 1; /* Return that we've actually done some work */
120 done_callback(ctrlp->fd, cbdata, ctrlp->bufp,
121 ctrlp->result.aio_return, ctrlp->result.aio_errno);
122 } else {
123 if (ctrlp->operation == _AIO_OPEN) {
124 /* The open operation was aborted.. */
125 int fd = ctrlp->result.aio_return;
126
127 if (fd >= 0)
128 aioClose(fd);
129 }
130 }
131 }
132
133 /* free data if requested to aioWrite() */
134 if (ctrlp->free_func)
135 ctrlp->free_func(ctrlp->bufp);
136
137 /* free temporary read buffer */
138 if (ctrlp->operation == _AIO_READ)
139 squidaio_xfree(ctrlp->bufp, ctrlp->len);
140
141 delete ctrlp;
142 }
143
144 return retval;
145}
146
147/* Flush all pending I/O */
148void
150{
151 if (!initialised)
152 return; /* nothing to do then */
153
154 /* Flush all pending operations */
155 debugs(32, 2, "aioSync: flushing pending I/O operations");
156
157 do {
158 callback();
159 } while (squidaio_sync());
160
161 debugs(32, 2, "aioSync: done");
162}
163
165 initialised(false)
166{}
167
168void
170{
171 storeAppendPrintf(sentry, "ASYNC IO Counters:\n");
172 storeAppendPrintf(sentry, " Operation\t# Requests\tNumber serviced\n");
175 storeAppendPrintf(sentry, " cancel\t%" PRIu64 "\t-\n", squidaio_counts.cancel);
180 storeAppendPrintf(sentry, " check_callback\t%" PRIu64 "\t-\n", squidaio_counts.check_callback);
181 storeAppendPrintf(sentry, " queue\t%d\t-\n", squidaio_get_queue_len());
182 squidaio_stats(sentry);
183}
184
186bool
188{
189 /*
190 * we should detect some 'too many files open' condition and return
191 * NULL here.
192 */
193#ifdef MAGIC2
194
195 if (aioQueueSize() > MAGIC2)
196 return true;
197
198#endif
199
200 return false;
201}
202
203int
205{
206 int loadav;
207 int ql;
208
209 ql = aioQueueSize();
210
211 if (ql == 0)
212 loadav = 0;
213
214 loadav = ql * 1000 / MAGIC1;
215
216 debugs(47, 9, "DiskThreadsIOStrategy::load: load=" << loadav);
217
218 return loadav;
219}
220
223{
224 if (shedLoad()) {
225 return nullptr;
226 }
227
228 return new DiskThreadsDiskFile(path);
229}
230
231bool
233{
234 return false;
235}
236
237void
239{
241 aioUnlink(path, nullptr, nullptr);
242}
243
#define _AIO_OPEN
#define _AIO_READ
@ _AIO_OP_OPENDIR
Definition: DiskThreads.h:52
@ _AIO_OP_NONE
Definition: DiskThreads.h:46
@ _AIO_OP_WRITE
Definition: DiskThreads.h:49
@ _AIO_OP_UNLINK
Definition: DiskThreads.h:51
@ _AIO_OP_OPEN
Definition: DiskThreads.h:47
@ _AIO_OP_READ
Definition: DiskThreads.h:48
@ _AIO_OP_CLOSE
Definition: DiskThreads.h:50
@ _AIO_OP_STAT
Definition: DiskThreads.h:53
#define MAGIC1
Definition: DiskThreads.h:34
#define MAGIC2
Definition: DiskThreads.h:36
void AIOCB(int fd, void *cbdata, const char *buf, int aio_return, int aio_errno)
Definition: DiskThreads.h:57
#define false
Definition: GnuRegex.c:240
StatCounters statCounter
Definition: StatCounters.cc:12
void squidaio_stats(StoreEntry *sentry)
Definition: aiops.cc:1002
void squidaio_shutdown(void)
Definition: aiops.cc:332
squidaio_result_t * squidaio_poll_done(void)
Definition: aiops.cc:904
void squidaio_xfree(void *p, int size)
Definition: aiops.cc:196
int squidaio_sync(void)
Definition: aiops.cc:954
int squidaio_get_queue_len(void)
Definition: aiops.cc:966
#define assert(EX)
Definition: assert.h:19
int aioQueueSize(void)
Definition: async_io.cc:199
void aioUnlink(const char *path, AIOCB *callback, void *callback_data)
Definition: async_io.cc:183
AIOCounts squidaio_counts
Definition: async_io.cc:18
void aioClose(int fd)
Definition: async_io.cc:47
dlink_list used_list
Definition: async_io.cc:26
#define cbdataReferenceValidDone(var, ptr)
Definition: cbdata.h:256
uint64_t read_start
Definition: DiskThreads.h:132
uint64_t write_finish
Definition: DiskThreads.h:131
uint64_t read_finish
Definition: DiskThreads.h:133
uint64_t stat_finish
Definition: DiskThreads.h:135
uint64_t write_start
Definition: DiskThreads.h:130
uint64_t close_finish
Definition: DiskThreads.h:128
uint64_t close_start
Definition: DiskThreads.h:127
uint64_t check_callback
Definition: DiskThreads.h:138
uint64_t cancel
Definition: DiskThreads.h:129
uint64_t stat_start
Definition: DiskThreads.h:134
uint64_t unlink_finish
Definition: DiskThreads.h:137
uint64_t open_start
Definition: DiskThreads.h:125
uint64_t open_finish
Definition: DiskThreads.h:126
uint64_t unlink_start
Definition: DiskThreads.h:136
static DiskThreadsIOStrategy Instance
virtual bool unlinkdUseful() const
virtual RefCount< DiskFile > newFile(char const *path)
static void aioStats(StoreEntry *sentry)
virtual void unlinkFile(char const *)
struct StatCounters::@136 syscalls
struct StatCounters::@136::@140 disk
Definition: cbdata.cc:60
AIOCB * done_handler
Definition: DiskThreads.h:78
FREE * free_func
Definition: DiskThreads.h:83
void * done_handler_data
Definition: DiskThreads.h:79
squidaio_result_t result
Definition: DiskThreads.h:80
dlink_node node
Definition: DiskThreads.h:84
enum _squidaio_request_type result_type
Definition: DiskThreads.h:64
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:196
void RegisterAction(char const *action, char const *desc, OBJH *handler, int pw_req_flag, int atomic)
Definition: Registration.cc:16
void storeAppendPrintf(StoreEntry *e, const char *fmt,...)
Definition: store.cc:828
#define PRIu64
Definition: types.h:120

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors