From 9a4a2e2286cb372ca462f6f25f78de686ea3e4ce Mon Sep 17 00:00:00 2001 From: "Anand V. Avati" Date: Sat, 18 Apr 2009 02:49:03 +0530 Subject: pruning buffer margin - do not destroy if no other non-filled arenas are in the pool --- libglusterfs/src/iobuf.c | 27 +++++++++++++++++++++++++-- libglusterfs/src/iobuf.h | 2 +- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/libglusterfs/src/iobuf.c b/libglusterfs/src/iobuf.c index 84e3b5efe..7cbc1702e 100644 --- a/libglusterfs/src/iobuf.c +++ b/libglusterfs/src/iobuf.c @@ -143,12 +143,31 @@ err: } +struct iobuf_arena * +__iobuf_arena_unprune (struct iobuf_pool *iobuf_pool) +{ + struct iobuf_arena *iobuf_arena = NULL; + struct iobuf_arena *tmp = NULL; + + list_for_each_entry (tmp, &iobuf_pool->purge.list, list) { + list_del_init (&tmp->list); + iobuf_arena = tmp; + break; + } + + return iobuf_arena; +} + + struct iobuf_arena * __iobuf_pool_add_arena (struct iobuf_pool *iobuf_pool) { struct iobuf_arena *iobuf_arena = NULL; - iobuf_arena = __iobuf_arena_alloc (iobuf_pool); + iobuf_arena = __iobuf_arena_unprune (iobuf_pool); + + if (!iobuf_arena) + iobuf_arena = __iobuf_arena_alloc (iobuf_pool); if (!iobuf_arena) return NULL; @@ -221,13 +240,17 @@ iobuf_pool_new (size_t arena_size, size_t page_size) } - void __iobuf_pool_prune (struct iobuf_pool *iobuf_pool) { struct iobuf_arena *iobuf_arena = NULL; struct iobuf_arena *tmp = NULL; + if (list_empty (&iobuf_pool->arenas.list)) + /* buffering - preserve this one arena (if at all) + for __iobuf_arena_unprune */ + return; + list_for_each_entry_safe (iobuf_arena, tmp, &iobuf_pool->purge.list, list) { if (iobuf_arena->active_cnt) diff --git a/libglusterfs/src/iobuf.h b/libglusterfs/src/iobuf.h index 4c3477084..71b115c5d 100644 --- a/libglusterfs/src/iobuf.h +++ b/libglusterfs/src/iobuf.h @@ -86,7 +86,7 @@ struct iobuf_pool { struct iobuf_arena arenas; /* head node arena (unused by itself) */ struct iobuf_arena filled; /* arenas without free iobufs */ - struct iobuf_arena purge; /* arenas to be purged right away */ + struct iobuf_arena purge; /* arenas which can be purged */ }; -- cgit