diff options
| author | Xavi Hernandez <xhernandez@redhat.com> | 2019-06-21 11:28:08 +0200 |
|---|---|---|
| committer | Atin Mukherjee <amukherj@redhat.com> | 2019-06-26 08:57:42 +0000 |
| commit | 1716a907da1a835b658740f1325033d7ddd44952 (patch) | |
| tree | aea3592d103ce087aecfb124955bb4750a678144 /libglusterfs/src/glusterfs | |
| parent | dc1b87fcfef08c9497b0c02b2410c9d18bbc2dba (diff) | |
core: fix memory allocation issues
Two problems have been identified that caused that gluster's memory
usage were twice higher than required.
1. An off by 1 error caused that all objects allocated from the memory
pools were taken from a pool bigger than required. Since each pool
corresponds to a size equal to a power of two, this was wasting half
of the available memory.
2. The header information used for accounting on each memory object was
not taken into consideration when searching for a suitable memory
pool. It was added later when each individual block was allocated.
This made this space "invisible" to memory accounting.
Credits: Thanks to Nithya Balachandran for identifying this problem and
testing this patch.
Fixes: bz#1722802
Change-Id: I90e27ad795fe51ca11c13080f62207451f6c138c
Signed-off-by: Xavi Hernandez <xhernandez@redhat.com>
Diffstat (limited to 'libglusterfs/src/glusterfs')
| -rw-r--r-- | libglusterfs/src/glusterfs/mem-pool.h | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/libglusterfs/src/glusterfs/mem-pool.h b/libglusterfs/src/glusterfs/mem-pool.h index 004aa179b19..e0441756be7 100644 --- a/libglusterfs/src/glusterfs/mem-pool.h +++ b/libglusterfs/src/glusterfs/mem-pool.h @@ -230,7 +230,10 @@ typedef struct pooled_obj_hdr { struct mem_pool *pool; } pooled_obj_hdr_t; -#define AVAILABLE_SIZE(p2) (1 << (p2)) +/* Each memory block inside a pool has a fixed size that is a power of two. + * However each object will have a header that will reduce the available + * space. */ +#define AVAILABLE_SIZE(p2) ((1UL << (p2)) - sizeof(pooled_obj_hdr_t)) typedef struct per_thread_pool { /* the pool that was used to request this allocation */ |
