/*
- * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
*
* Squid software is distributed under GPLv2+ license and includes
* contributions from numerous individuals and organizations.
#include <fcntl.h>
#include <dirent.h>
-#define RIDICULOUS_LENGTH 4096
+#define RIDICULOUS_LENGTH 4096
enum _squidaio_thread_status {
_THREAD_STARTING = 0,
squidaio_request_t *volatile head;
squidaio_request_t *volatile *volatile tailp;
unsigned long requests;
- unsigned long blocked; /* main failed to lock the queue */
+ unsigned long blocked; /* main failed to lock the queue */
} squidaio_request_queue_t;
typedef struct squidaio_thread_t squidaio_thread_t;
static int squidaio_initialised = 0;
#define AIO_LARGE_BUFS 16384
-#define AIO_MEDIUM_BUFS AIO_LARGE_BUFS >> 1
-#define AIO_SMALL_BUFS AIO_LARGE_BUFS >> 2
-#define AIO_TINY_BUFS AIO_LARGE_BUFS >> 3
-#define AIO_MICRO_BUFS 128
+#define AIO_MEDIUM_BUFS AIO_LARGE_BUFS >> 1
+#define AIO_SMALL_BUFS AIO_LARGE_BUFS >> 2
+#define AIO_TINY_BUFS AIO_LARGE_BUFS >> 3
+#define AIO_MICRO_BUFS 128
-static MemAllocator *squidaio_large_bufs = NULL; /* 16K */
-static MemAllocator *squidaio_medium_bufs = NULL; /* 8K */
-static MemAllocator *squidaio_small_bufs = NULL; /* 4K */
-static MemAllocator *squidaio_tiny_bufs = NULL; /* 2K */
-static MemAllocator *squidaio_micro_bufs = NULL; /* 128K */
+static MemAllocator *squidaio_large_bufs = NULL; /* 16K */
+static MemAllocator *squidaio_medium_bufs = NULL; /* 8K */
+static MemAllocator *squidaio_small_bufs = NULL; /* 4K */
+static MemAllocator *squidaio_tiny_bufs = NULL; /* 2K */
+static MemAllocator *squidaio_micro_bufs = NULL; /* 128K */
static int request_queue_len = 0;
static MemAllocator *squidaio_request_pool = NULL;
/* Create threads and get them to sit in their wait loop */
squidaio_thread_pool = memPoolCreate("aio_thread", sizeof(squidaio_thread_t));
- assert(NUMTHREADS);
+ assert(NUMTHREADS > 0);
for (i = 0; i < NUMTHREADS; ++i) {
threadp = (squidaio_thread_t *)squidaio_thread_pool->alloc();
squidaio_do_unlink(request);
break;
-#if AIO_OPENDIR /* Opendir not implemented yet */
+#if AIO_OPENDIR /* Opendir not implemented yet */
case _AIO_OP_OPENDIR:
squidaio_do_opendir(request);
request->err = EINVAL;
break;
}
- } else { /* cancelled */
+ } else { /* cancelled */
request->ret = -1;
request->err = EINTR;
}
CommIO::NotifyIOCompleted();
Sleep(0);
++ threadp->requests;
- } /* while forever */
+ } /* while forever */
CloseHandle(cond);
return 0;
-} /* squidaio_thread_loop */
+} /* squidaio_thread_loop */
static void
squidaio_queue_request(squidaio_request_t * request)
}
if (request_queue2.head) {
- static int filter = 0;
- static int filter_limit = 8;
+ static uint64_t filter = 0;
+ static uint64_t filter_limit = 8196;
if (++filter >= filter_limit) {
filter_limit += filter;
filter = 0;
- debugs(43, DBG_IMPORTANT, "squidaio_queue_request: WARNING - Queue congestion");
+ debugs(43, DBG_IMPORTANT, "squidaio_queue_request: WARNING - Queue congestion (growing to " << filter_limit << ")");
}
}
squidaio_sync();
debugs(43, DBG_CRITICAL, "squidaio_queue_request: Synced");
}
-} /* squidaio_queue_request */
+} /* squidaio_queue_request */
static void
squidaio_cleanup_request(squidaio_request_t * requestp)
}
squidaio_request_pool->freeOne(requestp);
-} /* squidaio_cleanup_request */
+} /* squidaio_cleanup_request */
int
squidaio_cancel(squidaio_result_t * resultp)
}
return 1;
-} /* squidaio_cancel */
+} /* squidaio_cancel */
int
squidaio_open(const char *path, int oflag, mode_t mode, squidaio_result_t * resultp)
goto AIO_REPOLL;
return resultp;
-} /* squidaio_poll_done */
+} /* squidaio_poll_done */
int
squidaio_operations_pending(void)
threadp = threadp->next;
}
}
+