]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/mem/PoolChunked.h
2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
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.
9 #ifndef _MEM_POOL_CHUNKED_H_
10 #define _MEM_POOL_CHUNKED_H_
14 #define MEM_CHUNK_SIZE 4 * 4096 /* 16KB ... 4 * VM_PAGE_SZ */
15 #define MEM_CHUNK_MAX_SIZE 256 * 1024 /* 2MB */
19 /// \ingroup MemPoolsAPI
20 class MemPoolChunked
: public MemImplementingAllocator
23 friend class MemChunk
;
24 MemPoolChunked(const char *label
, size_t obj_size
);
26 void convertFreeCacheToChunkFreeCache();
27 virtual void clean(time_t maxage
);
30 \param stats Object to be filled with statistical data about pool.
31 \retval Number of objects in use, ie. allocated.
33 virtual int getStats(MemPoolStats
* stats
, int accumulate
);
38 virtual int getInUseCount();
40 virtual void *allocate();
41 virtual void deallocate(void *, bool aggressive
);
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.
50 \note As a general guideline, increase chunk size only for pools that keep
51 * very many items for relatively long time.
53 virtual void setChunkSize(size_t chunksize
);
55 virtual bool idleTrigger(int shift
) const;
61 MemChunk
*nextFreeChunk
;
63 Splay
<MemChunk
*> allChunks
;
66 /// \ingroup MemPoolsAPI
70 MemChunk(MemPoolChunked
*pool
);
75 MemChunk
*nextFreeChunk
;
81 #endif /* _MEM_POOL_CHUNKED_H_ */