TS-3883: Fix madvise

Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/471b9699
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/471b9699
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/471b9699

Branch: refs/heads/master
Commit: 471b96992d1eb07b46b681e69096b5b1f18ff156
Parents: 3b8c3c4
Author: Phil Sorber <[email protected]>
Authored: Wed Oct 28 16:26:04 2015 -0600
Committer: Phil Sorber <[email protected]>
Committed: Thu Oct 29 10:02:53 2015 -0600

----------------------------------------------------------------------
 lib/ts/ink_memory.cc | 16 ++--------------
 lib/ts/ink_queue.cc  | 20 +++++++++++---------
 2 files changed, 13 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/471b9699/lib/ts/ink_memory.cc
----------------------------------------------------------------------
diff --git a/lib/ts/ink_memory.cc b/lib/ts/ink_memory.cc
index c865379..698ab78 100644
--- a/lib/ts/ink_memory.cc
+++ b/lib/ts/ink_memory.cc
@@ -191,22 +191,10 @@ ats_msync(caddr_t addr, size_t len, caddr_t end, int 
flags)
 int
 ats_madvise(caddr_t addr, size_t len, int flags)
 {
-#if defined(linux)
-  (void)addr;
-  (void)len;
-  (void)flags;
-  return 0;
-#else
-  size_t pagesize = ats_pagesize();
-  caddr_t a = (caddr_t)(((uintptr_t)addr) & ~(pagesize - 1));
-  size_t l = (len + (addr - a) + pagesize - 1) & ~(pagesize - 1);
-  int res = 0;
 #if HAVE_POSIX_MADVISE
-  res = posix_madvise(a, l, flags);
+  return posix_madvise(addr, len, flags);
 #else
-  res = madvise(a, l, flags);
-#endif
-  return res;
+  return madvise(addr, len, flags);
 #endif
 }
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/471b9699/lib/ts/ink_queue.cc
----------------------------------------------------------------------
diff --git a/lib/ts/ink_queue.cc b/lib/ts/ink_queue.cc
index bba2d53..18b6395 100644
--- a/lib/ts/ink_queue.cc
+++ b/lib/ts/ink_queue.cc
@@ -139,7 +139,7 @@ ink_freelist_init(InkFreeList **fl, const char *name, 
uint32_t type_size, uint32
   if (ats_hugepage_enabled()) {
     f->chunk_size = INK_ALIGN(chunk_size * f->type_size, ats_hugepage_size()) 
/ f->type_size;
   } else {
-    f->chunk_size = chunk_size;
+    f->chunk_size = INK_ALIGN(chunk_size * f->type_size, ats_pagesize()) / 
f->type_size;
   }
   SET_FREELIST_POINTER_VERSION(f->head, FROM_PTR(0), 0);
 
@@ -195,17 +195,19 @@ freelist_new(InkFreeList *f)
       uint32_t type_size = f->type_size;
       uint32_t i;
       void *newp = NULL;
+      size_t alloc_size = 0;
 
-      if (ats_hugepage_enabled())
-        newp = ats_alloc_hugepage(f->chunk_size * type_size);
+      if (ats_hugepage_enabled()) {
+        alloc_size = INK_ALIGN(f->chunk_size * f->type_size, 
ats_hugepage_size());
+        newp = ats_alloc_hugepage(alloc_size);
+      }
 
       if (newp == NULL) {
-        if (f->alignment)
-          newp = ats_memalign(f->alignment, f->chunk_size * type_size);
-        else
-          newp = ats_malloc(f->chunk_size * type_size);
+        alloc_size = INK_ALIGN(f->chunk_size * f->type_size, ats_pagesize());
+        newp = ats_memalign(ats_pagesize(), alloc_size);
       }
-      ats_madvise((caddr_t)newp, f->chunk_size * type_size, f->advice);
+
+      ats_madvise((caddr_t)newp, alloc_size, f->advice);
       SET_FREELIST_POINTER_VERSION(item, newp, 0);
 
       ink_atomic_increment((int *)&f->allocated, f->chunk_size);
@@ -256,7 +258,7 @@ malloc_new(InkFreeList *f)
     newp = ats_memalign(f->alignment, f->type_size);
   else
     newp = ats_malloc(f->type_size);
-  ats_madvise((caddr_t)newp, f->type_size, f->advice);
+
   return newp;
 }
 

Reply via email to