diff options
Diffstat (limited to 'libglusterfs/src/iobuf.h')
| -rw-r--r-- | libglusterfs/src/iobuf.h | 80 |
1 files changed, 52 insertions, 28 deletions
diff --git a/libglusterfs/src/iobuf.h b/libglusterfs/src/iobuf.h index fc8ff623a..5595309e1 100644 --- a/libglusterfs/src/iobuf.h +++ b/libglusterfs/src/iobuf.h @@ -1,20 +1,11 @@ /* - Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. */ #ifndef _IOBUF_H_ @@ -26,6 +17,9 @@ #include <sys/mman.h> #include <sys/uio.h> +#define GF_VARIABLE_IOBUF_COUNT 32 +#define GF_IOBREF_IOBUF_COUNT 16 + /* Lets try to define the new anonymous mapping * flag, in case the system is still using the * now deprecated MAP_ANON flag. @@ -37,6 +31,11 @@ #define MAP_ANONYMOUS MAP_ANON #endif +#define GF_ALIGN_BUF(ptr,bound) ((void *)((unsigned long)(ptr + bound - 1) & \ + (unsigned long)(~(bound - 1)))) + +#define GF_IOBUF_ALIGN_SIZE 512 + /* one allocatable unit for the consumers of the IOBUF API */ /* each unit hosts @page_size bytes of memory */ struct iobuf; @@ -49,6 +48,10 @@ struct iobuf_arena; /* expandable and contractable pool of memory, internally broken into arenas */ struct iobuf_pool; +struct iobuf_init_config { + size_t pagesize; + int32_t num_pages; +}; struct iobuf { union { @@ -64,6 +67,9 @@ struct iobuf { int ref; /* 0 == passive, >0 == active */ void *ptr; /* usable memory region by the consumer */ + + void *free_ptr; /* in case of stdalloc, this is the + one to be freed */ }; @@ -75,6 +81,13 @@ struct iobuf_arena { struct iobuf_arena *prev; }; }; + + size_t page_size; /* size of all iobufs in this arena */ + size_t arena_size; /* this is equal to + (iobuf_pool->arena_size / page_size) + * page_size */ + size_t page_count; + struct iobuf_pool *iobuf_pool; void *mem_base; @@ -86,25 +99,34 @@ struct iobuf_arena { int passive_cnt; struct iobuf passive; /* head node iobuf (unused by itself) */ + uint64_t alloc_cnt; /* total allocs in this pool */ + int max_active; /* max active buffers at a given time */ }; struct iobuf_pool { pthread_mutex_t mutex; - size_t page_size; /* size of all iobufs in this pool */ - size_t arena_size; /* size of memory region in arena */ + size_t arena_size; /* size of memory region in + arena */ + size_t default_page_size; /* default size of iobuf */ int arena_cnt; - struct iobuf_arena arenas; /* head node arena - (unused by itself) */ - struct iobuf_arena filled; /* arenas without free iobufs */ - struct iobuf_arena purge; /* arenas which can be purged */ -}; + struct list_head arenas[GF_VARIABLE_IOBUF_COUNT]; + /* array of arenas. Each element of the array is a list of arenas + holding iobufs of particular page_size */ + struct list_head filled[GF_VARIABLE_IOBUF_COUNT]; + /* array of arenas without free iobufs */ + struct list_head purge[GF_VARIABLE_IOBUF_COUNT]; + /* array of of arenas which can be purged */ + + uint64_t request_misses; /* mostly the requests for higher + value of iobufs */ +}; -struct iobuf_pool *iobuf_pool_new (size_t arena_size, size_t page_size); +struct iobuf_pool *iobuf_pool_new (void); void iobuf_pool_destroy (struct iobuf_pool *iobuf_pool); struct iobuf *iobuf_get (struct iobuf_pool *iobuf_pool); void iobuf_unref (struct iobuf *iobuf); @@ -113,14 +135,14 @@ void iobuf_pool_destroy (struct iobuf_pool *iobuf_pool); void iobuf_to_iovec(struct iobuf *iob, struct iovec *iov); #define iobuf_ptr(iob) ((iob)->ptr) -#define iobpool_pagesize(iobpool) ((iobpool)->page_size) -#define iobuf_pagesize(iob) (iobpool_pagesize((iob)->iobuf_arena->iobuf_pool)) +#define iobpool_default_pagesize(iobpool) ((iobpool)->default_page_size) +#define iobuf_pagesize(iob) (iob->iobuf_arena->page_size) struct iobref { gf_lock_t lock; int ref; - struct iobuf *iobrefs[8]; + struct iobuf *iobrefs[GF_IOBREF_IOBUF_COUNT]; }; struct iobref *iobref_new (); @@ -128,10 +150,12 @@ struct iobref *iobref_ref (struct iobref *iobref); void iobref_unref (struct iobref *iobref); int iobref_add (struct iobref *iobref, struct iobuf *iobuf); int iobref_merge (struct iobref *to, struct iobref *from); - +void iobref_clear (struct iobref *iobref); size_t iobuf_size (struct iobuf *iobuf); size_t iobref_size (struct iobref *iobref); void iobuf_stats_dump (struct iobuf_pool *iobuf_pool); +struct iobuf * +iobuf_get2 (struct iobuf_pool *iobuf_pool, size_t page_size); #endif /* !_IOBUF_H_ */ |
