From: serassio <> Date: Sat, 2 Apr 2005 04:11:28 +0000 (+0000) Subject: Bug #671: Several minor aufs issues X-Git-Tag: SQUID_3_0_PRE4~817 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d06925a4e2229dd28ac623a27ab8271dedcb0c96;p=thirdparty%2Fsquid.git Bug #671: Several minor aufs issues - Enhance performance by zero-copy writes, enabled by making the mem nodes reference counted. - Implement ASYNC_CLOSE define, default to off. - Remove unused aioFDWasClosed call - Kill warning about event notification filedescriptors still being open on shutdown. Also optimizes slightly by initializing the squidaio layer early, avoiding the need to check if initialized in each and every call. Forward port of 2.5 patches. --- diff --git a/src/DiskIO/DiskThreads/DiskThreads.h b/src/DiskIO/DiskThreads/DiskThreads.h index 8ec3d7baa9..3335a356e4 100644 --- a/src/DiskIO/DiskThreads/DiskThreads.h +++ b/src/DiskIO/DiskThreads/DiskThreads.h @@ -64,6 +64,8 @@ struct squidaio_ctrl_t dlink_node node; }; +void squidaio_init(void); +void squidaio_shutdown(void); int squidaio_cancel(squidaio_result_t *); int squidaio_open(const char *, int, mode_t, squidaio_result_t *); int squidaio_read(int, char *, int, off_t, int, squidaio_result_t *); diff --git a/src/DiskIO/DiskThreads/DiskThreadsDiskFile.cc b/src/DiskIO/DiskThreads/DiskThreadsDiskFile.cc index d25d0a9962..8b333f1340 100644 --- a/src/DiskIO/DiskThreads/DiskThreadsDiskFile.cc +++ b/src/DiskIO/DiskThreads/DiskThreadsDiskFile.cc @@ -1,6 +1,6 @@ /* - * $Id: DiskThreadsDiskFile.cc,v 1.4 2005/03/27 21:47:38 serassio Exp $ + * $Id: DiskThreadsDiskFile.cc,v 1.5 2005/04/01 21:11:28 serassio Exp $ * * DEBUG: section 79 Disk IO Routines * AUTHOR: Robert Collins @@ -51,6 +51,8 @@ DiskThreadsDiskFile::operator new (size_t) { CBDATA_INIT_TYPE(DiskThreadsDiskFile); DiskThreadsDiskFile *result = cbdataAlloc(DiskThreadsDiskFile); + squidaio_init(); + return result; } @@ -199,8 +201,16 @@ void DiskThreadsDiskFile::doClose() { if (fd > -1) { statCounter.syscalls.disk.closes++; +#if ASYNC_CLOSE + aioClose(fd); fd_close(fd); +#else + + aioCancel(fd); + file_close(fd); +#endif + store_open_disk_fd--; fd = -1; } diff --git a/src/DiskIO/DiskThreads/DiskThreadsIOStrategy.cc b/src/DiskIO/DiskThreads/DiskThreadsIOStrategy.cc index 5a4f72c000..007a53aeee 100644 --- a/src/DiskIO/DiskThreads/DiskThreadsIOStrategy.cc +++ b/src/DiskIO/DiskThreads/DiskThreadsIOStrategy.cc @@ -1,6 +1,6 @@ /* - * $Id: DiskThreadsIOStrategy.cc,v 1.1 2004/12/20 16:30:38 robertc Exp $ + * $Id: DiskThreadsIOStrategy.cc,v 1.2 2005/04/01 21:11:28 serassio Exp $ * * DEBUG: section 79 Squid-side Disk I/O functions. * AUTHOR: Robert Collins @@ -64,6 +64,8 @@ DiskThreadsIOStrategy::done(void) if (!initialised) return; + squidaio_shutdown(); + delete squidaio_ctrl_pool; squidaio_ctrl_pool = NULL; @@ -154,9 +156,6 @@ DiskThreadsIOStrategy::callback() if (ctrlp->operation == _AIO_READ) squidaio_xfree(ctrlp->bufp, ctrlp->len); - if (ctrlp->operation == _AIO_CLOSE) - aioFDWasClosed(ctrlp->fd); - squidaio_ctrl_pool->free(ctrlp); } @@ -198,13 +197,6 @@ DiskThreadsIOStrategy::aioStats(StoreEntry * sentry) storeAppendPrintf(sentry, "queue\t%d\t-\n", squidaio_get_queue_len()); } -void -DiskThreadsIOStrategy::aioFDWasClosed(int fd) -{ - if (fd_table[fd].flags.closing) - fd_close(fd); -} - DiskThreadsIOStrategy DiskThreadsIOStrategy::Instance; bool DiskThreadsIOStrategy::shedLoad() diff --git a/src/DiskIO/DiskThreads/DiskThreadsIOStrategy.h b/src/DiskIO/DiskThreads/DiskThreadsIOStrategy.h index c5201331a0..83f47f8cf4 100644 --- a/src/DiskIO/DiskThreads/DiskThreadsIOStrategy.h +++ b/src/DiskIO/DiskThreads/DiskThreadsIOStrategy.h @@ -1,6 +1,6 @@ /* - * $Id: DiskThreadsIOStrategy.h,v 1.1 2004/12/20 16:30:38 robertc Exp $ + * $Id: DiskThreadsIOStrategy.h,v 1.2 2005/04/01 21:11:28 serassio Exp $ * * DEBUG: section 79 Squid-side Disk I/O functions. * AUTHOR: Robert Collins @@ -67,7 +67,6 @@ public: private: static void aioStats(StoreEntry * sentry); - void aioFDWasClosed(int fd); }; #endif diff --git a/src/DiskIO/DiskThreads/aiops.cc b/src/DiskIO/DiskThreads/aiops.cc index 40ab532b11..c8980a8a71 100644 --- a/src/DiskIO/DiskThreads/aiops.cc +++ b/src/DiskIO/DiskThreads/aiops.cc @@ -1,5 +1,5 @@ /* - * $Id: aiops.cc,v 1.1 2004/12/20 16:30:38 robertc Exp $ + * $Id: aiops.cc,v 1.2 2005/04/01 21:11:28 serassio Exp $ * * DEBUG: section 43 AIOPS * AUTHOR: Stewart Forster @@ -74,7 +74,6 @@ typedef struct squidaio_request_t mode_t mode; int fd; char *bufferp; - char *tmpbufp; int buflen; off_t offset; int whence; @@ -113,7 +112,6 @@ struct squidaio_thread_t unsigned long requests; }; -static void squidaio_init(void); static void squidaio_queue_request(squidaio_request_t *); static void squidaio_cleanup_request(squidaio_request_t *); static void *squidaio_thread_loop(void *); @@ -249,7 +247,7 @@ squidaio_xstrfree(char *str) xfree(str); } -static void +void squidaio_init(void) { int i; @@ -355,6 +353,21 @@ squidaio_init(void) squidaio_initialised = 1; } +void +squidaio_shutdown(void) +{ + if (!squidaio_initialised) + return; + + /* This is the same as in squidaio_sync */ + do { + squidaio_poll_queues(); + } while (request_queue_len > 0); + + CommIO::NotifyIOClose(); + + squidaio_initialised = 0; +} static void * squidaio_thread_loop(void *ptr) @@ -623,8 +636,6 @@ squidaio_cleanup_request(squidaio_request_t * requestp) break; case _AIO_OP_WRITE: - squidaio_xfree(requestp->tmpbufp, requestp->buflen); - break; default: @@ -664,9 +675,6 @@ squidaio_open(const char *path, int oflag, mode_t mode, squidaio_result_t * resu { squidaio_request_t *requestp; - if (!squidaio_initialised) - squidaio_init(); - requestp = (squidaio_request_t *)squidaio_request_pool->alloc(); requestp->path = (char *) squidaio_xstrdup(path); @@ -702,9 +710,6 @@ squidaio_read(int fd, char *bufp, int bufs, off_t offset, int whence, squidaio_r { squidaio_request_t *requestp; - if (!squidaio_initialised) - squidaio_init(); - requestp = (squidaio_request_t *)squidaio_request_pool->alloc(); requestp->fd = fd; @@ -745,16 +750,11 @@ squidaio_write(int fd, char *bufp, int bufs, off_t offset, int whence, squidaio_ { squidaio_request_t *requestp; - if (!squidaio_initialised) - squidaio_init(); - requestp = (squidaio_request_t *)squidaio_request_pool->alloc(); requestp->fd = fd; - requestp->tmpbufp = (char *) squidaio_xmalloc(bufs); - - xmemcpy(requestp->tmpbufp, bufp, bufs); + requestp->bufferp = bufp; requestp->buflen = bufs; @@ -779,7 +779,7 @@ squidaio_write(int fd, char *bufp, int bufs, off_t offset, int whence, squidaio_ static void squidaio_do_write(squidaio_request_t * requestp) { - requestp->ret = write(requestp->fd, requestp->tmpbufp, requestp->buflen); + requestp->ret = write(requestp->fd, requestp->bufferp, requestp->buflen); requestp->err = errno; } @@ -789,9 +789,6 @@ squidaio_close(int fd, squidaio_result_t * resultp) { squidaio_request_t *requestp; - if (!squidaio_initialised) - squidaio_init(); - requestp = (squidaio_request_t *)squidaio_request_pool->alloc(); requestp->fd = fd; @@ -824,9 +821,6 @@ squidaio_stat(const char *path, struct stat *sb, squidaio_result_t * resultp) { squidaio_request_t *requestp; - if (!squidaio_initialised) - squidaio_init(); - requestp = (squidaio_request_t *)squidaio_request_pool->alloc(); requestp->path = (char *) squidaio_xstrdup(path); @@ -862,9 +856,6 @@ squidaio_unlink(const char *path, squidaio_result_t * resultp) { squidaio_request_t *requestp; - if (!squidaio_initialised) - squidaio_init(); - requestp = (squidaio_request_t *)squidaio_request_pool->alloc(); requestp->path = squidaio_xstrdup(path); @@ -895,9 +886,6 @@ squidaio_truncate(const char *path, off_t length, squidaio_result_t * resultp) { squidaio_request_t *requestp; - if (!squidaio_initialised) - squidaio_init(); - requestp = (squidaio_request_t *)squidaio_request_pool->alloc(); requestp->path = (char *) squidaio_xstrdup(path); @@ -935,9 +923,6 @@ squidaio_opendir(const char *path, squidaio_result_t * resultp) squidaio_request_t *requestp; int len; - if (!squidaio_initialised) - squidaio_init(); - requestp = squidaio_request_pool->alloc(); resultp->result_type = _AIO_OP_OPENDIR; diff --git a/src/comm.cc b/src/comm.cc index cc100a0c44..038759420f 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -1,6 +1,6 @@ /* - * $Id: comm.cc,v 1.401 2005/03/10 21:49:19 serassio Exp $ + * $Id: comm.cc,v 1.402 2005/04/01 21:11:28 serassio Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -2399,14 +2399,24 @@ void CommIO::Initialise() { pipe(DonePipe); DoneFD = DonePipe[1]; DoneReadFD = DonePipe[0]; - fd_open(DonePipe[0], FD_PIPE, "async-io completetion event: main"); - fd_open(DonePipe[1], FD_PIPE, "async-io completetion event: threads"); - commSetNonBlocking(DonePipe[0]); - commSetNonBlocking(DonePipe[1]); - commSetSelect(DonePipe[0], COMM_SELECT_READ, NULLFDHandler, NULL, 0); + fd_open(DoneReadFD, FD_PIPE, "async-io completetion event: main"); + fd_open(DoneFD, FD_PIPE, "async-io completetion event: threads"); + commSetNonBlocking(DoneReadFD); + commSetNonBlocking(DoneFD); + commSetSelect(DoneReadFD, COMM_SELECT_READ, NULLFDHandler, NULL, 0); Initialised = true; } +void CommIO::NotifyIOClose() { + /* Close done pipe signal */ + FlushPipe(); + close(DoneFD); + close(DoneReadFD); + fd_close(DoneFD); + fd_close(DoneReadFD); + Initialised = false; +} + bool CommIO::Initialised = false; bool CommIO::DoneSignalled = false; int CommIO::DoneFD = -1; diff --git a/src/comm.h b/src/comm.h index 5ac53d9b2d..88a2c5a7d2 100644 --- a/src/comm.h +++ b/src/comm.h @@ -43,6 +43,7 @@ public: static inline void NotifyIOCompleted(); static void ResetNotifications(); static void Initialise(); + static void NotifyIOClose(); private: static void NULLFDHandler(int, void *); diff --git a/src/mem_node.h b/src/mem_node.h index da43da6168..86f8f31d5e 100644 --- a/src/mem_node.h +++ b/src/mem_node.h @@ -1,6 +1,6 @@ /* - * $Id: mem_node.h,v 1.7 2004/08/30 05:12:31 robertc Exp $ + * $Id: mem_node.h,v 1.8 2005/04/01 21:11:28 serassio Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -58,6 +58,7 @@ public: StoreIOBuffer nodeBuffer; /* Private */ char data[SM_PAGE_SIZE]; + int uses; }; MEMPROXY_CLASS_INLINE(mem_node) diff --git a/src/stmem.cc b/src/stmem.cc index 63c4403632..dc5c8ed237 100644 --- a/src/stmem.cc +++ b/src/stmem.cc @@ -1,6 +1,6 @@ /* - * $Id: stmem.cc,v 1.87 2003/10/23 19:59:32 robertc Exp $ + * $Id: stmem.cc,v 1.88 2005/04/01 21:11:28 serassio Exp $ * * DEBUG: section 19 Store Memory Primitives * AUTHOR: Harvest Derived @@ -40,6 +40,13 @@ #include "MemObject.h" #include "Generic.h" +char * +mem_hdr::NodeGet(mem_node * aNode) +{ + aNode->uses++; + return aNode->data; +} + int mem_hdr::lowestOffset () const { @@ -76,7 +83,12 @@ void mem_hdr::unlink(mem_node *aNode) { nodes.remove (aNode, NodeCompare); - delete aNode; + + if (!aNode->uses) + delete aNode; + else + aNode->uses--; + } int diff --git a/src/stmem.h b/src/stmem.h index e39c4dca7f..04a8875d0e 100644 --- a/src/stmem.h +++ b/src/stmem.h @@ -1,6 +1,6 @@ /* - * $Id: stmem.h,v 1.7 2003/10/20 11:23:38 robertc Exp $ + * $Id: stmem.h,v 1.8 2005/04/01 21:11:28 serassio Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -65,6 +65,7 @@ public: * as a contianer ourselves */ const Splay &getNodes() const; + char * NodeGet(mem_node * aNode); /* Only for use of MemObject */ void internalAppend(const char *data, int len); diff --git a/src/store_swapout.cc b/src/store_swapout.cc index fc8811d11b..1137e2317e 100644 --- a/src/store_swapout.cc +++ b/src/store_swapout.cc @@ -1,6 +1,6 @@ /* - * $Id: store_swapout.cc,v 1.99 2005/01/03 16:08:26 robertc Exp $ + * $Id: store_swapout.cc,v 1.100 2005/04/01 21:11:28 serassio Exp $ * * DEBUG: section 20 Storage Manager Swapout Functions * AUTHOR: Duane Wessels @@ -148,7 +148,7 @@ doPages(StoreEntry *anEntry) mem->swapout.queue_offset += swap_buf_len; - storeIOWrite(mem->swapout.sio, mem->swapout.memnode->data, swap_buf_len, -1, NULL); + storeIOWrite(mem->swapout.sio, mem->data_hdr.NodeGet(mem->swapout.memnode), swap_buf_len, -1, NULL); /* the storeWrite() call might generate an error */ if (anEntry->swap_status != SWAPOUT_WRITING)