struct buffer *get_large_trash_chunk(void);
struct buffer *get_small_trash_chunk(void);
struct buffer *get_trash_chunk_sz(size_t size);
+struct buffer *get_best_trash_chunk(const struct buffer *buf, size_t size);
struct buffer *get_larger_trash_chunk(struct buffer *chunk);
int init_trash_buffers(int first);
else
return NULL;
}
+/* Returns a trash chunk accordingly to the requested size and never larger
+ * that the buffer <buf>. So if <buf> is a large buffer,
+ * alloc_trash_chunk_sz() function is called. Otherwise, if the size is
+ * smaller enough, a regular buffer is allocated. If <size> is too big and
+ * <buf> is not a large buffer, NULL is returned.
+ */
+static forceinline struct buffer *alloc_best_trash_chunk(const struct buffer *buf, size_t size)
+{
+ if (pool_head_large_trash && buf->size == pool_head_large_trash->size)
+ return alloc_trash_chunk_sz(size);
+ else if (size <= pool_head_trash->size)
+ return alloc_trash_chunk();
+ else
+ return NULL;
+}
/*
* free a trash chunk allocated by alloc_trash_chunk(). NOP on NULL.
return NULL;
}
+/* Returns a trash chunk accordingly to the requested size and never larger
+ * that the buffer <buf>. So if <buf> is a large buffer,
+ * get_trash_chunk_sz() function is called. Otherwise, if the size is
+ * smaller enough, a regular buffer is returned. If <size> is too big and
+ * <buf> is not a large buffer, NULL is returned.
+ */
+struct buffer *get_best_trash_chunk(const struct buffer *buf, size_t size)
+{
+ if (large_trash_size && buf->size == large_trash_size)
+ return get_trash_chunk_sz(size);
+ else if (size <= trash_size)
+ return get_trash_chunk();
+ else
+ return NULL;
+}
+
/* Returns a larger buffer than <chk> if possible or NULL otherwise. If a larger
* buffer is returned, content of <chk> are copied.
*/