This is an automated email from the ASF dual-hosted git repository.
duke8253 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new ecb4135 add -F option
ecb4135 is described below
commit ecb4135f0091174a3b2fc5cc495f0871bf5d1b58
Author: Fei Deng <[email protected]>
AuthorDate: Thu May 10 10:45:56 2018 -0500
add -F option
---
doc/appendices/command-line/traffic_server.en.rst | 6 +++
iocore/eventsystem/I_ProxyAllocator.h | 25 +++++++-----
iocore/eventsystem/ProxyAllocator.cc | 3 +-
lib/ts/Allocator.h | 49 ++++++++++++++---------
lib/ts/ink_args.cc | 1 +
lib/ts/ink_args.h | 1 +
lib/ts/ink_queue.cc | 30 +++++++++-----
lib/ts/ink_queue.h | 11 +++--
lib/ts/test_freelist.cc | 17 ++++----
proxy/Main.cc | 6 +--
proxy/http2/test_HPACK.cc | 7 ++--
11 files changed, 98 insertions(+), 58 deletions(-)
diff --git a/doc/appendices/command-line/traffic_server.en.rst
b/doc/appendices/command-line/traffic_server.en.rst
index 5b8cc01..4f46c71 100644
--- a/doc/appendices/command-line/traffic_server.en.rst
+++ b/doc/appendices/command-line/traffic_server.en.rst
@@ -53,6 +53,12 @@ use :manpage:`malloc(3)` for every allocation. Though this
option
should not commonly be needed, it may be beneficial in memory-constrained
environments or where the working set is highly variable.
+.. option:: -F, --disable_pfreelist
+
+Disable free list in ProxyAllocator which were left out by the -f
+option. Please note that this option is a temporary, testing
+option, and will be removed in the future.
+
.. option:: -o LEVEL, --dprintf_level LEVEL
.. option:: -R LEVEL, --regression LEVEL
diff --git a/iocore/eventsystem/I_ProxyAllocator.h
b/iocore/eventsystem/I_ProxyAllocator.h
index 7252adf..fec0ef9 100644
--- a/iocore/eventsystem/I_ProxyAllocator.h
+++ b/iocore/eventsystem/I_ProxyAllocator.h
@@ -36,6 +36,7 @@ class EThread;
extern int thread_freelist_high_watermark;
extern int thread_freelist_low_watermark;
+extern int cmd_disable_pfreelist;
struct ProxyAllocator {
int allocated;
@@ -48,7 +49,7 @@ template <class C>
inline C *
thread_alloc(ClassAllocator<C> &a, ProxyAllocator &l)
{
- if (l.freelist) {
+ if (!cmd_disable_pfreelist && l.freelist) {
C *v = (C *)l.freelist;
l.freelist = *(C **)l.freelist;
--(l.allocated);
@@ -62,7 +63,7 @@ template <class C>
inline C *
thread_alloc_init(ClassAllocator<C> &a, ProxyAllocator &l)
{
- if (l.freelist) {
+ if (!cmd_disable_pfreelist && l.freelist) {
C *v = (C *)l.freelist;
l.freelist = *(C **)l.freelist;
--(l.allocated);
@@ -113,11 +114,15 @@ void thread_freeup(Allocator &a, ProxyAllocator &l);
#define THREAD_ALLOC(_a, _t) thread_alloc(::_a, _t->_a)
#define THREAD_ALLOC_INIT(_a, _t) thread_alloc_init(::_a, _t->_a)
-#define THREAD_FREE(_p, _a, _t) \
- do { \
- *(char **)_p = (char *)_t->_a.freelist; \
- _t->_a.freelist = _p; \
- _t->_a.allocated++; \
- if (_t->_a.allocated > thread_freelist_high_watermark) \
- thread_freeup(::_a, _t->_a); \
- } while (0)
+#define THREAD_FREE(_p, _a, _t) \
+ if (!cmd_disable_pfreelist) { \
+ do { \
+ *(char **)_p = (char *)_t->_a.freelist; \
+ _t->_a.freelist = _p; \
+ _t->_a.allocated++; \
+ if (_t->_a.allocated > thread_freelist_high_watermark) \
+ thread_freeup(::_a, _t->_a); \
+ } while (0); \
+ } else { \
+ thread_free(::_a, _p); \
+ }
diff --git a/iocore/eventsystem/ProxyAllocator.cc
b/iocore/eventsystem/ProxyAllocator.cc
index e91aaab..4df9256 100644
--- a/iocore/eventsystem/ProxyAllocator.cc
+++ b/iocore/eventsystem/ProxyAllocator.cc
@@ -24,11 +24,12 @@
int thread_freelist_high_watermark = 512;
int thread_freelist_low_watermark = 32;
+extern int cmd_disable_pfreelist;
void *
thread_alloc(Allocator &a, ProxyAllocator &l)
{
- if (l.freelist) {
+ if (!cmd_disable_pfreelist && l.freelist) {
void *v = (void *)l.freelist;
l.freelist = *(void **)l.freelist;
--(l.allocated);
diff --git a/lib/ts/Allocator.h b/lib/ts/Allocator.h
index c831426..3b9671c 100644
--- a/lib/ts/Allocator.h
+++ b/lib/ts/Allocator.h
@@ -48,6 +48,8 @@
#define RND16(_x) (((_x) + 15) & ~15)
+extern int cmd_disable_pfreelist;
+
/** Allocator for fixed size memory blocks. */
class Allocator
{
@@ -59,24 +61,35 @@ public:
void *
alloc_void()
{
- return ink_freelist_new(this->fl);
+ return ink_freelist_new(this->fl, freelist_class_ops);
}
- /** Deallocate a block of memory allocated by the Allocator. */
+ /**
+ Deallocate a block of memory allocated by the Allocator.
+
+ @param ptr pointer to be freed.
+ */
void
free_void(void *ptr)
{
- ink_freelist_free(this->fl, ptr);
+ ink_freelist_free(this->fl, ptr, freelist_class_ops);
}
- /** Deallocate blocks of memory allocated by the Allocator. */
+ /**
+ Deallocate blocks of memory allocated by the Allocator.
+
+ @param head pointer to be freed.
+ @param tail pointer to be freed.
+ @param num_item of blocks to be freed.
+ */
void
free_void_bulk(void *head, void *tail, size_t num_item)
{
- ink_freelist_free_bulk(this->fl, head, tail, num_item);
+ ink_freelist_free_bulk(this->fl, head, tail, num_item, freelist_class_ops);
}
Allocator() { fl = nullptr; }
+
/**
Creates a new allocator.
@@ -117,7 +130,7 @@ public:
C *
alloc()
{
- void *ptr = ink_freelist_new(this->fl);
+ void *ptr = ink_freelist_new(this->fl, freelist_class_ops);
memcpy(ptr, (void *)&this->proto.typeObject, sizeof(C));
return (C *)ptr;
@@ -131,20 +144,20 @@ public:
void
free(C *ptr)
{
- ink_freelist_free(this->fl, ptr);
+ ink_freelist_free(this->fl, ptr, freelist_class_ops);
}
/**
- Deallocates objects of the templated type.
+ Deallocates objects of the templated type.
- @param head pointer to be freed.
- @param tail pointer to be freed.
- @param count of blocks to be freed.
+ @param head pointer to be freed.
+ @param tail pointer to be freed.
+ @param num_item of blocks to be freed.
*/
void
free_bulk(C *head, C *tail, size_t num_item)
{
- ink_freelist_free_bulk(this->fl, head, tail, num_item);
+ ink_freelist_free_bulk(this->fl, head, tail, num_item, freelist_class_ops);
}
/**
@@ -170,13 +183,13 @@ public:
}
/**
- Deallocate objects of the templated type via the inherited
- interface using void pointers.
+ Deallocate objects of the templated type via the inherited
+ interface using void pointers.
- @param head pointer to be freed.
- @param tail pointer to be freed.
- @param count of blocks
- */
+ @param head pointer to be freed.
+ @param tail pointer to be freed.
+ @param num_item of blocks.
+ */
void
free_void_bulk(void *head, void *tail, size_t num_item)
{
diff --git a/lib/ts/ink_args.cc b/lib/ts/ink_args.cc
index 7b9c5d8..68d54aa 100644
--- a/lib/ts/ink_args.cc
+++ b/lib/ts/ink_args.cc
@@ -41,6 +41,7 @@ Process arguments
const char *file_arguments[MAX_FILE_ARGUMENTS] = {nullptr};
const char *program_name = (char *)"Traffic Server";
unsigned n_file_arguments = 0;
+int cmd_disable_pfreelist = 0;
//
// Local variables
diff --git a/lib/ts/ink_args.h b/lib/ts/ink_args.h
index b3426d3..7176cca 100644
--- a/lib/ts/ink_args.h
+++ b/lib/ts/ink_args.h
@@ -84,6 +84,7 @@ struct ArgumentDescription {
extern const char *file_arguments[]; // exported by process_args()
extern unsigned n_file_arguments; // exported by process_args()
extern const char *program_name; // exported by process_args()
+extern int cmd_disable_pfreelist;
/* Print out arguments and values
*/
diff --git a/lib/ts/ink_queue.cc b/lib/ts/ink_queue.cc
index 0b2cd8a..b05f75f 100644
--- a/lib/ts/ink_queue.cc
+++ b/lib/ts/ink_queue.cc
@@ -91,8 +91,10 @@ static const ink_freelist_ops malloc_ops = {malloc_new,
malloc_free, malloc_bu
static const ink_freelist_ops freelist_ops = {freelist_new, freelist_free,
freelist_bulkfree};
static const ink_freelist_ops *default_ops = &freelist_ops;
-static ink_freelist_list *freelists = nullptr;
-static const ink_freelist_ops *freelist_freelist_ops = default_ops;
+const ink_freelist_ops *freelist_global_ops = default_ops;
+const ink_freelist_ops *freelist_class_ops = default_ops;
+
+static ink_freelist_list *freelists = nullptr;
const InkFreeListOps *
ink_freelist_malloc_ops()
@@ -107,13 +109,15 @@ ink_freelist_freelist_ops()
}
void
-ink_freelist_init_ops(const InkFreeListOps *ops)
+ink_freelist_init_ops(int nofl_global, int nofl_class)
{
// This *MUST* only be called at startup before any freelists allocate
anything. We will certainly crash if object
// allocated from the freelist are freed by malloc.
- ink_release_assert(freelist_freelist_ops == default_ops);
+ ink_release_assert(freelist_global_ops == default_ops);
+ ink_release_assert(freelist_class_ops == default_ops);
- freelist_freelist_ops = ops;
+ freelist_global_ops = nofl_global ? ink_freelist_malloc_ops() :
ink_freelist_freelist_ops();
+ freelist_class_ops = nofl_class ? ink_freelist_malloc_ops() :
ink_freelist_freelist_ops();
}
void
@@ -180,11 +184,12 @@ int fake_global_for_ink_queue = 0;
#endif
void *
-ink_freelist_new(InkFreeList *f)
+ink_freelist_new(InkFreeList *f, const InkFreeListOps *ops)
{
+ ink_assert(ops != nullptr);
void *ptr;
- if (likely(ptr = freelist_freelist_ops->fl_new(f))) {
+ if (likely(ptr = ops->fl_new(f))) {
ink_atomic_increment((int *)&f->used, 1);
}
@@ -270,11 +275,13 @@ malloc_new(InkFreeList *f)
}
void
-ink_freelist_free(InkFreeList *f, void *item)
+ink_freelist_free(InkFreeList *f, void *item, const InkFreeListOps *ops)
{
+ ink_assert(ops != nullptr);
+
if (likely(item != nullptr)) {
ink_assert(f->used != 0);
- freelist_freelist_ops->fl_free(f, item);
+ ops->fl_free(f, item);
ink_atomic_decrement((int *)&f->used, 1);
}
}
@@ -327,11 +334,12 @@ malloc_free(InkFreeList *f, void *item)
}
void
-ink_freelist_free_bulk(InkFreeList *f, void *head, void *tail, size_t num_item)
+ink_freelist_free_bulk(InkFreeList *f, void *head, void *tail, size_t
num_item, const InkFreeListOps *ops)
{
+ ink_assert(ops != nullptr);
ink_assert(f->used >= num_item);
- freelist_freelist_ops->fl_bulkfree(f, head, tail, num_item);
+ ops->fl_bulkfree(f, head, tail, num_item);
ink_atomic_decrement((int *)&f->used, num_item);
}
diff --git a/lib/ts/ink_queue.h b/lib/ts/ink_queue.h
index 98d0f48..a55720d 100644
--- a/lib/ts/ink_queue.h
+++ b/lib/ts/ink_queue.h
@@ -156,9 +156,12 @@ struct _InkFreeList {
typedef struct ink_freelist_ops InkFreeListOps;
typedef struct _InkFreeList InkFreeList;
+extern const ink_freelist_ops *freelist_global_ops;
+extern const ink_freelist_ops *freelist_class_ops;
+
const InkFreeListOps *ink_freelist_malloc_ops();
const InkFreeListOps *ink_freelist_freelist_ops();
-void ink_freelist_init_ops(const InkFreeListOps *);
+void ink_freelist_init_ops(int nofl_global, int nofl_class);
/*
* alignment must be a power of 2
@@ -168,9 +171,9 @@ InkFreeList *ink_freelist_create(const char *name, uint32_t
type_size, uint32_t
inkcoreapi void ink_freelist_init(InkFreeList **fl, const char *name, uint32_t
type_size, uint32_t chunk_size, uint32_t alignment);
inkcoreapi void ink_freelist_madvise_init(InkFreeList **fl, const char *name,
uint32_t type_size, uint32_t chunk_size,
uint32_t alignment, int advice);
-inkcoreapi void *ink_freelist_new(InkFreeList *f);
-inkcoreapi void ink_freelist_free(InkFreeList *f, void *item);
-inkcoreapi void ink_freelist_free_bulk(InkFreeList *f, void *head, void *tail,
size_t num_item);
+inkcoreapi void *ink_freelist_new(InkFreeList *f, const InkFreeListOps *ops);
+inkcoreapi void ink_freelist_free(InkFreeList *f, void *item, const
InkFreeListOps *ops);
+inkcoreapi void ink_freelist_free_bulk(InkFreeList *f, void *head, void *tail,
size_t num_item, const InkFreeListOps *ops);
void ink_freelists_dump(FILE *f);
void ink_freelists_dump_baselinerel(FILE *f);
void ink_freelists_snap_baseline();
diff --git a/lib/ts/test_freelist.cc b/lib/ts/test_freelist.cc
index a356155..48d1c27 100644
--- a/lib/ts/test_freelist.cc
+++ b/lib/ts/test_freelist.cc
@@ -37,12 +37,13 @@ test(void *d)
id = (intptr_t)d;
- time_t start = time(nullptr);
- int count = 0;
+ time_t start = time(nullptr);
+ int count = 0;
+ const InkFreeListOps *ops = ink_freelist_freelist_ops();
for (;;) {
- m1 = ink_freelist_new(flist);
- m2 = ink_freelist_new(flist);
- m3 = ink_freelist_new(flist);
+ m1 = ink_freelist_new(flist, ops);
+ m2 = ink_freelist_new(flist, ops);
+ m3 = ink_freelist_new(flist, ops);
if ((m1 == m2) || (m1 == m3) || (m2 == m3)) {
printf("0x%08" PRIx64 " 0x%08" PRIx64 " 0x%08" PRIx64 "\n",
(uint64_t)(uintptr_t)m1, (uint64_t)(uintptr_t)m2,
@@ -54,9 +55,9 @@ test(void *d)
memset(m2, id, 64);
memset(m3, id, 64);
- ink_freelist_free(flist, m1);
- ink_freelist_free(flist, m2);
- ink_freelist_free(flist, m3);
+ ink_freelist_free(flist, m1, ops);
+ ink_freelist_free(flist, m2, ops);
+ ink_freelist_free(flist, m3, ops);
// break out of the test if we have run more then 60 seconds
if (++count % 1000 == 0 && (start + 60) < time(nullptr)) {
diff --git a/proxy/Main.cc b/proxy/Main.cc
index 1c31fe1..67bd723 100644
--- a/proxy/Main.cc
+++ b/proxy/Main.cc
@@ -188,6 +188,8 @@ static ArgumentDescription argument_descriptions[] = {
{"httpport", 'p', "Port descriptor for HTTP Accept", "S*",
&http_accept_port_descriptor, "PROXY_HTTP_ACCEPT_PORT", nullptr},
{"dprintf_level", 'o', "Debug output level", "I", &cmd_line_dprintf_level,
"PROXY_DPRINTF_LEVEL", nullptr},
{"disable_freelist", 'f', "Disable the freelist memory allocator", "T",
&cmd_disable_freelist, "PROXY_DPRINTF_LEVEL", nullptr},
+ {"disable_pfreelist", 'F', "Disable the freelist memory allocator in
ProxyAllocator", "T", &cmd_disable_pfreelist,
+ "PROXY_DPRINTF_LEVEL", nullptr},
#if TS_HAS_TESTS
{"regression", 'R', "Regression Level (quick:1..long:3)", "I",
®ression_level, "PROXY_REGRESSION", nullptr},
@@ -1580,9 +1582,7 @@ main(int /* argc ATS_UNUSED */, const char **argv)
command_index = find_cmd_index(command_string);
command_valid = command_flag && command_index >= 0;
- if (cmd_disable_freelist) {
- ink_freelist_init_ops(ink_freelist_malloc_ops());
- }
+ ink_freelist_init_ops(cmd_disable_freelist, cmd_disable_pfreelist);
#if TS_HAS_TESTS
if (regression_list) {
diff --git a/proxy/http2/test_HPACK.cc b/proxy/http2/test_HPACK.cc
index c6f3b93..04b7261 100644
--- a/proxy/http2/test_HPACK.cc
+++ b/proxy/http2/test_HPACK.cc
@@ -45,6 +45,8 @@ static char cmd_output_dir[512] = "";
static const ArgumentDescription argument_descriptions[] = {
{"disable_freelist", 'f', "Disable the freelist memory allocator", "T",
&cmd_disable_freelist, nullptr, nullptr},
+ {"disable_pfreelist", 'F', "Disable the freelist memory allocator in
ProxyAllocator", "T", &cmd_disable_pfreelist,
+ "PROXY_DPRINTF_LEVEL", nullptr},
{"input_dir", 'i', "input dir", "S511", &cmd_input_dir, nullptr, nullptr},
{"output_dir", 'o', "output dir", "S511", &cmd_output_dir, nullptr, nullptr},
HELP_ARGUMENT_DESCRIPTION(),
@@ -397,9 +399,8 @@ main(int argc, const char **argv)
appVersionInfo.setup(PACKAGE_NAME, "test_HPACK", PACKAGE_VERSION, __DATE__,
__TIME__, BUILD_MACHINE, BUILD_PERSON, "");
process_args(&appVersionInfo, argument_descriptions,
countof(argument_descriptions), argv);
- if (cmd_disable_freelist) {
- ink_freelist_init_ops(ink_freelist_malloc_ops());
- }
+ ink_freelist_init_ops(cmd_disable_freelist, cmd_disable_pfreelist);
+
if (*cmd_input_dir) {
input_dir = cmd_input_dir;
if (*input_dir.end() != '/') {
--
To stop receiving notification emails like this one, please contact
[email protected].