Commit Graph

26 Commits

Author SHA1 Message Date
Avi Kivity
87f63f7b90 shared_ptr: rename to lw_shared_ptr (for light-weight)
The current shared_ptr implementation is efficient, but does not support
polymorphic types.

Rename it in order to make room for a polymorphic shared_ptr.
2015-01-04 22:38:49 +02:00
Avi Kivity
4453fd1d6a memory: add support for allocating memory via hugetlbfs
This is a little tricky, since we only know we want hugetlbfs after memory
has been initialized, so we start up in anonymous memory, and later
switch to hugetlbfs by copying it to hugetlb-backed memory and mremap()ing
it back into place.
2014-12-11 12:25:31 +02:00
Avi Kivity
ca2c7d8767 memory: abstract mmap() call
To support hugepages, we will need a different mmap() call, so abstract
it out.
2014-12-11 12:25:31 +02:00
Avi Kivity
0043c1a994 memory: drop duplicate madvise() call 2014-12-11 12:25:31 +02:00
Avi Kivity
be0ae4f5dc memory: Un-hide standard allocator functions
With -fvisibility=hidden, all executable symbols are hidden from shared
objects, allowing more optimizations (especially with -flto).  However, hiding
the allocator symbols mean that memory allocated in the executable cannot
be freed in a library, since they will use different allocators.

Fix by exposing these symbols with default visibility.

Fixes crash loading some dpdk libraries.
2014-12-01 14:49:04 +02:00
Avi Kivity
9ab5dce5c4 memory: fix throw specifiers on sized delete
Noticed by clang.
2014-11-26 14:56:40 +02:00
Avi Kivity
f32a8be723 memory: make statistics thread local
Noticed by Gleb.
2014-11-24 11:50:07 +02:00
Avi Kivity
5cd200831b memory: add allocation statistics collection 2014-11-23 19:28:07 +02:00
Avi Kivity
1a7fd983ac memory: fix buffer overrun
We store spans in freelist i if the span's size >= 2^i.  However, when
picking a span to satisfy an allocation, we must use the next larger list
if the size is not a power of two, so that we can be sure that all spans on
that list can satisfy that request.

The current code doesn't do that, so it under-allocates, leading to memory
corruption.
2014-11-15 11:52:39 -08:00
Avi Kivity
1f80f7ee14 memory: fix realloc()
Because memcpy() is declared by gcc as receiving non-null attributes, gcc
assumes that ptr != null, as it is passed into memcpy() (though with a size
of zero).  As a result it ignores the null pointer check in ::free(), and
calls memory::free() directly, which does not expect a null pointer.

Fix by only calling memcpy() when the ptr is non-null.
2014-10-23 15:59:52 +03:00
Tomasz Grabiec
1a84e3560c core: implement "reclaimer" instance methods when running with default allocator 2014-10-21 16:43:09 +02:00
Gleb Natapov
a1533cc671 memory: call MADV_DONTDUMP on the whole mmaped memory
We mmap 2*alloc bytes not alloc.
2014-10-21 12:20:22 +03:00
Avi Kivity
b90670417b memory: fix off-by-one in to-resize
cpu_pages::initialize() established the one-past-the-end page as a sentinel
to avoid boundary conditions checks.  cpu_pages::do_resize() considers the
last page as the sentinel.  This discrepancy causes the last page to be
considered free by do_resize, which promptly ends up as a use-after-free
page.

Fix by aligning do_resize() with initialize().
2014-10-15 16:44:36 +03:00
Avi Kivity
2d13f95a9f memory: support for non-hwloc builds 2014-10-13 15:41:18 +03:00
Avi Kivity
60b4756a36 smp: allow tuning memory size 2014-10-13 13:03:48 +03:00
Avi Kivity
56598903f6 memory: add support for reconfiguring memory
- add memory to a cpu
- bind that memory to a NUMA node
2014-10-13 13:03:46 +03:00
Avi Kivity
d89e09c9ed memory: switch page_list to use page indices instead of pointers
Two motivations:
1. reduce the size of struct page
2. allow relocating the page array; needed for dynamically changing
   the amount of memory supported.
2014-10-12 14:47:11 +03:00
Avi Kivity
37ef3bc899 memory: request huge page backing for heap
Worth about 12% on httpd.
2014-10-07 15:23:30 +03:00
Avi Kivity
6746bcfd68 memory: reclaim support
Allow memory users to declare methods of reclaiming memory (reclaimers),
and allow the main loop to declare a safe point for calling these reclaimers.

The memory mananger will then schedule calls to reclaimers when memory runs
low.
2014-10-07 15:14:44 +03:00
Nadav Har'El
5db2c1b506 build: Compile-time option to use default memory allocator
Add a compile-time option, DEFAULT_ALLOCATOR, to use the existing
memory allocator (malloc() and friends) instead of redefining it.

This option is a workaround needed to run Seastar on OSv.

Without this workaround, what seems to happen is that some code compiled
into the kernel (notably, libboost_program_options.a) uses the standard
malloc(), while inline code compiled into Seastar uses the seastar free()
to try and free that memory, resulting in a spectacular crash.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2014-10-06 14:59:36 +03:00
Avi Kivity
2b12c13055 memory: support sized deallocation
With N3778, the compiler can provide us with the size of the object,
so we can avoid looking it up in the page array.  Unfortunately only
implemented in clang at the moment.
2014-10-05 20:24:00 +03:00
Avi Kivity
9cd0e4f405 memory: improve allocation density
Instead of rounding up to a power-of-two, have four equally spaced
regions between powers of two.  For example:

   1024
   1280 (+256)
   1536 (+256)
   1792 (+256)
   2048 (+256)
   2560 (+512)
   3072 (+512)
   3584 (+512)
   4096 (+512)
2014-10-05 19:58:12 +03:00
Avi Kivity
e42158aea6 memory: small allocation support
Allocate small objects within spans, minimizing waste.

Each object size class has its own pool, and its own freelist.  On overflow
free objects are pushed into the spans; if a span is completely free, it is
returned to the main free list.
2014-10-05 19:58:10 +03:00
Avi Kivity
c407f5e091 memory: hook standard library allocation functions 2014-10-05 19:57:46 +03:00
Avi Kivity
b849b6b4cd memory: add support for aligned large allocations 2014-10-05 19:57:46 +03:00
Avi Kivity
86c0b7b7c9 memory: add per-cpu memory allocator
Largely inspired by tcmalloc, but simpler.  No support for small allocations
at the moment.
2014-10-05 19:57:40 +03:00