]> git.ipfire.org Git - thirdparty/squid.git/blame - src/mem/PoolChunked.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / mem / PoolChunked.h
CommitLineData
5c193dec
AJ
1/*
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
8cfaefed
HN
9#ifndef _MEM_POOL_CHUNKED_H_
10#define _MEM_POOL_CHUNKED_H_
11
ed6e9fb9 12#include "mem/Pool.h"
8cfaefed 13
ed6e9fb9 14#define MEM_CHUNK_SIZE 4 * 4096 /* 16KB ... 4 * VM_PAGE_SZ */
f53969cc 15#define MEM_CHUNK_MAX_SIZE 256 * 1024 /* 2MB */
8cfaefed
HN
16
17class MemChunk;
18
19/// \ingroup MemPoolsAPI
20class MemPoolChunked : public MemImplementingAllocator
21{
22public:
23 friend class MemChunk;
24 MemPoolChunked(const char *label, size_t obj_size);
25 ~MemPoolChunked();
26 void convertFreeCacheToChunkFreeCache();
27 virtual void clean(time_t maxage);
28
29 /**
f53969cc
SM
30 \param stats Object to be filled with statistical data about pool.
31 \retval Number of objects in use, ie. allocated.
8cfaefed
HN
32 */
33 virtual int getStats(MemPoolStats * stats, int accumulate);
34
35 void createChunk();
36 void *get();
37 void push(void *obj);
38 virtual int getInUseCount();
39protected:
40 virtual void *allocate();
2be7332c 41 virtual void deallocate(void *, bool aggressive);
8cfaefed
HN
42public:
43 /**
44 * Allows you tune chunk size of pooling. Objects are allocated in chunks
45 * instead of individually. This conserves memory, reduces fragmentation.
46 * Because of that memory can be freed also only in chunks. Therefore
47 * there is tradeoff between memory conservation due to chunking and free
48 * memory fragmentation.
49 *
50 \note As a general guideline, increase chunk size only for pools that keep
51 * very many items for relatively long time.
52 */
53 virtual void setChunkSize(size_t chunksize);
54
55 virtual bool idleTrigger(int shift) const;
56
57 size_t chunk_size;
58 int chunk_capacity;
8cfaefed
HN
59 int chunkCount;
60 void *freeCache;
61 MemChunk *nextFreeChunk;
62 MemChunk *Chunks;
63 Splay<MemChunk *> allChunks;
64};
65
66/// \ingroup MemPoolsAPI
67class MemChunk
68{
69public:
70 MemChunk(MemPoolChunked *pool);
71 ~MemChunk();
72 void *freeList;
73 void *objCache;
74 int inuse_count;
75 MemChunk *nextFreeChunk;
76 MemChunk *next;
77 time_t lastref;
78 MemPoolChunked *pool;
79};
80
81#endif /* _MEM_POOL_CHUNKED_H_ */
f53969cc 82