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