Skip to content

Commit

Permalink
TS-3883: Fix madvise
Browse files Browse the repository at this point in the history
  • Loading branch information
PSUdaemon committed Oct 29, 2015
1 parent 3b8c3c4 commit 471b969
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
16 changes: 2 additions & 14 deletions lib/ts/ink_memory.cc
Expand Up @@ -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
}

Expand Down
20 changes: 11 additions & 9 deletions lib/ts/ink_queue.cc
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 471b969

Please sign in to comment.