Squid-2.2.DEVEL3: Handle overloaded async-io more gracefully Make overloaded async-io a non-fatal error (block instead of terminate), and take some extra actions to limit the risk of overloading. Index: squid/src/aiops.c diff -u squid/src/aiops.c:1.1.1.14 squid/src/aiops.c:1.1.1.14.4.1 --- squid/src/aiops.c:1.1.1.14 Sun Jan 24 09:34:03 1999 +++ squid/src/aiops.c Thu Mar 18 01:15:26 1999 @@ -110,6 +110,7 @@ int aio_unlink(const char *, aio_result_t *); int aio_opendir(const char *, aio_result_t *); aio_result_t *aio_poll_done(); +int aio_sync(void); static void aio_init(void); static void aio_queue_request(aio_request_t *); @@ -386,8 +387,9 @@ } if (request_queue_len > RIDICULOUS_LENGTH) { debug(43, 0) ("aio_queue_request: Async request queue growing uncontrollably!\n"); - debug(43, 0) ("aio_queue_request: Possible infinite loop somewhere in squid. Restarting...\n"); - abort(); + debug(43, 0) ("aio_queue_request: Syncing pending I/O operations.. (blocking)\n"); + aio_sync(); + debug(43, 0) ("aio_queue_request: Synced\n"); } } /* aio_queue_request */ @@ -838,11 +840,30 @@ int aio_operations_pending(void) { - if (request_done_head) - return 1; - if (busy_threads_head) + return request_queue_len + (request_done_head != NULL) + (busy_threads_head != NULL); +} + +int +aio_overloaded(void) +{ + static time_t last_warn = 0; + if (aio_operations_pending() > RIDICULOUS_LENGTH / 4) { + if (squid_curtime >= (last_warn + 15)) { + debug(43, 0) ("Warning: Async-IO overloaded\n"); + last_warn = squid_curtime; + } return 1; + } return 0; +} + +int +aio_sync(void) +{ + do { + aio_poll_threads(); + } while(request_queue_len > 0); + return aio_operations_pending(); } static void Index: squid/src/async_io.c diff -u squid/src/async_io.c:1.1.1.9 squid/src/async_io.c:1.1.1.9.2.1 --- squid/src/async_io.c:1.1.1.9 Sun Feb 14 23:29:51 1999 +++ squid/src/async_io.c Thu Mar 18 01:15:27 1999 @@ -379,7 +379,7 @@ debug(32, 1) ("aioSync: flushing pending I/O operations\n"); do { aioCheckCallbacks(); - } while (aio_operations_pending()); + } while (aio_sync()); debug(32, 1) ("aioSync: done\n"); } Index: squid/src/protos.h diff -u squid/src/protos.h:1.1.1.37.2.1 squid/src/protos.h:1.1.1.37.2.2 --- squid/src/protos.h:1.1.1.37.2.1 Sat Mar 6 22:40:28 1999 +++ squid/src/protos.h Thu Mar 18 01:15:27 1999 @@ -77,6 +77,8 @@ extern int aio_opendir(const char *, aio_result_t *); extern aio_result_t *aio_poll_done(void); extern int aio_operations_pending(void); +extern int aio_overloaded(void); +extern int aio_sync(void); extern void aioCancel(int, void *); extern void aioOpen(const char *, int, mode_t, AIOCB *, void *, void *); Index: squid/src/store.c diff -u squid/src/store.c:1.1.1.36 squid/src/store.c:1.1.1.36.2.1 --- squid/src/store.c:1.1.1.36 Sun Feb 14 23:30:08 1999 +++ squid/src/store.c Thu Mar 18 01:15:27 1999 @@ -518,6 +518,10 @@ * out the object yet. */ return 1; +#if USE_ASYNC_IO + } else if (aio_overloaded()) { + debug(20, 2) ("storeCheckCachable: NO: Async-IO overloaded\n"); +#endif } else if (storeTooManyDiskFilesOpen()) { debug(20, 2) ("storeCheckCachable: NO: too many disk files open\n"); store_check_cachable_hist.no.too_many_open_files++;