]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/DiskIO/DiskThreads/DiskThreadsIOStrategy.cc
3 * DEBUG: section 79 Squid-side Disk I/O functions.
4 * AUTHOR: Robert Collins
6 * SQUID Web Proxy Cache http://www.squid-cache.org/
7 * ----------------------------------------------------------
9 * Squid is the result of efforts by numerous individuals from
10 * the Internet community; see the CONTRIBUTORS file for full
11 * details. Many organizations have provided support for Squid's
12 * development; see the SPONSORS file for full details. Squid is
13 * Copyrighted (C) 2001 by the Regents of the University of
14 * California; see the COPYRIGHT file for full details. Squid
15 * incorporates software developed and/or copyrighted by other
16 * sources; see the CREDITS file for full details.
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
32 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
37 #include "DiskThreadsDiskFile.h"
38 #include "DiskThreadsIOStrategy.h"
40 #include "mgr/Registration.h"
41 #include "SquidConfig.h"
42 #include "StatCounters.h"
46 DiskThreadsIOStrategy::init(void)
51 squidaio_ctrl_pool
= memPoolCreate("aio_ctrl", sizeof(squidaio_ctrl_t
));
56 * We'd like to call squidaio_init() here, but the configuration
57 * hasn't been parsed yet and we don't know how many cache_dirs
58 * there are, which means we don't know how many threads to start.
61 registerWithCacheManager();
65 DiskThreadsIOStrategy::registerWithCacheManager(void)
67 Mgr::RegisterAction("squidaio_counts", "Async IO Function Counters",
72 DiskThreadsIOStrategy::done(void)
79 delete squidaio_ctrl_pool
;
81 squidaio_ctrl_pool
= NULL
;
87 DiskThreadsIOStrategy::callback()
89 squidaio_result_t
*resultp
;
90 squidaio_ctrl_t
*ctrlp
;
94 ++squidaio_counts
.check_callback
;
97 if ((resultp
= squidaio_poll_done()) == NULL
)
100 ctrlp
= (squidaio_ctrl_t
*) resultp
->data
;
102 switch (resultp
->result_type
) {
106 case _AIO_OP_OPENDIR
:
110 ++squidaio_counts
.open_finish
;
114 ++squidaio_counts
.read_finish
;
118 ++squidaio_counts
.write_finish
;
122 ++squidaio_counts
.close_finish
;
126 ++squidaio_counts
.unlink_finish
;
130 ++squidaio_counts
.stat_finish
;
135 continue; /* XXX Should not happen */
137 dlinkDelete(&ctrlp
->node
, &used_list
);
139 if (ctrlp
->done_handler
) {
140 AIOCB
*done_callback
= ctrlp
->done_handler
;
142 ctrlp
->done_handler
= NULL
;
144 if (cbdataReferenceValidDone(ctrlp
->done_handler_data
, &cbdata
)) {
145 retval
= 1; /* Return that we've actually done some work */
146 done_callback(ctrlp
->fd
, cbdata
, ctrlp
->bufp
,
147 ctrlp
->result
.aio_return
, ctrlp
->result
.aio_errno
);
149 if (ctrlp
->operation
== _AIO_OPEN
) {
150 /* The open operation was aborted.. */
151 int fd
= ctrlp
->result
.aio_return
;
159 /* free data if requested to aioWrite() */
160 if (ctrlp
->free_func
)
161 ctrlp
->free_func(ctrlp
->bufp
);
163 /* free temporary read buffer */
164 if (ctrlp
->operation
== _AIO_READ
)
165 squidaio_xfree(ctrlp
->bufp
, ctrlp
->len
);
167 squidaio_ctrl_pool
->freeOne(ctrlp
);
173 /* Flush all pending I/O */
175 DiskThreadsIOStrategy::sync()
178 return; /* nothing to do then */
180 /* Flush all pending operations */
181 debugs(32, 2, "aioSync: flushing pending I/O operations");
185 } while (squidaio_sync());
187 debugs(32, 2, "aioSync: done");
190 DiskThreadsIOStrategy::DiskThreadsIOStrategy() : initialised (false) {}
193 DiskThreadsIOStrategy::aioStats(StoreEntry
* sentry
)
195 storeAppendPrintf(sentry
, "ASYNC IO Counters:\n");
196 storeAppendPrintf(sentry
, "Operation\t# Requests\tNumber serviced\n");
197 storeAppendPrintf(sentry
, "open\t%d\t%d\n", squidaio_counts
.open_start
, squidaio_counts
.open_finish
);
198 storeAppendPrintf(sentry
, "close\t%d\t%d\n", squidaio_counts
.close_start
, squidaio_counts
.close_finish
);
199 storeAppendPrintf(sentry
, "cancel\t%d\t-\n", squidaio_counts
.cancel
);
200 storeAppendPrintf(sentry
, "write\t%d\t%d\n", squidaio_counts
.write_start
, squidaio_counts
.write_finish
);
201 storeAppendPrintf(sentry
, "read\t%d\t%d\n", squidaio_counts
.read_start
, squidaio_counts
.read_finish
);
202 storeAppendPrintf(sentry
, "stat\t%d\t%d\n", squidaio_counts
.stat_start
, squidaio_counts
.stat_finish
);
203 storeAppendPrintf(sentry
, "unlink\t%d\t%d\n", squidaio_counts
.unlink_start
, squidaio_counts
.unlink_finish
);
204 storeAppendPrintf(sentry
, "check_callback\t%d\t-\n", squidaio_counts
.check_callback
);
205 storeAppendPrintf(sentry
, "queue\t%d\t-\n", squidaio_get_queue_len());
206 squidaio_stats(sentry
);
209 DiskThreadsIOStrategy
DiskThreadsIOStrategy::Instance
;
211 DiskThreadsIOStrategy::shedLoad()
214 * we should detect some 'too many files open' condition and return
219 if (aioQueueSize() > MAGIC2
)
228 DiskThreadsIOStrategy::load()
238 loadav
= ql
* 1000 / MAGIC1
;
240 debugs(47, 9, "DiskThreadsIOStrategy::load: load=" << loadav
);
246 DiskThreadsIOStrategy::newFile (char const *path
)
252 return new DiskThreadsDiskFile (path
, this);
256 DiskThreadsIOStrategy::unlinkdUseful() const
262 DiskThreadsIOStrategy::unlinkFile(char const *path
)
264 ++statCounter
.syscalls
.disk
.unlinks
;
265 aioUnlink(path
, NULL
, NULL
);