Motr
M0
|
Network buffer pool allocates and manages a pool of network buffers. Users request a buffer from the pool and after its usage is over gives back to the pool. More...
![]() |
Data Structures | |
struct | m0_net_buffer_pool_ops |
struct | m0_net_buffer_pool |
Enumerations | |
enum | { M0_BUFFER_ANY_COLOUR = ~0, M0_NET_BUFFER_POOL_THRESHOLD = 2 } |
Network buffer pool allocates and manages a pool of network buffers. Users request a buffer from the pool and after its usage is over gives back to the pool.
It provides support for a pool of network buffers involving no higher level interfaces than the network module itself. It is associated with a single network domain. Non-blocking interfaces are available to get and put network buffers. Call-backs are provided to announce when the pool is non-empty or low on free buffers.
Upon receiving the not_empty call back user can put back buffers which are not in use into the pool.
The "coloured" variant of the get operation is done by returning the most recently used buffer that is associated with a specific colour (transfer machine), or if none such are found, the least recently used buffer from the pool, if any.
Pool is protected by a lock, to get or put a buffer into the pool user must acquire the lock and release the lock once its usage is over.
To finalize the pool all the buffers must be returned back to the pool (i.e number of free buffers must be equal to the total number of buffers).
To describe a typical buffer pool usage pattern, suppose that one wants a buffer pool of 10, size of each segment is 1024, number of segments is 64 and threshold is 10.
First, user needs to provide m0_net_buffer_pool_ops:
To put back the buffer in the pool: To use any colour for the buffer variable colour should be M0_BUFFER_ANY_COLOUR.
anonymous enum |
Enumerator | |
---|---|
M0_BUFFER_ANY_COLOUR | |
M0_NET_BUFFER_POOL_THRESHOLD |
Definition at line 140 of file buffer_pool.h.
|
static |
It removes the given buffer from the pool
Definition at line 141 of file buffer_pool.c.
|
static |
M0_INTERNAL void m0_net_buffer_pool_fini | ( | struct m0_net_buffer_pool * | pool | ) |
Finalizes a buffer pool.
Definition at line 154 of file buffer_pool.c.
M0_INTERNAL struct m0_net_buffer * m0_net_buffer_pool_get | ( | struct m0_net_buffer_pool * | pool, |
uint32_t | colour | ||
) |
Gets a buffer from the pool. If the colour is specified (i.e non zero) and the corresponding coloured list is not empty then the buffer is taken from the head of this list. Otherwise the buffer is taken from the head of the per buffer pool list.
Definition at line 215 of file buffer_pool.c.
M0_INTERNAL int m0_net_buffer_pool_init | ( | struct m0_net_buffer_pool * | pool, |
struct m0_net_domain * | ndom, | ||
uint32_t | threshold, | ||
uint32_t | seg_nr, | ||
m0_bcount_t | seg_size, | ||
uint32_t | colours, | ||
unsigned | shift, | ||
bool | dont_dump | ||
) |
Initializes fields of a buffer pool and tlist, which are used to populate the pool using m0_net_buffer_pool_provision().
pool | Pool to initialize. |
ndom | Network domain to associate with the pool. |
threshold | Number of buffer below which to notify the user. |
seg_nr | Number of segments in each buffer. |
colours | Number of colours in the pool. |
seg_size | Size of each segment in a buffer. |
shift | Alignment needed for network buffers. |
Definition at line 82 of file buffer_pool.c.
M0_INTERNAL bool m0_net_buffer_pool_invariant | ( | const struct m0_net_buffer_pool * | pool | ) |
Checks the buffer pool.
Definition at line 50 of file buffer_pool.c.
M0_INTERNAL bool m0_net_buffer_pool_is_locked | ( | const struct m0_net_buffer_pool * | pool | ) |
Check whether buffer pool is locked or not.
Definition at line 191 of file buffer_pool.c.
M0_INTERNAL bool m0_net_buffer_pool_is_not_locked | ( | const struct m0_net_buffer_pool * | pool | ) |
Returns true when buffer pool is not locked.
Definition at line 197 of file buffer_pool.c.
M0_INTERNAL void m0_net_buffer_pool_lock | ( | struct m0_net_buffer_pool * | pool | ) |
Acquires the lock on buffer pool.
Definition at line 186 of file buffer_pool.c.
M0_INTERNAL int m0_net_buffer_pool_provision | ( | struct m0_net_buffer_pool * | pool, |
uint32_t | buf_nr | ||
) |
It adds the buf_nr buffers in the buffer pool. Suppose to add 10 items to the pool, m0_net_buffer_pool_provision(pool, 10) can be used.
pool | Pool to provision. |
buf_nr | Number of buffers to be added in the pool. |
Definition at line 125 of file buffer_pool.c.
M0_INTERNAL bool m0_net_buffer_pool_prune | ( | struct m0_net_buffer_pool * | pool | ) |
Removes a buffer from the pool to prune it.
Definition at line 310 of file buffer_pool.c.
M0_INTERNAL void m0_net_buffer_pool_put | ( | struct m0_net_buffer_pool * | pool, |
struct m0_net_buffer * | buf, | ||
uint32_t | colour | ||
) |
Puts the buffer back to the pool. If the colour is specfied then the buffer is put at the head of corresponding coloured list and also put at the tail of the global list.
Definition at line 243 of file buffer_pool.c.
M0_INTERNAL void m0_net_buffer_pool_unlock | ( | struct m0_net_buffer_pool * | pool | ) |
Releases the lock on buffer pool.
Definition at line 203 of file buffer_pool.c.
M0_TL_DEFINE | ( | m0_net_pool | , |
M0_INTERNAL | , | ||
struct m0_net_buffer | |||
) |
M0_TL_DESCR_DEFINE | ( | m0_net_pool | , |
"net_buffer_pool" | , | ||
M0_INTERNAL | , | ||
struct m0_net_buffer | , | ||
nb_lru | , | ||
nb_magic | , | ||
M0_NET_BUFFER_LINK_MAGIC | , | ||
M0_NET_BUFFER_HEAD_MAGIC | |||
) |
Descriptor for the tlist of buffers.
|
static |
Adds a buffer to the pool to increase the capacity.
Definition at line 270 of file buffer_pool.c.
|
static |
|
static |