3
* Memory pool type definitions
5
* Prealloc memory pools:
6
* These memory pools are memory allocators based on subdividing a single
7
* block of memory into homogenous objects. It's suitable for data structures
8
* with a statically configured maximum # of objects, such as using tunable
9
* parameters. It's not suitable for heterogenous data structures nor for
10
* data structures where the maximum count is unbounded.
12
* Since the memory for all the objects is preallocated during initialization,
13
* that memory is unavailable to the rest of the system. This is appropriate both for
14
* small data structures, and for medium/large data structures where the peak and average
15
* utilization are similar. For data structures where average utilization is low but peak
16
* is very high, it's better to use the real heap so the memory gets freed when it's
19
* Each individual memory pool can obtain it's memory from the user/client
20
* code or from the heap, as desired.
24
* The memory pool allocator uses the heap (malloc/free) for memory.
25
* In this case, the pool allocator is just providing statistics and instrumentation
26
* on top of the heap, without modifying the heap allocation implementation.
28
* The memory pool component consists of two major abstractions:
29
* Manager: the factory for memory pools
30
* Pool: an individual pool that can allocate objects
32
* The memory pool manager maintains an array of individual pools so that instrumentation
33
* can examine and manage all of them globally.
35
* Copyright (C) 2011, Broadcom Corporation. All Rights Reserved.
37
* Permission to use, copy, modify, and/or distribute this software for any
38
* purpose with or without fee is hereby granted, provided that the above
39
* copyright notice and this permission notice appear in all copies.
41
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
42
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
43
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
44
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
45
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
46
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
47
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
52
#ifndef _BCM_MPOOL_PRI_H
53
#define _BCM_MPOOL_PRI_H 1
57
#include "bcm_mpool_pub.h"
59
typedef struct bcm_mp_free_list {
60
struct bcm_mp_free_list *next;
63
typedef struct bcm_mp_prealloc_pool {
66
unsigned int padded_objsz;
67
void *malloc_memstart;
68
bcm_mp_free_list_t *free_objp;
69
} bcm_mp_prealloc_pool_t;
71
typedef struct bcm_mp_heap_pool {
76
typedef struct bcm_mp_pool {
78
char name[BCM_MP_NAMELEN];
86
bcm_mp_prealloc_pool_t p;
91
#define BCM_MP_TYPE_MASK 0x0003
92
#define BCM_MP_TYPE_HEAP 0
93
#define BCM_MP_TYPE_PREALLOC 1
95
#define BCM_MP_GET_POOL_TYPE(pool) (((pool)->flags) & BCM_MP_TYPE_MASK)
96
#define BCM_MP_SET_POOL_TYPE(pool, type) ((pool)->flags = ((pool)->flags & ~BCM_MP_TYPE_MASK) \
99
#define BCM_MP_POOL_IN_USE_MASK 0x0004
101
#define BCM_MP_SET_IN_USE(pool) ((pool)->flags |= BCM_MP_POOL_IN_USE_MASK)
102
#define BCM_MP_CLEAR_IN_USE(pool) ((pool)->flags &= ~BCM_MP_POOL_IN_USE_MASK)
103
#define BCM_MP_IS_IN_USE(pool) (((pool)->flags & BCM_MP_POOL_IN_USE_MASK) == \
104
BCM_MP_POOL_IN_USE_MASK)
106
typedef struct bcm_mpm_mgr {
107
bcm_mp_pool_t *pool_objs;
108
bcm_mp_free_list_t *free_pools;