From: wessels <> Date: Wed, 19 Aug 1998 04:42:17 +0000 (+0000) Subject: experimental OPTIMISTIC IO patch X-Git-Tag: SQUID_3_0_PRE1~2846 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9d66d5217ee52056300ea0caa29021c09b249672;p=thirdparty%2Fsquid.git experimental OPTIMISTIC IO patch --- diff --git a/src/comm.cc b/src/comm.cc index 4dde1626cb..8ed96164b7 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -1,7 +1,7 @@ /* - * $Id: comm.cc,v 1.283 1998/08/18 19:13:59 wessels Exp $ + * $Id: comm.cc,v 1.284 1998/08/18 22:42:17 wessels Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -834,7 +834,11 @@ comm_write(int fd, char *buf, int size, CWCB * handler, void *handler_data, FREE state->handler_data = handler_data; state->free_func = free_func; cbdataLock(handler_data); +#ifdef OPTIMISTIC_IO + commHandleWrite(fd, state); +#else commSetSelect(fd, COMM_SELECT_WRITE, commHandleWrite, state, 0); +#endif } /* a wrapper around comm_write to allow for MemBuf to be comm_written in a snap */ diff --git a/src/disk.cc b/src/disk.cc index 5185780b8f..4cfdb7554a 100644 --- a/src/disk.cc +++ b/src/disk.cc @@ -1,7 +1,7 @@ /* - * $Id: disk.cc,v 1.127 1998/08/18 21:15:43 wessels Exp $ + * $Id: disk.cc,v 1.128 1998/08/18 22:42:18 wessels Exp $ * * DEBUG: section 6 Disk I/O Routines * AUTHOR: Harvest Derived @@ -166,6 +166,9 @@ diskHandleWrite(int fd, void *notused) struct _fde_disk *fdd = &F->disk; if (!fdd->write_q) return; +#ifdef OPTIMISTIC_IO + assert(!F->flags.calling_io_handler); +#endif debug(6, 3) ("diskHandleWrite: FD %d\n", fd); /* We need to combine subsequent write requests after the first */ /* But only if we don't need to seek() in between them, ugh! */ @@ -329,11 +332,17 @@ diskHandleWriteComplete(int fd, void *data, int len, int errcode) if (fdd->wrt_handle_data != NULL) cbdataUnlock(fdd->wrt_handle_data); if (do_callback) { +#ifdef OPTIMISTIC_IO + F->flags.calling_io_handler = 1; +#endif fdd->wrt_handle(fd, status, len, fdd->wrt_handle_data); /* * NOTE, this callback can close the FD, so we must * not touch 'F', 'fdd', etc. after this. */ +#ifdef OPTIMISTIC_IO + F->flags.calling_io_handler = 0; +#endif return; } } @@ -381,9 +390,18 @@ file_write(int fd, #if USE_ASYNC_IO diskHandleWrite(fd, NULL); #else +#ifdef OPTIMISTIC_IO + if (F->flags.calling_io_handler) +#endif commSetSelect(fd, COMM_SELECT_WRITE, diskHandleWrite, NULL, 0); +#ifdef OPTIMISTIC_IO + else + diskHandleWrite(fd, NULL); +#endif #endif +#ifndef OPTIMISTIC_IO F->flags.write_daemon = 1; +#endif } } @@ -406,6 +424,9 @@ diskHandleRead(int fd, void *data) fde *F = &fd_table[fd]; int len; #endif +#ifdef OPTIMISTIC_IO + assert(!F->flags.calling_io_handler); +#endif /* OPTIMISTIC_IO */ #if USE_ASYNC_IO aioRead(fd, ctrl_dat->offset, @@ -432,6 +453,9 @@ diskHandleReadComplete(int fd, void *data, int len, int errcode) { dread_ctrl *ctrl_dat = data; int rc = DISK_OK; +#ifdef OPTIMISTIC_IO + fde *F = &fd_table[fd]; +#endif /* OPTIMISTIC_IO */ errno = errcode; if (len == -2 && errcode == -2) { /* Read cancelled - cleanup */ cbdataUnlock(ctrl_dat->client_data); @@ -450,8 +474,14 @@ diskHandleReadComplete(int fd, void *data, int len, int errcode) } else if (len == 0) { rc = DISK_EOF; } +#ifdef OPTIMISTIC_IO + F->flags.calling_io_handler = 1; +#endif /* OPTIMISTIC_IO */ if (cbdataValid(ctrl_dat->client_data)) ctrl_dat->handler(fd, ctrl_dat->buf, len, rc, ctrl_dat->client_data); +#ifdef OPTIMISTIC_IO + F->flags.calling_io_handler = 0; +#endif /* OPTIMISTIC_IO */ cbdataUnlock(ctrl_dat->client_data); memFree(MEM_DREAD_CTRL, ctrl_dat); } @@ -465,6 +495,9 @@ int file_read(int fd, char *buf, int req_len, off_t offset, DRCB * handler, void *client_data) { dread_ctrl *ctrl_dat; +#ifdef OPTIMISTIC_IO + fde *F = &fd_table[fd]; +#endif /* OPTIMISTIC_IO */ assert(fd >= 0); ctrl_dat = memAllocate(MEM_DREAD_CTRL); ctrl_dat->fd = fd; @@ -478,11 +511,18 @@ file_read(int fd, char *buf, int req_len, off_t offset, DRCB * handler, void *cl #if USE_ASYNC_IO diskHandleRead(fd, ctrl_dat); #else +#ifndef OPTIMISTIC_IO commSetSelect(fd, COMM_SELECT_READ, diskHandleRead, ctrl_dat, 0); +#else + if (F->flags.calling_io_handler) + commSetSelect(fd, COMM_SELECT_READ, diskHandleRead, ctrl_dat, 0); + else + diskHandleRead(fd, ctrl_dat); +#endif /* OPTIMISTIC_IO */ #endif return DISK_OK; } diff --git a/src/http.cc b/src/http.cc index f87a9c0d4c..4d8f6950f4 100644 --- a/src/http.cc +++ b/src/http.cc @@ -1,6 +1,6 @@ /* - * $Id: http.cc,v 1.307 1998/08/17 16:44:07 wessels Exp $ + * $Id: http.cc,v 1.308 1998/08/18 22:42:19 wessels Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -433,6 +433,16 @@ httpReadReply(int fd, void *data) if (httpState->reply_hdr_state < 2) httpProcessReplyHeader(httpState, buf, len); storeAppend(entry, buf, len); +#ifdef OPTIMISTIC_IO + if (entry->store_status == STORE_ABORTED) { + /* + * the above storeAppend() call could ABORT this entry, + * in that case, the server FD should already be closed. + * there's nothing for us to do. + */ + (void) 0; + } else +#endif if (httpPconnTransferDone(httpState)) { /* yes we have to clear all these! */ commSetDefer(fd, NULL, NULL); diff --git a/src/store.cc b/src/store.cc index 68178a8aba..2b1c97f9d5 100644 --- a/src/store.cc +++ b/src/store.cc @@ -1,6 +1,6 @@ /* - * $Id: store.cc,v 1.444 1998/08/18 18:36:10 wessels Exp $ + * $Id: store.cc,v 1.445 1998/08/18 22:42:21 wessels Exp $ * * DEBUG: section 20 Storage Manager * AUTHOR: Harvest Derived @@ -385,8 +385,14 @@ storeAppend(StoreEntry * e, const char *buf, int len) } if (EBIT_TEST(e->flag, DELAY_SENDING)) return; +#ifdef OPTIMISTIC_IO + storeLockObject(e); +#endif InvokeHandlers(e); storeCheckSwapOut(e); +#ifdef OPTIMISTIC_IO + storeUnlockObject(e); +#endif } #ifdef __STDC__ diff --git a/src/store_client.cc b/src/store_client.cc index c24332bb71..9cf7e75b4f 100644 --- a/src/store_client.cc +++ b/src/store_client.cc @@ -1,6 +1,6 @@ /* - * $Id: store_client.cc,v 1.36 1998/08/18 03:04:35 wessels Exp $ + * $Id: store_client.cc,v 1.37 1998/08/18 22:42:22 wessels Exp $ * * DEBUG: section 20 Storage Manager Client-Side Interface * AUTHOR: Duane Wessels @@ -271,14 +271,23 @@ storeClientFileRead(store_client * sc) { MemObject *mem = sc->entry->mem_obj; assert(sc->callback != NULL); +#ifndef OPTIMISTIC_IO if (mem->swap_hdr_sz == 0) +#else + sc->flags.disk_io_pending = 1; + if (mem->swap_hdr_sz == 0) { +#endif file_read(sc->swapin_fd, sc->copy_buf, sc->copy_size, 0, storeClientReadHeader, sc); +#ifndef OPTIMISTIC_IO else { +#else + } else { +#endif if (sc->entry->swap_status == SWAPOUT_WRITING) assert(mem->swapout.done_offset > sc->copy_offset + mem->swap_hdr_sz); file_read(sc->swapin_fd, @@ -288,7 +297,9 @@ storeClientFileRead(store_client * sc) storeClientReadBody, sc); } +#ifndef OPTIMISTIC_IO sc->flags.disk_io_pending = 1; +#endif } static void diff --git a/src/structs.h b/src/structs.h index 0c6982e8f4..daf596c34a 100644 --- a/src/structs.h +++ b/src/structs.h @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.204 1998/08/18 20:48:52 wessels Exp $ + * $Id: structs.h,v 1.205 1998/08/18 22:42:23 wessels Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -495,6 +495,9 @@ struct _fde { int nolinger:1; int nonblocking:1; int ipc:1; +#ifdef OPTIMISTIC_IO + int calling_io_handler:1; +#endif } flags; int bytes_read; int bytes_written;