Author: adrian.chadd
Date: Sat Mar 28 23:40:30 2009
New Revision: 13886
Modified:
branches/LUSCA_HEAD/libasyncio/aiops.c
branches/LUSCA_HEAD/libasyncio/aiops.h
branches/LUSCA_HEAD/libasyncio/aiops_win32.c
branches/LUSCA_HEAD/libasyncio/async_io.c
Log:
remove the memory pooled buffers in the asyncio code, just use xmalloc().
MemPools are a null operation for caching now - they're just for
accounting -
so this change removes the NUL'ing of buffers and the statistics keeping.
It should reduce the CPU used in heavy read workloads in AUFS and COSS.
Modified: branches/LUSCA_HEAD/libasyncio/aiops.c
==============================================================================
--- branches/LUSCA_HEAD/libasyncio/aiops.c (original)
+++ branches/LUSCA_HEAD/libasyncio/aiops.c Sat Mar 28 23:40:30 2009
@@ -114,18 +114,6 @@
static squidaio_thread_t *threads = NULL;
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
-
-static MemPool *squidaio_large_bufs = NULL; /* 16K */
-static MemPool *squidaio_medium_bufs = NULL; /* 8K */
-static MemPool *squidaio_small_bufs = NULL; /* 4K */
-static MemPool *squidaio_tiny_bufs = NULL; /* 2K */
-static MemPool *squidaio_micro_bufs = NULL; /* 128K */
-
static int request_queue_len = 0;
static MemPool *squidaio_request_pool = NULL;
static MemPool *squidaio_thread_pool = NULL;
@@ -152,75 +140,6 @@
#endif
static pthread_t main_thread;
-static MemPool *
-squidaio_get_pool(int size)
-{
- MemPool *p;
- if (size <= AIO_LARGE_BUFS) {
- if (size <= AIO_MICRO_BUFS)
- p = squidaio_micro_bufs;
- else if (size <= AIO_TINY_BUFS)
- p = squidaio_tiny_bufs;
- else if (size <= AIO_SMALL_BUFS)
- p = squidaio_small_bufs;
- else if (size <= AIO_MEDIUM_BUFS)
- p = squidaio_medium_bufs;
- else
- p = squidaio_large_bufs;
- } else
- p = NULL;
- return p;
-}
-
-void *
-squidaio_xmalloc(int size)
-{
- void *p;
- MemPool *pool;
-
- if ((pool = squidaio_get_pool(size)) != NULL) {
- p = memPoolAlloc(pool);
- } else
- p = xmalloc(size);
-
- return p;
-}
-
-static char *
-squidaio_xstrdup(const char *str)
-{
- char *p;
- int len = strlen(str) + 1;
-
- p = squidaio_xmalloc(len);
- strncpy(p, str, len);
-
- return p;
-}
-
-void
-squidaio_xfree(void *p, int size)
-{
- MemPool *pool;
-
- if ((pool = squidaio_get_pool(size)) != NULL) {
- memPoolFree(pool, p);
- } else
- xfree(p);
-}
-
-static void
-squidaio_xstrfree(char *str)
-{
- MemPool *pool;
- int len = strlen(str) + 1;
-
- if ((pool = squidaio_get_pool(len)) != NULL) {
- memPoolFree(pool, str);
- } else
- xfree(str);
-}
-
static void
squidaio_fdhandler(int fd, void *data)
{
@@ -333,11 +252,6 @@
/* Create request pool */
squidaio_request_pool = memPoolCreate("aio_request",
sizeof(squidaio_request_t));
- squidaio_large_bufs = memPoolCreate("squidaio_large_bufs",
AIO_LARGE_BUFS);
- squidaio_medium_bufs = memPoolCreate("squidaio_medium_bufs",
AIO_MEDIUM_BUFS);
- squidaio_small_bufs = memPoolCreate("squidaio_small_bufs",
AIO_SMALL_BUFS);
- squidaio_tiny_bufs = memPoolCreate("squidaio_tiny_bufs",
AIO_TINY_BUFS);
- squidaio_micro_bufs = memPoolCreate("squidaio_micro_bufs",
AIO_MICRO_BUFS);
squidaio_initialised = 1;
}
@@ -560,14 +474,14 @@
case _AIO_OP_STAT:
if (!cancelled && requestp->ret == 0)
xmemcpy(requestp->statp, requestp->tmpstatp, sizeof(struct stat));
- squidaio_xfree(requestp->tmpstatp, sizeof(struct stat));
- squidaio_xstrfree(requestp->path);
+ xfree(requestp->tmpstatp);
+ xfree(requestp->path);
break;
case _AIO_OP_OPEN:
if (cancelled && requestp->ret >= 0)
/* The open() was cancelled but completed */
close(requestp->ret);
- squidaio_xstrfree(requestp->path);
+ xfree(requestp->path);
break;
case _AIO_OP_CLOSE:
if (cancelled && requestp->ret < 0)
@@ -577,7 +491,7 @@
case _AIO_OP_UNLINK:
case _AIO_OP_TRUNCATE:
case _AIO_OP_OPENDIR:
- squidaio_xstrfree(requestp->path);
+ xfree(requestp->path);
break;
case _AIO_OP_READ:
break;
@@ -617,7 +531,7 @@
squidaio_request_t *requestp;
requestp = memPoolAlloc(squidaio_request_pool);
- requestp->path = (char *) squidaio_xstrdup(path);
+ requestp->path = (char *) xstrdup(path);
requestp->oflag = oflag;
requestp->mode = mode;
requestp->resultp = resultp;
@@ -738,9 +652,9 @@
squidaio_request_t *requestp;
requestp = memPoolAlloc(squidaio_request_pool);
- requestp->path = (char *) squidaio_xstrdup(path);
+ requestp->path = (char *) xstrdup(path);
requestp->statp = sb;
- requestp->tmpstatp = (struct stat *) squidaio_xmalloc(sizeof(struct
stat));
+ requestp->tmpstatp = (struct stat *) xcalloc(1, sizeof(struct stat));
requestp->resultp = resultp;
requestp->request_type = _AIO_OP_STAT;
requestp->cancelled = 0;
@@ -764,7 +678,7 @@
squidaio_request_t *requestp;
requestp = memPoolAlloc(squidaio_request_pool);
- requestp->path = squidaio_xstrdup(path);
+ requestp->path = xstrdup(path);
requestp->resultp = resultp;
requestp->request_type = _AIO_OP_UNLINK;
requestp->cancelled = 0;
@@ -789,7 +703,7 @@
squidaio_request_t *requestp;
requestp = memPoolAlloc(squidaio_request_pool);
- requestp->path = (char *) squidaio_xstrdup(path);
+ requestp->path = (char *) xstrdup(path);
requestp->offset = length;
requestp->resultp = resultp;
requestp->request_type = _AIO_OP_TRUNCATE;
Modified: branches/LUSCA_HEAD/libasyncio/aiops.h
==============================================================================
--- branches/LUSCA_HEAD/libasyncio/aiops.h (original)
+++ branches/LUSCA_HEAD/libasyncio/aiops.h Sat Mar 28 23:40:30 2009
@@ -84,7 +84,5 @@
int squidaio_operations_pending(void);
int squidaio_sync(void);
int squidaio_get_queue_len(void);
-void *squidaio_xmalloc(int size);
-void squidaio_xfree(void *p, int size);
#endif
Modified: branches/LUSCA_HEAD/libasyncio/aiops_win32.c
==============================================================================
--- branches/LUSCA_HEAD/libasyncio/aiops_win32.c (original)
+++ branches/LUSCA_HEAD/libasyncio/aiops_win32.c Sat Mar 28 23:40:30 2009
@@ -138,18 +138,6 @@
static squidaio_thread_t *threads = NULL;
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
-
-static MemPool *squidaio_large_bufs = NULL; /* 16K */
-static MemPool *squidaio_medium_bufs = NULL; /* 8K */
-static MemPool *squidaio_small_bufs = NULL; /* 4K */
-static MemPool *squidaio_tiny_bufs = NULL; /* 2K */
-static MemPool *squidaio_micro_bufs = NULL; /* 128K */
-
static int request_queue_len = 0;
static MemPool *squidaio_request_pool = NULL;
static MemPool *squidaio_thread_pool = NULL;
@@ -172,75 +160,6 @@
static int done_signalled = 0;
static HANDLE main_thread;
-static MemPool *
-squidaio_get_pool(int size)
-{
- MemPool *p;
- if (size <= AIO_LARGE_BUFS) {
- if (size <= AIO_MICRO_BUFS)
- p = squidaio_micro_bufs;
- else if (size <= AIO_TINY_BUFS)
- p = squidaio_tiny_bufs;
- else if (size <= AIO_SMALL_BUFS)
- p = squidaio_small_bufs;
- else if (size <= AIO_MEDIUM_BUFS)
- p = squidaio_medium_bufs;
- else
- p = squidaio_large_bufs;
- } else
- p = NULL;
- return p;
-}
-
-void *
-squidaio_xmalloc(int size)
-{
- void *p;
- MemPool *pool;
-
- if ((pool = squidaio_get_pool(size)) != NULL) {
- p = memPoolAlloc(pool);
- } else
- p = xmalloc(size);
-
- return p;
-}
-
-static char *
-squidaio_xstrdup(const char *str)
-{
- char *p;
- int len = strlen(str) + 1;
-
- p = squidaio_xmalloc(len);
- strncpy(p, str, len);
-
- return p;
-}
-
-void
-squidaio_xfree(void *p, int size)
-{
- MemPool *pool;
-
- if ((pool = squidaio_get_pool(size)) != NULL) {
- memPoolFree(pool, p);
- } else
- xfree(p);
-}
-
-static void
-squidaio_xstrfree(char *str)
-{
- MemPool *pool;
- int len = strlen(str) + 1;
-
- if ((pool = squidaio_get_pool(len)) != NULL) {
- memPoolFree(pool, str);
- } else
- xfree(str);
-}
-
static void
squidaio_fdhandler(int fd, void *data)
{
@@ -365,12 +284,6 @@
/* Create request pool */
squidaio_request_pool = memPoolCreate("aio_request",
sizeof(squidaio_request_t));
- squidaio_large_bufs = memPoolCreate("squidaio_large_bufs",
AIO_LARGE_BUFS);
- squidaio_medium_bufs = memPoolCreate("squidaio_medium_bufs",
AIO_MEDIUM_BUFS);
- squidaio_small_bufs = memPoolCreate("squidaio_small_bufs",
AIO_SMALL_BUFS);
- squidaio_tiny_bufs = memPoolCreate("squidaio_tiny_bufs",
AIO_TINY_BUFS);
- squidaio_micro_bufs = memPoolCreate("squidaio_micro_bufs",
AIO_MICRO_BUFS);
-
squidaio_initialised = 1;
}
@@ -834,7 +747,7 @@
requestp = memPoolAlloc(squidaio_request_pool);
requestp->path = (char *) squidaio_xstrdup(path);
requestp->statp = sb;
- requestp->tmpstatp = (struct stat *) squidaio_xmalloc(sizeof(struct
stat));
+ requestp->tmpstatp = (struct stat *) xcalloc(1, sizeof(struct stat));
requestp->resultp = resultp;
requestp->request_type = _AIO_OP_STAT;
requestp->cancelled = 0;
Modified: branches/LUSCA_HEAD/libasyncio/async_io.c
==============================================================================
--- branches/LUSCA_HEAD/libasyncio/async_io.c (original)
+++ branches/LUSCA_HEAD/libasyncio/async_io.c Sat Mar 28 23:40:30 2009
@@ -227,7 +227,7 @@
ctrlp->free_func(ctrlp->bufp);
/* free temporary read buffer */
if (ctrlp->operation == _AIO_READ)
- squidaio_xfree(ctrlp->bufp, ctrlp->len);
+ xfree(ctrlp->bufp);
}
dlinkDelete(m, &used_list);
memPoolFree(squidaio_ctrl_pool, ctrlp);
@@ -277,7 +277,7 @@
ctrlp->done_handler_data = callback_data;
ctrlp->operation = _AIO_READ;
ctrlp->len = len;
- ctrlp->bufp = squidaio_xmalloc(len);
+ ctrlp->bufp = xmalloc(len);
if (offset >= 0)
seekmode = SEEK_SET;
else {
@@ -388,7 +388,7 @@
ctrlp->free_func(ctrlp->bufp);
/* free temporary read buffer */
if (ctrlp->operation == _AIO_READ)
- squidaio_xfree(ctrlp->bufp, ctrlp->len);
+ xfree(ctrlp->bufp);
memPoolFree(squidaio_ctrl_pool, ctrlp);
}
return retval;
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"lusca-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/lusca-commit?hl=en
-~----------~----~----~----~------~----~------~--~---