]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/DiskIO/DiskThreads/DiskThreadsIOStrategy.cc
2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 79 Squid-side Disk I/O functions. */
12 #include "DiskThreadsDiskFile.h"
13 #include "DiskThreadsIOStrategy.h"
15 #include "mgr/Registration.h"
16 #include "SquidConfig.h"
17 #include "StatCounters.h"
20 /* squidaio_ctrl_t uses explicit alloc()/freeOne().
21 * XXX: convert to MEMPROXY_CLASS() API
26 DiskThreadsIOStrategy::init(void)
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.
39 registerWithCacheManager();
43 DiskThreadsIOStrategy::registerWithCacheManager(void)
45 Mgr::RegisterAction("squidaio_counts", "Async IO Function Counters",
50 DiskThreadsIOStrategy::done(void)
61 DiskThreadsIOStrategy::callback()
63 squidaio_result_t
*resultp
;
64 squidaio_ctrl_t
*ctrlp
;
68 ++squidaio_counts
.check_callback
;
71 if ((resultp
= squidaio_poll_done()) == NULL
)
74 ctrlp
= (squidaio_ctrl_t
*) resultp
->data
;
76 switch (resultp
->result_type
) {
84 ++squidaio_counts
.open_finish
;
88 ++squidaio_counts
.read_finish
;
92 ++squidaio_counts
.write_finish
;
96 ++squidaio_counts
.close_finish
;
100 ++squidaio_counts
.unlink_finish
;
104 ++squidaio_counts
.stat_finish
;
109 continue; /* XXX Should not happen */
111 dlinkDelete(&ctrlp
->node
, &used_list
);
113 if (ctrlp
->done_handler
) {
114 AIOCB
*done_callback
= ctrlp
->done_handler
;
116 ctrlp
->done_handler
= NULL
;
118 if (cbdataReferenceValidDone(ctrlp
->done_handler_data
, &cbdata
)) {
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
);
123 if (ctrlp
->operation
== _AIO_OPEN
) {
124 /* The open operation was aborted.. */
125 int fd
= ctrlp
->result
.aio_return
;
133 /* free data if requested to aioWrite() */
134 if (ctrlp
->free_func
)
135 ctrlp
->free_func(ctrlp
->bufp
);
137 /* free temporary read buffer */
138 if (ctrlp
->operation
== _AIO_READ
)
139 squidaio_xfree(ctrlp
->bufp
, ctrlp
->len
);
147 /* Flush all pending I/O */
149 DiskThreadsIOStrategy::sync()
152 return; /* nothing to do then */
154 /* Flush all pending operations */
155 debugs(32, 2, "aioSync: flushing pending I/O operations");
159 } while (squidaio_sync());
161 debugs(32, 2, "aioSync: done");
164 DiskThreadsIOStrategy::DiskThreadsIOStrategy() :
169 DiskThreadsIOStrategy::aioStats(StoreEntry
* sentry
)
171 storeAppendPrintf(sentry
, "ASYNC IO Counters:\n");
172 storeAppendPrintf(sentry
, " Operation\t# Requests\tNumber serviced\n");
173 storeAppendPrintf(sentry
, " open\t%" PRIu64
"\t%" PRIu64
"\n", squidaio_counts
.open_start
, squidaio_counts
.open_finish
);
174 storeAppendPrintf(sentry
, " close\t%" PRIu64
"\t%" PRIu64
"\n", squidaio_counts
.close_start
, squidaio_counts
.close_finish
);
175 storeAppendPrintf(sentry
, " cancel\t%" PRIu64
"\t-\n", squidaio_counts
.cancel
);
176 storeAppendPrintf(sentry
, " write\t%" PRIu64
"\t%" PRIu64
"\n", squidaio_counts
.write_start
, squidaio_counts
.write_finish
);
177 storeAppendPrintf(sentry
, " read\t%" PRIu64
"\t%" PRIu64
"\n", squidaio_counts
.read_start
, squidaio_counts
.read_finish
);
178 storeAppendPrintf(sentry
, " stat\t%" PRIu64
"\t%" PRIu64
"\n", squidaio_counts
.stat_start
, squidaio_counts
.stat_finish
);
179 storeAppendPrintf(sentry
, " unlink\t%" PRIu64
"\t%" PRIu64
"\n", squidaio_counts
.unlink_start
, squidaio_counts
.unlink_finish
);
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
);
185 DiskThreadsIOStrategy
DiskThreadsIOStrategy::Instance
;
187 DiskThreadsIOStrategy::shedLoad()
190 * we should detect some 'too many files open' condition and return
195 if (aioQueueSize() > MAGIC2
)
204 DiskThreadsIOStrategy::load()
214 loadav
= ql
* 1000 / MAGIC1
;
216 debugs(47, 9, "DiskThreadsIOStrategy::load: load=" << loadav
);
222 DiskThreadsIOStrategy::newFile (char const *path
)
228 return new DiskThreadsDiskFile (path
, this);
232 DiskThreadsIOStrategy::unlinkdUseful() const
238 DiskThreadsIOStrategy::unlinkFile(char const *path
)
240 ++statCounter
.syscalls
.disk
.unlinks
;
241 aioUnlink(path
, NULL
, NULL
);