summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libglusterfs/src/iobuf.c27
-rw-r--r--libglusterfs/src/iobuf.h2
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
@@ -144,11 +144,30 @@ 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 */
};