You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by du...@apache.org on 2018/12/19 15:30:52 UTC

[trafficserver] branch master updated: fix disable freelist options

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 35a7de1  fix disable freelist options
35a7de1 is described below

commit 35a7de1b9ea0f87ceeae3be5985c687f534eb16d
Author: Fei Deng <du...@gmail.com>
AuthorDate: Tue Dec 18 17:01:36 2018 -0600

    fix disable freelist options
---
 include/tscore/Allocator.h  | 14 ++++++--------
 include/tscore/ink_queue.h  | 11 ++++-------
 src/tscore/ink_queue.cc     | 28 ++++++++++------------------
 src/tscore/test_freelist.cc | 17 ++++++++---------
 4 files changed, 28 insertions(+), 42 deletions(-)

diff --git a/include/tscore/Allocator.h b/include/tscore/Allocator.h
index 4ed9094..3de986a 100644
--- a/include/tscore/Allocator.h
+++ b/include/tscore/Allocator.h
@@ -48,8 +48,6 @@
 
 #define RND16(_x) (((_x) + 15) & ~15)
 
-extern int cmd_disable_pfreelist;
-
 /** Allocator for fixed size memory blocks. */
 class Allocator
 {
@@ -61,7 +59,7 @@ public:
   void *
   alloc_void()
   {
-    return ink_freelist_new(this->fl, freelist_class_ops);
+    return ink_freelist_new(this->fl);
   }
 
   /**
@@ -72,7 +70,7 @@ public:
   void
   free_void(void *ptr)
   {
-    ink_freelist_free(this->fl, ptr, freelist_class_ops);
+    ink_freelist_free(this->fl, ptr);
   }
 
   /**
@@ -85,7 +83,7 @@ public:
   void
   free_void_bulk(void *head, void *tail, size_t num_item)
   {
-    ink_freelist_free_bulk(this->fl, head, tail, num_item, freelist_class_ops);
+    ink_freelist_free_bulk(this->fl, head, tail, num_item);
   }
 
   Allocator() { fl = nullptr; }
@@ -130,7 +128,7 @@ public:
   C *
   alloc()
   {
-    void *ptr = ink_freelist_new(this->fl, freelist_class_ops);
+    void *ptr = ink_freelist_new(this->fl);
 
     memcpy(ptr, (void *)&this->proto.typeObject, sizeof(C));
     return (C *)ptr;
@@ -144,7 +142,7 @@ public:
   void
   free(C *ptr)
   {
-    ink_freelist_free(this->fl, ptr, freelist_class_ops);
+    ink_freelist_free(this->fl, ptr);
   }
 
   /**
@@ -157,7 +155,7 @@ public:
   void
   free_bulk(C *head, C *tail, size_t num_item)
   {
-    ink_freelist_free_bulk(this->fl, head, tail, num_item, freelist_class_ops);
+    ink_freelist_free_bulk(this->fl, head, tail, num_item);
   }
 
   /**
diff --git a/include/tscore/ink_queue.h b/include/tscore/ink_queue.h
index 6d242cd..bc8a71e 100644
--- a/include/tscore/ink_queue.h
+++ b/include/tscore/ink_queue.h
@@ -156,12 +156,9 @@ 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(int nofl_global, int nofl_class);
+void ink_freelist_init_ops(int nofl_class, int nofl_proxy);
 
 /*
  * alignment must be a power of 2
@@ -171,9 +168,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, 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);
+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);
 void ink_freelists_dump(FILE *f);
 void ink_freelists_dump_baselinerel(FILE *f);
 void ink_freelists_snap_baseline();
diff --git a/src/tscore/ink_queue.cc b/src/tscore/ink_queue.cc
index f6e8787..0a6ef05 100644
--- a/src/tscore/ink_queue.cc
+++ b/src/tscore/ink_queue.cc
@@ -91,10 +91,8 @@ 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;
 
-const ink_freelist_ops *freelist_global_ops = default_ops;
-const ink_freelist_ops *freelist_class_ops  = default_ops;
-
-static ink_freelist_list *freelists = nullptr;
+static ink_freelist_list *freelists                = nullptr;
+static const ink_freelist_ops *freelist_global_ops = default_ops;
 
 const InkFreeListOps *
 ink_freelist_malloc_ops()
@@ -109,15 +107,13 @@ ink_freelist_freelist_ops()
 }
 
 void
-ink_freelist_init_ops(int nofl_global, int nofl_class)
+ink_freelist_init_ops(int nofl_class, int nofl_proxy)
 {
   // 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_global_ops == default_ops);
-  ink_release_assert(freelist_class_ops == default_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();
+  freelist_global_ops = (nofl_class || nofl_proxy) ? ink_freelist_malloc_ops() : ink_freelist_freelist_ops();
 }
 
 void
@@ -184,12 +180,11 @@ int fake_global_for_ink_queue = 0;
 #endif
 
 void *
-ink_freelist_new(InkFreeList *f, const InkFreeListOps *ops)
+ink_freelist_new(InkFreeList *f)
 {
-  ink_assert(ops != nullptr);
   void *ptr;
 
-  if (likely(ptr = ops->fl_new(f))) {
+  if (likely(ptr = freelist_global_ops->fl_new(f))) {
     ink_atomic_increment((int *)&f->used, 1);
   }
 
@@ -275,13 +270,11 @@ malloc_new(InkFreeList *f)
 }
 
 void
-ink_freelist_free(InkFreeList *f, void *item, const InkFreeListOps *ops)
+ink_freelist_free(InkFreeList *f, void *item)
 {
-  ink_assert(ops != nullptr);
-
   if (likely(item != nullptr)) {
     ink_assert(f->used != 0);
-    ops->fl_free(f, item);
+    freelist_global_ops->fl_free(f, item);
     ink_atomic_decrement((int *)&f->used, 1);
   }
 }
@@ -334,12 +327,11 @@ malloc_free(InkFreeList *f, void *item)
 }
 
 void
-ink_freelist_free_bulk(InkFreeList *f, void *head, void *tail, size_t num_item, const InkFreeListOps *ops)
+ink_freelist_free_bulk(InkFreeList *f, void *head, void *tail, size_t num_item)
 {
-  ink_assert(ops != nullptr);
   ink_assert(f->used >= num_item);
 
-  ops->fl_bulkfree(f, head, tail, num_item);
+  freelist_global_ops->fl_bulkfree(f, head, tail, num_item);
   ink_atomic_decrement((int *)&f->used, num_item);
 }
 
diff --git a/src/tscore/test_freelist.cc b/src/tscore/test_freelist.cc
index 1599510..3fdc27a 100644
--- a/src/tscore/test_freelist.cc
+++ b/src/tscore/test_freelist.cc
@@ -37,13 +37,12 @@ test(void *d)
 
   id = (intptr_t)d;
 
-  time_t start              = time(nullptr);
-  int count                 = 0;
-  const InkFreeListOps *ops = ink_freelist_freelist_ops();
+  time_t start = time(nullptr);
+  int count    = 0;
   for (;;) {
-    m1 = ink_freelist_new(flist, ops);
-    m2 = ink_freelist_new(flist, ops);
-    m3 = ink_freelist_new(flist, ops);
+    m1 = ink_freelist_new(flist);
+    m2 = ink_freelist_new(flist);
+    m3 = ink_freelist_new(flist);
 
     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,
@@ -55,9 +54,9 @@ test(void *d)
     memset(m2, id, 64);
     memset(m3, id, 64);
 
-    ink_freelist_free(flist, m1, ops);
-    ink_freelist_free(flist, m2, ops);
-    ink_freelist_free(flist, m3, ops);
+    ink_freelist_free(flist, m1);
+    ink_freelist_free(flist, m2);
+    ink_freelist_free(flist, m3);
 
     // break out of the test if we have run more then 60 seconds
     if (++count % 1000 == 0 && (start + 60) < time(nullptr)) {