Squashed 'deps/memkind/src/' content from commit bb9f19dd1

git-subtree-dir: deps/memkind/src
git-subtree-split: bb9f19dd1b3ed6cc5e1b35919564ccf6f4b32f69
This commit is contained in:
John Sully 2019-02-01 14:45:39 -05:00
commit 09a263e607
487 changed files with 133201 additions and 0 deletions

113
.gitignore vendored Normal file
View File

@ -0,0 +1,113 @@
.cproject
.project
autom4te.cache/
*.a
*.o
*.so
*.la
*.lo
.deps/
.dirstamp
.libs/
/aclocal.m4
/ar-lib
/compile
/config.guess
/config.h
/config.h.in
/config.log
/config.status
/config.sub
/configure
/depcomp
/config_tls.h
/install-sh
/libtool
/ltmain.sh
/m4/
/memkind-*.spec
/memkind-*.tar.gz
/Makefile
/Makefile.in
/missing
/stamp-h1
/stamp-h2
/jemalloc/obj/
/jemalloc/configure
/src/memkind_defines.h.in
/test/all_tests
/test/.deps/
/test/.dirstamp
/test/.libs/
/test/*.o
/test/performance/.deps/
/test/*.so
/test/check.sh.log
/test/check.sh.trs
/test-suite.log
/VERSION
/examples/.deps/
/examples/.dirstamp
/examples/.libs/
/examples/*.o
/examples/*.lo
/examples/*.la
/memkind-hbw-nodes
/test/allocator_perf_tool_tests
/test/autohbw_candidates
/test/locality_test
/test/decorator_test
/test/eratosthenes
/test/environerr_hbw_malloc_test
/test/environerr_test
/test/freeing_memory_segfault_test
/test/filter_memkind
/test/gb_page_tests_bind_policy
/test/hello_hbw
/test/hello_memkind
/test/hello_memkind_debug
/test/mallocerr_test
/test/memkind_allocated
/test/new_kind
/test/perf_tool
/test/pmem_kinds
/test/pmem_malloc
/test/pmem_malloc_unlimited
/test/pmem_usable_size
/test/pmem_alignment
/test/pmem_and_default_kind
/test/pmem_multithreads
/test/pmem_multithreads_onekind
/test/pmem_free_with_unknown_kind
/test/pmem_cpp_allocator
/test/schedcpu_test
/test/tieddisterr_test
/test/alloc_benchmark_glibc
/test/alloc_benchmark_hbw
/test/alloc_benchmark_tbb
/test/alloc_benchmark_pmem
/test/autohbw_test_helper
/test/environ_err_hbw_malloc_test
/test/trace_mechanism_test_helper
/examples/autohbw_candidates
/examples/eratosthenes
/examples/filter_memkind
/examples/hello_hbw
/examples/hello_memkind
/examples/hello_memkind_debug
/examples/memkind_allocated
/examples/new_kind
/examples/numakind_test
/examples/numakind_macro.h
/examples/pmem_kinds
/examples/pmem_malloc
/examples/pmem_malloc_unlimited
/examples/pmem_usable_size
/examples/pmem_alignment
/examples/pmem_and_default_kind
/examples/pmem_multithreads
/examples/pmem_multithreads_onekind
/examples/pmem_free_with_unknown_kind
/examples/pmem_cpp_allocator
/test-driver
/vs

80
.travis.yml Normal file
View File

@ -0,0 +1,80 @@
dist: trusty
sudo: required
language: cpp
cache: ccache
matrix:
fast_finish: true
include:
- name: "Astyle"
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
before_install:
- ./install_astyle.sh
script:
- ./astyle.sh
- name: "GCC 4.8"
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
- libnuma-dev
env:
- MATRIX_EVAL="CC=gcc-4.8 && CXX=g++-4.8 && JEMALLOC_CC=gcc-4.8 && JEMALLOC_CXX=g++-4.8"
install:
script:
- CXX=$JEMALLOC_CXX CC=$JEMALLOC_CC LDFLAGS="-lrt -Wl,--no-as-needed" ./build_jemalloc.sh
- ./autogen.sh
- LDFLAGS="-lrt -Wl,--no-as-needed" ./configure
- make all
- make checkprogs
before_install:
- eval "${MATRIX_EVAL}"
- name: "GCC 8.0"
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-8
- libnuma-dev
env:
- MATRIX_EVAL="CC=gcc-8 && CXX=g++-8 && JEMALLOC_CC=gcc-8 && JEMALLOC_CXX=g++-8"
install:
script:
- CXX=$JEMALLOC_CXX CC=$JEMALLOC_CC LDFLAGS="-lrt -Wl,--no-as-needed" ./build_jemalloc.sh
- ./autogen.sh
- LDFLAGS="-lrt -Wl,--no-as-needed" ./configure
- make all
- make checkprogs
before_install:
- eval "${MATRIX_EVAL}"
- name: "Clang 7"
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-7
packages:
- g++-4.8
- clang-7
- libnuma-dev
env:
- MATRIX_EVAL="CC=clang-7 && CXX=clang++-7 && JEMALLOC_CC=gcc-4.8 && JEMALLOC_CXX=g++-4.8"
install:
script:
- CXX=$JEMALLOC_CXX CC=$JEMALLOC_CC LDFLAGS="-lrt -Wl,--no-as-needed" ./build_jemalloc.sh
- ./autogen.sh
- LDFLAGS="-lrt -Wl,--no-as-needed" ./configure
- make all
before_install:
- eval "${MATRIX_EVAL}"

23
AUTHORS Normal file
View File

@ -0,0 +1,23 @@
Christopher Cantalupo <christopher.m.cantalupo@intel.com>
Vishwanath Venkatesan <vishwanath.venkatesan@intel.com>
Steven Hampson <steven.t.hampson@intel.com>
Krzysztof Czurylo <krzysztof.czurylo@intel.com>
Leobardo Rountree <leobardo.r.rountree@intel.com>
Hector Barajas Villalobos <hector.a.barajas.villalobos@intel.com>
Ruchira Sasanka <ruchira.sasanka@intel.com>
Krzysztof Kulakowski <krzysztof.kulakowski@intel.com>
Rafael Aquini <aquini@redhat.com>
Alexandr Konovalov <alexandr.konovalov@intel.com>
Grzegorz Ozanski <grzegorz.ozanski@intel.com>
Artur Koziej <artur.koziej@intel.com>
Jakub Dlugolecki <jakub.dlugolecki@intel.com>
Lukasz Anaczkowski <lukasz.anaczkowski@intel.com>
Agata Wozniak <agata.wozniak@intel.com>
Grzegorz Andrejczuk <grzegorz.andrejczuk@intel.com>
Kamil Patelczyk <kamil.patelczyk@intel.com>
Jeff Hammond <jeff.r.hammond@intel.com>
Aleksandra Hernik <aleksandra.hernik@intel.com>
Pawel Kochanek <pawel.b.kochanek@intel.com>
Katarzyna Wasiuta <katarzyna.wasiuta@intel.com>
Krzysztof Filipek <krzysztof.filipek@intel.com>
Michal Biesek <michal.biesek@intel.com>

134
CONTRIBUTING Normal file
View File

@ -0,0 +1,134 @@
CONTRIBUTING
============
This file is intended to help those interested in contributing to the
memkind library.
COMMUNICATION
=============
Please participate in the memkind mailing list:
https://lists.01.org/mailman/listinfo/memkind
There is also the option of opening an issue through github:
https://github.com/memkind/memkind/issues
The mailing list is intended for discussion and the issues are useful
for tracking progress on tasks. The TODO file lists out a number of
topics, and in order to prioritize one of them please open a github
issue with a related subject.
TESTING
=======
The tests require a Linux kernel newer than 3.11 (the details are
documented in the memkind README), and the reservation of 3000 huge
pages. The huge pages can be reserved with the following command:
$ sudo echo 3000 > /proc/sys/vm/nr_hugepages
Only in the case where gigabyte pages have been reserved will the
tests associated with gigabyte pages be executed. Reserving gigabyte
pages may require a modification to the kernel command line unless the
kernel is quite recent.
To test memkind simply execute the "make check" target after building.
This target calls memkind/test/test.sh with parameters
depending on the environment.
Most of the tests are written within the gtest framework, however, as
part of testing the example programs are also executed and the return
code of the executable determines pass or fail. The autotools test
infrastructure is used as a high level executor, but it does not track
individual tests. The consequence of this is that the autotools
output records only one high level test which passes in the case where
every underlying test was successful and fails if any underlying test
fails. The individual test results are recorded in the directory
called "gtest_output." Here you will find the log of the tests in
gtest_output/test.out and a set of junit style xml results: one for
each test. Note that a side effect of having only one autotools test
is that autotools parallel testing is disabled. We have
multi-threaded tests that use the OpenMP run-time which enables more
purposeful and deterministic testing of threading issues. Note that
the OpenMP run-time is only required for testing, it is not used by
the memkind library internally.
CODING STYLE
============
Before submitting a patch for inclusion, please run the modified
source code files through astyle with the following options
$ astyle --style=linux --indent=spaces=4 -S --max-continuation-indent=80 \
--max-code-length=80 --break-after-logical --indent-namespaces -z2 \
--align-pointer=name
More information about astyle can be found here:
http://astyle.sourceforge.net/
In C, source code constants are in all caps and everything else is in
all lower case. Underscores are used to separate words within a
symbol name. No camel case shall be used in C code. The test code is
largely written in C++. Here camel-case should be used for class
names and should always have a capitalized first letter. Other
symbols in C++ should generally follow the C style.
Most symbols with global scope shall be prefixed with "memkind_" or
"hbw_" depending on which interface they are a part of.
Any global variable shall have _g appended to the variable name and in
most cases shall be statically scoped within a single compilation
unit. The exception to that rule are static memory kinds that are
declared as extern within the associated interface header and are
constant after initialization. Global variables should be used in a
very narrow set of circumstances and in most cases modifications
should be guarded with pthread_once(3).
Functions not used outside of the compilation unit shall be declared
as static. All functions which are not declared as static shall be
documented in a man page and have an associated interface header file.
Preprocessor mark-up is discouraged when other options are possible.
Please use enum in place of #define when value control at configure or
build time is not required.
TESTS
=====
The current state of the tests is not nearly as well organized as it
could be. That being said, it is quite simple to add a new test.
Most C++ files in the test directory are associated with a single
gtest testing::Test class. These classes usually have several
associated test fixtures in the same file. If a new test can be added
as a fixture to an existing class, simply add the fixture to the file
and the test will be incorporated into the test infrastructure.
If a new class is required, create a new file and add it to the list
of "test_all_tests_SOURCES" in memkind/test/Makfile.mk and it will
be incorporated into the test infrastructure.
There are a few files which define classes which are not google test
classes. These are check.cpp, trial_generator.cpp and main.cpp. The
check.cpp file defines a class Check that can be used to validate
fundamental memkind features like NUMA node location, and page size.
The trial_generator.cpp file is used to abstract a sequence of
allocation and deallocation calls while performing checks on the
results of each call; this can be used to apply similar tests to all
of the different allocation APIs. The main.cpp file is a simple
wrapper around testing::InitGoogleTest and RUN_ALL_TESTS().
SUBMITTING A PATCH
==================
Please be sure that all tests pass before submission and that the
style conforms to the specifications given here. If a new feature is
implemented in the patch, please also include unit tests and an
example which exercises this feature. Once these requirements have
been met, please submit a pull request through github.

25
COPYING Normal file
View File

@ -0,0 +1,25 @@
Unless otherwise specified, files in the memkind source distribution are
subject to the following license:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

219
ChangeLog Normal file
View File

@ -0,0 +1,219 @@
* Mon Dec 10 2018 Michal Biesek <michal.biesek@intel.com> v1.8.0
- Fixed error with realloc/free method with passing thread-specific cache flag
- Fixed error with memkind_create_pmem(), if other PMEM kind was destroyed before
- Fixed error with zeroing large allocations in PMEM kind
- Added support to create kind without maximum size limit of PMEM kind (max_size=0)
- Extended memkind API with memkind_malloc_usable_size()
- Removed EXPERIMENTAL from most methods in memkind API
- Added MEMKIND_ERROR_ARENAS_CREATE code
- Added C++ allocator for PMEM kind
- Extended PMEM examples
- Fixed integration with Travis CI
- Extended Travis CI configuration with Astyle and Coverage
- Added PMEM kind tests
* Wed Jan 24 2018 Pawel Kochanek <pawel.b.kochanek@intel.com> v1.7.0
- Updated internally used jemalloc to upstream version 5.0.
- Fixed error that has been occuring while memkind was dynamically loaded.
- Fixed MEMKIND_HBW_NODES behavior for single NUMA node system.
- Removed licenses other than BSD 3-clause from COPYING.
- Changed build instructions.
- Added configurable jemalloc prefix in build scripts.
- Upgraded gtest to version 1.8.0.
- Added memory footprint tests.
- Added locality test for MEMKIND_PREFERRED.
- Applied test parametrization in BATests.
- Fixed problems with pytest testing in Travis.
- Added huge page configuration in several tests.
- Removed several symbols that are no longer exposed in public API from man pages.
- Fixed HBW_POLICY_BIND_ALL documentation.
* Tue Jun 13 2017 Artur Koziej <artur.koziej@intel.com> v1.6.0
- Introduced new policy HBW_POLICY_BIND_ALL.
- Introduced MEMKIND_HBW_ALL, MEMKIND_HBW_ALL_HUGETLB and MEMKIND_REGULAR kinds.
- Fixed hbw_posix_memalign_psize() return value in case of unsupported policy and
page size combination.
- Documented supported policy and page size combination for
hbw_posix_memalign_psize().
- Merged libmemkind.a and libjemalloc_pic.a into a single static library.
- Fixed OOM during tcache acquisition.
- Tuned huge pages configuration in memkind tests.
- Added stress tests for allocations with large random sizes.
- Added stress tests for allocations with random kinds.
- Extended policy and NUMA node binding tests.
- Fixed several Travis build problems.
- Removed gb_page_tests_preferred_policy tests.
* Tue Feb 21 2017 Krzysztof Kulakowski <krzysztof.kulakowski@intel.com> v1.5.0
- Intel(R) TBB scalable_allocator can be used as heap management alternative
to jemalloc (requires installed Intel (R) TBB package and environment variable
MEMKIND_HEAP_MANAGER=TBB)
- Updated internally used jemalloc to upstream version 4.3.1 (previously modified 3.5.1)
- Introduced new environment option MEMKIND_HOG_MEMORY. Setting it to "1" will prevent
memkind from releasing memory to OS.
- Introduced support for KNM processor from Intel(R) Xeon Phi(TM) family
- General cleanup of build scripts (e.g. fixed issues found on Ubuntu,
introduced simple build.sh script)
- Deprecated support for gigabyte-pages
- Removed number of previously deprecated symbols
* Thu Nov 17 2016 Krzysztof Kulakowski <krzysztof.kulakowski@intel.com> v1.4.0
- Introduced hbw_verify_memory_region() for verifying if provided memory
region fully falls into high-bandwidth memory (for details please take a look
at man/hbwmalloc.3).
- New API for creating kinds using set of predefined attributes:
memkind_create_kind(), memkind_destroy_kind() (for details please take a look
at man/memkind.3).
- Fixed issue in autohbw where it was reporting limit error regardless of
value provided.
- Added logging on error paths.
- Test base fixes and improvements.
* Tue Sep 27 2016 Krzysztof Kulakowski <krzysztof.kulakowski@intel.com> v1.3.0
- Introduced logging mechanism (for details please take a look at
man/memkind.3).
- Deprecated symbols: memkind_finalize(), memkind_get_num_kind(),
memkind_get_kind_by_partition(), memkind_get_kind_by_name(),
memkind_partition_mmap(), memkind_get_size(), MEMKIND_ERROR_MEMALIGN,
MEMKIND_ERROR_MALLCTL, MEMKIND_ERROR_GETCPU, MEMKIND_ERROR_PMTT,
MEMKIND_ERROR_TIEDISTANCE, MEMKIND_ERROR_ALIGNMENT, MEMKIND_ERROR_MALLOCX,
MEMKIND_ERROR_REPNAME, MEMKIND_ERROR_PTHREAD, MEMKIND_ERROR_BADPOLICY,
MEMKIND_ERROR_REPPOLICY.
- Added integration with hwloc (turned on with --with-hwloc).
- Cleanup of symbols exposed by libmemkind.so (e.g. no longer exposing libnuma
and jemalloc symbols).
- AutoHBW files have been moved to "memkind/autohbw" directory, code has
been refactored and tests have been added to appropriate scenarios.
- Library is now built with flags improving security (can be turned off
with --disable-secure configure time option).
- Changed configuration of jemalloc to turn off unused features.
* Thu Aug 18 2016 Krzysztof Kulakowski <krzysztof.kulakowski@intel.com> v1.2.0
- memkind_create() and memkind_ops have been deprecated (moved to
memkind_deprecated.h).
- Deprecated the headers from memkind/internal and added compile-time
warnings to them (plan is to remove those from rpm packages).
- autohbw files have been moved to memkind/autohbw directory.
- API decorators (memkind_malloc_pre, memkind_malloc_post etc.) now
need to be enabled with configure-time option --enable-decorators.
- Allocation time optimizations with up to 20% improvement.
* Wed Jul 13 2016 Krzysztof Kulakowski <krzysztof.kulakowski@intel.com> v1.1.1
- Performance improvement for memkind_free() in scenario where NULL
was passed as kind (reduced by 60%).
- Introduced integration with Travis CI.
- Fixed issue where memory returned from calloc was not filled with zeroes
when using memkind_pmem kinds.
- Fixed issue where interleave kinds was failing on systems without
Transparent Huge Pages module configured.
- Resolved several issues that was causing compilation errors on some systems.
- test/test.sh is now able to detect system configuration, and run only those
tests which requirements are meet.
- Added gtest to repo to avoid downloading it during build proecess.
* Mon May 23 2016 Krzysztof Kulakowski <krzysztof.kulakowski@intel.com> v1.1.0
- Implemented algorithm for detecting high-bandwidth memory on Intel Xeon Phi X200
without parsing PMTT.
- PMTT-parsing service has been removed.
- memkind struct definition from memkind.h has been replaced by forward
declaration. Definition has been moved to /internal/memkind_private.h and
shouldn't be considered as part of library interface anymore.
- Performance improvment for hugetlb kinds (check_available() is no longer
parsing sysfs every time).
- Performance fix by removing --enable-safe from jemmaloc build flags.
- New tests for validating high-bandwidth memory detection has been added.
- AFTS has been split into two groups: memkind-afts.ts and memkind-afts-ext.ts,
based on amount of required memory (for details view test/README).
* Thu Mar 03 2016 Artur Koziej <artur.koziej@intel.com> v1.0.0
- hbwmalloc.h released as stable API.
- Introduce API standards: STANDARD API, NON-STANDARD API, EXPERIMENTAL API.
- Introduce memkind versioning API.
- Fix type names in hbwmalloc API.
- Change error codes to POSIX standard ones in hbwmalloc API.
- Move API headers to include directory.
- Move NON-STANDARD API, or EXPERIMENTAL API to include/memkind/internal directory.
- New man page (memkind_interleave.3) describing interleave kind.
- Significant documentation improvement.
- Performance fix for jemalloc - significantly decrease of library initialization time.
- Enforce 2MB alignment in jemalloc due to the Linux kernel bug (munmap() fails for
huge pages, when the size is not aligned).
- Move to systemd defined service (memkind.service), drop init.d script.
- New rpm layout (memkind and memkind-devel).
- Remove false dependency on OpenMP.
- Extend test base for stress, longevity and initialization performance tests.
- Fix memory leak in ctl_growk().
- Rename namespace: hbwmalloc -> hbw.
- Rename class: hbwmalloc_allocator -> allocator.
* Thu Oct 15 2015 Krzysztof Kulakowski <krzysztof.kulakowski@intel.com> v0.3.0
- Added two new kinds: MEMKIND_INTERLEAVE and MEMKIND_HBW_INTERLEAVE
(for details please take a look at man/memkind.3)
- Added support for file-backed memory heaps
(for details please take a look at man/memkind_pmem.3)
- Added autohbw library, that intercepts the standard heap allocations,
which let use high-bandwidth memory without modifying existing codebase
(for details please take a look at examples/autohbw_README)
- jemalloc is now, staticly linked, internal component of memkind RPM
instead of rpm dependency.
- Added memkind_allocated example which demonstrates usage of memkind
with alignas() alignment specifier introduced in C++11
(for details please take a look at examples/README)
- Added support for using thread local storage to improve performance in
multithreaded applications (enabled by configure time option: --enable-tls)
- Added posibility to set number of jemalloc arenas per kind by
configure time parameter or enviromental variable
(for details please take a look at MEMKIND_ARENA_NUM_PER_KIND section
of man/memkind.3).
- Added decorators to the memkind allocation APIs.
These are weak symbols (pre and post for each API) which can modify
the input and output of each of the calls.
- Significantly extended test base (new groups of tests: performance,
multithreaded, PMTT, nagtive, stress).
* Fri Jan 9 2015 Christopher Cantalupo <christopher.m.cantalupo@intel.com> v0.2.0
- Bumped memkind ABI version to 0:1:0.
- Removed memkind_get_kind_for_free() from externally facing API's. Instead if
memkind_free() is called with zero passed for the kind then
memkind_get_kind_for_free() is called internally.
- Moved to single callback memkind_partition_mmap() to simplify
jemalloc modifications.
- Added hooks for setting file descriptor and offset for mmap enabling
file-backed memory kinds.
- Added a void pointer called "priv" to memkind structure for storing data for
user-defined kinds.
- Removed call to sched_getcpu(), now thread id is hashed to determine the arena
index.
- Added weak symbol hooks for decorating the heap management functions.
- Fixed several issues with init.d/memkind script and spec file scriptlets that
are exposed by SLES-12.
- Introduced an example library called numakind.
The numakind library will allocate from the closest NUMA node to a thread as
measured when that thread makes its first allocation call.
- Fixed error handling in memkind_gbtlb_mmap() that could cause a segfault when
gigabyte pages are not available.
- Added tests for PMTT parser.
- Removed binary mock PMTT table from source code, replaced it with a hexdump.
- Fixed a number of issues in test scripts which were suppressing errors.
- Removed unnecessary includes from header files.
- Better error checking in example code.
- Documentation update and clean up.
* Thu Nov 13 2014 Christopher Cantalupo <christopher.m.cantalupo@intel.com> v0.1.0
- Increased test code coverage significantly.
- Fixed bug in memkind_error_message() for MEMKIND_ERROR_TOOMANY.
- Removed memkind_arena_free() API since it was redundant with memkind_default_free().
- Static memkind structs are now declared as extern in the headers and defined in the
source files files rather than being statically defined in the headers.
* Thu Oct 30 2014 Christopher Cantalupo <christopher.m.cantalupo@intel.com> v0.0.9
- Now building with autotools.
- Updated documentation.
- Fixed typo in copyright.
- Fixed test scripts to properly handle return code of each test.
- Added C++03 standard allocator that uses hbw_malloc and hbw_free.
* Tue Sep 30 2014 Christopher Cantalupo <christopher.m.cantalupo@intel.com> v0.0.8
- Added GBTLB functionality, code clean up, documentation updates,
examples directory. Examples includes stream modified to use
memkind interface. Code coverage still lacking, and documentation
incomplete.

370
INSTALL Normal file
View File

@ -0,0 +1,370 @@
Installation Instructions
*************************
Copyright (C) 1994-1996, 1999-2002, 2004-2013 Free Software Foundation,
Inc.
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. This file is offered as-is,
without warranty of any kind.
Basic Installation
==================
Briefly, the shell commands `./configure; make; make install' should
configure, build, and install this package. The following
more-detailed instructions are generic; see the `README' file for
instructions specific to this package. Some packages provide this
`INSTALL' file but do not implement all of the features documented
below. The lack of an optional feature in a given package is not
necessarily a bug. More recommendations for GNU packages can be found
in *note Makefile Conventions: (standards)Makefile Conventions.
The `configure' shell script attempts to guess correct values for
various system-dependent variables used during compilation. It uses
those values to create a `Makefile' in each directory of the package.
It may also create one or more `.h' files containing system-dependent
definitions. Finally, it creates a shell script `config.status' that
you can run in the future to recreate the current configuration, and a
file `config.log' containing compiler output (useful mainly for
debugging `configure').
It can also use an optional file (typically called `config.cache'
and enabled with `--cache-file=config.cache' or simply `-C') that saves
the results of its tests to speed up reconfiguring. Caching is
disabled by default to prevent problems with accidental use of stale
cache files.
If you need to do unusual things to compile the package, please try
to figure out how `configure' could check whether to do them, and mail
diffs or instructions to the address given in the `README' so they can
be considered for the next release. If you are using the cache, and at
some point `config.cache' contains results you don't want to keep, you
may remove or edit it.
The file `configure.ac' (or `configure.in') is used to create
`configure' by a program called `autoconf'. You need `configure.ac' if
you want to change it or regenerate `configure' using a newer version
of `autoconf'.
The simplest way to compile this package is:
1. `cd' to the directory containing the package's source code and type
`./configure' to configure the package for your system.
Running `configure' might take a while. While running, it prints
some messages telling which features it is checking for.
2. Type `make' to compile the package.
3. Optionally, type `make check' to run any self-tests that come with
the package, generally using the just-built uninstalled binaries.
4. Type `make install' to install the programs and any data files and
documentation. When installing into a prefix owned by root, it is
recommended that the package be configured and built as a regular
user, and only the `make install' phase executed with root
privileges.
5. Optionally, type `make installcheck' to repeat any self-tests, but
this time using the binaries in their final installed location.
This target does not install anything. Running this target as a
regular user, particularly if the prior `make install' required
root privileges, verifies that the installation completed
correctly.
6. You can remove the program binaries and object files from the
source code directory by typing `make clean'. To also remove the
files that `configure' created (so you can compile the package for
a different kind of computer), type `make distclean'. There is
also a `make maintainer-clean' target, but that is intended mainly
for the package's developers. If you use it, you may have to get
all sorts of other programs in order to regenerate files that came
with the distribution.
7. Often, you can also type `make uninstall' to remove the installed
files again. In practice, not all packages have tested that
uninstallation works correctly, even though it is required by the
GNU Coding Standards.
8. Some packages, particularly those that use Automake, provide `make
distcheck', which can by used by developers to test that all other
targets like `make install' and `make uninstall' work correctly.
This target is generally not run by end users.
Compilers and Options
=====================
Some systems require unusual options for compilation or linking that
the `configure' script does not know about. Run `./configure --help'
for details on some of the pertinent environment variables.
You can give `configure' initial values for configuration parameters
by setting variables in the command line or in the environment. Here
is an example:
./configure CC=c99 CFLAGS=-g LIBS=-lposix
*Note Defining Variables::, for more details.
Compiling For Multiple Architectures
====================================
You can compile the package for more than one kind of computer at the
same time, by placing the object files for each architecture in their
own directory. To do this, you can use GNU `make'. `cd' to the
directory where you want the object files and executables to go and run
the `configure' script. `configure' automatically checks for the
source code in the directory that `configure' is in and in `..'. This
is known as a "VPATH" build.
With a non-GNU `make', it is safer to compile the package for one
architecture at a time in the source code directory. After you have
installed the package for one architecture, use `make distclean' before
reconfiguring for another architecture.
On MacOS X 10.5 and later systems, you can create libraries and
executables that work on multiple system types--known as "fat" or
"universal" binaries--by specifying multiple `-arch' options to the
compiler but only a single `-arch' option to the preprocessor. Like
this:
./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
CPP="gcc -E" CXXCPP="g++ -E"
This is not guaranteed to produce working output in all cases, you
may have to build one architecture at a time and combine the results
using the `lipo' tool if you have problems.
Installation Names
==================
By default, `make install' installs the package's commands under
`/usr/local/bin', include files under `/usr/local/include', etc. You
can specify an installation prefix other than `/usr/local' by giving
`configure' the option `--prefix=PREFIX', where PREFIX must be an
absolute file name.
You can specify separate installation prefixes for
architecture-specific files and architecture-independent files. If you
pass the option `--exec-prefix=PREFIX' to `configure', the package uses
PREFIX as the prefix for installing programs and libraries.
Documentation and other data files still use the regular prefix.
In addition, if you use an unusual directory layout you can give
options like `--bindir=DIR' to specify different values for particular
kinds of files. Run `configure --help' for a list of the directories
you can set and what kinds of files go in them. In general, the
default for these options is expressed in terms of `${prefix}', so that
specifying just `--prefix' will affect all of the other directory
specifications that were not explicitly provided.
The most portable way to affect installation locations is to pass the
correct locations to `configure'; however, many packages provide one or
both of the following shortcuts of passing variable assignments to the
`make install' command line to change installation locations without
having to reconfigure or recompile.
The first method involves providing an override variable for each
affected directory. For example, `make install
prefix=/alternate/directory' will choose an alternate location for all
directory configuration variables that were expressed in terms of
`${prefix}'. Any directories that were specified during `configure',
but not in terms of `${prefix}', must each be overridden at install
time for the entire installation to be relocated. The approach of
makefile variable overrides for each directory variable is required by
the GNU Coding Standards, and ideally causes no recompilation.
However, some platforms have known limitations with the semantics of
shared libraries that end up requiring recompilation when using this
method, particularly noticeable in packages that use GNU Libtool.
The second method involves providing the `DESTDIR' variable. For
example, `make install DESTDIR=/alternate/directory' will prepend
`/alternate/directory' before all installation names. The approach of
`DESTDIR' overrides is not required by the GNU Coding Standards, and
does not work on platforms that have drive letters. On the other hand,
it does better at avoiding recompilation issues, and works well even
when some directory options were not specified in terms of `${prefix}'
at `configure' time.
Optional Features
=================
If the package supports it, you can cause programs to be installed
with an extra prefix or suffix on their names by giving `configure' the
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
Some packages pay attention to `--enable-FEATURE' options to
`configure', where FEATURE indicates an optional part of the package.
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
is something like `gnu-as' or `x' (for the X Window System). The
`README' should mention any `--enable-' and `--with-' options that the
package recognizes.
For packages that use the X Window System, `configure' can usually
find the X include and library files automatically, but if it doesn't,
you can use the `configure' options `--x-includes=DIR' and
`--x-libraries=DIR' to specify their locations.
Some packages offer the ability to configure how verbose the
execution of `make' will be. For these packages, running `./configure
--enable-silent-rules' sets the default to minimal output, which can be
overridden with `make V=1'; while running `./configure
--disable-silent-rules' sets the default to verbose, which can be
overridden with `make V=0'.
Particular systems
==================
On HP-UX, the default C compiler is not ANSI C compatible. If GNU
CC is not installed, it is recommended to use the following options in
order to use an ANSI C compiler:
./configure CC="cc -Ae -D_XOPEN_SOURCE=500"
and if that doesn't work, install pre-built binaries of GCC for HP-UX.
HP-UX `make' updates targets which have the same time stamps as
their prerequisites, which makes it generally unusable when shipped
generated files such as `configure' are involved. Use GNU `make'
instead.
On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot
parse its `<wchar.h>' header file. The option `-nodtk' can be used as
a workaround. If GNU CC is not installed, it is therefore recommended
to try
./configure CC="cc"
and if that doesn't work, try
./configure CC="cc -nodtk"
On Solaris, don't put `/usr/ucb' early in your `PATH'. This
directory contains several dysfunctional programs; working variants of
these programs are available in `/usr/bin'. So, if you need `/usr/ucb'
in your `PATH', put it _after_ `/usr/bin'.
On Haiku, software installed for all users goes in `/boot/common',
not `/usr/local'. It is recommended to use the following options:
./configure --prefix=/boot/common
Specifying the System Type
==========================
There may be some features `configure' cannot figure out
automatically, but needs to determine by the type of machine the package
will run on. Usually, assuming the package is built to be run on the
_same_ architectures, `configure' can figure that out, but if it prints
a message saying it cannot guess the machine type, give it the
`--build=TYPE' option. TYPE can either be a short name for the system
type, such as `sun4', or a canonical name which has the form:
CPU-COMPANY-SYSTEM
where SYSTEM can have one of these forms:
OS
KERNEL-OS
See the file `config.sub' for the possible values of each field. If
`config.sub' isn't included in this package, then this package doesn't
need to know the machine type.
If you are _building_ compiler tools for cross-compiling, you should
use the option `--target=TYPE' to select the type of system they will
produce code for.
If you want to _use_ a cross compiler, that generates code for a
platform different from the build platform, you should specify the
"host" platform (i.e., that on which the generated programs will
eventually be run) with `--host=TYPE'.
Sharing Defaults
================
If you want to set default values for `configure' scripts to share,
you can create a site shell script called `config.site' that gives
default values for variables like `CC', `cache_file', and `prefix'.
`configure' looks for `PREFIX/share/config.site' if it exists, then
`PREFIX/etc/config.site' if it exists. Or, you can set the
`CONFIG_SITE' environment variable to the location of the site script.
A warning: not all `configure' scripts look for a site script.
Defining Variables
==================
Variables not defined in a site shell script can be set in the
environment passed to `configure'. However, some packages may run
configure again during the build, and the customized values of these
variables may be lost. In order to avoid this problem, you should set
them in the `configure' command line, using `VAR=value'. For example:
./configure CC=/usr/local2/bin/gcc
causes the specified `gcc' to be used as the C compiler (unless it is
overridden in the site shell script).
Unfortunately, this technique does not work for `CONFIG_SHELL' due to
an Autoconf limitation. Until the limitation is lifted, you can use
this workaround:
CONFIG_SHELL=/bin/bash ./configure CONFIG_SHELL=/bin/bash
`configure' Invocation
======================
`configure' recognizes the following options to control how it
operates.
`--help'
`-h'
Print a summary of all of the options to `configure', and exit.
`--help=short'
`--help=recursive'
Print a summary of the options unique to this package's
`configure', and exit. The `short' variant lists options used
only in the top level, while the `recursive' variant lists options
also present in any nested packages.
`--version'
`-V'
Print the version of Autoconf used to generate the `configure'
script, and exit.
`--cache-file=FILE'
Enable the cache: use and save the results of the tests in FILE,
traditionally `config.cache'. FILE defaults to `/dev/null' to
disable caching.
`--config-cache'
`-C'
Alias for `--cache-file=config.cache'.
`--quiet'
`--silent'
`-q'
Do not print messages saying which checks are being made. To
suppress all normal output, redirect it to `/dev/null' (any error
messages will still be shown).
`--srcdir=DIR'
Look for the package's source code in directory DIR. Usually
`configure' can determine that directory automatically.
`--prefix=DIR'
Use DIR as the installation prefix. *note Installation Names::
for more details, including other options available for fine-tuning
the installation locations.
`--no-create'
`-n'
Run the configure checks, but stop before creating any output
files.
`configure' also accepts some other, not widely useful, options. Run
`configure --help' for more details.

469
MANIFEST Normal file
View File

@ -0,0 +1,469 @@
AUTHORS
COPYING
CONTRIBUTING
ChangeLog
INSTALL
Makefile.am
NEWS
PULL_REQUEST_TEMPLATE.md
README
.travis.yml
astyle.sh
autogen.sh
build.sh
build_jemalloc.sh
configure.ac
autohbw/Makefile.mk
autohbw/autohbw.c
autohbw/autohbw_get_src_lines.pl
autohbw/autohbw_README
autohbw/autohbw_test.sh
examples/autohbw_candidates.c
examples/filter_example.c
examples/hello_memkind_example.c
examples/README
examples/Makefile.mk
examples/hello_hbw_example.c
examples/memkind_allocated_example.cpp
examples/memkind_allocated.hpp
examples/memkind_decorator_debug.c
examples/pmem_kinds.c
examples/pmem_malloc.c
examples/pmem_malloc_unlimited.c
examples/pmem_usable_size.c
examples/pmem_alignment.c
examples/pmem_and_default_kind.c
examples/pmem_multithreads.c
examples/pmem_multithreads_onekind.c
examples/pmem_free_with_unknown_kind.c
examples/pmem_cpp_allocator.cpp
install_astyle.sh
m4/ax_cxx_compile_stdcxx.m4
m4/ax_cxx_compile_stdcxx_11.m4
m4/ax_pthread.m4
man/memkind-hbw-nodes.1
man/hbwmalloc.3
man/memkind.3
man/memkind_arena.3
man/memkind_default.3
man/memkind_hbw.3
man/memkind_hugetlb.3
man/memkind_pmem.3
man/hbwallocator.3
man/pmemallocator.3
man/autohbw.7
memkind.spec.mk
src/heap_manager.c
src/hbwmalloc.c
src/memkind.c
src/memkind_arena.c
src/memkind_default.c
src/memkind_gbtlb.c
src/memkind_hbw.c
src/memkind_regular.c
src/memkind_hugetlb.c
src/memkind_interleave.c
src/memkind_pmem.c
src/memkind_log.c
src/memkind-hbw-nodes.c
src/tbb_wrapper.c
src/Makefile.mk
include/hbwmalloc.h
include/memkind.h
include/memkind_deprecated.h
include/hbw_allocator.h
include/pmem_allocator.h
include/memkind/internal/heap_manager.h
include/memkind/internal/memkind_arena.h
include/memkind/internal/memkind_default.h
include/memkind/internal/memkind_gbtlb.h
include/memkind/internal/memkind_hbw.h
include/memkind/internal/memkind_regular.h
include/memkind/internal/memkind_hugetlb.h
include/memkind/internal/memkind_interleave.h
include/memkind/internal/memkind_pmem.h
include/memkind/internal/memkind_private.h
include/memkind/internal/memkind_log.h
include/memkind/internal/tbb_wrapper.h
include/memkind/internal/tbb_mem_pool_policy.h
test/Makefile.mk
test/Allocator.hpp
test/TestPolicy.hpp
test/test.sh
test/multithreaded_tests.cpp
test/gb_page_tests_bind_policy.cpp
test/environ_err_hbw_malloc_test.cpp
test/negative_tests.cpp
test/trial_generator.cpp
test/check.h
test/trial_generator.h
test/bat_tests.cpp
test/main.cpp
test/common.h
test/static_kinds_list.h
test/check.cpp
test/error_message_tests.cpp
test/get_arena_test.cpp
test/locality_test.cpp
test/memkind_pmem_tests.cpp
test/memkind_pmem_long_time_tests.cpp
test/memory_footprint_test.cpp
test/memory_manager.h
test/random_sizes_allocator.h
test/proc_stat.h
test/static_kinds_tests.cpp
test/huge_page_test.cpp
test/hbw_verify_function_test.cpp
test/hbw_detection_test.py
test/autohbw_test.py
test/trace_mechanism_test.py
test/memkind-afts.ts
test/memkind-afts-ext.ts
test/memkind-slts.ts
test/memkind-perf.ts
test/memkind-perf-ext.ts
test/memkind-pytests.ts
test/performance/framework.hpp
test/performance/framework.cpp
test/performance/operations.hpp
test/performance/perf_tests.hpp
test/performance/perf_tests.cpp
test/hbw_allocator_tests.cpp
test/decorator_test.cpp
test/decorator_test.h
test/alloc_performance_tests.cpp
test/allocator_perf_tool/AllocationSizes.hpp
test/allocator_perf_tool/Allocation_info.hpp
test/allocator_perf_tool/Allocation_info.cpp
test/allocator_perf_tool/Allocator.hpp
test/allocator_perf_tool/AllocatorFactory.hpp
test/allocator_perf_tool/CSVLogger.hpp
test/allocator_perf_tool/CommandLine.hpp
test/allocator_perf_tool/Configuration.hpp
test/allocator_perf_tool/ConsoleLog.hpp
test/allocator_perf_tool/FunctionCalls.hpp
test/allocator_perf_tool/FunctionCallsPerformanceTask.cpp
test/allocator_perf_tool/FunctionCallsPerformanceTask.h
test/allocator_perf_tool/GTestAdapter.hpp
test/allocator_perf_tool/Iterator.hpp
test/allocator_perf_tool/JemallocAllocatorWithTimer.hpp
test/allocator_perf_tool/Makefile
test/allocator_perf_tool/MemkindAllocatorWithTimer.hpp
test/allocator_perf_tool/Numastat.hpp
test/allocator_perf_tool/Runnable.hpp
test/allocator_perf_tool/PmemMockup.cpp
test/allocator_perf_tool/PmemMockup.hpp
test/allocator_perf_tool/ScenarioWorkload.cpp
test/allocator_perf_tool/ScenarioWorkload.h
test/allocator_perf_tool/StandardAllocatorWithTimer.hpp
test/allocator_perf_tool/Stats.hpp
test/allocator_perf_tool/StressIncreaseToMax.cpp
test/allocator_perf_tool/StressIncreaseToMax.h
test/allocator_perf_tool/Task.hpp
test/allocator_perf_tool/TaskFactory.hpp
test/allocator_perf_tool/Tests.hpp
test/allocator_perf_tool/Thread.hpp
test/allocator_perf_tool/TimerSysTime.hpp
test/allocator_perf_tool/VectorIterator.hpp
test/allocator_perf_tool/Workload.hpp
test/allocator_perf_tool/WrappersMacros.hpp
test/allocator_perf_tool/HugePageUnmap.hpp
test/allocator_perf_tool/HugePageOrganizer.hpp
test/allocator_perf_tool/HBWmallocAllocatorWithTimer.hpp
test/allocator_perf_tool/main.cpp
test/allocate_to_max_stress_test.cpp
test/memkind_versioning_tests.cpp
test/heap_manager_init_perf_test.cpp
test/autohbw_test_helper.c
test/trace_mechanism_test_helper.c
test/python_framework/cmd_helper.py
test/python_framework/huge_page_organizer.py
test/python_framework/__init__.py
test/draw_plots.py
test/run_alloc_benchmark.sh
test/alloc_benchmark.c
test/load_tbbmalloc_symbols.c
test/tbbmalloc.h
test/freeing_memory_segfault_test.cpp
test/dlopen_test.cpp
test/gtest_fused/gtest/gtest-all.cc
test/gtest_fused/gtest/gtest.h
test/pmem_allocator_tests.cpp
jemalloc/.appveyor.yml
jemalloc/.autom4te.cfg
jemalloc/.gitattributes
jemalloc/.gitignore
jemalloc/.travis.yml
jemalloc/COPYING
jemalloc/ChangeLog
jemalloc/INSTALL.md
jemalloc/Makefile.in
jemalloc/README
jemalloc/autogen.sh
jemalloc/bin/jemalloc-config.in
jemalloc/bin/jemalloc.sh.in
jemalloc/bin/jeprof.in
jemalloc/build-aux/config.guess
jemalloc/build-aux/config.sub
jemalloc/build-aux/install-sh
jemalloc/config.stamp.in
jemalloc/configure.ac
jemalloc/doc/html.xsl.in
jemalloc/doc/jemalloc.xml.in
jemalloc/doc/manpages.xsl.in
jemalloc/doc/stylesheet.xsl
jemalloc/include/jemalloc/internal/arena_externs.h
jemalloc/include/jemalloc/internal/arena_inlines_a.h
jemalloc/include/jemalloc/internal/arena_inlines_b.h
jemalloc/include/jemalloc/internal/arena_structs_a.h
jemalloc/include/jemalloc/internal/arena_structs_b.h
jemalloc/include/jemalloc/internal/arena_types.h
jemalloc/include/jemalloc/internal/assert.h
jemalloc/include/jemalloc/internal/atomic.h
jemalloc/include/jemalloc/internal/atomic_c11.h
jemalloc/include/jemalloc/internal/atomic_gcc_atomic.h
jemalloc/include/jemalloc/internal/atomic_gcc_sync.h
jemalloc/include/jemalloc/internal/atomic_msvc.h
jemalloc/include/jemalloc/internal/background_thread_externs.h
jemalloc/include/jemalloc/internal/background_thread_inlines.h
jemalloc/include/jemalloc/internal/background_thread_structs.h
jemalloc/include/jemalloc/internal/base_externs.h
jemalloc/include/jemalloc/internal/base_inlines.h
jemalloc/include/jemalloc/internal/base_structs.h
jemalloc/include/jemalloc/internal/base_types.h
jemalloc/include/jemalloc/internal/bit_util.h
jemalloc/include/jemalloc/internal/bitmap.h
jemalloc/include/jemalloc/internal/ckh.h
jemalloc/include/jemalloc/internal/ctl.h
jemalloc/include/jemalloc/internal/extent_dss.h
jemalloc/include/jemalloc/internal/extent_externs.h
jemalloc/include/jemalloc/internal/extent_inlines.h
jemalloc/include/jemalloc/internal/extent_mmap.h
jemalloc/include/jemalloc/internal/extent_structs.h
jemalloc/include/jemalloc/internal/extent_types.h
jemalloc/include/jemalloc/internal/hash.h
jemalloc/include/jemalloc/internal/hooks.h
jemalloc/include/jemalloc/internal/jemalloc_internal_decls.h
jemalloc/include/jemalloc/internal/jemalloc_internal_defs.h.in
jemalloc/include/jemalloc/internal/jemalloc_internal_externs.h
jemalloc/include/jemalloc/internal/jemalloc_internal_includes.h
jemalloc/include/jemalloc/internal/jemalloc_internal_inlines_a.h
jemalloc/include/jemalloc/internal/jemalloc_internal_inlines_b.h
jemalloc/include/jemalloc/internal/jemalloc_internal_inlines_c.h
jemalloc/include/jemalloc/internal/jemalloc_internal_macros.h
jemalloc/include/jemalloc/internal/jemalloc_internal_types.h
jemalloc/include/jemalloc/internal/jemalloc_preamble.h.in
jemalloc/include/jemalloc/internal/large_externs.h
jemalloc/include/jemalloc/internal/malloc_io.h
jemalloc/include/jemalloc/internal/mutex.h
jemalloc/include/jemalloc/internal/mutex_pool.h
jemalloc/include/jemalloc/internal/mutex_prof.h
jemalloc/include/jemalloc/internal/nstime.h
jemalloc/include/jemalloc/internal/pages.h
jemalloc/include/jemalloc/internal/ph.h
jemalloc/include/jemalloc/internal/private_namespace.sh
jemalloc/include/jemalloc/internal/private_symbols.sh
jemalloc/include/jemalloc/internal/prng.h
jemalloc/include/jemalloc/internal/prof_externs.h
jemalloc/include/jemalloc/internal/prof_inlines_a.h
jemalloc/include/jemalloc/internal/prof_inlines_b.h
jemalloc/include/jemalloc/internal/prof_structs.h
jemalloc/include/jemalloc/internal/prof_types.h
jemalloc/include/jemalloc/internal/public_namespace.sh
jemalloc/include/jemalloc/internal/public_unnamespace.sh
jemalloc/include/jemalloc/internal/ql.h
jemalloc/include/jemalloc/internal/qr.h
jemalloc/include/jemalloc/internal/rb.h
jemalloc/include/jemalloc/internal/rtree.h
jemalloc/include/jemalloc/internal/rtree_tsd.h
jemalloc/include/jemalloc/internal/size_classes.sh
jemalloc/include/jemalloc/internal/smoothstep.h
jemalloc/include/jemalloc/internal/smoothstep.sh
jemalloc/include/jemalloc/internal/spin.h
jemalloc/include/jemalloc/internal/stats.h
jemalloc/include/jemalloc/internal/stats_tsd.h
jemalloc/include/jemalloc/internal/sz.h
jemalloc/include/jemalloc/internal/tcache_externs.h
jemalloc/include/jemalloc/internal/tcache_inlines.h
jemalloc/include/jemalloc/internal/tcache_structs.h
jemalloc/include/jemalloc/internal/tcache_types.h
jemalloc/include/jemalloc/internal/ticker.h
jemalloc/include/jemalloc/internal/tsd.h
jemalloc/include/jemalloc/internal/tsd_generic.h
jemalloc/include/jemalloc/internal/tsd_malloc_thread_cleanup.h
jemalloc/include/jemalloc/internal/tsd_tls.h
jemalloc/include/jemalloc/internal/tsd_types.h
jemalloc/include/jemalloc/internal/tsd_win.h
jemalloc/include/jemalloc/internal/util.h
jemalloc/include/jemalloc/internal/witness.h
jemalloc/include/jemalloc/jemalloc.sh
jemalloc/include/jemalloc/jemalloc_defs.h.in
jemalloc/include/jemalloc/jemalloc_macros.h.in
jemalloc/include/jemalloc/jemalloc_mangle.sh
jemalloc/include/jemalloc/jemalloc_protos.h.in
jemalloc/include/jemalloc/jemalloc_rename.sh
jemalloc/include/jemalloc/jemalloc_typedefs.h.in
jemalloc/include/msvc_compat/C99/stdbool.h
jemalloc/include/msvc_compat/C99/stdint.h
jemalloc/include/msvc_compat/strings.h
jemalloc/include/msvc_compat/windows_extra.h
jemalloc/jemalloc.pc.in
jemalloc/m4/ax_cxx_compile_stdcxx.m4
jemalloc/msvc/ReadMe.txt
jemalloc/msvc/jemalloc_vc2015.sln
jemalloc/msvc/projects/vc2015/jemalloc/jemalloc.vcxproj
jemalloc/msvc/projects/vc2015/jemalloc/jemalloc.vcxproj.filters
jemalloc/msvc/projects/vc2015/test_threads/test_threads.cpp
jemalloc/msvc/projects/vc2015/test_threads/test_threads.h
jemalloc/msvc/projects/vc2015/test_threads/test_threads.vcxproj
jemalloc/msvc/projects/vc2015/test_threads/test_threads.vcxproj.filters
jemalloc/msvc/projects/vc2015/test_threads/test_threads_main.cpp
jemalloc/run_tests.sh
jemalloc/scripts/gen_run_tests.py
jemalloc/scripts/gen_travis.py
jemalloc/src/arena.c
jemalloc/src/background_thread.c
jemalloc/src/base.c
jemalloc/src/bitmap.c
jemalloc/src/ckh.c
jemalloc/src/ctl.c
jemalloc/src/extent.c
jemalloc/src/extent_dss.c
jemalloc/src/extent_mmap.c
jemalloc/src/hash.c
jemalloc/src/hooks.c
jemalloc/src/jemalloc.c
jemalloc/src/jemalloc_cpp.cpp
jemalloc/src/large.c
jemalloc/src/malloc_io.c
jemalloc/src/mutex.c
jemalloc/src/mutex_pool.c
jemalloc/src/nstime.c
jemalloc/src/pages.c
jemalloc/src/prng.c
jemalloc/src/prof.c
jemalloc/src/rtree.c
jemalloc/src/spin.c
jemalloc/src/stats.c
jemalloc/src/sz.c
jemalloc/src/tcache.c
jemalloc/src/ticker.c
jemalloc/src/tsd.c
jemalloc/src/witness.c
jemalloc/src/zone.c
jemalloc/test/include/test/SFMT-alti.h
jemalloc/test/include/test/SFMT-params.h
jemalloc/test/include/test/SFMT-params11213.h
jemalloc/test/include/test/SFMT-params1279.h
jemalloc/test/include/test/SFMT-params132049.h
jemalloc/test/include/test/SFMT-params19937.h
jemalloc/test/include/test/SFMT-params216091.h
jemalloc/test/include/test/SFMT-params2281.h
jemalloc/test/include/test/SFMT-params4253.h
jemalloc/test/include/test/SFMT-params44497.h
jemalloc/test/include/test/SFMT-params607.h
jemalloc/test/include/test/SFMT-params86243.h
jemalloc/test/include/test/SFMT-sse2.h
jemalloc/test/include/test/SFMT.h
jemalloc/test/include/test/btalloc.h
jemalloc/test/include/test/extent_hooks.h
jemalloc/test/include/test/jemalloc_test.h.in
jemalloc/test/include/test/jemalloc_test_defs.h.in
jemalloc/test/include/test/math.h
jemalloc/test/include/test/mq.h
jemalloc/test/include/test/mtx.h
jemalloc/test/include/test/test.h
jemalloc/test/include/test/thd.h
jemalloc/test/include/test/timer.h
jemalloc/test/integration/MALLOCX_ARENA.c
jemalloc/test/integration/aligned_alloc.c
jemalloc/test/integration/allocated.c
jemalloc/test/integration/extent.c
jemalloc/test/integration/extent.sh
jemalloc/test/integration/mallocx.c
jemalloc/test/integration/mallocx.sh
jemalloc/test/integration/overflow.c
jemalloc/test/integration/posix_memalign.c
jemalloc/test/integration/rallocx.c
jemalloc/test/integration/sdallocx.c
jemalloc/test/integration/thread_arena.c
jemalloc/test/integration/thread_tcache_enabled.c
jemalloc/test/integration/xallocx.c
jemalloc/test/integration/xallocx.sh
jemalloc/test/src/SFMT.c
jemalloc/test/src/btalloc.c
jemalloc/test/src/btalloc_0.c
jemalloc/test/src/btalloc_1.c
jemalloc/test/src/math.c
jemalloc/test/src/mq.c
jemalloc/test/src/mtx.c
jemalloc/test/src/test.c
jemalloc/test/src/thd.c
jemalloc/test/src/timer.c
jemalloc/test/stress/microbench.c
jemalloc/test/test.sh.in
jemalloc/test/unit/SFMT.c
jemalloc/test/unit/a0.c
jemalloc/test/unit/arena_reset.c
jemalloc/test/unit/arena_reset_prof.c
jemalloc/test/unit/arena_reset_prof.sh
jemalloc/test/unit/atomic.c
jemalloc/test/unit/background_thread.c
jemalloc/test/unit/base.c
jemalloc/test/unit/bit_util.c
jemalloc/test/unit/bitmap.c
jemalloc/test/unit/ckh.c
jemalloc/test/unit/decay.c
jemalloc/test/unit/decay.sh
jemalloc/test/unit/extent_quantize.c
jemalloc/test/unit/fork.c
jemalloc/test/unit/hash.c
jemalloc/test/unit/hooks.c
jemalloc/test/unit/junk.c
jemalloc/test/unit/junk.sh
jemalloc/test/unit/junk_alloc.c
jemalloc/test/unit/junk_alloc.sh
jemalloc/test/unit/junk_free.c
jemalloc/test/unit/junk_free.sh
jemalloc/test/unit/mallctl.c
jemalloc/test/unit/malloc_io.c
jemalloc/test/unit/math.c
jemalloc/test/unit/mq.c
jemalloc/test/unit/mtx.c
jemalloc/test/unit/nstime.c
jemalloc/test/unit/pack.c
jemalloc/test/unit/pack.sh
jemalloc/test/unit/pages.c
jemalloc/test/unit/ph.c
jemalloc/test/unit/prng.c
jemalloc/test/unit/prof_accum.c
jemalloc/test/unit/prof_accum.sh
jemalloc/test/unit/prof_active.c
jemalloc/test/unit/prof_active.sh
jemalloc/test/unit/prof_gdump.c
jemalloc/test/unit/prof_gdump.sh
jemalloc/test/unit/prof_idump.c
jemalloc/test/unit/prof_idump.sh
jemalloc/test/unit/prof_reset.c
jemalloc/test/unit/prof_reset.sh
jemalloc/test/unit/prof_tctx.c
jemalloc/test/unit/prof_tctx.sh
jemalloc/test/unit/prof_thread_name.c
jemalloc/test/unit/prof_thread_name.sh
jemalloc/test/unit/ql.c
jemalloc/test/unit/qr.c
jemalloc/test/unit/rb.c
jemalloc/test/unit/retained.c
jemalloc/test/unit/rtree.c
jemalloc/test/unit/size_classes.c
jemalloc/test/unit/slab.c
jemalloc/test/unit/smoothstep.c
jemalloc/test/unit/spin.c
jemalloc/test/unit/stats.c
jemalloc/test/unit/stats_print.c
jemalloc/test/unit/ticker.c
jemalloc/test/unit/tsd.c
jemalloc/test/unit/witness.c
jemalloc/test/unit/zero.c
jemalloc/test/unit/zero.sh
build_jemalloc.sh

435
Makefile.am Normal file
View File

@ -0,0 +1,435 @@
#
# Copyright (C) 2014 - 2018 Intel Corporation.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice(s),
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice(s),
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
ACLOCAL_AMFLAGS = -I m4
AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/jemalloc/obj/include
lib_LTLIBRARIES = libmemkind.la
libmemkind_la_SOURCES = src/hbwmalloc.c \
src/heap_manager.c \
src/memkind_arena.c \
src/memkind.c \
src/memkind_default.c \
src/memkind_gbtlb.c \
src/memkind_hbw.c \
src/memkind_regular.c \
src/memkind_hugetlb.c \
src/memkind_pmem.c \
src/memkind_interleave.c \
src/memkind_log.c \
src/tbb_wrapper.c \
# end
libmemkind_la_LIBADD = jemalloc/obj/lib/libjemalloc_pic.a
libmemkind_la_LDFLAGS = -version-info 0:1:0 -ldl
include_HEADERS = include/hbwmalloc.h \
include/hbw_allocator.h \
include/pmem_allocator.h \
include/memkind.h \
include/memkind_deprecated.h \
# end
nonstandardincludedir = $(includedir)/memkind/internal
nonstandardinclude_HEADERS = include/memkind/internal/memkind_arena.h \
include/memkind/internal/heap_manager.h \
include/memkind/internal/memkind_default.h \
include/memkind/internal/memkind_gbtlb.h \
include/memkind/internal/memkind_hbw.h \
include/memkind/internal/memkind_regular.h \
include/memkind/internal/memkind_hugetlb.h \
include/memkind/internal/memkind_interleave.h \
include/memkind/internal/memkind_pmem.h \
include/memkind/internal/memkind_private.h \
include/memkind/internal/memkind_log.h \
include/memkind/internal/tbb_wrapper.h \
include/memkind/internal/tbb_mem_pool_policy.h \
# end
EXTRA_DIST = astyle.sh \
autogen.sh \
build.sh \
build_jemalloc.sh \
examples/README \
test/test.sh \
VERSION \
CONTRIBUTING \
memkind-$(VERSION).spec \
memkind.spec.mk \
jemalloc/.appveyor.yml \
jemalloc/.autom4te.cfg \
jemalloc/.gitattributes \
jemalloc/.gitignore \
jemalloc/.travis.yml \
jemalloc/COPYING \
jemalloc/ChangeLog \
jemalloc/INSTALL.md \
jemalloc/Makefile.in \
jemalloc/README \
jemalloc/autogen.sh \
jemalloc/bin/jemalloc-config.in \
jemalloc/bin/jemalloc.sh.in \
jemalloc/bin/jeprof.in \
jemalloc/build-aux/config.guess \
jemalloc/build-aux/config.sub \
jemalloc/build-aux/install-sh \
jemalloc/config.stamp.in \
jemalloc/configure.ac \
jemalloc/doc/html.xsl.in \
jemalloc/doc/jemalloc.xml.in \
jemalloc/doc/manpages.xsl.in \
jemalloc/doc/stylesheet.xsl \
jemalloc/include/jemalloc/internal/arena_externs.h \
jemalloc/include/jemalloc/internal/arena_inlines_a.h \
jemalloc/include/jemalloc/internal/arena_inlines_b.h \
jemalloc/include/jemalloc/internal/arena_structs_a.h \
jemalloc/include/jemalloc/internal/arena_structs_b.h \
jemalloc/include/jemalloc/internal/arena_types.h \
jemalloc/include/jemalloc/internal/assert.h \
jemalloc/include/jemalloc/internal/atomic.h \
jemalloc/include/jemalloc/internal/atomic_c11.h \
jemalloc/include/jemalloc/internal/atomic_gcc_atomic.h \
jemalloc/include/jemalloc/internal/atomic_gcc_sync.h \
jemalloc/include/jemalloc/internal/atomic_msvc.h \
jemalloc/include/jemalloc/internal/background_thread_externs.h \
jemalloc/include/jemalloc/internal/background_thread_inlines.h \
jemalloc/include/jemalloc/internal/background_thread_structs.h \
jemalloc/include/jemalloc/internal/base_externs.h \
jemalloc/include/jemalloc/internal/base_inlines.h \
jemalloc/include/jemalloc/internal/base_structs.h \
jemalloc/include/jemalloc/internal/base_types.h \
jemalloc/include/jemalloc/internal/bit_util.h \
jemalloc/include/jemalloc/internal/bitmap.h \
jemalloc/include/jemalloc/internal/ckh.h \
jemalloc/include/jemalloc/internal/ctl.h \
jemalloc/include/jemalloc/internal/extent_dss.h \
jemalloc/include/jemalloc/internal/extent_externs.h \
jemalloc/include/jemalloc/internal/extent_inlines.h \
jemalloc/include/jemalloc/internal/extent_mmap.h \
jemalloc/include/jemalloc/internal/extent_structs.h \
jemalloc/include/jemalloc/internal/extent_types.h \
jemalloc/include/jemalloc/internal/hash.h \
jemalloc/include/jemalloc/internal/hooks.h \
jemalloc/include/jemalloc/internal/jemalloc_internal_decls.h \
jemalloc/include/jemalloc/internal/jemalloc_internal_defs.h.in \
jemalloc/include/jemalloc/internal/jemalloc_internal_externs.h \
jemalloc/include/jemalloc/internal/jemalloc_internal_includes.h \
jemalloc/include/jemalloc/internal/jemalloc_internal_inlines_a.h \
jemalloc/include/jemalloc/internal/jemalloc_internal_inlines_b.h \
jemalloc/include/jemalloc/internal/jemalloc_internal_inlines_c.h \
jemalloc/include/jemalloc/internal/jemalloc_internal_macros.h \
jemalloc/include/jemalloc/internal/jemalloc_internal_types.h \
jemalloc/include/jemalloc/internal/jemalloc_preamble.h.in \
jemalloc/include/jemalloc/internal/large_externs.h \
jemalloc/include/jemalloc/internal/malloc_io.h \
jemalloc/include/jemalloc/internal/mutex.h \
jemalloc/include/jemalloc/internal/mutex_pool.h \
jemalloc/include/jemalloc/internal/mutex_prof.h \
jemalloc/include/jemalloc/internal/nstime.h \
jemalloc/include/jemalloc/internal/pages.h \
jemalloc/include/jemalloc/internal/ph.h \
jemalloc/include/jemalloc/internal/private_namespace.sh \
jemalloc/include/jemalloc/internal/private_symbols.sh \
jemalloc/include/jemalloc/internal/prng.h \
jemalloc/include/jemalloc/internal/prof_externs.h \
jemalloc/include/jemalloc/internal/prof_inlines_a.h \
jemalloc/include/jemalloc/internal/prof_inlines_b.h \
jemalloc/include/jemalloc/internal/prof_structs.h \
jemalloc/include/jemalloc/internal/prof_types.h \
jemalloc/include/jemalloc/internal/public_namespace.sh \
jemalloc/include/jemalloc/internal/public_unnamespace.sh \
jemalloc/include/jemalloc/internal/ql.h \
jemalloc/include/jemalloc/internal/qr.h \
jemalloc/include/jemalloc/internal/rb.h \
jemalloc/include/jemalloc/internal/rtree.h \
jemalloc/include/jemalloc/internal/rtree_tsd.h \
jemalloc/include/jemalloc/internal/size_classes.sh \
jemalloc/include/jemalloc/internal/smoothstep.h \
jemalloc/include/jemalloc/internal/smoothstep.sh \
jemalloc/include/jemalloc/internal/spin.h \
jemalloc/include/jemalloc/internal/stats.h \
jemalloc/include/jemalloc/internal/stats_tsd.h \
jemalloc/include/jemalloc/internal/sz.h \
jemalloc/include/jemalloc/internal/tcache_externs.h \
jemalloc/include/jemalloc/internal/tcache_inlines.h \
jemalloc/include/jemalloc/internal/tcache_structs.h \
jemalloc/include/jemalloc/internal/tcache_types.h \
jemalloc/include/jemalloc/internal/ticker.h \
jemalloc/include/jemalloc/internal/tsd.h \
jemalloc/include/jemalloc/internal/tsd_generic.h \
jemalloc/include/jemalloc/internal/tsd_malloc_thread_cleanup.h \
jemalloc/include/jemalloc/internal/tsd_tls.h \
jemalloc/include/jemalloc/internal/tsd_types.h \
jemalloc/include/jemalloc/internal/tsd_win.h \
jemalloc/include/jemalloc/internal/util.h \
jemalloc/include/jemalloc/internal/witness.h \
jemalloc/include/jemalloc/jemalloc.sh \
jemalloc/include/jemalloc/jemalloc_defs.h.in \
jemalloc/include/jemalloc/jemalloc_macros.h.in \
jemalloc/include/jemalloc/jemalloc_mangle.sh \
jemalloc/include/jemalloc/jemalloc_protos.h.in \
jemalloc/include/jemalloc/jemalloc_rename.sh \
jemalloc/include/jemalloc/jemalloc_typedefs.h.in \
jemalloc/include/msvc_compat/C99/stdbool.h \
jemalloc/include/msvc_compat/C99/stdint.h \
jemalloc/include/msvc_compat/strings.h \
jemalloc/include/msvc_compat/windows_extra.h \
jemalloc/jemalloc.pc.in \
jemalloc/m4/ax_cxx_compile_stdcxx.m4 \
jemalloc/msvc/ReadMe.txt \
jemalloc/msvc/jemalloc_vc2015.sln \
jemalloc/msvc/projects/vc2015/jemalloc/jemalloc.vcxproj \
jemalloc/msvc/projects/vc2015/jemalloc/jemalloc.vcxproj.filters \
jemalloc/msvc/projects/vc2015/test_threads/test_threads.cpp \
jemalloc/msvc/projects/vc2015/test_threads/test_threads.h \
jemalloc/msvc/projects/vc2015/test_threads/test_threads.vcxproj \
jemalloc/msvc/projects/vc2015/test_threads/test_threads.vcxproj.filters \
jemalloc/msvc/projects/vc2015/test_threads/test_threads_main.cpp \
jemalloc/run_tests.sh \
jemalloc/scripts/gen_run_tests.py \
jemalloc/scripts/gen_travis.py \
jemalloc/src/arena.c \
jemalloc/src/background_thread.c \
jemalloc/src/base.c \
jemalloc/src/bitmap.c \
jemalloc/src/ckh.c \
jemalloc/src/ctl.c \
jemalloc/src/extent.c \
jemalloc/src/extent_dss.c \
jemalloc/src/extent_mmap.c \
jemalloc/src/hash.c \
jemalloc/src/hooks.c \
jemalloc/src/jemalloc.c \
jemalloc/src/jemalloc_cpp.cpp \
jemalloc/src/large.c \
jemalloc/src/malloc_io.c \
jemalloc/src/mutex.c \
jemalloc/src/mutex_pool.c \
jemalloc/src/nstime.c \
jemalloc/src/pages.c \
jemalloc/src/prng.c \
jemalloc/src/prof.c \
jemalloc/src/rtree.c \
jemalloc/src/spin.c \
jemalloc/src/stats.c \
jemalloc/src/sz.c \
jemalloc/src/tcache.c \
jemalloc/src/ticker.c \
jemalloc/src/tsd.c \
jemalloc/src/witness.c \
jemalloc/src/zone.c \
jemalloc/test/include/test/SFMT-alti.h \
jemalloc/test/include/test/SFMT-params.h \
jemalloc/test/include/test/SFMT-params11213.h \
jemalloc/test/include/test/SFMT-params1279.h \
jemalloc/test/include/test/SFMT-params132049.h \
jemalloc/test/include/test/SFMT-params19937.h \
jemalloc/test/include/test/SFMT-params216091.h \
jemalloc/test/include/test/SFMT-params2281.h \
jemalloc/test/include/test/SFMT-params4253.h \
jemalloc/test/include/test/SFMT-params44497.h \
jemalloc/test/include/test/SFMT-params607.h \
jemalloc/test/include/test/SFMT-params86243.h \
jemalloc/test/include/test/SFMT-sse2.h \
jemalloc/test/include/test/SFMT.h \
jemalloc/test/include/test/btalloc.h \
jemalloc/test/include/test/extent_hooks.h \
jemalloc/test/include/test/jemalloc_test.h.in \
jemalloc/test/include/test/jemalloc_test_defs.h.in \
jemalloc/test/include/test/math.h \
jemalloc/test/include/test/mq.h \
jemalloc/test/include/test/mtx.h \
jemalloc/test/include/test/test.h \
jemalloc/test/include/test/thd.h \
jemalloc/test/include/test/timer.h \
jemalloc/test/integration/MALLOCX_ARENA.c \
jemalloc/test/integration/aligned_alloc.c \
jemalloc/test/integration/allocated.c \
jemalloc/test/integration/extent.c \
jemalloc/test/integration/extent.sh \
jemalloc/test/integration/mallocx.c \
jemalloc/test/integration/mallocx.sh \
jemalloc/test/integration/overflow.c \
jemalloc/test/integration/posix_memalign.c \
jemalloc/test/integration/rallocx.c \
jemalloc/test/integration/sdallocx.c \
jemalloc/test/integration/thread_arena.c \
jemalloc/test/integration/thread_tcache_enabled.c \
jemalloc/test/integration/xallocx.c \
jemalloc/test/integration/xallocx.sh \
jemalloc/test/src/SFMT.c \
jemalloc/test/src/btalloc.c \
jemalloc/test/src/btalloc_0.c \
jemalloc/test/src/btalloc_1.c \
jemalloc/test/src/math.c \
jemalloc/test/src/mq.c \
jemalloc/test/src/mtx.c \
jemalloc/test/src/test.c \
jemalloc/test/src/thd.c \
jemalloc/test/src/timer.c \
jemalloc/test/stress/microbench.c \
jemalloc/test/test.sh.in \
jemalloc/test/unit/SFMT.c \
jemalloc/test/unit/a0.c \
jemalloc/test/unit/arena_reset.c \
jemalloc/test/unit/arena_reset_prof.c \
jemalloc/test/unit/arena_reset_prof.sh \
jemalloc/test/unit/atomic.c \
jemalloc/test/unit/background_thread.c \
jemalloc/test/unit/base.c \
jemalloc/test/unit/bit_util.c \
jemalloc/test/unit/bitmap.c \
jemalloc/test/unit/ckh.c \
jemalloc/test/unit/decay.c \
jemalloc/test/unit/decay.sh \
jemalloc/test/unit/extent_quantize.c \
jemalloc/test/unit/fork.c \
jemalloc/test/unit/hash.c \
jemalloc/test/unit/hooks.c \
jemalloc/test/unit/junk.c \
jemalloc/test/unit/junk.sh \
jemalloc/test/unit/junk_alloc.c \
jemalloc/test/unit/junk_alloc.sh \
jemalloc/test/unit/junk_free.c \
jemalloc/test/unit/junk_free.sh \
jemalloc/test/unit/mallctl.c \
jemalloc/test/unit/malloc_io.c \
jemalloc/test/unit/math.c \
jemalloc/test/unit/mq.c \
jemalloc/test/unit/mtx.c \
jemalloc/test/unit/nstime.c \
jemalloc/test/unit/pack.c \
jemalloc/test/unit/pack.sh \
jemalloc/test/unit/pages.c \
jemalloc/test/unit/ph.c \
jemalloc/test/unit/prng.c \
jemalloc/test/unit/prof_accum.c \
jemalloc/test/unit/prof_accum.sh \
jemalloc/test/unit/prof_active.c \
jemalloc/test/unit/prof_active.sh \
jemalloc/test/unit/prof_gdump.c \
jemalloc/test/unit/prof_gdump.sh \
jemalloc/test/unit/prof_idump.c \
jemalloc/test/unit/prof_idump.sh \
jemalloc/test/unit/prof_reset.c \
jemalloc/test/unit/prof_reset.sh \
jemalloc/test/unit/prof_tctx.c \
jemalloc/test/unit/prof_tctx.sh \
jemalloc/test/unit/prof_thread_name.c \
jemalloc/test/unit/prof_thread_name.sh \
jemalloc/test/unit/ql.c \
jemalloc/test/unit/qr.c \
jemalloc/test/unit/rb.c \
jemalloc/test/unit/retained.c \
jemalloc/test/unit/rtree.c \
jemalloc/test/unit/size_classes.c \
jemalloc/test/unit/slab.c \
jemalloc/test/unit/smoothstep.c \
jemalloc/test/unit/spin.c \
jemalloc/test/unit/stats.c \
jemalloc/test/unit/stats_print.c \
jemalloc/test/unit/ticker.c \
jemalloc/test/unit/tsd.c \
jemalloc/test/unit/witness.c \
jemalloc/test/unit/zero.c \
jemalloc/test/unit/zero.sh \
build_jemalloc.sh \
# end
dist_doc_DATA = README COPYING VERSION
dist_man_MANS = man/memkind-hbw-nodes.1 \
man/hbwmalloc.3 \
man/memkind.3 \
man/memkind_arena.3 \
man/memkind_default.3 \
man/memkind_hbw.3 \
man/memkind_hugetlb.3 \
man/memkind_pmem.3 \
man/hbwallocator.3 \
man/pmemallocator.3 \
man/autohbw.7 \
# end
CLEANFILES = memkind-$(VERSION).spec
DISTCLEANFILES = VERSION
bin_PROGRAMS = memkind-hbw-nodes
memkind_hbw_nodes_SOURCES = src/memkind-hbw-nodes.c
memkind_hbw_nodes_LDADD = libmemkind.la
bin_SCRIPTS =
check_PROGRAMS =
noinst_PROGRAMS =
noinst_LTLIBRARIES =
noinst_HEADERS =
TESTS =
req_flags = -fvisibility=hidden -Wall -Werror -msse4.2 -D_GNU_SOURCE -DMEMKIND_INTERNAL_API -DJE_PREFIX=$(JE_PREFIX)
AM_CFLAGS = $(req_flags)
AM_CXXFLAGS = $(req_flags)
.PHONY: checkprogs
# create libtool .lo files from jemalloc objects
$(jemalloc_objects): jemalloc/obj/src/%.lo: jemalloc/obj/src/%.pic.o jemalloc/obj/src/%.o
@echo "# $@ - a libtool object file" > $@
@echo "# Generated by "`libtool --version | head -n 1` >> $@
@echo "# Actually generated by memkind build system spoofing libtool" >> $@
@echo "pic_object='$*.pic.o'" >> $@
@echo "non_pic_object='$*.o'" >> $@
# build check programs without running tests
checkprogs: libmemkind.la $(check_PROGRAMS)
memkind-$(VERSION).spec:
$(MAKE) version="$(VERSION)" -f memkind.spec.mk $@
rpm: dist
$(MAKE) version="$(VERSION)" CPPFLAGS="$(CPPFLAGS)" LDFLAGS="$(LDFLAGS)" \
-f memkind.spec.mk $@
all: static_lib
# the script merge memkind and jemalloc libraries into one static library.
define ar_prog
create libmemkind.a\n\
addlib .libs/libmemkind.a\n\
addlib jemalloc/obj/lib/libjemalloc_pic.a\n\
save\n\
end
endef
static_lib: jemalloc/obj/lib/libjemalloc_pic.a libmemkind.la
bash -c "ar -M < <(echo -e '$(ar_prog)')"
cp libmemkind.a .libs/
rm libmemkind.a
include autohbw/Makefile.mk
include test/Makefile.mk
include examples/Makefile.mk
include src/Makefile.mk

42
NEWS Normal file
View File

@ -0,0 +1,42 @@
OPEN DEVELOPMENT
================
We are moving to a more open development model with memkind.
- The memkind github organization:
https://github.com/memkind
- Rather than posting bulk patches at time of tag, we are posting more
incremental patches with finer grain commit details.
- There is now a "dev" branch in the memkind repository and a
"memkind-dev" branch in the memkind fork of the jemalloc repository.
These will be used for open development work.
- There is a memkind web page here:
http://memkind.github.io/memkind
- We have posted an architecture document here:
http://memkind.github.io/memkind/memkind_arch_20150318.pdf
- We invite you to join the memkind mailing list:
https://lists.01.org/mailman/listinfo/memkind
- Feel free to open a github issue, especially if there is a TODO item
that you would like to prioritize.
- We have posted source and binary RPMs for several distributions here:
http://download.opensuse.org/repositories/home:/cmcantalupo/
- memkind is also avaiable in Fedora package repository (devel, EPEL7):
https://admin.fedoraproject.org/pkgdb/package/memkind/
- Pull requests are welcome.
- White space formatting generally conforms to
$ astyle --style=linux --indent=spaces=4 -S --max-continuation-indent=80 \
--max-code-length=80 --break-after-logical --indent-namespaces -z2 \
--align-pointer=name
- For more information about astyle:
http://astyle.sourceforge.net/

29
PULL_REQUEST_TEMPLATE.md Normal file
View File

@ -0,0 +1,29 @@
<!--- Provide a general summary of your changes in the Title above -->
### Description
<!--- Describe your changes in detail -->
<!--- If it fixes an open issue, please link to the issue here. -->
### Types of changes
<!--- Put an `x` in the box(es) that apply -->
- [ ] Bugfix (non-breaking change which fixes issue linked in Description above)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Documentation (correction or otherwise)
- [ ] Cosmetics (whitespace, appearance)
- [ ] Other
### Checklist
<!--- Put an `x` in the box(es) that apply -->
- [ ] Code compiles without errors
- [ ] All tests pass locally with my changes (see TESTING section in CONTRIBUTING file)
- [ ] Created tests which will fail without the change (if possible)
- [ ] Extended the README/documentation (if necessary)
- [ ] All newly added files have proprietary license (if necessary)
- [ ] All newly added files are referenced in MANIFEST files (if necessary)
## Further comments
<!--- If this is a relatively large or complex change, kick off the discussion by explaining why you -->
<!--- choose the solution you did and what alternatives you considered, etc... -->

251
README Normal file
View File

@ -0,0 +1,251 @@
MEMKIND
=======
[![Build Status](https://travis-ci.org/memkind/memkind.svg)](https://travis-ci.org/memkind/memkind)
[![MEMKIND version](https://img.shields.io/github/tag/memkind/memkind.svg)](https://github.com/memkind/memkind/releases/latest)
[![Coverage Status](http://codecov.io/github/memkind/memkind/coverage.svg?branch=master)](http://codecov.io/gh/memkind/memkind?branch=master)
DISCLAIMER
----------
SEE COPYING FILE FOR LICENSE INFORMATION.
THIS SOFTWARE IS PROVIDED AS A DEVELOPMENT SNAPSHOT TO AID
COLLABORATION AND WAS NOT ISSUED AS A RELEASED PRODUCT BY INTEL.
LAST UPDATE
-----------
Krzysztof Kulakowski <krzysztof.kulakowski@intel.com>
Tuesday Mar 1 2016
SUMMARY
-------
The memkind library is a user extensible heap manager built on top of
jemalloc which enables control of memory characteristics and a
partitioning of the heap between kinds of memory. The kinds of memory
are defined by operating system memory policies that have been applied
to virtual address ranges. Memory characteristics supported by
memkind without user extension include control of NUMA and page size
features. The jemalloc non-standard interface has been extended to
enable specialized arenas to make requests for virtual memory from the
operating system through the memkind partition interface. Through the
other memkind interfaces the user can control and extend memory
partition features and allocate memory while selecting enabled
features.
API
---
The memkind library delivers two interfaces:
* hbwmalloc.h - recommended for high-bandwidth memory use cases (stable)
* memkind.h - generic interface for more complex use cases (partially unstable)
For more detailed information about those interfaces see
corresponding manpages (located in man/ subdir):
man memkind
or
man hbwmalloc
BUILD REQUIREMENTS
------------------
To build the memkind libraries on a RHEL Linux system first install
the required packages with the following command:
sudo yum install numactl-devel gcc-c++ unzip
On a SLES Linux system install the dependencies with the following
command:
sudo zypper install libnuma-devel gcc-c++ unzip
The memkind library uses the GNU autotools (Autoconf, Automake,
Libtool and m4) for configuration and build. The configure scripts
and gtest source code are distributed with the source tarball included
in the source RPM, and this tarball is created with the memkind "make
dist" target. In contrast to the distributed source tarball, the git
repository does not include any generated files nor the gtest source
code. For this reason some additional steps are required when
building from a checkout of the git repo. Those steps include running
the bash script called "autogen.sh" prior to configure. This script
will populate a VERSION file based on "git describe", and use
autoreconf to generate a configure script. The gtest library is
required for building the test content. This is downloaded
automatically prior to building the test content from the googlecode
website based on a target describe in memkind/test/Makefile.mk.
BUILDING
--------
a) Building jemalloc
The memkind library has a dependency on a related fork of jemalloc.
The jemalloc source was forked from jemalloc version 5.0. This source tree
is located within the jemalloc subdirectory of the memkind source. The jemalloc
source code has been kept close to the original form, and in particular
the build system has been lightly modified.
The developer must configure and build jemalloc prior to configuring
and building memkind. You can do that using included shell script:
export JE_PREFIX=jemk_
./build_jemalloc.sh
Alternatively you can follow this step-by-step instruction:
cd jemalloc
autoconf
mkdir obj
cd obj
../configure --enable-autogen --with-jemalloc-prefix=jemk_ --without-export \
--disable-stats --disable-fill \
--with-malloc-conf="narenas:256,lg_tcache_max:12"
make
cd ../..
Note: JE_PREFIX can be set to arbitrary value, including empty one.
b) Building memkind
Building and installing memkind can be as simple as typing the following while
in the root directory of the source tree:
./build.sh
make install
Alternatively you can follow this step-by-step instruction:
export JE_PREFIX=jemk_
./autogen.sh
./configure
make
make install
this should configure, build, and install this package.
See the output of:
./configure --help
for more information about either the memkind or the jemalloc
configuration options. Some useful information about building with autotools
can also be found in the INSTALL file.
**Important Notes:**
If you are using build.sh script and later want to call 'make' command directly,
then you need to call firstly:
export JE_PREFIX=jemk_
otherwise you will get an error like:
undefined reference to mallocx
RUN REQUIREMENTS
----------------
Requires kernel patch introduced in Linux v3.11 that impacts
functionality of the NUMA system calls. This is patch is commit
3964acd0dbec123aa0a621973a2a0580034b4788 in the linux-stable git
repository from kernel.org. Red Hat has back-ported this patch to the
v3.10 kernel in the RHEL 7.0 GA release, so RHEL 7.0 onward supports
memkind even though this kernel version predates v3.11.
Functionality related to hugepages allocation require patches
e0ec90ee7e6f6cbaa6d59ffb48d2a7af5e80e61d and
099730d67417dfee273e9b10ac2560ca7fac7eb9 from kernel org. Without them
physical memory may end up being located on incorrect NUMA node.
Applications using the memkind library require that libnuma and
libpthread be available for dynamic linking at run time. Both of
these libraries should be available by default, but they can be
installed on RHEL Linux with the following command:
sudo yum install pthread numactl
and on a SLES Linux system with:
sudo zypper install pthread libnuma
To use the interfaces for obtaining 2MB pages please be sure
to follow the instructions here:
https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt
and pay particular attention to the use of the procfs files:
/proc/sys/vm/nr_hugepages
/proc/sys/vm/nr_overcommit_hugepages
for enabling the kernel's huge page pool.
To use the file-backed kind of memory (PMEM), please be sure that
filesystem which is used for PMEM kind supports FALLOC_FL_PUNCH_HOLE flag:
http://man7.org/linux/man-pages/man2/fallocate.2.html
SETTING LOGGING MECHANISM
-------------------------
In memkind library logging mechanism could be enabled by setting MEMKIND_DEBUG
environment variable. Setting MEMKIND_DEBUG to "1" enables printing messages
like errors and general information about environment to stderr.
SETTING HEAP MANAGER
--------------------
In memkind library heap management can be adjusted with MEMKIND_HEAP_MANAGER
environment variable, which allows for switching to one of the available
heap managers.
Values:
JEMALLOC sets the jemalloc heap manager
TBB sets Intel Threading Building Blocks heap manager. This option requires installed
Intel Threading Building Blocks library.
If the MEMKIND_HEAP_MANAGER is not set then the jemalloc heap manager will be used by default.
TESTING
-------
All existing tests pass. For more information on how to execute tests
see the CONTRIBUTING file.
When tests are run on a NUMA platform without high bandwidth memory
the MEMKIND_HBW_NODES environment variable is used in conjunction with
"numactl --membind" to force standard allocations to one NUMA node and
high bandwidth allocations through a different NUMA node. See next
section for more details.
SIMULATE HIGH BANDWIDTH MEMORY
------------------------------
A method for testing for the benefit of high bandwidth memory on a
dual socket Intel(R) Xeon(TM) system is to use the QPI bus to simulate
slow memory. This is not an accurate model of the bandwidth and
latency characteristics of the Intel's 2nd generation Intel(R) Xeon Phi(TM)
Product Family on package memory, but is a reasonable way to determine
which data structures rely critically on bandwidth.
If the application a.out has been modified to use high bandwidth
memory with the memkind library then this can be done with numactl as
follows with the bash shell:
export MEMKIND_HBW_NODES=0
numactl --membind=1 --cpunodebind=0 a.out
or with csh:
setenv MEMKIND_HBW_NODES 0
numactl --membind=1 --cpunodebind=0 a.out
The MEMKIND_HBW_NODES environment variable set to zero will bind high
bandwidth allocations to NUMA node 0. The --membind=1 flag to numactl
will bind standard allocations, static and stack variables to NUMA
node 1. The --cpunodebind=0 option to numactl will bind the process
threads to CPUs associated with NUMA node 0. With this configuration
standard allocations will be fetched across the QPI bus, and high
bandwidth allocations will be local to the process CPU.
NOTES
-----
* Using memkind with Transparent Huge Pages enabled may result in
undesirably high memory footprint. To avoid that disable THP using following
instruction: https://www.kernel.org/doc/Documentation/vm/transhuge.txt
STATUS
------
Different interfaces can represent different maturity level
(as described in corresponding man pages).
Feedback on design and implementation is greatly appreciated.

1
README.md Symbolic link
View File

@ -0,0 +1 @@
README

51
astyle.sh Executable file
View File

@ -0,0 +1,51 @@
#!/bin/bash
#
# Copyright (C) 2018 Intel Corporation.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice(s),
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice(s),
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ASTYLE_MIN_VER="3.1"
ASTYLE_OPT="--style=linux --indent=spaces=4 -S -r --max-continuation-indent=80 "
ASTYLE_OPT+="--max-code-length=80 --break-after-logical --indent-namespaces -z2 "
ASTYLE_OPT+="--align-pointer=name"
if ! ASTYLE=$(which astyle)
then
echo "Package astyle was not found. Unable to check source files format policy." >&2
exit 1
fi
ASTYLE_VER=$(astyle --version 2>&1 | awk '{print $NF}')
if (( $(echo "$ASTYLE_VER < $ASTYLE_MIN_VER" | bc -l) ));
then
echo "Minimal required version of astyle is $ASTYLE_MIN_VER. Detected version is $ASTYLE_VER" >&2
echo "Unable to check source files format policy." >&2
exit 1
fi
$ASTYLE $ASTYLE_OPT ./*.c,*.cpp,*.h,*.hpp --exclude=jemalloc > astyle.out
if TEST=$(cat astyle.out | grep -c Formatted)
then
cat astyle.out
git --no-pager diff
echo "Please fix style issues as shown above"
exit 1
else
echo "Source code is compliant with format policy. No style issues were found."
exit 0
fi

48
autogen.sh Executable file
View File

@ -0,0 +1,48 @@
#!/bin/bash
#
# Copyright (C) 2014-2017 Intel Corporation.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice(s),
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice(s),
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
set -e
# If the VERSION file does not exist, then create it based on git
# describe or if not in a git repo just set VERSION to 0.0.0.
if [ ! -f VERSION ]; then
if [ -f .git/config ]; then
sha=$(git describe --long --always | awk -F- '{print $(NF)}')
release=$(git describe --long | awk -F- '{print $(NF-1)}')
version=$(git describe --long | sed -e "s|\(.*\)-$release-$sha|\1|" -e "s|-|+|g" -e "s|^v||")
if [ "$release" == "" ]; then
version=${sha}
else
version=${version}+dev${release}-${sha}
fi
else
echo "WARNING: VERSION file does not exist and working directory is not a git repository, setting verison to 0.0.0" 2>&1
version=0.0.0
fi
echo $version > VERSION
fi
autoreconf --install

37
autohbw/Makefile.mk Normal file
View File

@ -0,0 +1,37 @@
#
# Copyright (C) 2014 - 2016 Intel Corporation.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice(s),
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice(s),
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
lib_LTLIBRARIES += autohbw/libautohbw.la \
# end
EXTRA_DIST += autohbw/autohbw_get_src_lines.pl
autohbw_libautohbw_la_LIBADD = libmemkind.la
autohbw_libautohbw_la_SOURCES = autohbw/autohbw.c
clean-local: autohbw-clean
autohbw-clean:
rm -f autohbw/*.gcno

457
autohbw/autohbw.c Normal file
View File

@ -0,0 +1,457 @@
/*
* Copyright (C) 2015 - 2018 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice(s),
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
///////////////////////////////////////////////////////////////////////////
// File : autohbw.c
// Purpose: Library to automatically allocate HBW (MCDRAM)
// Author : Ruchira Sasanka (ruchira DOT sasanka AT intel DOT com)
// Date : Jan 30, 2015
///////////////////////////////////////////////////////////////////////////
#include <memkind.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define AUTOHBW_EXPORT __attribute__((visibility("default")))
#define AUTOHBW_INIT __attribute__((constructor))
//-2 = nothing is printed
//-1 = critical messages are printed
// 0 = no log messages for allocations are printed but INFO messages are printed
// 1 = a log message is printed for each allocation (Default)
// 2 = a log message is printed for each allocation with a backtrace
enum {
ALWAYS = -1,
INFO,
ALLOC,
VERBOSE
};
// Default is to print allocations
static int LogLevel = ALLOC;
// Allocations of size greater than low limit promoted to HBW memory.
// If there is a high limit specified, allocations larger than this limit
// will not be allocated in HBW.
static size_t HBWLowLimit = 1 * 1024 * 1024;
static size_t HBWHighLimit = -1ull;
// Whether we have initialized HBW arena of memkind library -- by making
// a dummy call to it. HBW arena (and hence any memkind_* call with kind
// HBW) must NOT be used until this flag is set true.
static bool MemkindInitDone = false;
// Following is the type of HBW memory that is allocated using memkind.
// By changing this type, this library can be used to allocate other
// types of memory types (e.g., MEMKIND_HUGETLB, MEMKIND_GBTLB,
// MEMKIND_HBW_HUGETLB etc.)
static memkind_t hbw_kind;
// API control for HBW allocations.
static bool isAutoHBWEnabled = true;
#define LOG(level, ...) \
do { \
if (LogLevel >= level) { \
fprintf(stderr, __VA_ARGS__); \
} \
} while (0)
static bool isAllocInHBW(size_t size)
{
if (!MemkindInitDone)
return false;
if (!isAutoHBWEnabled)
return false;
if (size < HBWLowLimit)
return false;
if (size > HBWHighLimit)
return false;
return true;
}
// Returns the limit in bytes using a limit value and a multiplier
// character like K, M, G
static size_t getLimit(size_t limit, char lchar)
{
// Now read the trailing character (e.g., K, M, G)
// Based on the character, determine the multiplier
if ((limit > 0) && isalpha(lchar)) {
long mult = 1;
switch (toupper(lchar)) {
case 'G':
mult *= 1024;
case 'M':
mult *= 1024;
case 'K':
mult *= 1024;
}
// check for overflow, saturate at max
if (limit >= -1ull / mult)
return -1ull;
return limit * mult;
}
return limit;
}
// Once HBWLowLimit (and HBWHighLimit) are set, call this method to
// inform the user about the size range of arrays that will be allocated
// in HBW
static void printLimits()
{
// Inform according to the limits set
if ((HBWLowLimit > 0) && (HBWHighLimit < -1ull)) {
// if both high and low limits are specified, we use a range
LOG(INFO, "INFO: Allocations between %ldK - %ldK will be allocated in "
"HBW. Set AUTO_HBW_SIZE=X:Y to change this limit.\n",
HBWLowLimit / 1024, HBWHighLimit / 1024);
} else if (HBWLowLimit > 0) {
// if only a low limit is provided, use that
LOG(INFO, "INFO: Allocations greater than %ldK will be allocated in HBW."
" Set AUTO_HBW_SIZE=X:Y to change this limit.\n",
HBWLowLimit / 1024);
} else if (HBWHighLimit < -1ull) {
// if only a high limit is provided, use that
LOG(INFO, "INFO: Allocations smaller than %ldK will be allocated in HBW. "
"Set AUTO_HBW_SIZE=X:Y to change this limit.\n",
HBWHighLimit / 1024);
} else {
// none of limits is set to non-edge value, everything goes to HBW
LOG(INFO, "INFO: All allocation will be done in HBW.");
}
}
struct kind_name_t {
memkind_t *kind;
const char *name;
};
static struct kind_name_t named_kinds[] = {
{ &MEMKIND_DEFAULT, "memkind_default" },
{ &MEMKIND_HUGETLB, "memkind_hugetlb" },
{ &MEMKIND_INTERLEAVE, "memkind_interleave" },
{ &MEMKIND_HBW, "memkind_hbw" },
{ &MEMKIND_HBW_PREFERRED, "memkind_hbw_preferred" },
{ &MEMKIND_HBW_HUGETLB, "memkind_hbw_hugetlb" },
{ &MEMKIND_HBW_PREFERRED_HUGETLB, "memkind_hbw_preferred_hugetlb" },
{ &MEMKIND_HBW_GBTLB, "memkind_hbw_gbtlb" },
{ &MEMKIND_HBW_PREFERRED_GBTLB, "memkind_hbw_preferred_gbtlb" },
{ &MEMKIND_GBTLB, "memkind_gbtlb" },
{ &MEMKIND_HBW_INTERLEAVE, "memkind_hbw_interleave" },
};
static memkind_t get_kind_by_name(const char *name)
{
int i;
for (i = 0; i < sizeof(named_kinds) / sizeof(named_kinds[0]); ++i)
if (strcasecmp(named_kinds[i].name, name) == 0)
return *named_kinds[i].kind;
return 0;
}
// Read from the environment and sets global variables
// Env variables are:
// AUTO_HBW_SIZE = gives the size for auto HBW allocation
// AUTO_HBW_LOG = gives logging level
static void setEnvValues()
{
// STEP: Read the log level from the env variable. Do this early because
// printing depends on this
char *log_str = getenv("AUTO_HBW_LOG");
if (log_str && strlen(log_str)) {
int level = atoi(log_str);
LogLevel = level;
LOG(ALWAYS, "INFO: Setting log level to %d\n", LogLevel);
}
if (LogLevel == INFO) {
LOG(INFO, "INFO: HBW allocation stats will not be printed. "
"Set AUTO_HBW_LOG to enable.\n");
} else if (LogLevel == ALLOC) {
LOG(INFO, "INFO: Only HBW allocations will be printed. "
"Set AUTO_HBW_LOG to disable/enable.\n");
} else if (LogLevel == VERBOSE) {
LOG(INFO, "INFO: HBW allocation with backtrace info will be printed. "
"Set AUTO_HBW_LOG to disable.\n");
}
// Set the memory type allocated by this library. By default, it is
// MEMKIND_HBW, but we can use this library to allocate other memory
// types
const char *memtype_str = getenv("AUTO_HBW_MEM_TYPE");
if (memtype_str && strlen(memtype_str)) {
// Find the memkind_t using the name the user has provided in the env variable
memkind_t mty = get_kind_by_name(memtype_str);
if (mty != 0) {
hbw_kind = mty;
LOG(INFO, "INFO: Setting HBW memory type to %s\n", memtype_str);
} else {
LOG(ALWAYS, "WARN: Memory type %s not recognized. Using default type\n",
memtype_str);
}
}
// STEP: Set the size limits (thresholds) for HBW allocation
//
// Reads the environment variable
const char *size_str = getenv("AUTO_HBW_SIZE");
if (size_str) {
size_t lowlim = HBWLowLimit / 1024;
size_t highlim = HBWHighLimit / 1024;
char lowC = 'K', highC = 'K';
if (size_str) {
char *ptr = (char *)size_str;
lowlim = strtoll(ptr, &ptr, 10);
if (*ptr != 0 && *ptr != ':')
lowC = *ptr++;
else
lowC = ' ';
if (*ptr++ == ':') {
highlim = strtoll(ptr, &ptr, 10);
if (*ptr)
highC = *ptr;
else
highC = ' ';
}
LOG(INFO, "INFO: lowlim=%zu(%c), highlim=%zu(%c)\n", lowlim, lowC, highlim,
highC);
}
HBWLowLimit = getLimit(lowlim, lowC);
HBWHighLimit = getLimit(highlim, highC);
if (HBWLowLimit >= HBWHighLimit) {
LOG(ALWAYS, "WARN: In AUTO_HBW_SIZE=X:Y, X cannot be greater or equal to Y. "
"None of allocations will use HBW memory.\n");
}
} else {
// if the user did not specify any limits, inform that we are using
// default limits
LOG(INFO, "INFO: Using default values for array size thresholds. "
"Set AUTO_HBW_SIZE=X:Y to change.\n");
}
// inform the user about limits
printLimits();
}
// This function is executed at library load time.
// Initialize HBW arena by making a dummy allocation/free at library load
// time. Until HBW initialization is complete, we must not call any
// allocation routines with HBW as kind.
static void AUTOHBW_INIT autohbw_load(void)
{
// First set the default memory type this library allocates. This can
// be overridden by env variable
// Note: 'memkind_hbw_preferred' will allow falling back to DDR but
// 'memkind_hbw will not'
// Note: If HBM is not installed on a system, memkind_hbw_preferred call
// would fail. Therefore, we need to check for availability first.
if (memkind_check_available(MEMKIND_HBW) != 0) {
LOG(ALWAYS, "WARN: *** No HBM found in system. Will use default (DDR) "
"OR user specified type ***\n");
hbw_kind = MEMKIND_DEFAULT;
} else {
hbw_kind = MEMKIND_HBW_PREFERRED;
}
// Read any env variables. This has to be done first because DbgLevel
// is set using env variables and debug printing is used below
setEnvValues(); // read any env variables
LOG(INFO, "INFO: autohbw.so loaded!\n");
// dummy HBW call to initialize HBW arena
void *pp = memkind_malloc(hbw_kind, 16);
if (pp == 0) {
LOG(ALWAYS, "\t-HBW init call FAILED. "
"Is required memory type present on your system?\n");
abort();
}
LOG(ALWAYS, "\t-HBW int call succeeded\n");
memkind_free(hbw_kind, pp);
MemkindInitDone = true; // enable HBW allocation
}
static void *MemkindMalloc(size_t size)
{
LOG(VERBOSE, "In my memkind malloc sz:%ld ... ", size);
bool useHbw = isAllocInHBW(size);
memkind_t kind = useHbw ? hbw_kind : MEMKIND_DEFAULT;
if (useHbw)
LOG(VERBOSE, "\tHBW");
void *ptr = memkind_malloc(kind, size);
LOG(VERBOSE, "\tptr:%p\n", ptr);
return ptr;
}
static void *MemkindCalloc(size_t nmemb, size_t size)
{
LOG(VERBOSE, "In my memkind calloc sz:%ld ..", size * nmemb);
bool useHbw = isAllocInHBW(size);
memkind_t kind = useHbw ? hbw_kind : MEMKIND_DEFAULT;
if (useHbw)
LOG(VERBOSE, "\tHBW");
void *ptr = memkind_calloc(kind, nmemb, size);
LOG(VERBOSE, "\tptr:%p\n", ptr);
return ptr;
}
static void *MemkindRealloc(void *ptr, size_t size)
{
LOG(VERBOSE, "In my memkind realloc sz:%ld, p1:%p ..", size, ptr);
bool useHbw = isAllocInHBW(size);
memkind_t kind = useHbw ? hbw_kind : MEMKIND_DEFAULT;
if (useHbw)
LOG(VERBOSE, "\tHBW");
void *nptr = memkind_realloc(kind, ptr, size);
LOG(VERBOSE, "\tptr=%p\n", nptr);
return nptr;
}
static int MemkindAlign(void **memptr, size_t alignment, size_t size)
{
LOG(VERBOSE, "In my memkind align sz:%ld .. ", size);
bool useHbw = isAllocInHBW(size);
memkind_t kind = useHbw ? hbw_kind : MEMKIND_DEFAULT;
if (useHbw)
LOG(VERBOSE, "\tHBW");
int ret = memkind_posix_memalign(kind, memptr, alignment, size);
LOG(VERBOSE, "\tptr:%p\n", *memptr);
return ret;
}
// memkind_free does not need the exact kind, if kind is 0. Then
// the library can figure out the proper kind itself.
static void MemkindFree(void *ptr)
{
// avoid to many useless logs
if (ptr)
LOG(VERBOSE, "In my memkind free, ptr:%p\n", ptr);
memkind_free(0, ptr);
}
//--------------------------------------------------------------------------
// ------------------ Public API of autohbw ----------------------
//--------------------------------------------------------------------------
AUTOHBW_EXPORT void enableAutoHBW()
{
isAutoHBWEnabled = true;
LOG(INFO, "INFO: HBW allocations enabled by application (for this rank)\n");
}
AUTOHBW_EXPORT void disableAutoHBW()
{
isAutoHBWEnabled = false;
LOG(INFO, "INFO: HBW allocations disabled by application (for this rank)\n");
}
AUTOHBW_EXPORT void *malloc(size_t size)
{
return MemkindMalloc(size);
}
AUTOHBW_EXPORT void *calloc(size_t nmemb, size_t size)
{
return MemkindCalloc(nmemb, size);
}
AUTOHBW_EXPORT void *realloc(void *ptr, size_t size)
{
return MemkindRealloc(ptr, size);
}
AUTOHBW_EXPORT int posix_memalign(void **memptr, size_t alignment, size_t size)
{
return MemkindAlign(memptr, alignment, size);
}
// Warn about deprecated function usage.
AUTOHBW_EXPORT void *valloc(size_t size)
{
LOG(ALWAYS, "use of deprecated valloc. Use posix_memalign instead\n");
void *memptr = 0;
size_t boundary = sysconf(_SC_PAGESIZE);
int status = MemkindAlign(&memptr, boundary, size);
if (status == 0 && memptr != 0)
return memptr;
return 0;
}
// Warn about deprecated function usage.
AUTOHBW_EXPORT void *memalign(size_t boundary, size_t size)
{
LOG(ALWAYS, "use of deprecated memalign. Use posix_memalign instead\n");
void *memptr = 0;
int status = MemkindAlign(&memptr, boundary, size);
if (status == 0 && memptr != 0)
return memptr;
return 0;
}
AUTOHBW_EXPORT void free(void *ptr)
{
return MemkindFree(ptr);
}

92
autohbw/autohbw_README Normal file
View File

@ -0,0 +1,92 @@
README for auothbw library
Ruchira Sasanka (ruchira DOT sasanka AT intel DOT com)
2015 April 8
PURPOSE
-------
The autohbw library is used to automatically allocate high-bandwidth (HBW)
memory without any modifications to source code of your application.
This library intercepts the standard heap allocations (e.g., malloc, calloc)
in your program so that it can serve those allocations out of HBW memory.
There are two libraries installed at the same location as memkind library:
1) libautohbw.so -- dynamic library
2) libautohbw.a -- static library (provided for static linking)
USAGE
-----
To use the dynamic library, insert LD_PRELOAD=libautohbw.so and libmekind.so
before your commandline. For instance,
LD_PRELOAD=libautohbw.so /bin/ls
executes Unix ls utility with autohbw library. You can execute the
above command on the prompt or put it in a shell script. An example of
the latter approach is given in ./autohbw_test.sh. Make sure that
LD_LIBRARY_PATH enviornment variable contains the path to libautohbw.so
and libmekind.so before you exeute the above command.
To use the statically linked library, insert -lautohbw -lmemkind
on your link line. You will have to provide the library path with -L to
point to the above libraries. If you are linking your program statically
(e.g., with -static or -fast flags in ifort/icc), you must use the static
version of autohbw library (libautohbw.a).
It is possible to temporarily disable/enable automatic HBM allocations by
calling disableAutoHBW() and enableAutoHBW() in your source code. To call
these routines, please include autohbw_api.h header file and link with
-lautohbw.
Usage with MPI programs
-----------------------
To use with MPI programs, you need to create a shell script to do the
LD_PRELOAD. E.g.,
mpirun -n 2 ./autohbw_test.sh
ENVIORNMENT VARIABLES
---------------------
The following enviornment variables control the behavior of the autohbw
library:
AUTO_HBW_SIZE=x[:y]
Indicates that any allocation larger than x and smaller than y should be
allocated in HBW memory. x and y can be followed by a K, M, or G to
indicate the size in Kilo/Memga/Giga bytes (e.g., 4K, 3M, 2G).
Examples:
AUTO_HBW_SIZE=4K # all allocation larger than 4K allocated in HBW
AUTO_HBW_SIZE=1M:5M # allocations betwen 1M and 5M allocated in HBW
AUTO_HBW_LOG=level
Sets the value of logging (printing) level. If level is:
-1 = no messages are printed
0 = no log messages for allocations are printed but INFO messages
are printed
1 = a log message is printed for each allocation (Default)
2 = a log message is printed for each allocation with a backtrace
Redirect this output and use autohbw_get_src_lines.pl to find
source lines for each allocation. Your application must be compiled
with -g to see source lines.
Notes:
1. Logging adds extra overhead. Therefore, performance critical runs,
logging level should be 0
2. The amount of free memory printed with log messages is only
approximate -- e.g. pages that are not touched yet are excluded
Examples:
AUTO_HBW_LOG=1
AUTO_HBW_MEM_TYPE=memory_type
Sets the type of memory type that should be automatically allocated. By
default, this type is MEMKIND_HBW_PREFERRED, if MCDRAM is found in your
system; otherwise, the default is MEMKIND_DEFAULT. The names of memory
types are definedin memkind(3) man page. If you are requesting any huge
TLB pages, pleasemake sure that the requested type is currently enabled
in your OS.
Examples:
AUTO_HBW_MEM_TYPE=MEMKIND_HBW_PREFERRED (default, if MCDRAM present)
AUTO_HBW_MEM_TYPE=MEMKIND_DEFAULT (default, if MCDRAM absent)
AUTO_HBW_MEM_TYPE=MEMKIND_HBW_HUGETLB
AUTO_HBW_MEM_TYPE=MEMKIND_HUGETLB

49
autohbw/autohbw_api.h Normal file
View File

@ -0,0 +1,49 @@
/*
* Copyright (C) 2015 - 2016 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice(s),
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
///////////////////////////////////////////////////////////////////////////
// File : autohbw_api.h
// Purpose: Header file to include, to use API calls to AutoHBW
// Author : Ruchira Sasanka (ruchira.sasanka AT intel.com)
// Date : Jan 30, 2015
///////////////////////////////////////////////////////////////////////////
#ifndef AUTOHBW_API_H
#define AUTOHBW_API_H
#ifdef __cplusplus
extern "C" {
#endif
// Temporarily enable HBM allocations
void enableAutoHBW();
// Temporarily disable HBM allocations
void disableAutoHBW();
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,106 @@
#!/usr/bin/perl
#
# Copyright (C) 2015 - 2016 Intel Corporation.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice(s),
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice(s),
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
use strict;
my $usage = "Usage: get_autohbw_srclines.pl output_log_of_AutoHBW executable";
# Check for 2 arguments
#
if (@ARGV != 2) {
print $usage, "\n";
exit;
}
# Read the command line arguments
#
my $LogF = shift @ARGV;
my $BinaryF = shift @ARGV;
&main();
sub main {
print("Info: Reading AutoHBW log from: $LogF\n");
print("Info: Binary file: $BinaryF\n");
# open the log file produced by AutoHBM and look at lines starting
# with Log
open LOGF, "grep Log $LogF |" or die "Can't open log file $LogF";
my $line;
# Read each log line
#
while ($line = <LOGF>) {
# if the line contain 3 backtrace addresses, try to find the source
# lines for them
#
if ($line =~ /^(Log:.*)Backtrace:.*0x([0-9a-f]+).*0x([0-9a-f]+).*0x([0-9a-f]+)/ ) {
# Read the pointers
#
my @ptrs;
my $pre = $1;
$ptrs[0] = $2;
$ptrs[1] = $3;
$ptrs[2] = $4;
# prints the first portion of the line
#
print $pre, "\n";
# for each of the pointers, lookup its source line using
# addr2line and print the src line(s) if found
#
my $i=0;
for ($i=0; $i < @ptrs; $i++) {
my $addr = $ptrs[$i];
open SRCL, "addr2line -e $BinaryF 0x$addr |"
or die "addr2line fail";
my $srcl = <SRCL>;
if ($srcl =~ /^\?/) {
} else {
print "\t- Src: $srcl";
}
}
}
}
}

37
autohbw/autohbw_test.sh Executable file
View File

@ -0,0 +1,37 @@
#!/bin/bash
# Copyright (C) 2015 - 2016 Intel Corporation.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice(s),
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice(s),
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# The following is needed if your system does not really have HBW nodes.
# Please see 'man memkind' for a description of this variable
#
# export MEMKIND_HBW_NODES=0
# Set any autohbw env variables
#
export AUTO_HBW_SIZE=4K
# Make sure you have set LD_LIBRARY_PATH to lib directory with libautohbw.so
# and libmemkind.so
#
LD_PRELOAD=libautohbw.so:libmemkind.so /bin/ls

48
build.sh Executable file
View File

@ -0,0 +1,48 @@
#!/bin/bash
#
# Copyright (C) 2016 Intel Corporation.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice(s),
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice(s),
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
set -e
if [ -z "$JE_PREFIX" ]; then
export JE_PREFIX=jemk_
fi
cd $(dirname $0)
EXTRA_CONF=$@
if [ ! -f ./jemalloc/obj/lib/libjemalloc_pic.a ]; then
./build_jemalloc.sh $EXTRA_CONF
fi
if [ ! -f ./configure ]; then
./autogen.sh
fi
if [ ! -f ./Makefile ]; then
./configure $EXTRA_CONF
fi
#use V=1 for full cmdlines of build
make all -j $MAKEOPTS
make checkprogs -j $MAKEOPTS

35
build_jemalloc.sh Executable file
View File

@ -0,0 +1,35 @@
#!/bin/bash
#
# Copyright (C) 2016 - 2018 Intel Corporation.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice(s),
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice(s),
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
EXTRA_CONF=$@
cd jemalloc
test -e configure || autoconf
test -e obj || mkdir obj
cd obj
../configure --enable-autogen --with-jemalloc-prefix=$JE_PREFIX --without-export \
--disable-stats --disable-fill \
$EXTRA_CONF --with-malloc-conf="narenas:256,lg_tcache_max:12"
make -j`nproc`

53
config.h.in~ Normal file
View File

@ -0,0 +1,53 @@
/* config.h.in. Generated from configure.ac by autoheader. */
/* Upper bound for number of arenas per kind */
#undef ARENA_LIMIT_PER_KIND
/* define if the compiler supports basic C++11 syntax */
#undef HAVE_CXX11
/* Define to 1 if you have the `numa' library (-lnuma). */
#undef HAVE_LIBNUMA
/* Have PTHREAD_PRIO_INHERIT. */
#undef HAVE_PTHREAD_PRIO_INHERIT
/* Enables code for debugging */
#undef MEMKIND_DEBUG
/* Enables decorators */
#undef MEMKIND_DECORATION_ENABLED
/* Enables TLS usage for mapping arenas to threads */
#undef MEMKIND_TLS
/* TLS model attribute */
#undef MEMKIND_TLS_MODEL
/* Name of package */
#undef PACKAGE
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the home page for this package. */
#undef PACKAGE_URL
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* Define to necessary symbol if this constant uses a non-standard name on
your system. */
#undef PTHREAD_CREATE_JOINABLE
/* Version number of package */
#undef VERSION

197
configure.ac Normal file
View File

@ -0,0 +1,197 @@
#
# Copyright (C) 2014 - 2018 Intel Corporation.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice(s),
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice(s),
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.64])
AC_INIT([memkind],m4_esyscmd([tr -d '\n' < VERSION]))
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_SRCDIR([memkind.spec.mk])
AM_INIT_AUTOMAKE([-Wall -Werror foreign 1.11 silent-rules subdir-objects parallel-tests tar-pax])
AM_SILENT_RULES([yes])
# Checks for programs and libraries.
AM_PROG_AR
AC_PROG_CXX
AC_PROG_CC
AC_OPENMP
AC_CHECK_LIB(numa, numa_available, [], [AC_MSG_ERROR([libnuma is required dependency])])
AX_PTHREAD([LIBS="$PTHREAD_LIBS $LIBS" CFLAGS="$CFLAGS $PTHREAD_CFLAGS" CC="$PTHREAD_CC"],
[AC_MSG_ERROR([pthreads are required dependency])])
AM_PROG_CC_C_O
#============================tls===============================================
# Check for tls_model attribute support
SAVED_CFLAGS="${CFLAGS}"
CFLAGS="$CFLAGS -Werror"
AC_MSG_CHECKING([for tls_model attribute support])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
[[
static __thread int __attribute__((tls_model("local-dynamic"))) x;
]],
[[
x = 1234;
]])],
[AC_MSG_RESULT([yes])
tls_model="1"],
[AC_MSG_RESULT([no])
tls_model="0"])
CFLAGS="${SAVED_CFLAGS}"
if test "x${tls_model}" = "x1" ; then
AC_DEFINE([MEMKIND_TLS_MODEL],
[__attribute__((tls_model("initial-exec")))], [TLS model attribute])
else
AC_DEFINE([MEMKIND_TLS_MODEL], [ ], [TLS model attribute])
fi
AC_ARG_ENABLE([tls],
[AS_HELP_STRING([--enable-tls], [Enable thread-local storage (__thread keyword)])],
[if test "x$enable_tls" = "xyes" ; then
enable_tls="1"
else
enable_tls="0"
fi
],
[enable_tls="0"]
)
if test "x${enable_tls}" = "x1" ; then
AC_MSG_CHECKING([for TLS support])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
[[
__thread int x;
]], [[
x = 1234;
]])],
AC_MSG_RESULT([yes]),
AC_MSG_RESULT([no])
enable_tls="0")
fi
if test "x${enable_tls}" = "x1" ; then
AC_DEFINE([MEMKIND_TLS], [ ], [Enables TLS usage for mapping arenas to threads])
fi
AC_SUBST([enable_tls])
#============================decorators========================================
AC_ARG_ENABLE([decorators],
[AS_HELP_STRING([--enable-decorators], [Enable decorators])],
[if test "x$enable_decorators" = "xyes" ; then
enable_decorators="1"
else
enable_decorators="0"
fi
],
[enable_decorators="0"]
)
if test "x${enable_decorators}" = "x1" ; then
AC_DEFINE([MEMKIND_DECORATION_ENABLED], [ ], [Enables decorators])
fi
AC_SUBST([enable_decorators])
#============================debug=============================================
AC_ARG_ENABLE([debug],
[AS_HELP_STRING([--enable-debug], [Build debugging code and compile with -O0 -g])],
[if test "x$enable_debug" = "xno" ; then
enable_debug="0"
else
enable_debug="1"
fi
],
[enable_debug="0"]
)
if test "x$enable_debug" = "x1" ; then
AC_DEFINE([MEMKIND_DEBUG], [ ], [Enables code for debugging])
CFLAGS="$CFLAGS -O0 -g"
CXXFLAGS="$CXXFLAGS -O0 -g"
fi
AC_SUBST([enable_debug])
#============================gcov==============================================
AC_ARG_ENABLE([gcov],
[AS_HELP_STRING([--enable-gcov], [Build code with gcov instructions])],
[if test "x$enable_gcov" = "xno" ; then
enable_gcov="0"
else
enable_gcov="1"
fi
],
[enable_gcov="0"]
)
if test "x$enable_gcov" = "x1" ; then
CFLAGS="$CFLAGS -O0 -fprofile-arcs -ftest-coverage"
CXXFLAGS="$CXXFLAGS -O0 -fprofile-arcs -ftest-coverage"
fi
AC_SUBST([enable_gcov])
#============================secure_flags======================================
AC_ARG_ENABLE([secure],
[AS_HELP_STRING([--enable-secure], [Build library with security enchantments])],
[if test "x$enable_secure" = "xno" ; then
enable_secure="0"
else
enable_secure="1"
fi
],
[enable_secure="1"]
)
if test "x$enable_secure" = "x1" ; then
CFLAGS="$CFLAGS -fstack-protector"
LDFLAGS="$LDFLAGS -Wl,-z,relro,-z,now"
if test "$CFLAGS" != "${CFLAGS%-O0*}" ; then # if CFLAGS contains -O0
echo "WARNING: Could not apply FORTIFY_SOURCE=2 due to lack of optimization (-O0)"
else
CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2" #FORTITFY_SOURCE does not work with -O0 (ex. if enable_debug=1 or enable_gcov=1)
fi
fi
AC_SUBST([enable_secure])
#============================arena_limit=======================================
arena_limit=256;
AC_ARG_VAR(ARENA_LIMIT,
[Upper bound for number of arenas per kind, if set to 0 then no limit]
)
if test "$ARENA_LIMIT" != "" ; then
arena_limit=$ARENA_LIMIT;
fi
AC_DEFINE_UNQUOTED([ARENA_LIMIT_PER_KIND], $arena_limit, [Upper bound for number of arenas per kind])
#============================cxx11=============================================
AX_CXX_COMPILE_STDCXX_11([noext], [optional])
AM_CONDITIONAL([HAVE_CXX11], [test "x$HAVE_CXX11" = x1])
LT_PREREQ([2.2])
LT_INIT
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

View File

@ -0,0 +1,302 @@
.gitignore
AUTHORS
COPYING
CONTRIBUTING
INSTALL
NEWS
PULL_REQUEST_TEMPLATE.md
README
VERSION
m4/ax_cxx_compile_stdcxx.m4
m4/ax_cxx_compile_stdcxx_11.m4
m4/ax_pthread.m4
ChangeLog
.travis.yml
autohbw/autohbw_README
examples/README
test/memkind-afts.ts
test/memkind-afts-ext.ts
test/memkind-slts.ts
test/memkind-perf.ts
test/memkind-perf-ext.ts
test/memkind-pytests.ts
test/gtest_fused/gtest/gtest-all.cc
test/gtest_fused/gtest/gtest.h
jemalloc/.appveyor.yml
jemalloc/.autom4te.cfg
jemalloc/.gitattributes
jemalloc/.gitignore
jemalloc/.travis.yml
jemalloc/COPYING
jemalloc/ChangeLog
jemalloc/INSTALL.md
jemalloc/Makefile.in
jemalloc/README
jemalloc/autogen.sh
jemalloc/bin/jemalloc-config.in
jemalloc/bin/jemalloc.sh.in
jemalloc/bin/jeprof.in
jemalloc/build-aux/config.guess
jemalloc/build-aux/config.sub
jemalloc/build-aux/install-sh
jemalloc/config.stamp.in
jemalloc/configure.ac
jemalloc/doc/html.xsl.in
jemalloc/doc/jemalloc.xml.in
jemalloc/doc/manpages.xsl.in
jemalloc/doc/stylesheet.xsl
jemalloc/include/jemalloc/internal/arena_externs.h
jemalloc/include/jemalloc/internal/arena_inlines_a.h
jemalloc/include/jemalloc/internal/arena_inlines_b.h
jemalloc/include/jemalloc/internal/arena_structs_a.h
jemalloc/include/jemalloc/internal/arena_structs_b.h
jemalloc/include/jemalloc/internal/arena_types.h
jemalloc/include/jemalloc/internal/assert.h
jemalloc/include/jemalloc/internal/atomic.h
jemalloc/include/jemalloc/internal/atomic_c11.h
jemalloc/include/jemalloc/internal/atomic_gcc_atomic.h
jemalloc/include/jemalloc/internal/atomic_gcc_sync.h
jemalloc/include/jemalloc/internal/atomic_msvc.h
jemalloc/include/jemalloc/internal/background_thread_externs.h
jemalloc/include/jemalloc/internal/background_thread_inlines.h
jemalloc/include/jemalloc/internal/background_thread_structs.h
jemalloc/include/jemalloc/internal/base_externs.h
jemalloc/include/jemalloc/internal/base_inlines.h
jemalloc/include/jemalloc/internal/base_structs.h
jemalloc/include/jemalloc/internal/base_types.h
jemalloc/include/jemalloc/internal/bit_util.h
jemalloc/include/jemalloc/internal/bitmap.h
jemalloc/include/jemalloc/internal/ckh.h
jemalloc/include/jemalloc/internal/ctl.h
jemalloc/include/jemalloc/internal/extent_dss.h
jemalloc/include/jemalloc/internal/extent_externs.h
jemalloc/include/jemalloc/internal/extent_inlines.h
jemalloc/include/jemalloc/internal/extent_mmap.h
jemalloc/include/jemalloc/internal/extent_structs.h
jemalloc/include/jemalloc/internal/extent_types.h
jemalloc/include/jemalloc/internal/hash.h
jemalloc/include/jemalloc/internal/hooks.h
jemalloc/include/jemalloc/internal/jemalloc_internal_decls.h
jemalloc/include/jemalloc/internal/jemalloc_internal_defs.h.in
jemalloc/include/jemalloc/internal/jemalloc_internal_externs.h
jemalloc/include/jemalloc/internal/jemalloc_internal_includes.h
jemalloc/include/jemalloc/internal/jemalloc_internal_inlines_a.h
jemalloc/include/jemalloc/internal/jemalloc_internal_inlines_b.h
jemalloc/include/jemalloc/internal/jemalloc_internal_inlines_c.h
jemalloc/include/jemalloc/internal/jemalloc_internal_macros.h
jemalloc/include/jemalloc/internal/jemalloc_internal_types.h
jemalloc/include/jemalloc/internal/jemalloc_preamble.h.in
jemalloc/include/jemalloc/internal/large_externs.h
jemalloc/include/jemalloc/internal/malloc_io.h
jemalloc/include/jemalloc/internal/mutex.h
jemalloc/include/jemalloc/internal/mutex_pool.h
jemalloc/include/jemalloc/internal/mutex_prof.h
jemalloc/include/jemalloc/internal/nstime.h
jemalloc/include/jemalloc/internal/pages.h
jemalloc/include/jemalloc/internal/ph.h
jemalloc/include/jemalloc/internal/private_namespace.sh
jemalloc/include/jemalloc/internal/private_symbols.sh
jemalloc/include/jemalloc/internal/prng.h
jemalloc/include/jemalloc/internal/prof_externs.h
jemalloc/include/jemalloc/internal/prof_inlines_a.h
jemalloc/include/jemalloc/internal/prof_inlines_b.h
jemalloc/include/jemalloc/internal/prof_structs.h
jemalloc/include/jemalloc/internal/prof_types.h
jemalloc/include/jemalloc/internal/public_namespace.sh
jemalloc/include/jemalloc/internal/public_unnamespace.sh
jemalloc/include/jemalloc/internal/ql.h
jemalloc/include/jemalloc/internal/qr.h
jemalloc/include/jemalloc/internal/rb.h
jemalloc/include/jemalloc/internal/rtree.h
jemalloc/include/jemalloc/internal/rtree_tsd.h
jemalloc/include/jemalloc/internal/size_classes.sh
jemalloc/include/jemalloc/internal/smoothstep.h
jemalloc/include/jemalloc/internal/smoothstep.sh
jemalloc/include/jemalloc/internal/spin.h
jemalloc/include/jemalloc/internal/stats.h
jemalloc/include/jemalloc/internal/stats_tsd.h
jemalloc/include/jemalloc/internal/sz.h
jemalloc/include/jemalloc/internal/tcache_externs.h
jemalloc/include/jemalloc/internal/tcache_inlines.h
jemalloc/include/jemalloc/internal/tcache_structs.h
jemalloc/include/jemalloc/internal/tcache_types.h
jemalloc/include/jemalloc/internal/ticker.h
jemalloc/include/jemalloc/internal/tsd.h
jemalloc/include/jemalloc/internal/tsd_generic.h
jemalloc/include/jemalloc/internal/tsd_malloc_thread_cleanup.h
jemalloc/include/jemalloc/internal/tsd_tls.h
jemalloc/include/jemalloc/internal/tsd_types.h
jemalloc/include/jemalloc/internal/tsd_win.h
jemalloc/include/jemalloc/internal/util.h
jemalloc/include/jemalloc/internal/witness.h
jemalloc/include/jemalloc/jemalloc.sh
jemalloc/include/jemalloc/jemalloc_defs.h.in
jemalloc/include/jemalloc/jemalloc_macros.h.in
jemalloc/include/jemalloc/jemalloc_mangle.sh
jemalloc/include/jemalloc/jemalloc_protos.h.in
jemalloc/include/jemalloc/jemalloc_rename.sh
jemalloc/include/jemalloc/jemalloc_typedefs.h.in
jemalloc/include/msvc_compat/C99/stdbool.h
jemalloc/include/msvc_compat/C99/stdint.h
jemalloc/include/msvc_compat/strings.h
jemalloc/include/msvc_compat/windows_extra.h
jemalloc/jemalloc.pc.in
jemalloc/m4/ax_cxx_compile_stdcxx.m4
jemalloc/msvc/ReadMe.txt
jemalloc/msvc/jemalloc_vc2015.sln
jemalloc/msvc/projects/vc2015/jemalloc/jemalloc.vcxproj
jemalloc/msvc/projects/vc2015/jemalloc/jemalloc.vcxproj.filters
jemalloc/msvc/projects/vc2015/test_threads/test_threads.cpp
jemalloc/msvc/projects/vc2015/test_threads/test_threads.h
jemalloc/msvc/projects/vc2015/test_threads/test_threads.vcxproj
jemalloc/msvc/projects/vc2015/test_threads/test_threads.vcxproj.filters
jemalloc/msvc/projects/vc2015/test_threads/test_threads_main.cpp
jemalloc/run_tests.sh
jemalloc/scripts/gen_run_tests.py
jemalloc/scripts/gen_travis.py
jemalloc/src/arena.c
jemalloc/src/background_thread.c
jemalloc/src/base.c
jemalloc/src/bitmap.c
jemalloc/src/ckh.c
jemalloc/src/ctl.c
jemalloc/src/extent.c
jemalloc/src/extent_dss.c
jemalloc/src/extent_mmap.c
jemalloc/src/hash.c
jemalloc/src/hooks.c
jemalloc/src/jemalloc.c
jemalloc/src/jemalloc_cpp.cpp
jemalloc/src/large.c
jemalloc/src/malloc_io.c
jemalloc/src/mutex.c
jemalloc/src/mutex_pool.c
jemalloc/src/nstime.c
jemalloc/src/pages.c
jemalloc/src/prng.c
jemalloc/src/prof.c
jemalloc/src/rtree.c
jemalloc/src/spin.c
jemalloc/src/stats.c
jemalloc/src/sz.c
jemalloc/src/tcache.c
jemalloc/src/ticker.c
jemalloc/src/tsd.c
jemalloc/src/witness.c
jemalloc/src/zone.c
jemalloc/test/include/test/SFMT-alti.h
jemalloc/test/include/test/SFMT-params.h
jemalloc/test/include/test/SFMT-params11213.h
jemalloc/test/include/test/SFMT-params1279.h
jemalloc/test/include/test/SFMT-params132049.h
jemalloc/test/include/test/SFMT-params19937.h
jemalloc/test/include/test/SFMT-params216091.h
jemalloc/test/include/test/SFMT-params2281.h
jemalloc/test/include/test/SFMT-params4253.h
jemalloc/test/include/test/SFMT-params44497.h
jemalloc/test/include/test/SFMT-params607.h
jemalloc/test/include/test/SFMT-params86243.h
jemalloc/test/include/test/SFMT-sse2.h
jemalloc/test/include/test/SFMT.h
jemalloc/test/include/test/btalloc.h
jemalloc/test/include/test/extent_hooks.h
jemalloc/test/include/test/jemalloc_test.h.in
jemalloc/test/include/test/jemalloc_test_defs.h.in
jemalloc/test/include/test/math.h
jemalloc/test/include/test/mq.h
jemalloc/test/include/test/mtx.h
jemalloc/test/include/test/test.h
jemalloc/test/include/test/thd.h
jemalloc/test/include/test/timer.h
jemalloc/test/integration/MALLOCX_ARENA.c
jemalloc/test/integration/aligned_alloc.c
jemalloc/test/integration/allocated.c
jemalloc/test/integration/extent.c
jemalloc/test/integration/extent.sh
jemalloc/test/integration/mallocx.c
jemalloc/test/integration/mallocx.sh
jemalloc/test/integration/overflow.c
jemalloc/test/integration/posix_memalign.c
jemalloc/test/integration/rallocx.c
jemalloc/test/integration/sdallocx.c
jemalloc/test/integration/thread_arena.c
jemalloc/test/integration/thread_tcache_enabled.c
jemalloc/test/integration/xallocx.c
jemalloc/test/integration/xallocx.sh
jemalloc/test/src/SFMT.c
jemalloc/test/src/btalloc.c
jemalloc/test/src/btalloc_0.c
jemalloc/test/src/btalloc_1.c
jemalloc/test/src/math.c
jemalloc/test/src/mq.c
jemalloc/test/src/mtx.c
jemalloc/test/src/test.c
jemalloc/test/src/thd.c
jemalloc/test/src/timer.c
jemalloc/test/stress/microbench.c
jemalloc/test/test.sh.in
jemalloc/test/unit/SFMT.c
jemalloc/test/unit/a0.c
jemalloc/test/unit/arena_reset.c
jemalloc/test/unit/arena_reset_prof.c
jemalloc/test/unit/arena_reset_prof.sh
jemalloc/test/unit/atomic.c
jemalloc/test/unit/background_thread.c
jemalloc/test/unit/base.c
jemalloc/test/unit/bit_util.c
jemalloc/test/unit/bitmap.c
jemalloc/test/unit/ckh.c
jemalloc/test/unit/decay.c
jemalloc/test/unit/decay.sh
jemalloc/test/unit/extent_quantize.c
jemalloc/test/unit/fork.c
jemalloc/test/unit/hash.c
jemalloc/test/unit/hooks.c
jemalloc/test/unit/junk.c
jemalloc/test/unit/junk.sh
jemalloc/test/unit/junk_alloc.c
jemalloc/test/unit/junk_alloc.sh
jemalloc/test/unit/junk_free.c
jemalloc/test/unit/junk_free.sh
jemalloc/test/unit/mallctl.c
jemalloc/test/unit/malloc_io.c
jemalloc/test/unit/math.c
jemalloc/test/unit/mq.c
jemalloc/test/unit/mtx.c
jemalloc/test/unit/nstime.c
jemalloc/test/unit/pack.c
jemalloc/test/unit/pack.sh
jemalloc/test/unit/pages.c
jemalloc/test/unit/ph.c
jemalloc/test/unit/prng.c
jemalloc/test/unit/prof_accum.c
jemalloc/test/unit/prof_accum.sh
jemalloc/test/unit/prof_active.c
jemalloc/test/unit/prof_active.sh
jemalloc/test/unit/prof_gdump.c
jemalloc/test/unit/prof_gdump.sh
jemalloc/test/unit/prof_idump.c
jemalloc/test/unit/prof_idump.sh
jemalloc/test/unit/prof_reset.c
jemalloc/test/unit/prof_reset.sh
jemalloc/test/unit/prof_tctx.c
jemalloc/test/unit/prof_tctx.sh
jemalloc/test/unit/prof_thread_name.c
jemalloc/test/unit/prof_thread_name.sh
jemalloc/test/unit/ql.c
jemalloc/test/unit/qr.c
jemalloc/test/unit/rb.c
jemalloc/test/unit/retained.c
jemalloc/test/unit/rtree.c
jemalloc/test/unit/size_classes.c
jemalloc/test/unit/slab.c
jemalloc/test/unit/smoothstep.c
jemalloc/test/unit/spin.c
jemalloc/test/unit/stats.c
jemalloc/test/unit/stats_print.c
jemalloc/test/unit/ticker.c
jemalloc/test/unit/tsd.c
jemalloc/test/unit/witness.c
jemalloc/test/unit/zero.c
jemalloc/test/unit/zero.sh
include/memkind/internal/tbb_mem_pool_policy.h

View File

@ -0,0 +1,159 @@
astyle.sh
autogen.sh
build.sh
build_jemalloc.sh
install_astyle.sh
Makefile.am
configure.ac
autohbw/Makefile.mk
autohbw/autohbw.c
autohbw/autohbw_get_src_lines.pl
autohbw/autohbw_test.sh
examples/Makefile.mk
examples/autohbw_candidates.c
examples/filter_example.c
examples/hello_hbw_example.c
examples/memkind_allocated_example.cpp
examples/memkind_allocated.hpp
examples/hello_memkind_example.c
examples/memkind_decorator_debug.c
man/memkind-hbw-nodes.1
man/autohbw.7
man/hbwmalloc.3
man/memkind.3
man/memkind_arena.3
man/memkind_default.3
man/memkind_hbw.3
man/memkind_hugetlb.3
man/hbwallocator.3
man/pmemallocator.3
memkind.spec.mk
src/heap_manager.c
src/hbwmalloc.c
src/memkind.c
src/memkind_arena.c
src/memkind_default.c
src/memkind_gbtlb.c
src/memkind_hbw.c
src/memkind_regular.c
src/memkind_hugetlb.c
src/memkind_interleave.c
src/memkind_log.c
src/memkind-hbw-nodes.c
src/tbb_wrapper.c
src/Makefile.mk
include/hbwmalloc.h
include/memkind.h
include/memkind_deprecated.h
include/hbw_allocator.h
include/pmem_allocator.h
include/memkind/internal/heap_manager.h
include/memkind/internal/memkind_arena.h
include/memkind/internal/memkind_default.h
include/memkind/internal/memkind_gbtlb.h
include/memkind/internal/memkind_hbw.h
include/memkind/internal/memkind_regular.h
include/memkind/internal/memkind_hugetlb.h
include/memkind/internal/memkind_interleave.h
include/memkind/internal/memkind_pmem.h
include/memkind/internal/memkind_private.h
include/memkind/internal/memkind_log.h
include/memkind/internal/tbb_wrapper.h
test/Makefile.mk
test/Allocator.hpp
test/TestPolicy.hpp
test/bat_tests.cpp
test/check.cpp
test/check.h
test/common.h
test/static_kinds_list.h
test/environ_err_hbw_malloc_test.cpp
test/gb_page_tests_bind_policy.cpp
test/main.cpp
test/multithreaded_tests.cpp
test/negative_tests.cpp
test/test.sh
test/trial_generator.cpp
test/trial_generator.h
test/error_message_tests.cpp
test/get_arena_test.cpp
test/locality_test.cpp
test/memkind_pmem_tests.cpp
test/memkind_pmem_long_time_tests.cpp
test/memory_footprint_test.cpp
test/memory_manager.h
test/random_sizes_allocator.h
test/proc_stat.h
test/static_kinds_tests.cpp
test/huge_page_test.cpp
test/hbw_verify_function_test.cpp
test/performance/framework.hpp
test/performance/framework.cpp
test/performance/operations.hpp
test/performance/perf_tests.hpp
test/performance/perf_tests.cpp
test/hbw_allocator_tests.cpp
test/decorator_test.cpp
test/decorator_test.h
test/alloc_performance_tests.cpp
test/allocator_perf_tool/AllocationSizes.hpp
test/allocator_perf_tool/Allocation_info.hpp
test/allocator_perf_tool/Allocation_info.cpp
test/allocator_perf_tool/Allocator.hpp
test/allocator_perf_tool/AllocatorFactory.hpp
test/allocator_perf_tool/CSVLogger.hpp
test/allocator_perf_tool/CommandLine.hpp
test/allocator_perf_tool/Configuration.hpp
test/allocator_perf_tool/ConsoleLog.hpp
test/allocator_perf_tool/FunctionCalls.hpp
test/allocator_perf_tool/FunctionCallsPerformanceTask.cpp
test/allocator_perf_tool/FunctionCallsPerformanceTask.h
test/allocator_perf_tool/GTestAdapter.hpp
test/allocator_perf_tool/Iterator.hpp
test/allocator_perf_tool/JemallocAllocatorWithTimer.hpp
test/allocator_perf_tool/Makefile
test/allocator_perf_tool/MemkindAllocatorWithTimer.hpp
test/allocator_perf_tool/Numastat.hpp
test/allocator_perf_tool/Runnable.hpp
test/allocator_perf_tool/PmemMockup.cpp
test/allocator_perf_tool/PmemMockup.hpp
test/allocator_perf_tool/ScenarioWorkload.cpp
test/allocator_perf_tool/ScenarioWorkload.h
test/allocator_perf_tool/StandardAllocatorWithTimer.hpp
test/allocator_perf_tool/Stats.hpp
test/allocator_perf_tool/StressIncreaseToMax.cpp
test/allocator_perf_tool/StressIncreaseToMax.h
test/allocator_perf_tool/Task.hpp
test/allocator_perf_tool/TaskFactory.hpp
test/allocator_perf_tool/Tests.hpp
test/allocator_perf_tool/Thread.hpp
test/allocator_perf_tool/TimerSysTime.hpp
test/allocator_perf_tool/VectorIterator.hpp
test/allocator_perf_tool/Workload.hpp
test/allocator_perf_tool/WrappersMacros.hpp
test/allocator_perf_tool/HugePageUnmap.hpp
test/allocator_perf_tool/HugePageOrganizer.hpp
test/allocator_perf_tool/HBWmallocAllocatorWithTimer.hpp
test/allocator_perf_tool/main.cpp
test/allocate_to_max_stress_test.cpp
test/memkind_versioning_tests.cpp
test/heap_manager_init_perf_test.cpp
test/autohbw_test_helper.c
test/trace_mechanism_test_helper.c
test/hbw_detection_test.py
test/autohbw_test.py
test/trace_mechanism_test.py
test/python_framework/cmd_helper.py
test/python_framework/huge_page_organizer.py
test/python_framework/__init__.py
test/draw_plots.py
test/run_alloc_benchmark.sh
test/alloc_benchmark.c
test/load_tbbmalloc_symbols.c
test/tbbmalloc.h
test/freeing_memory_segfault_test.cpp
test/dlopen_test.cpp
test/pmem_allocator_tests.cpp
man/memkind_pmem.3
src/memkind_pmem.c

View File

@ -0,0 +1,10 @@
examples/pmem_kinds.c
examples/pmem_malloc.c
examples/pmem_malloc_unlimited.c
examples/pmem_usable_size.c
examples/pmem_alignment.c
examples/pmem_and_default_kind
examples/pmem_multithreads.c
examples/pmem_multithreads_onekind.c
examples/pmem_free_with_unknown_kind.c
examples/pmem_cpp_allocator.cpp

View File

@ -0,0 +1,23 @@
/*
* Copyright (C) 2014 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice(s),
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) 2015, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY LOG OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

View File

@ -0,0 +1,36 @@
/*
* Copyright (C) 2000 - 2014, Intel Corp.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
* substantially similar to the "NO WARRANTY" disclaimer below
* ("Disclaimer") and any redistribution must be conditioned upon
* including a substantially similar Disclaimer requirement for further
* binary redistribution.
* 3. Neither the names of the above-listed copyright holders nor the names
* of any contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* NO WARRANTY
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*/

5
debian/changelog vendored Normal file
View File

@ -0,0 +1,5 @@
memkind (0.0.0) UNRELEASED; urgency=low
* See ChangeLog for more details
-- Krzysztof Kulakowski <krzysztof.kulakowski@intel.com> Mon, 12 Dec 2016 15:53:31 +0000

1
debian/compat vendored Normal file
View File

@ -0,0 +1 @@
9

25
debian/control vendored Normal file
View File

@ -0,0 +1,25 @@
Source: memkind
Section: utils
Priority: optional
Maintainer: Krzysztof Kulakowski <krzysztof.kulakowski@intel.com>
Build-Depends: debhelper (>= 8.0.0)
Standards-Version: 3.9.4
Homepage: https://github.com/memkind/memkind
Package: memkind
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description:
The memkind library is an user extensible heap manager built on top of
jemalloc which enables control of memory characteristics and a
partitioning of the heap between kinds of memory. The kinds of memory
are defined by operating system memory policies that have been applied
to virtual address ranges. Memory characteristics supported by
memkind without user extension include control of NUMA and page size
features. The jemalloc non-standard interface has been extended to
enable specialized arenas to make requests for virtual memory from the
operating system through the memkind partition interface. Through the
other memkind interfaces the user can control and extend memory
partition features and allocate memory while selecting enabled
features. This software is being made available for early evaluation.
Feedback on design or implementation is greatly appreciated.

21
debian/rules vendored Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/make -f
# -*- makefile -*-
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
# ignore tests during build
override_dh_auto_test:
override_dh_auto_configure:
./build_jemalloc.sh
./autogen.sh
dh_auto_configure -- --prefix=/usr --libdir=/usr/lib \
--includedir=/usr/include --sbindir=/usr/sbin --enable-cxx11 \
--mandir=/usr/share/man --docdir=/usr/share/doc/memkind
override_dh_auto_build:
dh_auto_build -- checkprogs
%:
dh $@

85
examples/Makefile.mk Normal file
View File

@ -0,0 +1,85 @@
#
# Copyright (C) 2014 - 2018 Intel Corporation.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice(s),
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice(s),
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
noinst_PROGRAMS += examples/hello_memkind \
examples/hello_memkind_debug \
examples/hello_hbw \
examples/filter_memkind \
examples/pmem_kinds \
examples/pmem_malloc \
examples/pmem_malloc_unlimited \
examples/pmem_usable_size \
examples/pmem_alignment \
examples/pmem_and_default_kind \
examples/pmem_multithreads \
examples/pmem_multithreads_onekind \
examples/pmem_free_with_unknown_kind \
examples/autohbw_candidates \
# end
if HAVE_CXX11
noinst_PROGRAMS += examples/memkind_allocated
noinst_PROGRAMS += examples/pmem_cpp_allocator
endif
examples_hello_memkind_LDADD = libmemkind.la
examples_hello_memkind_debug_LDADD = libmemkind.la
examples_hello_hbw_LDADD = libmemkind.la
examples_filter_memkind_LDADD = libmemkind.la
examples_pmem_kinds_LDADD = libmemkind.la
examples_pmem_malloc_LDADD = libmemkind.la
examples_pmem_malloc_unlimited_LDADD = libmemkind.la
examples_pmem_usable_size_LDADD = libmemkind.la
examples_pmem_alignment_LDADD = libmemkind.la
examples_pmem_and_default_kind_LDADD = libmemkind.la
examples_pmem_multithreads_LDADD = libmemkind.la
examples_pmem_multithreads_onekind_LDADD = libmemkind.la
examples_pmem_free_with_unknown_kind_LDADD = libmemkind.la
examples_autohbw_candidates_LDADD = libmemkind.la
if HAVE_CXX11
examples_memkind_allocated_LDADD = libmemkind.la
examples_pmem_cpp_allocator_LDADD = libmemkind.la
endif
examples_hello_memkind_SOURCES = examples/hello_memkind_example.c
examples_hello_memkind_debug_SOURCES = examples/hello_memkind_example.c examples/memkind_decorator_debug.c
examples_hello_hbw_SOURCES = examples/hello_hbw_example.c
examples_filter_memkind_SOURCES = examples/filter_example.c
examples_pmem_kinds_SOURCES = examples/pmem_kinds.c
examples_pmem_malloc_SOURCES = examples/pmem_malloc.c
examples_pmem_malloc_unlimited_SOURCES = examples/pmem_malloc_unlimited.c
examples_pmem_usable_size_SOURCES = examples/pmem_usable_size.c
examples_pmem_alignment_SOURCES = examples/pmem_alignment.c
examples_pmem_and_default_kind_SOURCES = examples/pmem_and_default_kind.c
examples_pmem_multithreads_SOURCES = examples/pmem_multithreads.c
examples_pmem_multithreads_onekind_SOURCES = examples/pmem_multithreads_onekind.c
examples_pmem_free_with_unknown_kind_SOURCES = examples/pmem_free_with_unknown_kind.c
examples_autohbw_candidates_SOURCES = examples/autohbw_candidates.c
if HAVE_CXX11
examples_memkind_allocated_SOURCES = examples/memkind_allocated_example.cpp examples/memkind_allocated.hpp
examples_pmem_cpp_allocator_SOURCES = examples/pmem_cpp_allocator.cpp
endif
clean-local:
rm -f examples/*.gcno examples/*.gcda

80
examples/README Normal file
View File

@ -0,0 +1,80 @@
# Memkind examples
The example directory contains example codes that use the memkind
interface.
## PMEM
The pmem_*.c(pp) demonstrates how to create and use a file-backed memory kind.
The default pmem path is "/tmp/".
Custom directory is pass as first argument to all of PMEM example programs,
e.g. to execute pmem_malloc example in /mnt/pmem location, call:
./pmem_malloc /mnt/pmem/
### pmem_kinds.c
This example shows how to create and destroy pmem kind with defined or unlimited size.
### pmem_malloc.c
This example shows how to allocate memory and possibility to exceed pmem kind size.
### pmem_malloc_unlimited.c
This example shows how to allocate memory with unlimited kind size.
### pmem_usable_size.c
This example shows difference between the expected and the actual allocation size.
### pmem_alignment.c
This example shows how to use memkind alignment and how it affects allocations.
### pmem_multithreads.c
This example shows how to use multithreading with independent pmem kinds.
### pmem_multithreads_onekind.c
This example shows how to use multithreading with one main pmem kind.
### pmem_and_default_kind.c
This example shows how to allocate in standard memory and file-backed memory (pmem kind).
### pmem_free_with_unknown_kind.c
This example shows how to allocate in standard memory and file-backed memory (pmem kind)
and free memory without a need to remember which kind it belongs to.
### pmem_cpp_allocator.cpp
This example shows usage of C++ allocator mechanism designed for file-backed memory
kind with different data structures like: vector, list and map.
## Other memkind examples
The simplest example is the hello_example.c which is a hello world
variant. The filter_example.c shows how you would use high bandwidth
memory to store a reduction of a larger data set stored in DDR. There is
also an example of how to create user defined kinds. This example
creates kinds which isolate allocations to a single NUMA node each
backed by a single arena.
The memkind_allocated example is simple usage of memkind in C++11 which
shows how memkind can be used to allocate objects, and consists of two files:
memkind_allocated.hpp - which is definition of template class that should be
inherited and parametrized by derived type (curiously recurring template
pattern), to let deriving class allocate their objects using specified kind.
memkind_allocated_example.cpp - which is usage example of this approach.
Logic of memkind_allocated is based on overriding operator new() in template,
and allocating memory on kind specified in new() parameter, or by overridable
static method getClassKind(). This implementation also supports alignment
specifier's (alignas() - new feature in C++11).
The downside of this approach is that it will work properly only if
memkind_allocated template is inherited once in inheritance chain (which
probably makes that not very useful for most scenarios). Other thing is that it
overriding class new() operator which can cause various problems if used
unwisely.

View File

@ -0,0 +1,122 @@
/*
* Copyright (C) 2015 - 2018 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice(s),
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
///////////////////////////////////////////////////////////////////////////
// File : autohbw_candidates.c
// Purpose: Shows which functions are interposed by AutoHBW library.
// : These functions can be used for testing purposes
// Author : Ruchira Sasanka (ruchira.sasanka AT intel.com)
// Date : Sept 10, 2015
///////////////////////////////////////////////////////////////////////////
#include <memkind.h>
#include <stdlib.h>
#include <stdio.h>
///////////////////////////////////////////////////////////////////////////
// This function contains an example case for each heap allocation function
// intercepted by the AutoHBW library
///////////////////////////////////////////////////////////////////////////
//volatile is needed to prevent optimizing out below hooks
volatile int memkind_called_g;
void memkind_malloc_post(struct memkind *kind, size_t size, void **result)
{
memkind_called_g = 1;
}
void memkind_calloc_post(struct memkind *kind, size_t nmemb, size_t size,
void **result)
{
memkind_called_g = 1;
}
void memkind_posix_memalign_post(struct memkind *kind, void **memptr,
size_t alignment, size_t size, int *err)
{
memkind_called_g = 1;
}
void memkind_realloc_post(struct memkind *kind, void *ptr, size_t size,
void **result)
{
memkind_called_g = 1;
}
void memkind_free_pre(struct memkind **kind, void **ptr)
{
memkind_called_g = 1;
}
void finish_testcase(int fail_condition, const char *fail_message, int *err)
{
if(memkind_called_g != 1 || fail_condition) {
printf("%s\n", fail_message);
*err= -1;
}
memkind_called_g = 0;
}
int main()
{
int err = 0;
const size_t size = 1024 * 1024; // 1M of data
void *buf = NULL;
memkind_called_g = 0;
// Test 1: Test malloc and free
buf = malloc(size);
finish_testcase(buf==NULL, "Malloc failed!", &err);
free(buf);
finish_testcase(0, "Free after malloc failed!", &err);
// Test 2: Test calloc and free
buf = calloc(size, 1);
finish_testcase(buf==NULL, "Calloc failed!", &err);
free(buf);
finish_testcase(0, "Free after calloc failed!", &err);
// Test 3: Test realloc and free
buf = malloc(size);
finish_testcase(buf==NULL, "Malloc before realloc failed!", &err);
buf = realloc(buf, size * 2);
finish_testcase(buf==NULL, "Realloc failed!", &err);
free(buf);
finish_testcase(0, "Free after realloc failed!", &err);
// Test 4: Test posix_memalign and free
int ret = posix_memalign(&buf, 64, size);
finish_testcase(ret, "Posix_memalign failed!", &err);
free(buf);
finish_testcase(0, "Free after posix_memalign failed!", &err);
return err;
}

87
examples/filter_example.c Normal file
View File

@ -0,0 +1,87 @@
/*
* Copyright (C) 2014 - 2016 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice(s),
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <memkind.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
int main(int argc, char **argv)
{
const size_t stream_len = 1024 * 1024;
const size_t filter_len = 1024;
const size_t num_filter = stream_len / filter_len;
size_t i, j;
double *stream = NULL;
double *filter = NULL;
double *result = NULL;
srandom(0);
stream = (double *)memkind_malloc(MEMKIND_DEFAULT, stream_len * sizeof(double));
if (stream == NULL) {
perror("<memkind>");
fprintf(stderr, "Unable to allocate stream\n");
return errno ? -errno : 1;
}
filter = (double *)memkind_malloc(MEMKIND_HBW, filter_len * sizeof(double));
if (filter == NULL) {
perror("<memkind>");
fprintf(stderr, "Unable to allocate filter\n");
return errno ? -errno : 1;
}
result = (double *)memkind_calloc(MEMKIND_HBW, filter_len, sizeof(double));
if (result == NULL) {
perror("<memkind>");
fprintf(stderr, "Unable to allocate result\n");
return errno ? -errno : 1;
}
for (i = 0; i < stream_len; i++) {
stream[i] = (double)(random())/(double)(RAND_MAX);
}
for (i = 0; i < filter_len; i++) {
filter[i] = (double)(i)/(double)(filter_len);
}
for (i = 0; i < num_filter; i++) {
for (j = 0; j < filter_len; j++) {
result[j] += stream[i * filter_len + j] * filter[j];
}
}
for (i = 0; i < filter_len; i++) {
fprintf(stdout, "%.6e\n", result[i]);
}
memkind_free(MEMKIND_HBW, result);
memkind_free(MEMKIND_HBW, filter);
memkind_free(MEMKIND_DEFAULT, stream);
return 0;
}

View File

@ -0,0 +1,81 @@
/*
* Copyright (C) 2014 - 2018 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice(s),
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <hbwmalloc.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
int main(int argc, char **argv)
{
const size_t size = 512;
char *default_str = NULL;
char *hbw_str = NULL;
char *hbw_hugetlb_str = NULL;
int err = 0;
default_str = (char *)malloc(size);
if (default_str == NULL) {
perror("malloc()");
fprintf(stderr, "Unable to allocate default string\n");
err = errno ? -errno : 1;
goto exit;
}
hbw_str = (char *)hbw_malloc(size);
if (hbw_str == NULL) {
perror("hbw_malloc()");
fprintf(stderr, "Unable to allocate hbw string\n");
err = errno ? -errno : 1;
goto exit;
}
err = hbw_posix_memalign_psize((void **)&hbw_hugetlb_str, 2097152, size,
HBW_PAGESIZE_2MB);
if (err) {
perror("hbw_posix_memalign()");
fprintf(stderr, "Unable to allocate hbw hugetlb string\n");
err = errno ? -errno : 1;
goto exit;
}
sprintf(default_str, "Hello world from standard memory\n");
sprintf(hbw_str, "Hello world from high bandwidth memory\n");
sprintf(hbw_hugetlb_str, "Hello world from high bandwidth 2 MB paged memory\n");
fprintf(stdout, "%s", default_str);
fprintf(stdout, "%s", hbw_str);
fprintf(stdout, "%s", hbw_hugetlb_str);
exit:
if (hbw_hugetlb_str) {
hbw_free(hbw_hugetlb_str);
}
if (hbw_str) {
hbw_free(hbw_str);
}
if (default_str) {
free(default_str);
}
return err;
}

View File

@ -0,0 +1,115 @@
/*
* Copyright (C) 2014 - 2018 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice(s),
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <memkind.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
int main(int argc, char **argv)
{
const size_t size = 512;
char *default_str = NULL;
char *hugetlb_str = NULL;
char *hbw_str = NULL;
char *hbw_hugetlb_str = NULL;
char *hbw_preferred_str = NULL;
char *hbw_preferred_hugetlb_str = NULL;
char *hbw_interleave_str = NULL;
default_str = (char *)memkind_malloc(MEMKIND_DEFAULT, size);
if (default_str == NULL) {
perror("memkind_malloc()");
fprintf(stderr, "Unable to allocate default string\n");
return errno ? -errno : 1;
}
hugetlb_str = (char *)memkind_malloc(MEMKIND_HUGETLB, size);
if (hugetlb_str == NULL) {
perror("memkind_malloc()");
fprintf(stderr, "Unable to allocate hugetlb string\n");
return errno ? -errno : 1;
}
hbw_str = (char *)memkind_malloc(MEMKIND_HBW, size);
if (hbw_str == NULL) {
perror("memkind_malloc()");
fprintf(stderr, "Unable to allocate hbw string\n");
return errno ? -errno : 1;
}
hbw_hugetlb_str = (char *)memkind_malloc(MEMKIND_HBW_HUGETLB, size);
if (hbw_hugetlb_str == NULL) {
perror("memkind_malloc()");
fprintf(stderr, "Unable to allocate hbw_hugetlb string\n");
return errno ? -errno : 1;
}
hbw_preferred_str = (char *)memkind_malloc(MEMKIND_HBW_PREFERRED, size);
if (hbw_preferred_str == NULL) {
perror("memkind_malloc()");
fprintf(stderr, "Unable to allocate hbw_preferred string\n");
return errno ? -errno : 1;
}
hbw_preferred_hugetlb_str = (char *)memkind_malloc(
MEMKIND_HBW_PREFERRED_HUGETLB, size);
if (hbw_preferred_hugetlb_str == NULL) {
perror("memkind_malloc()");
fprintf(stderr, "Unable to allocate hbw_preferred_hugetlb string\n");
return errno ? -errno : 1;
}
hbw_interleave_str = (char *)memkind_malloc(MEMKIND_HBW_INTERLEAVE, size);
if (hbw_interleave_str == NULL) {
perror("memkind_malloc()");
fprintf(stderr,"Unable to allocate hbw_interleave string\n");
return errno ? -errno : 1;
}
sprintf(default_str, "Hello world from standard memory\n");
sprintf(hugetlb_str, "Hello world from standard memory with 2 MB pages\n");
sprintf(hbw_str, "Hello world from high bandwidth memory\n");
sprintf(hbw_hugetlb_str, "Hello world from high bandwidth 2 MB paged memory\n");
sprintf(hbw_preferred_str,
"Hello world from high bandwidth memory if sufficient resources exist\n");
sprintf(hbw_preferred_hugetlb_str,
"Hello world from high bandwidth 2 MB paged memory if sufficient resources exist\n");
sprintf(hbw_interleave_str,
"Hello world from high bandwidth interleaved memory\n");
fprintf(stdout, "%s", default_str);
fprintf(stdout, "%s", hugetlb_str);
fprintf(stdout, "%s", hbw_str);
fprintf(stdout, "%s", hbw_hugetlb_str);
fprintf(stdout, "%s", hbw_preferred_str);
fprintf(stdout, "%s", hbw_preferred_hugetlb_str);
fprintf(stdout, "%s", hbw_interleave_str);
memkind_free(MEMKIND_HBW_INTERLEAVE, hbw_interleave_str);
memkind_free(MEMKIND_HBW_PREFERRED_HUGETLB, hbw_preferred_hugetlb_str);
memkind_free(MEMKIND_HBW_PREFERRED, hbw_preferred_str);
memkind_free(MEMKIND_HBW_HUGETLB, hbw_hugetlb_str);
memkind_free(MEMKIND_HBW, hbw_str);
memkind_free(MEMKIND_HUGETLB, hugetlb_str);
memkind_free(MEMKIND_DEFAULT, default_str);
return 0;
}

View File

@ -0,0 +1,107 @@
/*
* Copyright (C) 2014 - 2018 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice(s),
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <memkind.h>
#include <cstdlib>
#include <new>
template <class deriving_class>
class memkind_allocated
{
public:
static memkind_t getClassKind()
{
return MEMKIND_DEFAULT;
}
void *operator new(std::size_t size)
{
return deriving_class::operator new(size, deriving_class::getClassKind());
}
void *operator new[](std::size_t size)
{
return deriving_class::operator new(size, deriving_class::getClassKind());
}
void *operator new(std::size_t size, memkind_t memory_kind)
{
void *result_ptr = NULL;
int allocation_result = 0;
//This check if deriving_class has specified alignment, which is suitable
//to be used with posix_memalign()
if(alignof(deriving_class) < sizeof(void *)) {
result_ptr = memkind_malloc(memory_kind, size);
allocation_result = result_ptr ? 1 : 0;
} else {
allocation_result = memkind_posix_memalign(memory_kind, &result_ptr,
alignof(deriving_class), size);
}
if(allocation_result) {
throw std::bad_alloc();
}
return result_ptr;
}
void *operator new[](std::size_t size, memkind_t memory_kind)
{
return deriving_class::operator new(size, memory_kind);
}
void operator delete(void *ptr, memkind_t memory_kind)
{
memkind_free(memory_kind, ptr);
}
void operator delete(void *ptr)
{
memkind_free(0, ptr);
}
void operator delete[](void *ptr)
{
deriving_class::operator delete(ptr);
}
void operator delete[](void *ptr, memkind_t memory_kind)
{
deriving_class::operator delete(ptr, memory_kind);
}
protected:
memkind_allocated()
{
}
~memkind_allocated()
{
}
};

View File

@ -0,0 +1,105 @@
/*
* Copyright (C) 2014 - 2018 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice(s),
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <memkind.h>
#include "memkind_allocated.hpp"
// This code is example usage of C++11 features with custom allocator,
// support for C++11 is required.
#include <iostream>
#if __cplusplus > 199711L
#include <cstdlib>
#include <new>
#include <string>
//example class definition, which derive from memkind_allocated template to
//have objects allocated with memkind, and have alignment specified by alignas()
class alignas(128) memkind_allocated_example : public
memkind_allocated<memkind_allocated_example>
{
std::string message;
public:
//Override method for returning class default kind to make objects be by default allocated on High-Bandwith Memory
static memkind_t getClassKind()
{
return MEMKIND_HBW;
}
memkind_allocated_example(std::string my_message)
{
this->message = my_message;
}
memkind_allocated_example()
{
}
void print_message()
{
std::cout << message << std::endl;
std::cout << "Memory adress of this object is: " << (void *)this << std::endl
<< std::endl;
}
};
int main()
{
memkind_t specified_kind = MEMKIND_HBW_HUGETLB;
memkind_allocated_example *default_kind_example = new memkind_allocated_example(
std::string("This object has been allocated using class default kind, which is: MEMKIND_DEFAULT") );
default_kind_example->print_message();
delete default_kind_example;
memkind_allocated_example *specified_kind_example = new(
specified_kind) memkind_allocated_example(
std::string("This object has been allocated using specified kind, which is: MEMKIND_HBW_HUGETLB") );
specified_kind_example->print_message();
delete specified_kind_example;
//examples for using same aproach for allocating arrays of objects, note that objects created that way can be initialized only with default (unparameterized) constructor
memkind_allocated_example *default_kind_array_example = new
memkind_allocated_example[5]();
delete[] default_kind_array_example;
memkind_allocated_example *specified_kind_array_example = new(
specified_kind) memkind_allocated_example[5]();
delete[] specified_kind_array_example;
return 0;
}
#else //If C++11 is not avaiable - do nothing.
int main()
{
std::cout << "WARNING: because your compiler does not support C++11 standard,"
<< std::endl;
std::cout << "this example is only as a dummy placeholder." << std::endl;
return 0;
}
#endif

View File

@ -0,0 +1,64 @@
/*
* Copyright (C) 2014 - 2018 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice(s),
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <memkind.h>
#include <stdlib.h>
#include <stdio.h>
/* This is an example that enables debug printing on every alloction call */
static void memkind_debug(const char *func, memkind_t kind, size_t size,
void *ptr)
{
fprintf(stderr, "[ DEBUG ] func=%s kind=%p size=%zu ptr=0x%lx\n", func, kind,
size, (size_t)ptr);
}
void memkind_malloc_post(memkind_t kind, size_t size, void **result)
{
memkind_debug("memkind_malloc", kind, size, *result);
}
void memkind_calloc_post(memkind_t kind, size_t nmemb, size_t size,
void **result)
{
memkind_debug("memkind_calloc", kind, nmemb * size, *result);
}
void memkind_posix_memalign_post(memkind_t kind, void **memptr,
size_t alignment, size_t size, int *err)
{
memkind_debug("memkind_posix_memalign", kind, size, *memptr);
}
void memkind_realloc_post(memkind_t kind, void *ptr, size_t size, void **result)
{
memkind_debug("memkind_realloc", kind, size, *result);
}
void memkind_free_pre(memkind_t kind, void **ptr)
{
memkind_debug("memkind_free", kind, 0, *ptr);
}

136
examples/pmem_alignment.c Normal file
View File

@ -0,0 +1,136 @@
/*
* Copyright (c) 2018 Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY LOG OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <memkind.h>
#include <stdio.h>
#include <errno.h>
#include <sys/stat.h>
#define PMEM_MAX_SIZE (1024 * 1024 * 32)
static char *PMEM_DIR = "/tmp/";
int main(int argc, char *argv[])
{
struct memkind *pmem_kind = NULL;
int err = 0;
struct stat st;
if (argc > 2) {
fprintf(stderr, "Usage: %s [pmem_kind_dir_path]", argv[0]);
return 1;
} else if (argc == 2) {
if (stat(argv[1], &st) != 0 || !S_ISDIR(st.st_mode)) {
fprintf(stderr, "%s : Invalid path to pmem kind directory", argv[1]);
return 1;
} else {
PMEM_DIR = argv[1];
}
}
fprintf(stdout,
"This example shows how to use memkind alignment and how it affects allocations.\nPMEM kind directory: %s\n",
PMEM_DIR);
/* Create PMEM partition with PMEM_MAX_SIZE size */
err = memkind_create_pmem(PMEM_DIR, PMEM_MAX_SIZE, &pmem_kind);
if (err) {
perror("memkind_create_pmem()");
fprintf(stderr, "Unable to create pmem partition err=%d errno=%d\n", err,
errno);
return errno ? -errno : 1;
}
char *pmem_str10 = NULL;
char *pmem_str11 = NULL;
/* Lets make two 32 bytes allocations */
pmem_str10 = (char *)memkind_malloc(pmem_kind, 32);
if (pmem_str10 == NULL) {
perror("memkind_malloc()");
fprintf(stderr, "Unable to allocate pmem string (pmem_str10)\n");
return errno ? -errno : 1;
}
pmem_str11 = (char *)memkind_malloc(pmem_kind, 32);
if (pmem_str11 == NULL) {
perror("memkind_malloc()");
fprintf(stderr, "Unable to allocate pmem string (pmem_str11)\n");
return errno ? -errno : 1;
}
/* They will be very close to each other in memory */
if (pmem_str11 - pmem_str10 != 32) {
fprintf(stderr, "Something went wrong\n");
return 1;
}
memkind_free(pmem_kind, pmem_str10);
memkind_free(pmem_kind, pmem_str11);
/* Lets make two 32 bytes allocations with alignment 64 this time */
err = memkind_posix_memalign(pmem_kind, (void **)&pmem_str10, 64, 32);
if (err) {
perror("memkind_posix_memalign()");
fprintf(stderr, "Unable to allocate pmem string (pmem_str10) with alignment\n");
return errno ? -errno : 1;
}
err = memkind_posix_memalign(pmem_kind, (void **)&pmem_str11, 64, 32);
if (err) {
perror("memkind_posix_memalign()");
fprintf(stderr, "Unable to allocate pmem string (pmem_str11) with alignment\n");
return errno ? -errno : 1;
}
/* This time addresses are not close to each other, they are aligned to 64 */
if (pmem_str11 - pmem_str10 != 64) {
fprintf(stderr, "Something went wrong with alignment allocation\n");
return 1;
}
memkind_free(pmem_kind, pmem_str10);
memkind_free(pmem_kind, pmem_str11);
err = memkind_destroy_kind(pmem_kind);
if (err) {
perror("memkind_destroy_kind()");
fprintf(stderr, "Unable to destroy pmem partition\n");
return errno ? -errno : 1;
}
fprintf(stdout,
"The memory has been successfully allocated using memkind alignment.");
return 0;
}

View File

@ -0,0 +1,149 @@
/*
* Copyright (c) 2018 Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY LOG OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <memkind.h>
#include <stdio.h>
#include <errno.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/time.h>
#define MB (1024 * 1024)
#define HEAP_LIMIT_SIMULATE (1024 * MB)
static char *PMEM_DIR = "/tmp/";
int main(int argc, char *argv[])
{
const size_t size = 512;
struct memkind *pmem_kind = NULL;
int err = 0;
errno = 0;
struct stat st;
if (argc > 2) {
fprintf(stderr, "Usage: %s [pmem_kind_dir_path]", argv[0]);
return 1;
} else if (argc == 2) {
if (stat(argv[1], &st) != 0 || !S_ISDIR(st.st_mode)) {
fprintf(stderr, "%s : Invalid path to pmem kind directory", argv[1]);
return 1;
} else {
PMEM_DIR = argv[1];
}
}
//operation below limit the current size of heap
//to show different place of allocation
const struct rlimit heap_limit = { HEAP_LIMIT_SIMULATE, HEAP_LIMIT_SIMULATE };
err = setrlimit(RLIMIT_DATA, &heap_limit);
if (err) {
perror("setrlimit()");
fprintf(stderr, "Unable to set heap limit\n");
return errno ? -errno : 1;
}
char *ptr_default = NULL;
char *ptr_default_not_possible = NULL;
char *ptr_pmem = NULL;
fprintf(stdout,
"This example shows how to allocate memory using standard memory (MEMKIND_DEFAULT) "
"and file-backed kind of memory (PMEM).\nPMEM kind directory: %s\n",
PMEM_DIR);
err = memkind_create_pmem(PMEM_DIR, 0, &pmem_kind);
if (err) {
perror("memkind_create_pmem()");
fprintf(stderr, "Unable to create pmem partition err=%d errno=%d\n", err,
errno);
return errno ? -errno : 1;
}
ptr_default = (char *)memkind_malloc(MEMKIND_DEFAULT, size);
if (!ptr_default) {
perror("memkind_malloc()");
fprintf(stderr, "Unable allocate 512 bytes in standard memory");
return errno ? -errno : 1;
}
errno = 0;
ptr_default_not_possible = (char *)memkind_malloc(MEMKIND_DEFAULT,
HEAP_LIMIT_SIMULATE);
if (ptr_default_not_possible) {
perror("memkind_malloc()");
fprintf(stderr,
"Failure, this allocation should not be possible "
"(expected result was NULL), because of setlimit function\n");
return errno ? -errno : 1;
}
if (errno != ENOMEM) {
perror("memkind_malloc()");
fprintf(stderr,
"Failure, this allocation should set errno to ENOMEM value, because of setlimit function\n");
return errno ? -errno : 1;
}
errno = 0;
ptr_pmem = (char *)memkind_malloc(pmem_kind, HEAP_LIMIT_SIMULATE);
if (!ptr_pmem) {
perror("memkind_malloc()");
fprintf(stderr, "Unable allocate HEAP_LIMIT_SIMULATE in file-backed memory");
return errno ? -errno : 1;
}
if (errno != 0) {
perror("memkind_malloc()");
fprintf(stderr, "Failure, this allocation should not set errno value\n");
return errno ? -errno : 1;
}
sprintf(ptr_default, "Hello world from standard memory - ptr_default\n");
sprintf(ptr_pmem, "Hello world from file-backed memory - ptr_pmem\n");
fprintf(stdout, "%s", ptr_default);
fprintf(stdout, "%s", ptr_pmem);
memkind_free(MEMKIND_DEFAULT, ptr_default);
memkind_free(pmem_kind, ptr_pmem);
err = memkind_destroy_kind(pmem_kind);
if (err) {
perror("memkind_destroy_kind()");
fprintf(stderr, "Unable to destroy pmem partition\n");
return errno ? -errno : 1;
}
fprintf(stdout, "Memory was successfully allocated and released.\n");
return 0;
}

View File

@ -0,0 +1,166 @@
/*
* Copyright (c) 2018 Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY LOG OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "pmem_allocator.h"
#include <sys/stat.h>
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <string>
#include <scoped_allocator>
#include <cassert>
#define STL_VECTOR_TEST
#define STL_LIST_TEST
#if _GLIBCXX_USE_CXX11_ABI
#define STL_VEC_STRING_TEST
#define STL_MAP_INT_STRING_TEST
#endif
void cpp_allocator_test(const char *pmem_directory)
{
std::cout << "TEST SCOPE: HELLO" << std::endl;
size_t pmem_max_size = 1024*1024*1024;
#ifdef STL_VECTOR_TEST
{
std::cout << "VECTOR OPEN" << std::endl;
pmem::allocator<int> alc{ pmem_directory, pmem_max_size };
std::vector<int, pmem::allocator<int>> vector{ alc };
for (int i = 0; i < 20; ++i) {
vector.push_back(0xDEAD + i);
assert(vector.back() == 0xDEAD + i);
}
std::cout << "VECTOR CLOSE" << std::endl;
}
#endif
#ifdef STL_LIST_TEST
{
std::cout << "LIST OPEN" << std::endl;
pmem::allocator<int> alc{ pmem_directory, pmem_max_size };
std::list<int, pmem::allocator<int>> list{ alc };
const int nx2 = 4;
for (int i = 0; i < nx2; ++i) {
list.emplace_back(0xBEAC011 + i);
assert(list.back() == 0xBEAC011 + i);
}
for (int i = 0; i < nx2; ++i) {
list.pop_back();
}
std::cout << "LIST CLOSE" << std::endl;
}
#endif
#ifdef STL_VEC_STRING_TEST
{
std::cout << "STRINGED VECTOR OPEN" << std::endl;
typedef pmem::allocator<char> str_alloc_t;
typedef std::basic_string<char, std::char_traits<char>, str_alloc_t>
pmem_string;
typedef pmem::allocator<pmem_string> vec_alloc_t;
vec_alloc_t vec_alloc{ pmem_directory, pmem_max_size };
str_alloc_t str_alloc{ pmem_directory, pmem_max_size };
std::vector<pmem_string, std::scoped_allocator_adaptor<vec_alloc_t> >
vec{ std::scoped_allocator_adaptor<vec_alloc_t>(vec_alloc) };
pmem_string arg{ "Very very loooong striiiing", str_alloc };
vec.push_back(arg);
assert(vec.back() == arg);
std::cout << "STRINGED VECTOR CLOSE" << std::endl;
}
#endif
#ifdef STL_MAP_INT_STRING_TEST
{
std::cout << "INT_STRING MAP OPEN" << std::endl;
typedef std::basic_string<char, std::char_traits<char>, pmem::allocator<char>>
pmem_string;
typedef int key_t;
typedef pmem_string value_t;
typedef pmem::allocator<char> allocator_t;
typedef std::map<key_t, value_t, std::less<key_t>, std::scoped_allocator_adaptor<allocator_t>>
map_t;
allocator_t allocator( pmem_directory, pmem_max_size );
value_t source_str1("Lorem ipsum dolor ", allocator);
value_t source_str2("sit amet consectetuer adipiscing elit", allocator );
map_t target_map{ std::scoped_allocator_adaptor<allocator_t>(allocator) };
target_map[key_t(165)] = source_str1;
assert(target_map[key_t(165)] == source_str1);
target_map[key_t(165)] = source_str2;
assert(target_map[key_t(165)] == source_str2);
std::cout << "INT_STRING MAP CLOSE" << std::endl;
}
#endif
std::cout << "TEST SCOPE: GOODBYE" << std::endl;
}
int main(int argc, char *argv[])
{
const char *pmem_directory = "/tmp/";
if (argc > 2) {
std::cerr << "Usage: pmem_cpp_allocator [directory path]\n"
<< "\t[directory path] - directory where temporary file is created (default = \"/tmp/\")"
<< std::endl;
return 0;
} else if (argc == 2) {
struct stat st;
if (stat(argv[1], &st) != 0 || !S_ISDIR(st.st_mode)) {
fprintf(stderr,"%s : Invalid path to pmem kind directory", argv[1]);
return 1;
}
pmem_directory = argv[1];
}
cpp_allocator_test(pmem_directory);
return 0;
}

View File

@ -0,0 +1,118 @@
/*
* Copyright (c) 2018 Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY LOG OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <memkind.h>
#include <stdio.h>
#include <errno.h>
#include <sys/stat.h>
static char *PMEM_DIR = "/tmp/";
static const size_t PMEM_PART_SIZE = MEMKIND_PMEM_MIN_SIZE + 4 * 1024;
int main(int argc, char **argv)
{
const size_t size = 512;
struct memkind *pmem_kind = NULL;
struct stat st;
const int arraySize = 100;
char *ptr[100] = { NULL };
int i = 0;
int err = 0;
if (argc > 2) {
fprintf(stderr, "Usage: %s [pmem_kind_dir_path]", argv[0]);
return 1;
} else if (argc == 2) {
if (stat(argv[1], &st) != 0 || !S_ISDIR(st.st_mode)) {
fprintf(stderr, "%s : Invalid path to pmem kind directory", argv[1]);
return 1;
} else {
PMEM_DIR = argv[1];
}
}
fprintf(stdout,
"This example shows how to use memkind_free with unknown kind as a parameter.\n");
err = memkind_create_pmem(PMEM_DIR, PMEM_PART_SIZE, &pmem_kind);
if (err) {
perror("memkind_create_pmem()");
fprintf(stderr, "Unable to create pmem partition err=%d errno=%d\n", err,
errno);
return errno ? -errno : 1;
}
for (i = 0; i < arraySize; ++i) {
if (i < 50) {
ptr[i] = memkind_malloc(MEMKIND_DEFAULT, size);
if (ptr[i] == NULL) {
perror("memkind_malloc()");
fprintf(stderr, "Unable to allocate memkind default\n");
return errno ? -errno : 1;
}
} else {
ptr[i] = memkind_malloc(pmem_kind, size);
if (ptr[i] == NULL) {
perror("memkind_malloc()");
fprintf(stderr, "Unable to allocate pmem\n");
return errno ? -errno : 1;
}
}
}
fprintf(stdout,
"Memory was successfully allocated in default kind and pmem kind.\n");
sprintf(ptr[10], "Hello world from standard memory - ptr[10].\n");
sprintf(ptr[40], "Hello world from standard memory - ptr[40].\n");
sprintf(ptr[80], "Hello world from persistent memory - ptr[80].\n");
fprintf(stdout, "%s", ptr[10]);
fprintf(stdout, "%s", ptr[40]);
fprintf(stdout, "%s", ptr[80]);
fprintf(stdout, "Free memory without specifying kind.\n");
for (i = 0; i < arraySize; ++i) {
memkind_free(NULL, ptr[i]);
}
err = memkind_destroy_kind(pmem_kind);
if (err) {
perror("memkind_destroy_kind()");
fprintf(stderr, "Unable to destroy pmem partition\n");
return errno ? -errno : 1;
}
fprintf(stdout, "Memory was successfully released.\n");
return 0;
}

126
examples/pmem_kinds.c Normal file
View File

@ -0,0 +1,126 @@
/*
* Copyright (c) 2018 Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY LOG OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <memkind.h>
#include <stdio.h>
#include <errno.h>
#include <sys/stat.h>
#define PMEM_MAX_SIZE (1024 * 1024 * 32)
static char *PMEM_DIR = "/tmp/";
int main(int argc, char *argv[])
{
struct memkind *pmem_kinds[10] = {NULL};
struct memkind *pmem_kind = NULL;
struct memkind *pmem_kind_unlimited = NULL;
int err = 0, i = 0;
struct stat st;
if (argc > 2) {
fprintf(stderr, "Usage: %s [pmem_kind_dir_path]", argv[0]);
return 1;
} else if (argc == 2) {
if (stat(argv[1], &st) != 0 || !S_ISDIR(st.st_mode)) {
fprintf(stderr, "%s : Invalid path to pmem kind directory", argv[1]);
return 1;
} else {
PMEM_DIR = argv[1];
}
}
fprintf(stdout,
"This example shows how to create and destroy pmem kind with defined or unlimited size."
"\nPMEM kind directory: %s\n",
PMEM_DIR);
/* Create PMEM partition with specific size */
err = memkind_create_pmem(PMEM_DIR, PMEM_MAX_SIZE, &pmem_kind);
if (err) {
perror("memkind_create_pmem()");
fprintf(stderr, "Unable to create pmem partition err=%d errno=%d\n", err,
errno);
return errno ? -errno : 1;
}
/* Create PMEM partition with unlimited size */
err = memkind_create_pmem(PMEM_DIR, 0, &pmem_kind_unlimited);
if (err) {
perror("memkind_create_pmem()");
fprintf(stderr, "Unable to create pmem partition err=%d errno=%d\n", err,
errno);
return errno ? -errno : 1;
}
/* and delete them */
err = memkind_destroy_kind(pmem_kind);
if (err) {
perror("memkind_destroy_kind()");
fprintf(stderr, "Unable to destroy pmem partition\n");
return errno ? -errno : 1;
}
err = memkind_destroy_kind(pmem_kind_unlimited);
if (err) {
perror("memkind_destroy_kind()");
fprintf(stderr, "Unable to destroy pmem partition\n");
return errno ? -errno : 1;
}
/* Create many PMEM kinds */
for (i = 0; i < 10; i++) {
err = memkind_create_pmem(PMEM_DIR, PMEM_MAX_SIZE, &pmem_kinds[i]);
if (err) {
perror("memkind_create_pmem()");
fprintf(stderr, "Unable to create pmem partition err=%d errno=%d\n", err,
errno);
return errno ? -errno : 1;
}
}
/* and delete them */
for (i = 0; i < 10; i++) {
err = memkind_destroy_kind(pmem_kinds[i]);
if (err) {
perror("memkind_pmem_destroy()");
fprintf(stderr, "Unable to destroy pmem partition\n");
return errno ? -errno : 1;
}
}
fprintf(stdout, "PMEM kinds have been successfully created and destroyed.");
return 0;
}

135
examples/pmem_malloc.c Normal file
View File

@ -0,0 +1,135 @@
/*
* Copyright (c) 2015 - 2018 Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY LOG OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <memkind.h>
#include <stdio.h>
#include <errno.h>
#include <sys/stat.h>
#define PMEM_MAX_SIZE (1024 * 1024 * 32)
static char *PMEM_DIR = "/tmp/";
int main(int argc, char *argv[])
{
struct memkind *pmem_kind = NULL;
int err = 0;
struct stat st;
if (argc > 2) {
fprintf(stderr, "Usage: %s [pmem_kind_dir_path]", argv[0]);
return 1;
} else if (argc == 2) {
if (stat(argv[1], &st) != 0 || !S_ISDIR(st.st_mode)) {
fprintf(stderr, "%s : Invalid path to pmem kind directory", argv[1]);
return 1;
} else {
PMEM_DIR = argv[1];
}
}
fprintf(stdout,
"This example shows how to allocate memory and possibility to exceed pmem kind size."
"\nPMEM kind directory: %s\n",
PMEM_DIR);
/* Create PMEM partition with specific size */
err = memkind_create_pmem(PMEM_DIR, PMEM_MAX_SIZE, &pmem_kind);
if (err) {
perror("memkind_create_pmem()");
fprintf(stderr, "Unable to create pmem partition err=%d errno=%d\n", err,
errno);
return errno ? -errno : 1;
}
char *pmem_str1 = NULL;
char *pmem_str2 = NULL;
char *pmem_str3 = NULL;
char *pmem_str4 = NULL;
// allocate 512 Bytes of 32 MB available
pmem_str1 = (char *)memkind_malloc(pmem_kind, 512);
if (pmem_str1 == NULL) {
perror("memkind_malloc()");
fprintf(stderr, "Unable to allocate pmem string (pmem_str1)\n");
return errno ? -errno : 1;
}
// allocate 8 MB of 31.9 MB available
pmem_str2 = (char *)memkind_malloc(pmem_kind, 8 * 1024 * 1024);
if (pmem_str2 == NULL) {
perror("memkind_malloc()");
fprintf(stderr, "Unable to allocate pmem string (pmem_str11)\n");
return errno ? -errno : 1;
}
// allocate 16 MB of 23.9 MB available
pmem_str3 = (char *)memkind_malloc(pmem_kind, 16 * 1024 * 1024);
if (pmem_str3 == NULL) {
perror("memkind_malloc()");
fprintf(stderr, "Unable to allocate pmem string (pmem_str12)\n");
return errno ? -errno : 1;
}
// allocate 16 MB of 7.9 MB available -- Out Of Memory expected
pmem_str4 = (char *)memkind_malloc(pmem_kind, 16 * 1024 * 1024);
if (pmem_str4 != NULL) {
perror("memkind_malloc()");
fprintf(stderr,
"Failure, this allocation should not be possible (expected result was NULL)\n");
return errno ? -errno : 1;
}
sprintf(pmem_str1, "Hello world from pmem - pmem_str1\n");
sprintf(pmem_str2, "Hello world from pmem - pmem_str2\n");
sprintf(pmem_str3, "Hello world from persistent memory - pmem_str3\n");
fprintf(stdout, "%s", pmem_str1);
fprintf(stdout, "%s", pmem_str2);
fprintf(stdout, "%s", pmem_str3);
memkind_free(pmem_kind, pmem_str1);
memkind_free(pmem_kind, pmem_str2);
memkind_free(pmem_kind, pmem_str3);
err = memkind_destroy_kind(pmem_kind);
if (err) {
perror("memkind_destroy_kind()");
fprintf(stderr, "Unable to destroy pmem partition\n");
return errno ? -errno : 1;
}
fprintf(stdout, "Memory was successfully allocated and released.\n");
return 0;
}

View File

@ -0,0 +1,105 @@
/*
* Copyright (c) 2018 Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY LOG OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <memkind.h>
#include <stdio.h>
#include <errno.h>
#include <sys/stat.h>
static char *PMEM_DIR = "/tmp/";
int main(int argc, char *argv[])
{
struct memkind *pmem_kind_unlimited = NULL;
int err = 0;
struct stat st;
if (argc > 2) {
fprintf(stderr, "Usage: %s [pmem_kind_dir_path]", argv[0]);
return 1;
} else if (argc == 2) {
if (stat(argv[1], &st) != 0 || !S_ISDIR(st.st_mode)) {
fprintf(stderr, "%s : Invalid path to pmem kind directory ", argv[1]);
return 1;
} else {
PMEM_DIR = argv[1];
}
}
fprintf(stdout,
"This example shows how to allocate memory with unlimited kind size."
"nPMEM kind directory: %s\n",
PMEM_DIR);
/* Create PMEM partition with unlimited size */
err = memkind_create_pmem(PMEM_DIR, 0, &pmem_kind_unlimited);
if (err) {
perror("memkind_create_pmem()");
fprintf(stderr, "Unable to create pmem partition err=%d errno=%d\n", err,
errno);
return errno ? -errno : 1;
}
char *pmem_str10 = NULL;
char *pmem_str11 = NULL;
/* Huge allocation */
pmem_str10 = (char *)memkind_malloc(pmem_kind_unlimited, 32 * 1024 * 1024);
if (pmem_str10 == NULL) {
perror("memkind_malloc()");
fprintf(stderr, "Unable to allocate pmem string (pmem_str10)\n");
return errno ? -errno : 1;
}
/* Another huge allocation, kind size is only limited by OS resources */
pmem_str11 = (char *)memkind_malloc(pmem_kind_unlimited, 32 * 1024 * 1024);
if (pmem_str11 == NULL) {
perror("memkind_malloc()");
fprintf(stderr, "Unable to allocate pmem string (pmem_str11)\n");
return errno ? -errno : 1;
}
memkind_free(pmem_kind_unlimited, pmem_str10);
memkind_free(pmem_kind_unlimited, pmem_str11);
err = memkind_destroy_kind(pmem_kind_unlimited);
if (err) {
perror("memkind_destroy_kind()");
fprintf(stderr, "Unable to destroy pmem partition\n");
return errno ? -errno : 1;
}
fprintf(stdout, "Memory was successfully allocated and released.");
return 0;
}

View File

@ -0,0 +1,138 @@
/*
* Copyright (c) 2018 Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY LOG OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <memkind.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <pthread.h>
#include <sys/stat.h>
#include <unistd.h>
#define PMEM_MAX_SIZE (1024 * 1024 * 32)
#define NUM_THREADS 10
static char *PMEM_DIR = "/tmp/";
void *thread_ind(void *arg);
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
int main(int argc, char *argv[])
{
int err = 0;
struct stat st;
if (argc > 2) {
fprintf(stderr, "Usage: %s [pmem_kind_dir_path]", argv[0]);
return 1;
} else if (argc == 2) {
if (stat(argv[1], &st) != 0 || !S_ISDIR(st.st_mode)) {
fprintf(stderr, "%s : Invalid path to pmem kind directory", argv[1]);
return 1;
} else {
PMEM_DIR = argv[1];
}
}
fprintf(stdout,
"This example shows how to use multithreading with independent pmem kinds."
"\nPMEM kind directory: %s\n",
PMEM_DIR);
pthread_t pmem_threads[NUM_THREADS];
int t;
/* Lets create many independent threads */
for (t = 0; t < NUM_THREADS; t++) {
err = pthread_create(&pmem_threads[t], NULL, thread_ind, NULL);
if (err) {
fprintf(stderr, "Unable to create a thread\n");
return 1;
}
}
sleep(1);
pthread_cond_broadcast(&cond);
for (t = 0; t < NUM_THREADS; t++) {
err = pthread_join(pmem_threads[t], NULL);
if (err) {
fprintf(stderr, "Thread join failed\n");
return 1;
}
}
fprintf(stdout, "Threads successfully allocated memory in the PMEM kinds.");
return 0;
}
void *thread_ind(void *arg)
{
struct memkind *pmem_kind;
pthread_mutex_lock(&mutex);
pthread_cond_wait(&cond, &mutex);
pthread_mutex_unlock(&mutex);
/* Create a pmem kind in thread */
int err = memkind_create_pmem(PMEM_DIR, PMEM_MAX_SIZE, &pmem_kind);
if (err) {
perror("thread memkind_create_pmem()");
fprintf(stderr, "Unable to create pmem partition err=%d errno=%d\n", err,
errno);
return NULL;
}
/* Alloc something */
void *test = memkind_malloc(pmem_kind, 32);
if (test == NULL) {
perror("thread memkind_malloc()");
fprintf(stderr, "Unable to allocate pmem (test)\n");
return NULL;
}
/* Free resources */
memkind_free(pmem_kind, test);
/* And destroy pmem kind */
err = memkind_destroy_kind(pmem_kind);
if (err) {
perror("thread memkind_pmem_destroy()");
fprintf(stderr, "Unable to destroy pmem partition\n");
}
return NULL;
}

View File

@ -0,0 +1,159 @@
/*
* Copyright (c) 2018 Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY LOG OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <memkind.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <pthread.h>
#include <sys/stat.h>
#include <unistd.h>
#define NUM_THREADS 10
static char *PMEM_DIR = "/tmp/";
struct arg_struct {
int id;
struct memkind *kind;
int **ptr;
};
void *thread_onekind(void *arg);
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
int main(int argc, char *argv[])
{
struct memkind *pmem_kind_unlimited = NULL;
int err = 0;
struct stat st;
if (argc > 2) {
fprintf(stderr, "Usage: %s [pmem_kind_dir_path]", argv[0]);
return 1;
} else if (argc == 2) {
if (stat(argv[1], &st) != 0 || !S_ISDIR(st.st_mode)) {
fprintf(stderr, "%s : Invalid path to pmem kind directory", argv[1]);
return 1;
} else {
PMEM_DIR = argv[1];
}
}
fprintf(stdout,
"This example shows how to use multithreading with one main pmem kind."
"\nPMEM kind directory: %s\n",
PMEM_DIR);
/* Create PMEM partition with unlimited size */
err = memkind_create_pmem(PMEM_DIR, 0, &pmem_kind_unlimited);
if (err) {
perror("memkind_create_pmem()");
fprintf(stderr, "Unable to create pmem partition err=%d errno=%d\n", err,
errno);
return errno ? -errno : 1;
}
/* Create a few threads which will access to our main pmem_kind */
pthread_t pmem_threads[NUM_THREADS];
int *pmem_tint[NUM_THREADS][100];
int t = 0, i = 0;
struct arg_struct *args[NUM_THREADS];
for (t = 0; t<NUM_THREADS; t++) {
args[t] = malloc(sizeof(struct arg_struct));
args[t]->id = t;
args[t]->ptr = &pmem_tint[t][0];
args[t]->kind = pmem_kind_unlimited;
err = pthread_create(&pmem_threads[t], NULL, thread_onekind, (void *)args[t]);
if (err) {
fprintf(stderr, "Unable to create a thread\n");
return 1;
}
}
sleep(1);
pthread_cond_broadcast(&cond);
for (t = 0; t < NUM_THREADS; t++) {
err = pthread_join(pmem_threads[t], NULL);
if (err) {
fprintf(stderr, "Thread join failed\n");
return 1;
}
}
/* Check if we can read the values outside of threads and free resources */
for (t = 0; t < NUM_THREADS; t++) {
for (i = 0; i < 100; i++) {
if(*pmem_tint[t][i] != t) {
perror("read thread memkind_malloc()");
fprintf(stderr, "pmem_tint value has not been saved correctly in the thread\n");
return 1;
}
memkind_free(args[t]->kind, *(args[t]->ptr+i));
}
free(args[t]);
}
fprintf(stdout, "Threads successfully allocated memory in the PMEM kind.");
return 0;
}
void *thread_onekind(void *arg)
{
struct arg_struct *args = (struct arg_struct *)arg;
int i;
pthread_mutex_lock(&mutex);
pthread_cond_wait(&cond, &mutex);
pthread_mutex_unlock(&mutex);
/* Lets alloc int and put there thread ID */
for (i = 0; i < 100; i++) {
*(args->ptr+i) = (int *)memkind_malloc(args->kind, sizeof(int));
if (*(args->ptr+i) == NULL) {
perror("thread memkind_malloc()");
fprintf(stderr, "Unable to allocate pmem int\n");
return NULL;
}
**(args->ptr+i) = args->id;
}
return NULL;
}

172
examples/pmem_usable_size.c Normal file
View File

@ -0,0 +1,172 @@
/*
* Copyright (c) 2018 Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY LOG OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <memkind.h>
#include <stdio.h>
#include <errno.h>
#include <sys/stat.h>
static char *PMEM_DIR = "/tmp/";
int main(int argc, char *argv[])
{
struct memkind *pmem_kind_unlimited = NULL;
int err = 0;
struct stat st;
if (argc > 2) {
fprintf(stderr, "Usage: %s [pmem_kind_dir_path]", argv[0]);
return 1;
} else if (argc == 2) {
if (stat(argv[1], &st) != 0 || !S_ISDIR(st.st_mode)) {
fprintf(stderr, "%s : Invalid path to pmem kind directory", argv[1]);
return 1;
} else {
PMEM_DIR = argv[1];
}
}
fprintf(stdout,
"This example shows difference between the expected and the actual allocation size."
"\nPMEM kind directory: %s\n",
PMEM_DIR);
/* Create PMEM partition with unlimited size */
err = memkind_create_pmem(PMEM_DIR, 0, &pmem_kind_unlimited);
if (err) {
perror("memkind_create_pmem()");
fprintf(stderr, "Unable to create pmem partition err=%d errno=%d\n", err,
errno);
return errno ? -errno : 1;
}
char *pmem_str10 = NULL;
char *pmem_str11 = NULL;
char *pmem_str12 = NULL;
/* 32 bytes allocation */
pmem_str10 = (char *)memkind_malloc(pmem_kind_unlimited, 32);
if (pmem_str10 == NULL) {
perror("memkind_malloc()");
fprintf(stderr, "Unable to allocate pmem string (pmem_str10)\n");
return errno ? -errno : 1;
}
/* Check real usable size for this allocation */
if (memkind_malloc_usable_size(pmem_kind_unlimited, pmem_str10) != 32) {
perror("memkind_default_malloc_usable_size()");
fprintf(stderr, "Wrong usable size\n");
return 1;
}
/* 31 bytes allocation */
pmem_str11 = (char *)memkind_malloc(pmem_kind_unlimited, 31);
if (pmem_str11 == NULL) {
perror("memkind_malloc()");
fprintf(stderr, "Unable to allocate pmem string (pmem_str11)\n");
return errno ? -errno : 1;
}
/* Check real usable size for this allocation, its 32 again */
if (memkind_malloc_usable_size(pmem_kind_unlimited, pmem_str11) != 32) {
perror("memkind_default_malloc_usable_size()");
fprintf(stderr, "Wrong usable size\n");
return 1;
}
/* 33 bytes allocation */
pmem_str12 = (char *)memkind_malloc(pmem_kind_unlimited, 33);
if (pmem_str11 == NULL) {
perror("memkind_malloc()");
fprintf(stderr, "Unable to allocate pmem string (pmem_str12)\n");
return errno ? -errno : 1;
}
/* Check real usable size for this allocation, its 48 now */
if (memkind_malloc_usable_size(pmem_kind_unlimited, pmem_str12) != 48) {
perror("memkind_default_malloc_usable_size()");
fprintf(stderr, "Wrong usable size\n");
return 1;
}
memkind_free(pmem_kind_unlimited, pmem_str10);
memkind_free(pmem_kind_unlimited, pmem_str11);
memkind_free(pmem_kind_unlimited, pmem_str12);
/* 5MB allocation */
pmem_str10 = (char *)memkind_malloc(pmem_kind_unlimited, 5 * 1024 * 1024);
if (pmem_str10 == NULL) {
perror("memkind_malloc()");
fprintf(stderr, "Unable to allocate pmem string (pmem_str10)\n");
return errno ? -errno : 1;
}
/* Check real usable size for this allocation */
if (memkind_malloc_usable_size(pmem_kind_unlimited,
pmem_str10) != 5 * 1024 * 1024) {
perror("memkind_default_malloc_usable_size()");
fprintf(stderr, "Wrong usable size\n");
return 1;
}
/* 5MB + 1B allocation */
pmem_str11 = (char *)memkind_malloc(pmem_kind_unlimited, 5 * 1024 * 1024 + 1);
if (pmem_str11 == NULL) {
perror("memkind_malloc()");
fprintf(stderr, "Unable to allocate pmem string (pmem_str11)\n");
return errno ? -errno : 1;
}
/* Check real usable size for this allocation, its 6MB now */
if (memkind_malloc_usable_size(pmem_kind_unlimited,
pmem_str11) != 6 * 1024 * 1024) {
perror("memkind_default_malloc_usable_size()");
fprintf(stderr, "Wrong usable size\n");
return 1;
}
memkind_free(pmem_kind_unlimited, pmem_str10);
memkind_free(pmem_kind_unlimited, pmem_str11);
err = memkind_destroy_kind(pmem_kind_unlimited);
if (err) {
perror("memkind_destroy_kind()");
fprintf(stderr, "Unable to destroy pmem partition\n");
return errno ? -errno : 1;
}
fprintf(stdout,
"The real size of the allocation has been successfully read.");
return 0;
}

134
include/hbw_allocator.h Normal file
View File

@ -0,0 +1,134 @@
/*
* Copyright (C) 2014 - 2018 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice(s),
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <hbwmalloc.h>
#include <stddef.h>
#include <new>
/*
* Header file for the C++ allocator compatible with the C++ standard library allocator concepts.
* More details in hbwallocator(3) man page.
* Note: memory heap management is based on hbwmalloc, refer to the hbwmalloc man page for more information.
*
* Functionality defined in this header is considered as EXPERIMENTAL API.
* API standards are described in memkind(3) man page.
*/
namespace hbw
{
template <class T>
class allocator
{
public:
/*
* Public member types required and defined by the standard library allocator concepts.
*/
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T *pointer;
typedef const T *const_pointer;
typedef T &reference;
typedef const T &const_reference;
typedef T value_type;
template <class U>
struct rebind {
typedef hbw::allocator<U> other;
};
/*
* Public member functions required and defined by the standard library allocator concepts.
*/
allocator() throw() { }
template <class U>
allocator(const allocator<U> &) throw() { }
~allocator() throw() { }
pointer address(reference x) const
{
return &x;
}
const_pointer address(const_reference x) const
{
return &x;
}
/*
* Allocates n*sizeof(T) bytes of high bandwidth memory using hbw_malloc().
* Throws std::bad_alloc when cannot allocate memory.
*/
pointer allocate(size_type n, const void * = 0)
{
if (n > this->max_size()) {
throw std::bad_alloc();
}
pointer result = static_cast<pointer>(hbw_malloc(n * sizeof(T)));
if (!result) {
throw std::bad_alloc();
}
return result;
}
/*
* Deallocates memory associated with pointer returned by allocate() using hbw_free().
*/
void deallocate(pointer p, size_type n)
{
hbw_free(static_cast<void *>(p));
}
size_type max_size() const throw()
{
return size_t(-1) / sizeof(T);
}
void construct(pointer p, const_reference val)
{
::new(p) value_type(val);
}
void destroy(pointer p)
{
p->~T();
}
};
template <class T, class U>
bool operator==(const allocator<T> &, const allocator<U> &)
{
return true;
}
template <class T, class U>
bool operator!=(const allocator<T> &, const allocator<U> &)
{
return false;
}
}

238
include/hbwmalloc.h Normal file
View File

@ -0,0 +1,238 @@
/*
* Copyright (C) 2014 - 2018 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice(s),
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stdlib.h>
/*
* Header file for the high bandwidth memory interface.
*
* This file defines the external API's and enumerations for the
* hbwmalloc library. These interfaces define a heap manager that
* targets the high bandwidth memory numa nodes.
*
* hbwmalloc.h functionality is considered as stable API (STANDARD API).
*
* Please read hbwmalloc(3) man page for or more details.
*/
/*
* Fallback policy.
*
* Policy that determines behavior when there is not enough free high
* bandwidth memory to satisfy a user request. This enum is used with
* hbw_get_policy() and hbw_set_policy().
*/
typedef enum {
/*
* If insufficient high bandwidth memory pages on nearest NUMA node are
* available then OOM killer will be triggered.
*/
HBW_POLICY_BIND = 1,
/*
* If insufficient high bandwidth memory pages are available fall
* back on standard memory pages.
*/
HBW_POLICY_PREFERRED = 2,
/*
* Interleave pages across high bandwidth nodes. If insufficient memory
* pages are available then OOM killer will be triggered.
*/
HBW_POLICY_INTERLEAVE = 3,
/*
* If insufficient high bandwidth memory pages are available then
* OOM killer will be triggered.
*/
HBW_POLICY_BIND_ALL = 4,
} hbw_policy_t;
/*
* Page size selection.
*
* The hbw_posix_memalign_psize() API gives the user the option to
* select the page size from this enumerated list.
*/
typedef enum {
/*
* The four kilobyte page size option. Note that with transparent huge
* pages enabled these allocations may be promoted by the operating system
* to two megabyte pages.
*/
HBW_PAGESIZE_4KB = 1,
/*
* The two megabyte page size option.
*/
HBW_PAGESIZE_2MB = 2,
/*
* This option is deprecated.
* Allocate high bandwidth memory using 1GB chunks backed by huge pages.
*/
HBW_PAGESIZE_1GB_STRICT = 3,
/*
* This option is deprecated.
* Allocate high bandwidth memory using 1GB chunks backed by huge pages.
*/
HBW_PAGESIZE_1GB = 4,
/*
* Helper representing value of the last enum element incremented by 1.
* Shall not be treated as a valid value for functions taking hbw_pagesize_t
* as parameter.
*/
HBW_PAGESIZE_MAX_VALUE
} hbw_pagesize_t;
/*
* Flags for hbw_verify_ptr function
*/
enum {
/*
* This option touches first byte of all pages in address range starting from "addr" to "addr" + "size"
* by read and write (so the content will be overwitten by the same data as it was read).
*/
HBW_TOUCH_PAGES = (1 << 0)
};
/*
* Returns the current fallback policy when insufficient high bandwidth memory
* is available.
*/
hbw_policy_t hbw_get_policy(void);
/*
* Sets the current fallback policy. The policy can be modified only once in
* the lifetime of an application and before calling hbw_*alloc() or
* hbw_posix_memalign*() function.
* Note: If the policy is not set, than HBW_POLICY_PREFERRED will be used by
* default.
*
* Returns:
* 0: on success
* EPERM: if hbw_set_policy () was called more than once
* EINVAL: if mode argument was neither HBW_POLICY_PREFERRED, HBW_POLICY_BIND, HBW_POLICY_BIND_ALL nor HBW_POLICY_INTERLEAVE
*/
int hbw_set_policy(hbw_policy_t mode);
/*
* Verifies high bandwidth memory availability.
* Returns:
* 0: if high bandwidth memory is available
* ENODEV: if high-bandwidth memory is unavailable.
*/
int hbw_check_available(void);
/*
* Verifies if allocated memory fully fall into high bandwidth memory.
* Returns:
* 0: if memory in address range from "addr" to "addr" + "size" is allocated in high bandwidth memory
* -1: if any region of memory was not allocated in high bandwidth memory
* EINVAL: if addr is NULL, size equals 0 or flags contained unsupported bit set
* EFAULT: could not verify memory
*/
int hbw_verify_memory_region(void *addr, size_t size, int flags);
/*
* Allocates size bytes of uninitialized high bandwidth memory.
* The allocated space is suitably aligned (after possible pointer
* coercion) for storage of any type of object. If size is zero then
* hbw_malloc() returns NULL.
*/
void *hbw_malloc(size_t size);
/*
* Allocates space for num objects in high bandwidth memory, each size bytes
* in length.
* The result is identical to calling hbw_malloc() with an argument of
* num*size, with the exception that the allocated memory is explicitly
* initialized to zero bytes.
* If num or size is 0, then hbw_calloc() returns NULL.
*/
void *hbw_calloc(size_t num, size_t size);
/*
* Allocates size bytes of high bandwidth memory such that the allocation's
* base address is an even multiple of alignment, and returns the allocation
* in the value pointed to by memptr. The requested alignment must be a power
* of 2 at least as large as sizeof(void *).
* Returns:
* 0: on success
* ENOMEM: if there was insufficient memory to satisfy the request
* EINVAL: if the alignment parameter was not a power of two, or was less than sizeof(void *)
*/
int hbw_posix_memalign(void **memptr, size_t alignment, size_t size);
/*
* Allocates size bytes of high bandwidth memory such that the allocation's
* base address is an even multiple of alignment, and returns the allocation
* in the value pointed to by memptr. The requested alignment must be a power
* of 2 at least as large as sizeof(void *). The memory will be allocated
* using pages determined by the pagesize variable.
* Returns:
* 0: on success
* ENOMEM: if there was insufficient memory to satisfy the request
* EINVAL: if the alignment parameter was not a power of two, or was less than sizeof(void *)
*/
int hbw_posix_memalign_psize(void **memptr, size_t alignment, size_t size,
hbw_pagesize_t pagesize);
/*
* Changes the size of the previously allocated memory referenced by ptr to
* size bytes of the specified kind. The contents of the memory are unchanged
* up to the lesser of the new and old size.
* If the new size is larger, the contents of the newly allocated portion
* of the memory are undefined.
* Upon success, the memory referenced by ptr is freed and a pointer to the
* newly allocated high bandwidth memory is returned.
* Note: memkind_realloc() may move the memory allocation, resulting in a
* different return value than ptr.
* If ptr is NULL, the hbw_realloc() function behaves identically to
* hbw_malloc() for the specified size. The address ptr, if not NULL,
* was returned by a previous call to hbw_malloc(), hbw_calloc(),
* hbw_realloc(), or hbw_posix_memalign(). Otherwise, or if hbw_free(ptr)
* was called before, undefined behavior occurs.
* Note: hbw_realloc() cannot be used with a pointer returned by
* hbw_posix_memalign_psize().
*/
void *hbw_realloc(void *ptr, size_t size);
/*
* Causes the allocated memory referenced by ptr to be made
* available for future allocations. If ptr is NULL, no action occurs.
* The address ptr, if not NULL, must have been returned by a previous call
* to hbw_malloc(), hbw_calloc(), hbw_realloc(), hbw_posix_memalign(), or
* hbw_posix_memalign_psize(). Otherwise, if hbw_free(ptr) was called before,
* undefined behavior occurs.
*/
void hbw_free(void *ptr);
#ifdef __cplusplus
}
#endif

324
include/memkind.h Normal file
View File

@ -0,0 +1,324 @@
/*
* Copyright (C) 2014 - 2018 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice(s),
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/types.h>
/**
* Header file for the memkind heap manager.
* More details in memkind(3) man page.
*
* API standards are described in memkind(3) man page.
*/
/// \warning EXPERIMENTAL API
#define _MEMKIND_BIT(N) (1ull << N)
/// \brief Memkind memory types
/// \warning EXPERIMENTAL API
typedef enum memkind_memtype_t {
/**
* Select standard memory, the same as process use.
*/
MEMKIND_MEMTYPE_DEFAULT = _MEMKIND_BIT(0),
/**
* Select high bandwidth memory (HBM).
* There must be at least two memories with different bandwidth to
* determine the HBM.
*/
MEMKIND_MEMTYPE_HIGH_BANDWIDTH = _MEMKIND_BIT(1)
} memkind_memtype_t;
#undef _MEMKIND_BIT
/// \brief Memkind policy
/// \warning EXPERIMENTAL API
typedef enum memkind_policy_t {
/**
* Allocate local memory.
* If there is not enough memory to satisfy the request errno is set to
* ENOMEM and the allocated pointer is set to NULL.
*/
MEMKIND_POLICY_BIND_LOCAL = 0,
/**
* Memory locality is ignored.
* If there is not enough memory to satisfy the request errno is set to
* ENOMEM and the allocated pointer is set to NULL.
*/
MEMKIND_POLICY_BIND_ALL,
/**
* Allocate preferred memory that is local.
* If there is not enough preferred memory to satisfy the request or
* preferred memory is not available, the allocation will fall back on any
* other memory.
*/
MEMKIND_POLICY_PREFERRED_LOCAL,
/**
* Interleave allocation across local memory.
* For n memory types the allocation will be interleaved across all of
* them.
*/
MEMKIND_POLICY_INTERLEAVE_LOCAL,
/**
* Interleave allocation. Locality is ignored.
* For n memory types the allocation will be interleaved across all of
* them.
*/
MEMKIND_POLICY_INTERLEAVE_ALL,
/**
* Max policy value.
*/
MEMKIND_POLICY_MAX_VALUE
} memkind_policy_t;
/// \brief Memkind bits definition
/// \warning EXPERIMENTAL API
/// \note The bits specify flags and masks. Bits <0,1,2,...,7> are reserved for page size, where page sizes are encoded
/// by base-2 logarithm. If the page size bits are set to zero value, than default page size will be used.
typedef enum memkind_bits_t {
MEMKIND_MASK_PAGE_SIZE_2MB = 21ull, /**< Allocations backed by 2 MB page size (2^21 = 2MB) */
} memkind_bits_t;
/// \brief Memkind type definition
/// \warning EXPERIMENTAL API
typedef struct memkind *memkind_t;
/// \brief Memkind constant values
/// \warning EXPERIMENTAL API
enum memkind_const {
MEMKIND_MAX_KIND = 512, /**< Maximum number of kinds */
MEMKIND_ERROR_MESSAGE_SIZE = 128, /**< Error message size */
MEMKIND_PMEM_MIN_SIZE = (1024 * 1024 * 16) /**< The minimum size which allows to limit the file-backed memory partition */
};
/// \brief Memkind operation statuses
/// \warning EXPERIMENTAL API
enum {
MEMKIND_SUCCESS = 0, /**< Operation success */
MEMKIND_ERROR_UNAVAILABLE = -1, /**< Error: Memory kind is not available */
MEMKIND_ERROR_MBIND = -2, /**< Error: Call to mbind() failed */
MEMKIND_ERROR_MMAP = -3, /**< Error: Call to mmap() failed */
MEMKIND_ERROR_MALLOC = -6, /**< Error: Call to malloc() failed */
MEMKIND_ERROR_ENVIRON = -12, /**< Error: Unable to parse environment variable */
MEMKIND_ERROR_INVALID = -13, /**< Error: Invalid argument */
MEMKIND_ERROR_TOOMANY = -15, /**< Error: Attempt to initialize more than MEMKIND_MAX_KIND number of kinds */
MEMKIND_ERROR_BADOPS = -17, /**< Error: Invalid memkind_ops structure */
MEMKIND_ERROR_HUGETLB = -18, /**< Error: Unable to allocate huge pages */
MEMKIND_ERROR_MEMTYPE_NOT_AVAILABLE = -20, /**< Error: Requested memory type is not available */
MEMKIND_ERROR_OPERATION_FAILED = -21, /**< Error: Operation failed */
MEMKIND_ERROR_ARENAS_CREATE = -22, /**< Error: Call to jemalloc's arenas.create failed */
MEMKIND_ERROR_RUNTIME = -255 /**< Error: Unspecified run-time error */
};
///
/// \brief Create kind that allocates memory with specific memory type, memory binding policy and flags.
/// \warning EXPERIMENTAL API
/// \note Currently implemented memory type and policy configurations:
///. {MEMKIND_MEMTYPE_DEFAULT, MEMKIND_POLICY_PREFERRED_LOCAL},
///. {MEMKIND_MEMTYPE_HIGH_BANDWIDTH, MEMKIND_POLICY_BIND_LOCAL},
/// {MEMKIND_MEMTYPE_HIGH_BANDWIDTH, MEMKIND_POLICY_PREFERRED_LOCAL},
/// {MEMKIND_MEMTYPE_HIGH_BANDWIDTH, MEMKIND_POLICY_INTERLEAVE_ALL},
/// {MEMKIND_MEMTYPE_DEFAULT | MEMKIND_MEMTYPE_HIGH_BANDWIDTH, MEMKIND_POLICY_INTERLEAVE_ALL}.
/// \param memtype_flags determine the memory types to allocate from by combination of memkind_memtype_t values.
/// This field cannot have zero value.
/// \param policy specify policy for page binding to memory types selected by memtype_flags.
/// This field must be set to memkind_policy_t value. If policy is set to MEMKIND_POLICY_PREFERRED_LOCAL then only one memory
/// type must be selected. Note: the value cannot be set to MEMKIND_POLICY_MAX_VALUE.
/// \param flags the field must be set to a combination of memkind_bits_t values.
/// \param kind pointer to kind which will be created
/// \return Memkind operation status, MEMKIND_SUCCESS on success, MEMKIND_ERROR_MEMTYPE_NOT_AVAILABLE or MEMKIND_ERROR_INVALID on failure
///
int memkind_create_kind(memkind_memtype_t memtype_flags,
memkind_policy_t policy,
memkind_bits_t flags,
memkind_t *kind);
///
/// \brief Destroy previously created kind object, which must have been returned
/// by a call to memkind_create_kind() or memkind_create_pmem().
/// The function has undefined behavior when the handle is invalid or
/// memkind_destroy_kind(kind) was already called before
/// \warning EXPERIMENTAL API
/// \note if the kind was returned by memkind_create_kind() all allocated memory must be freed
/// before kind is destroyed, otherwise this will cause memory leak.
/// \param kind specified memory kind
/// \return Memkind operation status, MEMKIND_SUCCESS on success, MEMKIND_ERROR_OPERATION_FAILED on failure
///
int memkind_destroy_kind(memkind_t kind);
#include "memkind_deprecated.h"
/// \warning EXPERIMENTAL API
extern memkind_t MEMKIND_REGULAR;
/// \warning EXPERIMENTAL API
extern memkind_t MEMKIND_DEFAULT;
/// \warning EXPERIMENTAL API
extern memkind_t MEMKIND_HUGETLB;
/// \warning EXPERIMENTAL API
extern memkind_t MEMKIND_HBW;
/// \warning EXPERIMENTAL API
extern memkind_t MEMKIND_HBW_ALL;
/// \warning EXPERIMENTAL API
extern memkind_t MEMKIND_HBW_PREFERRED;
/// \warning EXPERIMENTAL API
extern memkind_t MEMKIND_HBW_HUGETLB;
/// \warning EXPERIMENTAL API
extern memkind_t MEMKIND_HBW_ALL_HUGETLB;
/// \warning EXPERIMENTAL API
extern memkind_t MEMKIND_HBW_PREFERRED_HUGETLB;
/// \warning EXPERIMENTAL API
extern memkind_t MEMKIND_HBW_INTERLEAVE;
/// \warning EXPERIMENTAL API
extern memkind_t MEMKIND_INTERLEAVE;
///
/// \brief Get Memkind API version
/// \note STANDARD API
/// \return Version number represented by a single integer number(major * 1000000 + minor * 1000 + patch)
///
int memkind_get_version();
///
/// \brief Convert error number into an error message
/// \note STANDARD API
/// \param err error number
/// \param msg error message
/// \param size size of message
///
void memkind_error_message(int err, char *msg, size_t size);
///
/// \brief Create a new PMEM (file-backed) kind of given size on top of a temporary file
/// in the given directory dir
/// \note STANDARD API
/// \param dir path to specified directory to temporary file
/// \param max_size size limit for kind
/// \param kind pointer to kind which will be created
/// \return Memkind operation status, MEMKIND_SUCCESS on success, other values on failure
///
int memkind_create_pmem(const char *dir, size_t max_size, memkind_t *kind);
///
/// \brief Check if kind is available
/// \note STANDARD API
/// \param kind specified memory kind
/// \return Memkind operation status, MEMKIND_SUCCESS on success, other values on failure
///
int memkind_check_available(memkind_t kind);
/* HEAP MANAGEMENT INTERFACE */
///
/// \brief Allocates size bytes of uninitialized storage of the specified kind
/// \note STANDARD API
/// \param kind specified memory kind
/// \param size number of bytes to allocate
/// \return Pointer to the allocated memory
///
void *memkind_malloc(memkind_t kind, size_t size);
///
/// \brief Obtain size of block of memory allocated with the memkind API
/// \note STANDARD API
/// \param kind specified memory kind
/// \param ptr pointer to the allocated memory
/// \return Number of usable bytes
///
size_t memkind_malloc_usable_size(memkind_t kind, void *ptr);
///
/// \brief Allocates memory of the specified kind for an array of num elements
/// of size bytes each and initializes all bytes in the allocated storage to zero
/// \note STANDARD API
/// \param kind specified memory kind
/// \param num number of objects
/// \param size specified size of each element
/// \return Pointer to the allocated memory
///
void *memkind_calloc(memkind_t kind, size_t num, size_t size);
/// \brief Allocates size bytes of the specified kind and places the address of the allocated memory
/// in *memptr. The address of the allocated memory will be a multiple of alignment,
/// which must be a power of two and a multiple of sizeof(void *)
/// \note EXPERIMENTAL API
/// \param kind specified memory kind
/// \param memptr address of the allocated memory
/// \param alignment specified alignment of bytes
/// \param size specified size of bytes
/// \return Memkind operation status, MEMKIND_SUCCESS on success, EINVAL or ENOMEM on failure
///
int memkind_posix_memalign(memkind_t kind, void **memptr, size_t alignment,
size_t size);
///
/// \brief Reallocates memory of the specified kind
/// \note STANDARD API
/// \param kind specified memory kind
/// \param ptr pointer to the memory block to be reallocated
/// \param size new size for the memory block in bytes
/// \return Pointer to the allocated memory
///
void *memkind_realloc(memkind_t kind, void *ptr, size_t size);
///
/// \brief Free the memory space of the specified kind pointed by ptr
/// \note STANDARD API
/// \param kind specified memory kind
/// \param ptr pointer to the allocated memory
///
void memkind_free(memkind_t kind, void *ptr);
int memkind_fd(struct memkind *kind);
void memkind_pmem_remapfd(struct memkind *kind, int fdNew);
int memkind_tmpfile(const char *dir, int *fd);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,30 @@
/*
* Copyright (C) 2017 - 2018 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice(s),
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <memkind.h>
void heap_manager_init(struct memkind *kind);
void heap_manager_free(struct memkind *kind, void *ptr);

View File

@ -0,0 +1,68 @@
/*
* Copyright (C) 2014 - 2018 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice(s),
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#ifndef MEMKIND_INTERNAL_API
#warning "DO NOT INCLUDE THIS FILE! IT IS INTERNAL MEMKIND API AND SOON WILL BE REMOVED FROM BIN & DEVEL PACKAGES"
#endif
#include <memkind.h>
#include <jemalloc/jemalloc.h>
#include <memkind/internal/memkind_private.h>
/*
* Header file for the jemalloc arena allocation memkind operations.
* More details in memkind_arena(3) man page.
*
* Functionality defined in this header is considered as EXPERIMENTAL API.
* API standards are described in memkind(3) man page.
*/
struct memkind *get_kind_by_arena(unsigned arena_ind);
int memkind_arena_create(struct memkind *kind, struct memkind_ops *ops,
const char *name);
int memkind_arena_create_map(struct memkind *kind, extent_hooks_t *hooks);
int memkind_arena_destroy(struct memkind *kind);
void *memkind_arena_malloc(struct memkind *kind, size_t size);
void *memkind_arena_calloc(struct memkind *kind, size_t num, size_t size);
void *memkind_arena_pmem_calloc(struct memkind *kind, size_t num, size_t size);
int memkind_arena_posix_memalign(struct memkind *kind, void **memptr,
size_t alignment, size_t size);
void *memkind_arena_realloc(struct memkind *kind, void *ptr, size_t size);
int memkind_bijective_get_arena(struct memkind *kind, unsigned int *arena,
size_t size);
int memkind_thread_get_arena(struct memkind *kind, unsigned int *arena,
size_t size);
int memkind_arena_finalize(struct memkind *kind);
void memkind_arena_init(struct memkind *kind);
void memkind_arena_free(struct memkind *kind, void *ptr);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,76 @@
/*
* Copyright (C) 2014 - 2018 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice(s),
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#ifndef MEMKIND_INTERNAL_API
#warning "DO NOT INCLUDE THIS FILE! IT IS INTERNAL MEMKIND API AND SOON WILL BE REMOVED FROM BIN & DEVEL PACKAGES"
#endif
#include <memkind.h>
#include <memkind/internal/memkind_private.h>
/*
* Header file for the default implementations for memkind operations.
* More details in memkind_default(3) man page.
*
* Functionality defined in this header is considered as EXPERIMENTAL API.
* API standards are described in memkind(3) man page.
*/
int memkind_default_create(struct memkind *kind, struct memkind_ops *ops,
const char *name);
int memkind_default_destroy(struct memkind *kind);
void *memkind_default_malloc(struct memkind *kind, size_t size);
void *memkind_default_calloc(struct memkind *kind, size_t num, size_t size);
int memkind_default_posix_memalign(struct memkind *kind, void **memptr,
size_t alignment, size_t size);
void *memkind_default_realloc(struct memkind *kind, void *ptr, size_t size);
void memkind_default_free(struct memkind *kind, void *ptr);
void *memkind_default_mmap(struct memkind *kind, void *addr, size_t size);
int memkind_default_mbind(struct memkind *kind, void *ptr, size_t size);
int memkind_default_get_mmap_flags(struct memkind *kind, int *flags);
int memkind_default_get_mbind_mode(struct memkind *kind, int *mode);
int memkind_default_get_mbind_nodemask(struct memkind *kind,
unsigned long *nodemask, unsigned long maxnode);
int memkind_preferred_get_mbind_mode(struct memkind *kind, int *mode);
int memkind_interleave_get_mbind_mode(struct memkind *kind, int *mode);
int memkind_nohugepage_madvise(struct memkind *kind, void *addr, size_t size);
int memkind_posix_check_alignment(struct memkind *kind, size_t alignment);
void memkind_default_init_once(void);
size_t memkind_default_malloc_usable_size(struct memkind *kind, void *ptr);
static inline bool size_out_of_bounds(size_t size)
{
return !size;
}
extern struct memkind_ops MEMKIND_DEFAULT_OPS;
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,47 @@
/*
* Copyright (C) 2014 - 2016 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice(s),
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#ifndef MEMKIND_INTERNAL_API
#warning "DO NOT INCLUDE THIS FILE! IT IS INTERNAL MEMKIND API AND SOON WILL BE REMOVED FROM BIN & DEVEL PACKAGES"
#endif
#include <memkind.h>
/*
* Header file for the gigabyte TLB memkind operations.
*
* All function declarations has been moved to memkind_deprecated.h
* because of end of GBTLB support.
*
* API standards are described in memkind(3) man page.
*/
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,70 @@
/*
* Copyright (C) 2014 - 2017 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice(s),
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#ifndef MEMKIND_INTERNAL_API
#warning "DO NOT INCLUDE THIS FILE! IT IS INTERNAL MEMKIND API AND SOON WILL BE REMOVED FROM BIN & DEVEL PACKAGES"
#endif
#include <memkind.h>
/*
* Header file for the high bandwidth memory memkind operations.
* More details in memkind_hbw(3) man page.
*
* Functionality defined in this header is considered as EXPERIMENTAL API.
* API standards are described in memkind(3) man page.
*/
int memkind_hbw_check_available(struct memkind *kind);
int memkind_hbw_hugetlb_check_available(struct memkind *kind);
int memkind_hbw_get_mbind_nodemask(struct memkind *kind,
unsigned long *nodemask,
unsigned long maxnode);
int memkind_hbw_all_get_mbind_nodemask(struct memkind *kind,
unsigned long *nodemask,
unsigned long maxnode);
void memkind_hbw_init_once(void);
void memkind_hbw_all_init_once(void);
void memkind_hbw_hugetlb_init_once(void);
void memkind_hbw_all_hugetlb_init_once(void);
void memkind_hbw_preferred_init_once(void);
void memkind_hbw_preferred_hugetlb_init_once(void);
void memkind_hbw_interleave_init_once(void);
extern struct memkind_ops MEMKIND_HBW_OPS;
extern struct memkind_ops MEMKIND_HBW_ALL_OPS;
extern struct memkind_ops MEMKIND_HBW_HUGETLB_OPS;
extern struct memkind_ops MEMKIND_HBW_ALL_HUGETLB_OPS;
extern struct memkind_ops MEMKIND_HBW_PREFERRED_OPS;
extern struct memkind_ops MEMKIND_HBW_PREFERRED_HUGETLB_OPS;
extern struct memkind_ops MEMKIND_HBW_INTERLEAVE_OPS;
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,52 @@
/*
* Copyright (C) 2014 - 2017 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice(s),
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#ifndef MEMKIND_INTERNAL_API
#warning "DO NOT INCLUDE THIS FILE! IT IS INTERNAL MEMKIND API AND SOON WILL BE REMOVED FROM BIN & DEVEL PACKAGES"
#endif
#include <memkind.h>
/*
* Header file for the hugetlb memory memkind operations.
* More details in memkind_hugetlb(3) man page.
*
* Functionality defined in this header is considered as EXPERIMENTAL API.
* API standards are described in memkind(3) man page.
*/
int memkind_hugetlb_get_mmap_flags(struct memkind *kind, int *flags);
void memkind_hugetlb_init_once(void);
int memkind_hugetlb_check_available_2mb(struct memkind *kind);
extern struct memkind_ops MEMKIND_HUGETLB_OPS;
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,47 @@
/*
* Copyright (C) 2015 - 2017 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice(s),
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#ifndef MEMKIND_INTERNAL_API
#warning "DO NOT INCLUDE THIS FILE! IT IS INTERNAL MEMKIND API AND SOON WILL BE REMOVED FROM BIN & DEVEL PACKAGES"
#endif
/*
* Header file for the interleave memory memkind operations.
*
* Functionality defined in this header is considered as EXPERIMENTAL API.
* API standards are described in memkind(3) man page.
*/
void memkind_interleave_init_once(void);
extern struct memkind_ops MEMKIND_INTERLEAVE_OPS;
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,52 @@
/*
* Copyright (C) 2014 - 2018 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice(s),
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#define PRINTF_FORMAT __attribute__ ((format (printf, 1, 2)))
/*
* For printing informational messages
* Requires environment variable MEMKIND_DEBUG to be set to appropriate value
*/
void log_info(const char *format, ...) PRINTF_FORMAT;
/*
* For printing messages regarding errors and failures
* Requires environment variable MEMKIND_DEBUG to be set to appropriate value
*/
void log_err(const char *format, ...) PRINTF_FORMAT;
/*
* For printing messages regarding fatal errors before calling abort()
* Works *no matter* of MEMKIND_DEBUG state
*/
void log_fatal(const char *format, ...)PRINTF_FORMAT;
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,75 @@
/*
* Copyright (C) 2015 - 2018 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice(s),
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#ifndef MEMKIND_INTERNAL_API
#warning "DO NOT INCLUDE THIS FILE! IT IS INTERNAL MEMKIND API AND SOON WILL BE REMOVED FROM BIN & DEVEL PACKAGES"
#endif
#include <memkind.h>
#include "memkind_default.h"
#include "memkind_arena.h"
#include <pthread.h>
/*
* Header file for the file-backed memory memkind operations.
* More details in memkind_pmem(3) man page.
*
* Functionality defined in this header is considered as EXPERIMENTAL API.
* API standards are described in memkind(3) man page.
*/
#define MEMKIND_PMEM_CHUNK_SIZE (1ull << 21ull) // 2MB
int memkind_pmem_create(struct memkind *kind, struct memkind_ops *ops,
const char *name);
int memkind_pmem_destroy(struct memkind *kind);
void *memkind_pmem_mmap(struct memkind *kind, void *addr, size_t size);
int memkind_pmem_get_mmap_flags(struct memkind *kind, int *flags);
struct memkind_pmem_extent {
void *addrBase;
size_t cb;
off_t offset;
};
struct memkind_pmem {
int fd;
off_t offset;
size_t max_size;
pthread_mutex_t pmem_lock;
int cextents;
int cextentsAlloc;
struct memkind_pmem_extent *rgextents;
};
extern struct memkind_ops MEMKIND_PMEM_OPS;
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,127 @@
/*
* Copyright (C) 2016 - 2018 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice(s),
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#ifndef MEMKIND_INTERNAL_API
#warning "DO NOT INCLUDE THIS FILE! IT IS INTERNAL MEMKIND API AND SOON WILL BE REMOVED FROM BIN & DEVEL PACKAGES"
#endif
#include "memkind.h"
#include <stdbool.h>
#include <pthread.h>
#ifdef __GNUC__
# define MEMKIND_LIKELY(x) __builtin_expect(!!(x), 1)
# define MEMKIND_UNLIKELY(x) __builtin_expect(!!(x), 0)
#else
# define MEMKIND_LIKELY(x) (x)
# define MEMKIND_UNLIKELY(x) (x)
#endif
#ifndef MEMKIND_EXPORT
# define MEMKIND_EXPORT __attribute__((visibility("default")))
#endif
#ifndef JE_PREFIX
#error "Can't find JE_PREFIX define. Define one or use build.sh script."
#endif
// This ladder call is required due to meanders of C's preprocessor logic.
// Without it, JE_PREFIX would be used directly (i.e. 'JE_PREFIX') and not
// substituted with defined value.
#define JE_SYMBOL2(a, b) a ## b
#define JE_SYMBOL1(a, b) JE_SYMBOL2(a, b)
#define JE_SYMBOL(b) JE_SYMBOL1(JE_PREFIX, b)
// Redefine symbols
#define jemk_malloc JE_SYMBOL(malloc)
#define jemk_mallocx JE_SYMBOL(mallocx)
#define jemk_calloc JE_SYMBOL(calloc)
#define jemk_rallocx JE_SYMBOL(rallocx)
#define jemk_realloc JE_SYMBOL(realloc)
#define jemk_mallctl JE_SYMBOL(mallctl)
#define jemk_memalign JE_SYMBOL(memalign)
#define jemk_posix_memalign JE_SYMBOL(posix_memalign)
#define jemk_free JE_SYMBOL(free)
#define jemk_dallocx JE_SYMBOL(dallocx)
#define jemk_malloc_usable_size JE_SYMBOL(malloc_usable_size)
/// \note EXPERIMENTAL API
int je_get_defrag_hint(void *ptr, int *bin_util, int *run_util);
enum memkind_const_private {
MEMKIND_NAME_LENGTH_PRIV = 64
};
struct memkind_ops {
int (* create)(struct memkind *kind, struct memkind_ops *ops, const char *name);
int (* destroy)(struct memkind *kind);
void *(* malloc)(struct memkind *kind, size_t size);
void *(* calloc)(struct memkind *kind, size_t num, size_t size);
int (* posix_memalign)(struct memkind *kind, void **memptr, size_t alignment,
size_t size);
void *(* realloc)(struct memkind *kind, void *ptr, size_t size);
void (* free)(struct memkind *kind, void *ptr);
void *(* mmap)(struct memkind *kind, void *addr, size_t size);
int (* mbind)(struct memkind *kind, void *ptr, size_t size);
int (* madvise)(struct memkind *kind, void *addr, size_t size);
int (* get_mmap_flags)(struct memkind *kind, int *flags);
int (* get_mbind_mode)(struct memkind *kind, int *mode);
int (* get_mbind_nodemask)(struct memkind *kind, unsigned long *nodemask,
unsigned long maxnode);
int (* get_arena)(struct memkind *kind, unsigned int *arena, size_t size);
int (* check_available)(struct memkind *kind);
int (* check_addr)(struct memkind *kind, void *addr);
void (* init_once)(void);
int (* finalize)(struct memkind *kind);
size_t (* malloc_usable_size)(struct memkind *kind, void *addr);
};
struct memkind {
struct memkind_ops *ops;
unsigned int partition;
char name[MEMKIND_NAME_LENGTH_PRIV];
pthread_once_t init_once;
unsigned int arena_map_len; // is power of 2
unsigned int *arena_map; // To be deleted beyond 1.2.0+
pthread_key_t arena_key;
void *priv;
unsigned int
arena_map_mask; // arena_map_len - 1 to optimize modulo operation on arena_map_len
unsigned int arena_zero; // index first jemalloc arena of this kind
};
void memkind_init(memkind_t kind, bool check_numa);
void *kind_mmap(struct memkind *kind, void *addr, size_t size);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,51 @@
/*
* Copyright (C) 2017 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice(s),
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#ifndef MEMKIND_INTERNAL_API
#warning "DO NOT INCLUDE THIS FILE! IT IS INTERNAL MEMKIND API AND SOON WILL BE REMOVED FROM BIN & DEVEL PACKAGES"
#endif
#include <memkind.h>
/*
* Header file for the regular memory memkind operations.
* More details in memkind_regular(3) man page.
*
* Functionality defined in this header is considered as EXPERIMENTAL API.
* API standards are described in memkind(3) man page.
*/
extern struct memkind_ops MEMKIND_REGULAR_OPS;
int memkind_regular_all_get_mbind_nodemask(struct memkind *kind,
unsigned long *nodemask,
unsigned long maxnode);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,34 @@
/*
Copyright (c) 2005-2018 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <stdint.h>
typedef void *(*rawAllocType)(intptr_t pool_id, size_t *bytes);
typedef int (*rawFreeType)(intptr_t pool_id, void *raw_ptr, size_t raw_bytes);
struct MemPoolPolicy {
rawAllocType pAlloc;
rawFreeType pFree;
size_t granularity;
int version;
unsigned fixedPool : 1,
keepAllMemory : 1,
reserved : 30;
};

View File

@ -0,0 +1,41 @@
/*
* Copyright (C) 2017 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice(s),
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <memkind.h>
#include <memkind_deprecated.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ops callbacks are replaced by TBB callbacks. */
void tbb_initialize(struct memkind *kind);
/* ptr pointer must come from the valid TBB pool allocation */
void tbb_pool_free(struct memkind *kind, void *ptr);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,85 @@
/*
* Copyright (C) 2016 - 2018 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice(s),
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* !!!!!!!!!!!!!!!!!!!
* !!! WARNING !!!
* !!! PLEASE READ !!!
* !!!!!!!!!!!!!!!!!!!
*
* This header file contains all memkind deprecated symbols.
*
* Please avoid usage of this API in newly developed code, as
* eventually this code is subject for removal.
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#ifndef MEMKIND_DEPRECATED
#ifdef __GNUC__
#define MEMKIND_DEPRECATED(func) func __attribute__ ((deprecated))
#elif defined(_MSC_VER)
#define MEMKIND_DEPRECATED(func) __declspec(deprecated) func
#else
#pragma message("WARNING: You need to implement MEMKIND_DEPRECATED for this compiler")
#define MEMKIND_DEPRECATED(func) func
#endif
#endif
/*
* Symbols related to GBTLB that are no longer supported
*/
extern memkind_t MEMKIND_HBW_GBTLB;
extern memkind_t MEMKIND_HBW_PREFERRED_GBTLB;
extern memkind_t MEMKIND_GBTLB;
int MEMKIND_DEPRECATED(memkind_get_kind_by_partition(int partition,
memkind_t *kind));
enum memkind_base_partition {
MEMKIND_PARTITION_DEFAULT = 0,
MEMKIND_PARTITION_HBW = 1,
MEMKIND_PARTITION_HBW_HUGETLB = 2,
MEMKIND_PARTITION_HBW_PREFERRED = 3,
MEMKIND_PARTITION_HBW_PREFERRED_HUGETLB = 4,
MEMKIND_PARTITION_HUGETLB = 5,
MEMKIND_PARTITION_HBW_GBTLB = 6,
MEMKIND_PARTITION_HBW_PREFERRED_GBTLB = 7,
MEMKIND_PARTITION_GBTLB = 8,
MEMKIND_PARTITION_HBW_INTERLEAVE = 9,
MEMKIND_PARTITION_INTERLEAVE = 10,
MEMKIND_PARTITION_REGULAR = 11,
MEMKIND_PARTITION_HBW_ALL = 12,
MEMKIND_PARTITION_HBW_ALL_HUGETLB = 13,
MEMKIND_NUM_BASE_KIND
};
#ifdef __cplusplus
}
#endif

201
include/pmem_allocator.h Normal file
View File

@ -0,0 +1,201 @@
/*
* Copyright (C) 2018 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice(s),
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <memory>
#include <string>
#include <exception>
#include <type_traits>
#include <atomic>
#include <cstddef>
#include "memkind.h"
/*
* Header file for the C++ allocator compatible with the C++ standard library allocator concepts.
* More details in pmemallocator(3) man page.
* Note: memory heap management is based on memkind_malloc, refer to the memkind(3) man page for more
* information.
*
* Functionality defined in this header is considered as EXPERIMENTAL API.
* API standards are described in memkind(3) man page.
*/
namespace pmem
{
namespace internal
{
class kind_wrapper_t
{
public:
kind_wrapper_t(const char *dir, std::size_t max_size)
{
int err_c = memkind_create_pmem(dir, max_size, &kind);
if (err_c) {
throw std::runtime_error(
std::string("An error occured while creating pmem kind; error code: ") +
std::to_string(err_c));
}
}
kind_wrapper_t(const kind_wrapper_t &) = delete;
void operator=(const kind_wrapper_t &) = delete;
~kind_wrapper_t()
{
memkind_destroy_kind(kind);
}
memkind_t get() const
{
return kind;
}
private:
memkind_t kind;
};
}
template<typename T>
class allocator
{
using kind_wrapper_t = internal::kind_wrapper_t;
std::shared_ptr<kind_wrapper_t> kind_wrapper_ptr;
public:
using value_type = T;
using pointer = value_type*;
using const_pointer = const value_type*;
using reference = value_type&;
using const_reference = const value_type&;
using size_type = size_t;
using difference_type = ptrdiff_t;
template<class U>
struct rebind {
using other = allocator<U>;
};
template<typename U>
friend class allocator;
#ifndef _GLIBCXX_USE_CXX11_ABI
/* This is a workaround for compilers (e.g GCC 4.8) that uses C++11 standard,
* but use old - non C++11 ABI */
template<typename V = void>
explicit allocator()
{
static_assert(std::is_same<V, void>::value,
"pmem::allocator cannot be compiled without CXX11 ABI");
}
#endif
explicit allocator(const char *dir, size_t max_size) :
kind_wrapper_ptr(std::make_shared<kind_wrapper_t>(dir, max_size))
{
}
explicit allocator(const std::string &dir, size_t max_size) :
allocator(dir.c_str(), max_size)
{
}
allocator(const allocator &other) = default;
template <typename U>
allocator(const allocator<U> &other) noexcept : kind_wrapper_ptr(
other.kind_wrapper_ptr)
{
}
allocator(allocator &&other) = default;
template <typename U>
allocator(allocator<U> &&other) noexcept :
kind_wrapper_ptr(std::move(other.kind_wrapper_ptr))
{
}
allocator<T> &operator = (const allocator &other) = default;
template <typename U>
allocator<T> &operator = (const allocator<U> &other) noexcept
{
kind_wrapper_ptr = other.kind_wrapper_ptr;
return *this;
}
allocator<T> &operator = (allocator &&other) = default;
template <typename U>
allocator<T> &operator = (allocator<U> &&other) noexcept
{
kind_wrapper_ptr = std::move(other.kind_wrapper_ptr);
return *this;
}
pointer allocate(size_type n) const
{
pointer result = static_cast<pointer>(memkind_malloc(kind_wrapper_ptr->get(),
n*sizeof(T)));
if (!result) {
throw std::bad_alloc();
}
return result;
}
void deallocate(pointer p, size_type n) const
{
memkind_free(kind_wrapper_ptr->get(), static_cast<void *>(p));
}
template <class U, class... Args>
void construct(U *p, Args &&... args) const
{
::new((void *)p) U(std::forward<Args>(args)...);
}
void destroy(pointer p) const
{
p->~value_type();
}
template <typename U, typename V>
friend bool operator ==(const allocator<U> &lhs, const allocator<V> &rhs);
template <typename U, typename V>
friend bool operator !=(const allocator<U> &lhs, const allocator<V> &rhs);
};
template <typename U, typename V>
bool operator ==(const allocator<U> &lhs, const allocator<V> &rhs)
{
return lhs.kind_wrapper_ptr->get() == rhs.kind_wrapper_ptr->get();
}
template <typename U, typename V>
bool operator !=(const allocator<U> &lhs, const allocator<V> &rhs)
{
return !(lhs == rhs);
}
}

31
install_astyle.sh Executable file
View File

@ -0,0 +1,31 @@
#!/bin/bash
#
# Copyright (C) 2018 Intel Corporation.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice(s),
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice(s),
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
set -ex
curl -SL https://sourceforge.net/projects/astyle/files/astyle/astyle%203.1/astyle_3.1_linux.tar.gz -o /tmp/astyle.tar.gz
tar -xzvf /tmp/astyle.tar.gz -C /tmp/
echo "Install astyle"
cd /tmp/astyle/build/gcc
make
sudo make install

42
jemalloc/.appveyor.yml Normal file
View File

@ -0,0 +1,42 @@
version: '{build}'
environment:
matrix:
- MSYSTEM: MINGW64
CPU: x86_64
MSVC: amd64
- MSYSTEM: MINGW32
CPU: i686
MSVC: x86
- MSYSTEM: MINGW64
CPU: x86_64
- MSYSTEM: MINGW32
CPU: i686
- MSYSTEM: MINGW64
CPU: x86_64
MSVC: amd64
CONFIG_FLAGS: --enable-debug
- MSYSTEM: MINGW32
CPU: i686
MSVC: x86
CONFIG_FLAGS: --enable-debug
- MSYSTEM: MINGW64
CPU: x86_64
CONFIG_FLAGS: --enable-debug
- MSYSTEM: MINGW32
CPU: i686
CONFIG_FLAGS: --enable-debug
install:
- set PATH=c:\msys64\%MSYSTEM%\bin;c:\msys64\usr\bin;%PATH%
- if defined MSVC call "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" %MSVC%
- if defined MSVC pacman --noconfirm -Rsc mingw-w64-%CPU%-gcc gcc
- pacman --noconfirm -Suy mingw-w64-%CPU%-make
build_script:
- bash -c "autoconf"
- bash -c "./configure $CONFIG_FLAGS"
- mingw32-make
- file lib/jemalloc.dll
- mingw32-make tests
- mingw32-make -k check

3
jemalloc/.autom4te.cfg Normal file
View File

@ -0,0 +1,3 @@
begin-language: "Autoconf-without-aclocal-m4"
args: --no-cache
end-language: "Autoconf-without-aclocal-m4"

1
jemalloc/.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
* text=auto eol=lf

91
jemalloc/.gitignore vendored Normal file
View File

@ -0,0 +1,91 @@
/bin/jemalloc-config
/bin/jemalloc.sh
/bin/jeprof
/config.stamp
/config.log
/config.status
/configure
/doc/html.xsl
/doc/manpages.xsl
/doc/jemalloc.xml
/doc/jemalloc.html
/doc/jemalloc.3
/jemalloc.pc
/lib/
/Makefile
/include/jemalloc/internal/jemalloc_preamble.h
/include/jemalloc/internal/jemalloc_internal_defs.h
/include/jemalloc/internal/private_namespace.gen.h
/include/jemalloc/internal/private_namespace.h
/include/jemalloc/internal/private_namespace_jet.gen.h
/include/jemalloc/internal/private_namespace_jet.h
/include/jemalloc/internal/private_symbols.awk
/include/jemalloc/internal/private_symbols_jet.awk
/include/jemalloc/internal/public_namespace.h
/include/jemalloc/internal/public_symbols.txt
/include/jemalloc/internal/public_unnamespace.h
/include/jemalloc/internal/size_classes.h
/include/jemalloc/jemalloc.h
/include/jemalloc/jemalloc_defs.h
/include/jemalloc/jemalloc_macros.h
/include/jemalloc/jemalloc_mangle.h
/include/jemalloc/jemalloc_mangle_jet.h
/include/jemalloc/jemalloc_protos.h
/include/jemalloc/jemalloc_protos_jet.h
/include/jemalloc/jemalloc_rename.h
/include/jemalloc/jemalloc_typedefs.h
/src/*.[od]
/src/*.sym
/run_tests.out/
/test/test.sh
test/include/test/jemalloc_test.h
test/include/test/jemalloc_test_defs.h
/test/integration/[A-Za-z]*
!/test/integration/[A-Za-z]*.*
/test/integration/*.[od]
/test/integration/*.out
/test/integration/cpp/[A-Za-z]*
!/test/integration/cpp/[A-Za-z]*.*
/test/integration/cpp/*.[od]
/test/integration/cpp/*.out
/test/src/*.[od]
/test/stress/[A-Za-z]*
!/test/stress/[A-Za-z]*.*
/test/stress/*.[od]
/test/stress/*.out
/test/unit/[A-Za-z]*
!/test/unit/[A-Za-z]*.*
/test/unit/*.[od]
/test/unit/*.out
/VERSION
*.pdb
*.sdf
*.opendb
*.opensdf
*.cachefile
*.suo
*.user
*.sln.docstates
*.tmp
/msvc/Win32/
/msvc/x64/
/msvc/projects/*/*/Debug*/
/msvc/projects/*/*/Release*/
/msvc/projects/*/*/Win32/
/msvc/projects/*/*/x64/

155
jemalloc/.travis.yml Normal file
View File

@ -0,0 +1,155 @@
language: generic
matrix:
include:
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: osx
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=clang CXX=clang++ COMPILER_FLAGS="" CONFIGURE_FLAGS="" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="-m32" CONFIGURE_FLAGS="" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
addons:
apt:
packages:
- gcc-multilib
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--enable-debug" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--enable-prof" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--disable-stats" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--with-malloc-conf=tcache:false" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--with-malloc-conf=dss:primary" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--with-malloc-conf=percpu_arena:percpu" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--with-malloc-conf=background_thread:true" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: osx
env: CC=clang CXX=clang++ COMPILER_FLAGS="" CONFIGURE_FLAGS="" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: osx
env: CC=gcc CXX=g++ COMPILER_FLAGS="-m32" CONFIGURE_FLAGS="" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: osx
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--enable-debug" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: osx
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--disable-stats" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: osx
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--with-malloc-conf=tcache:false" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=clang CXX=clang++ COMPILER_FLAGS="-m32" CONFIGURE_FLAGS="" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
addons:
apt:
packages:
- gcc-multilib
- os: linux
env: CC=clang CXX=clang++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--enable-debug" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=clang CXX=clang++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--enable-prof" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=clang CXX=clang++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--disable-stats" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=clang CXX=clang++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--with-malloc-conf=tcache:false" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=clang CXX=clang++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--with-malloc-conf=dss:primary" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=clang CXX=clang++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--with-malloc-conf=percpu_arena:percpu" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=clang CXX=clang++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--with-malloc-conf=background_thread:true" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="-m32" CONFIGURE_FLAGS="--enable-debug" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
addons:
apt:
packages:
- gcc-multilib
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="-m32" CONFIGURE_FLAGS="--enable-prof" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
addons:
apt:
packages:
- gcc-multilib
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="-m32" CONFIGURE_FLAGS="--disable-stats" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
addons:
apt:
packages:
- gcc-multilib
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="-m32" CONFIGURE_FLAGS="--with-malloc-conf=tcache:false" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
addons:
apt:
packages:
- gcc-multilib
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="-m32" CONFIGURE_FLAGS="--with-malloc-conf=dss:primary" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
addons:
apt:
packages:
- gcc-multilib
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="-m32" CONFIGURE_FLAGS="--with-malloc-conf=percpu_arena:percpu" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
addons:
apt:
packages:
- gcc-multilib
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="-m32" CONFIGURE_FLAGS="--with-malloc-conf=background_thread:true" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
addons:
apt:
packages:
- gcc-multilib
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--enable-debug --enable-prof" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--enable-debug --disable-stats" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--enable-debug --with-malloc-conf=tcache:false" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--enable-debug --with-malloc-conf=dss:primary" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--enable-debug --with-malloc-conf=percpu_arena:percpu" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--enable-debug --with-malloc-conf=background_thread:true" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--enable-prof --disable-stats" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--enable-prof --with-malloc-conf=tcache:false" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--enable-prof --with-malloc-conf=dss:primary" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--enable-prof --with-malloc-conf=percpu_arena:percpu" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--enable-prof --with-malloc-conf=background_thread:true" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--disable-stats --with-malloc-conf=tcache:false" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--disable-stats --with-malloc-conf=dss:primary" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--disable-stats --with-malloc-conf=percpu_arena:percpu" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--disable-stats --with-malloc-conf=background_thread:true" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--with-malloc-conf=tcache:false,dss:primary" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--with-malloc-conf=tcache:false,percpu_arena:percpu" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--with-malloc-conf=tcache:false,background_thread:true" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--with-malloc-conf=dss:primary,percpu_arena:percpu" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--with-malloc-conf=dss:primary,background_thread:true" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
- os: linux
env: CC=gcc CXX=g++ COMPILER_FLAGS="" CONFIGURE_FLAGS="--with-malloc-conf=percpu_arena:percpu,background_thread:true" EXTRA_CFLAGS="-Werror -Wno-array-bounds"
before_script:
- autoconf
- ./configure ${COMPILER_FLAGS:+ CC="$CC $COMPILER_FLAGS" CXX="$CXX $COMPILER_FLAGS" } $CONFIGURE_FLAGS
- make -j3
- make -j3 tests
script:
- make check

27
jemalloc/COPYING Normal file
View File

@ -0,0 +1,27 @@
Unless otherwise specified, files in the jemalloc source distribution are
subject to the following license:
--------------------------------------------------------------------------------
Copyright (C) 2002-2017 Jason Evans <jasone@canonware.com>.
All rights reserved.
Copyright (C) 2007-2012 Mozilla Foundation. All rights reserved.
Copyright (C) 2009-2017 Facebook, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice(s),
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice(s),
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------

1230
jemalloc/ChangeLog Normal file

File diff suppressed because it is too large Load Diff

411
jemalloc/INSTALL.md Normal file
View File

@ -0,0 +1,411 @@
Building and installing a packaged release of jemalloc can be as simple as
typing the following while in the root directory of the source tree:
./configure
make
make install
If building from unpackaged developer sources, the simplest command sequence
that might work is:
./autogen.sh
make dist
make
make install
Note that documentation is not built by the default target because doing so
would create a dependency on xsltproc in packaged releases, hence the
requirement to either run 'make dist' or avoid installing docs via the various
install_* targets documented below.
## Advanced configuration
The 'configure' script supports numerous options that allow control of which
functionality is enabled, where jemalloc is installed, etc. Optionally, pass
any of the following arguments (not a definitive list) to 'configure':
* `--help`
Print a definitive list of options.
* `--prefix=<install-root-dir>`
Set the base directory in which to install. For example:
./configure --prefix=/usr/local
will cause files to be installed into /usr/local/include, /usr/local/lib,
and /usr/local/man.
* `--with-version=(<major>.<minor>.<bugfix>-<nrev>-g<gid>|VERSION)`
The VERSION file is mandatory for successful configuration, and the
following steps are taken to assure its presence:
1) If --with-version=<major>.<minor>.<bugfix>-<nrev>-g<gid> is specified,
generate VERSION using the specified value.
2) If --with-version is not specified in either form and the source
directory is inside a git repository, try to generate VERSION via 'git
describe' invocations that pattern-match release tags.
3) If VERSION is missing, generate it with a bogus version:
0.0.0-0-g0000000000000000000000000000000000000000
Note that --with-version=VERSION bypasses (1) and (2), which simplifies
VERSION configuration when embedding a jemalloc release into another
project's git repository.
* `--with-rpath=<colon-separated-rpath>`
Embed one or more library paths, so that libjemalloc can find the libraries
it is linked to. This works only on ELF-based systems.
* `--with-mangling=<map>`
Mangle public symbols specified in <map> which is a comma-separated list of
name:mangled pairs.
For example, to use ld's --wrap option as an alternative method for
overriding libc's malloc implementation, specify something like:
--with-mangling=malloc:__wrap_malloc,free:__wrap_free[...]
Note that mangling happens prior to application of the prefix specified by
--with-jemalloc-prefix, and mangled symbols are then ignored when applying
the prefix.
* `--with-jemalloc-prefix=<prefix>`
Prefix all public APIs with <prefix>. For example, if <prefix> is
"prefix_", API changes like the following occur:
malloc() --> prefix_malloc()
malloc_conf --> prefix_malloc_conf
/etc/malloc.conf --> /etc/prefix_malloc.conf
MALLOC_CONF --> PREFIX_MALLOC_CONF
This makes it possible to use jemalloc at the same time as the system
allocator, or even to use multiple copies of jemalloc simultaneously.
By default, the prefix is "", except on OS X, where it is "je_". On OS X,
jemalloc overlays the default malloc zone, but makes no attempt to actually
replace the "malloc", "calloc", etc. symbols.
* `--without-export`
Don't export public APIs. This can be useful when building jemalloc as a
static library, or to avoid exporting public APIs when using the zone
allocator on OSX.
* `--with-private-namespace=<prefix>`
Prefix all library-private APIs with <prefix>je_. For shared libraries,
symbol visibility mechanisms prevent these symbols from being exported, but
for static libraries, naming collisions are a real possibility. By
default, <prefix> is empty, which results in a symbol prefix of je_ .
* `--with-install-suffix=<suffix>`
Append <suffix> to the base name of all installed files, such that multiple
versions of jemalloc can coexist in the same installation directory. For
example, libjemalloc.so.0 becomes libjemalloc<suffix>.so.0.
* `--with-malloc-conf=<malloc_conf>`
Embed `<malloc_conf>` as a run-time options string that is processed prior to
the malloc_conf global variable, the /etc/malloc.conf symlink, and the
MALLOC_CONF environment variable. For example, to change the default decay
time to 30 seconds:
--with-malloc-conf=decay_ms:30000
* `--enable-debug`
Enable assertions and validation code. This incurs a substantial
performance hit, but is very useful during application development.
* `--disable-stats`
Disable statistics gathering functionality. See the "opt.stats_print"
option documentation for usage details.
* `--enable-prof`
Enable heap profiling and leak detection functionality. See the "opt.prof"
option documentation for usage details. When enabled, there are several
approaches to backtracing, and the configure script chooses the first one
in the following list that appears to function correctly:
+ libunwind (requires --enable-prof-libunwind)
+ libgcc (unless --disable-prof-libgcc)
+ gcc intrinsics (unless --disable-prof-gcc)
* `--enable-prof-libunwind`
Use the libunwind library (http://www.nongnu.org/libunwind/) for stack
backtracing.
* `--disable-prof-libgcc`
Disable the use of libgcc's backtracing functionality.
* `--disable-prof-gcc`
Disable the use of gcc intrinsics for backtracing.
* `--with-static-libunwind=<libunwind.a>`
Statically link against the specified libunwind.a rather than dynamically
linking with -lunwind.
* `--disable-thp`
Disable transparent huge page (THP) integration. This option can be useful
when cross compiling.
* `--disable-fill`
Disable support for junk/zero filling of memory. See the "opt.junk" and
"opt.zero" option documentation for usage details.
* `--disable-zone-allocator`
Disable zone allocator for Darwin. This means jemalloc won't be hooked as
the default allocator on OSX/iOS.
* `--enable-utrace`
Enable utrace(2)-based allocation tracing. This feature is not broadly
portable (FreeBSD has it, but Linux and OS X do not).
* `--enable-xmalloc`
Enable support for optional immediate termination due to out-of-memory
errors, as is commonly implemented by "xmalloc" wrapper function for malloc.
See the "opt.xmalloc" option documentation for usage details.
* `--enable-lazy-lock`
Enable code that wraps pthread_create() to detect when an application
switches from single-threaded to multi-threaded mode, so that it can avoid
mutex locking/unlocking operations while in single-threaded mode. In
practice, this feature usually has little impact on performance unless
thread-specific caching is disabled.
* `--disable-cache-oblivious`
Disable cache-oblivious large allocation alignment for large allocation
requests with no alignment constraints. If this feature is disabled, all
large allocations are page-aligned as an implementation artifact, which can
severely harm CPU cache utilization. However, the cache-oblivious layout
comes at the cost of one extra page per large allocation, which in the
most extreme case increases physical memory usage for the 16 KiB size class
to 20 KiB.
* `--disable-syscall`
Disable use of syscall(2) rather than {open,read,write,close}(2). This is
intended as a workaround for systems that place security limitations on
syscall(2).
* `--disable-cxx`
Disable C++ integration. This will cause new and delete operator
implementations to be omitted.
* `--with-xslroot=<path>`
Specify where to find DocBook XSL stylesheets when building the
documentation.
* `--with-lg-page=<lg-page>`
Specify the base 2 log of the allocator page size, which must in turn be at
least as large as the system page size. By default the configure script
determines the host's page size and sets the allocator page size equal to
the system page size, so this option need not be specified unless the
system page size may change between configuration and execution, e.g. when
cross compiling.
* `--with-lg-page-sizes=<lg-page-sizes>`
Specify the comma-separated base 2 logs of the page sizes to support. This
option may be useful when cross compiling in combination with
`--with-lg-page`, but its primary use case is for integration with FreeBSD's
libc, wherein jemalloc is embedded.
* `--with-lg-hugepage=<lg-hugepage>`
Specify the base 2 log of the system huge page size. This option is useful
when cross compiling, or when overriding the default for systems that do
not explicitly support huge pages.
* `--with-lg-quantum=<lg-quantum>`
Specify the base 2 log of the minimum allocation alignment. jemalloc needs
to know the minimum alignment that meets the following C standard
requirement (quoted from the April 12, 2011 draft of the C11 standard):
> The pointer returned if the allocation succeeds is suitably aligned so
that it may be assigned to a pointer to any type of object with a
fundamental alignment requirement and then used to access such an object
or an array of such objects in the space allocated [...]
This setting is architecture-specific, and although jemalloc includes known
safe values for the most commonly used modern architectures, there is a
wrinkle related to GNU libc (glibc) that may impact your choice of
<lg-quantum>. On most modern architectures, this mandates 16-byte
alignment (<lg-quantum>=4), but the glibc developers chose not to meet this
requirement for performance reasons. An old discussion can be found at
<https://sourceware.org/bugzilla/show_bug.cgi?id=206> . Unlike glibc,
jemalloc does follow the C standard by default (caveat: jemalloc
technically cheats for size classes smaller than the quantum), but the fact
that Linux systems already work around this allocator noncompliance means
that it is generally safe in practice to let jemalloc's minimum alignment
follow glibc's lead. If you specify `--with-lg-quantum=3` during
configuration, jemalloc will provide additional size classes that are not
16-byte-aligned (24, 40, and 56).
The following environment variables (not a definitive list) impact configure's
behavior:
* `CFLAGS="?"`
* `CXXFLAGS="?"`
Pass these flags to the C/C++ compiler. Any flags set by the configure
script are prepended, which means explicitly set flags generally take
precedence. Take care when specifying flags such as -Werror, because
configure tests may be affected in undesirable ways.
* `EXTRA_CFLAGS="?"`
* `EXTRA_CXXFLAGS="?"`
Append these flags to CFLAGS/CXXFLAGS, without passing them to the
compiler(s) during configuration. This makes it possible to add flags such
as -Werror, while allowing the configure script to determine what other
flags are appropriate for the specified configuration.
* `CPPFLAGS="?"`
Pass these flags to the C preprocessor. Note that CFLAGS is not passed to
'cpp' when 'configure' is looking for include files, so you must use
CPPFLAGS instead if you need to help 'configure' find header files.
* `LD_LIBRARY_PATH="?"`
'ld' uses this colon-separated list to find libraries.
* `LDFLAGS="?"`
Pass these flags when linking.
* `PATH="?"`
'configure' uses this to find programs.
In some cases it may be necessary to work around configuration results that do
not match reality. For example, Linux 4.5 added support for the MADV_FREE flag
to madvise(2), which can cause problems if building on a host with MADV_FREE
support and deploying to a target without. To work around this, use a cache
file to override the relevant configuration variable defined in configure.ac,
e.g.:
echo "je_cv_madv_free=no" > config.cache && ./configure -C
## Advanced compilation
To build only parts of jemalloc, use the following targets:
build_lib_shared
build_lib_static
build_lib
build_doc_html
build_doc_man
build_doc
To install only parts of jemalloc, use the following targets:
install_bin
install_include
install_lib_shared
install_lib_static
install_lib
install_doc_html
install_doc_man
install_doc
To clean up build results to varying degrees, use the following make targets:
clean
distclean
relclean
## Advanced installation
Optionally, define make variables when invoking make, including (not
exclusively):
* `INCLUDEDIR="?"`
Use this as the installation prefix for header files.
* `LIBDIR="?"`
Use this as the installation prefix for libraries.
* `MANDIR="?"`
Use this as the installation prefix for man pages.
* `DESTDIR="?"`
Prepend DESTDIR to INCLUDEDIR, LIBDIR, DATADIR, and MANDIR. This is useful
when installing to a different path than was specified via --prefix.
* `CC="?"`
Use this to invoke the C compiler.
* `CFLAGS="?"`
Pass these flags to the compiler.
* `CPPFLAGS="?"`
Pass these flags to the C preprocessor.
* `LDFLAGS="?"`
Pass these flags when linking.
* `PATH="?"`
Use this to search for programs used during configuration and building.
## Development
If you intend to make non-trivial changes to jemalloc, use the 'autogen.sh'
script rather than 'configure'. This re-generates 'configure', enables
configuration dependency rules, and enables re-generation of automatically
generated source files.
The build system supports using an object directory separate from the source
tree. For example, you can create an 'obj' directory, and from within that
directory, issue configuration and build commands:
autoconf
mkdir obj
cd obj
../configure --enable-autogen
make
## Documentation
The manual page is generated in both html and roff formats. Any web browser
can be used to view the html manual. The roff manual page can be formatted
prior to installation via the following command:
nroff -man -t doc/jemalloc.3

563
jemalloc/Makefile.in Normal file
View File

@ -0,0 +1,563 @@
# Clear out all vpaths, then set just one (default vpath) for the main build
# directory.
vpath
vpath % .
# Clear the default suffixes, so that built-in rules are not used.
.SUFFIXES :
SHELL := /bin/sh
CC := @CC@
CXX := @CXX@
# Configuration parameters.
DESTDIR =
BINDIR := $(DESTDIR)@BINDIR@
INCLUDEDIR := $(DESTDIR)@INCLUDEDIR@
LIBDIR := $(DESTDIR)@LIBDIR@
DATADIR := $(DESTDIR)@DATADIR@
MANDIR := $(DESTDIR)@MANDIR@
srcroot := @srcroot@
objroot := @objroot@
abs_srcroot := @abs_srcroot@
abs_objroot := @abs_objroot@
# Build parameters.
CPPFLAGS := @CPPFLAGS@ -I$(srcroot)include -I$(objroot)include
CONFIGURE_CFLAGS := @CONFIGURE_CFLAGS@
SPECIFIED_CFLAGS := @SPECIFIED_CFLAGS@
EXTRA_CFLAGS := @EXTRA_CFLAGS@
CFLAGS := $(strip $(CONFIGURE_CFLAGS) $(SPECIFIED_CFLAGS) $(EXTRA_CFLAGS))
CONFIGURE_CXXFLAGS := @CONFIGURE_CXXFLAGS@
SPECIFIED_CXXFLAGS := @SPECIFIED_CXXFLAGS@
EXTRA_CXXFLAGS := @EXTRA_CXXFLAGS@
CXXFLAGS := $(strip $(CONFIGURE_CXXFLAGS) $(SPECIFIED_CXXFLAGS) $(EXTRA_CXXFLAGS))
LDFLAGS := @LDFLAGS@
EXTRA_LDFLAGS := @EXTRA_LDFLAGS@
LIBS := @LIBS@
RPATH_EXTRA := @RPATH_EXTRA@
SO := @so@
IMPORTLIB := @importlib@
O := @o@
A := @a@
EXE := @exe@
LIBPREFIX := @libprefix@
REV := @rev@
install_suffix := @install_suffix@
ABI := @abi@
XSLTPROC := @XSLTPROC@
AUTOCONF := @AUTOCONF@
_RPATH = @RPATH@
RPATH = $(if $(1),$(call _RPATH,$(1)))
cfghdrs_in := $(addprefix $(srcroot),@cfghdrs_in@)
cfghdrs_out := @cfghdrs_out@
cfgoutputs_in := $(addprefix $(srcroot),@cfgoutputs_in@)
cfgoutputs_out := @cfgoutputs_out@
enable_autogen := @enable_autogen@
enable_prof := @enable_prof@
enable_zone_allocator := @enable_zone_allocator@
MALLOC_CONF := @JEMALLOC_CPREFIX@MALLOC_CONF
link_whole_archive := @link_whole_archive@
DSO_LDFLAGS = @DSO_LDFLAGS@
SOREV = @SOREV@
PIC_CFLAGS = @PIC_CFLAGS@
CTARGET = @CTARGET@
LDTARGET = @LDTARGET@
TEST_LD_MODE = @TEST_LD_MODE@
MKLIB = @MKLIB@
AR = @AR@
ARFLAGS = @ARFLAGS@
DUMP_SYMS = @DUMP_SYMS@
AWK := @AWK@
CC_MM = @CC_MM@
LM := @LM@
INSTALL = @INSTALL@
ifeq (macho, $(ABI))
TEST_LIBRARY_PATH := DYLD_FALLBACK_LIBRARY_PATH="$(objroot)lib"
else
ifeq (pecoff, $(ABI))
TEST_LIBRARY_PATH := PATH="$(PATH):$(objroot)lib"
else
TEST_LIBRARY_PATH :=
endif
endif
LIBJEMALLOC := $(LIBPREFIX)jemalloc$(install_suffix)
# Lists of files.
BINS := $(objroot)bin/jemalloc-config $(objroot)bin/jemalloc.sh $(objroot)bin/jeprof
C_HDRS := $(objroot)include/jemalloc/jemalloc$(install_suffix).h
C_SRCS := $(srcroot)src/jemalloc.c \
$(srcroot)src/arena.c \
$(srcroot)src/background_thread.c \
$(srcroot)src/base.c \
$(srcroot)src/bitmap.c \
$(srcroot)src/ckh.c \
$(srcroot)src/ctl.c \
$(srcroot)src/extent.c \
$(srcroot)src/extent_dss.c \
$(srcroot)src/extent_mmap.c \
$(srcroot)src/hash.c \
$(srcroot)src/hooks.c \
$(srcroot)src/large.c \
$(srcroot)src/malloc_io.c \
$(srcroot)src/mutex.c \
$(srcroot)src/mutex_pool.c \
$(srcroot)src/nstime.c \
$(srcroot)src/pages.c \
$(srcroot)src/prng.c \
$(srcroot)src/prof.c \
$(srcroot)src/rtree.c \
$(srcroot)src/stats.c \
$(srcroot)src/spin.c \
$(srcroot)src/sz.c \
$(srcroot)src/tcache.c \
$(srcroot)src/ticker.c \
$(srcroot)src/tsd.c \
$(srcroot)src/witness.c
ifeq ($(enable_zone_allocator), 1)
C_SRCS += $(srcroot)src/zone.c
endif
ifeq ($(IMPORTLIB),$(SO))
STATIC_LIBS := $(objroot)lib/$(LIBJEMALLOC).$(A)
endif
ifdef PIC_CFLAGS
STATIC_LIBS += $(objroot)lib/$(LIBJEMALLOC)_pic.$(A)
else
STATIC_LIBS += $(objroot)lib/$(LIBJEMALLOC)_s.$(A)
endif
DSOS := $(objroot)lib/$(LIBJEMALLOC).$(SOREV)
ifneq ($(SOREV),$(SO))
DSOS += $(objroot)lib/$(LIBJEMALLOC).$(SO)
endif
ifeq (1, $(link_whole_archive))
LJEMALLOC := -Wl,--whole-archive -L$(objroot)lib -l$(LIBJEMALLOC) -Wl,--no-whole-archive
else
LJEMALLOC := $(objroot)lib/$(LIBJEMALLOC).$(IMPORTLIB)
endif
PC := $(objroot)jemalloc.pc
MAN3 := $(objroot)doc/jemalloc$(install_suffix).3
DOCS_XML := $(objroot)doc/jemalloc$(install_suffix).xml
DOCS_HTML := $(DOCS_XML:$(objroot)%.xml=$(objroot)%.html)
DOCS_MAN3 := $(DOCS_XML:$(objroot)%.xml=$(objroot)%.3)
DOCS := $(DOCS_HTML) $(DOCS_MAN3)
C_TESTLIB_SRCS := $(srcroot)test/src/btalloc.c $(srcroot)test/src/btalloc_0.c \
$(srcroot)test/src/btalloc_1.c $(srcroot)test/src/math.c \
$(srcroot)test/src/mtx.c $(srcroot)test/src/mq.c \
$(srcroot)test/src/SFMT.c $(srcroot)test/src/test.c \
$(srcroot)test/src/thd.c $(srcroot)test/src/timer.c
ifeq (1, $(link_whole_archive))
C_UTIL_INTEGRATION_SRCS :=
C_UTIL_CPP_SRCS :=
else
C_UTIL_INTEGRATION_SRCS := $(srcroot)src/nstime.c $(srcroot)src/malloc_io.c
C_UTIL_CPP_SRCS := $(srcroot)src/nstime.c $(srcroot)src/malloc_io.c
endif
TESTS_UNIT := \
$(srcroot)test/unit/a0.c \
$(srcroot)test/unit/arena_reset.c \
$(srcroot)test/unit/atomic.c \
$(srcroot)test/unit/background_thread.c \
$(srcroot)test/unit/base.c \
$(srcroot)test/unit/bitmap.c \
$(srcroot)test/unit/ckh.c \
$(srcroot)test/unit/decay.c \
$(srcroot)test/unit/extent_quantize.c \
$(srcroot)test/unit/fork.c \
$(srcroot)test/unit/hash.c \
$(srcroot)test/unit/hooks.c \
$(srcroot)test/unit/junk.c \
$(srcroot)test/unit/junk_alloc.c \
$(srcroot)test/unit/junk_free.c \
$(srcroot)test/unit/mallctl.c \
$(srcroot)test/unit/malloc_io.c \
$(srcroot)test/unit/math.c \
$(srcroot)test/unit/mq.c \
$(srcroot)test/unit/mtx.c \
$(srcroot)test/unit/pack.c \
$(srcroot)test/unit/pages.c \
$(srcroot)test/unit/ph.c \
$(srcroot)test/unit/prng.c \
$(srcroot)test/unit/prof_accum.c \
$(srcroot)test/unit/prof_active.c \
$(srcroot)test/unit/prof_gdump.c \
$(srcroot)test/unit/prof_idump.c \
$(srcroot)test/unit/prof_reset.c \
$(srcroot)test/unit/prof_tctx.c \
$(srcroot)test/unit/prof_thread_name.c \
$(srcroot)test/unit/ql.c \
$(srcroot)test/unit/qr.c \
$(srcroot)test/unit/rb.c \
$(srcroot)test/unit/retained.c \
$(srcroot)test/unit/rtree.c \
$(srcroot)test/unit/SFMT.c \
$(srcroot)test/unit/size_classes.c \
$(srcroot)test/unit/slab.c \
$(srcroot)test/unit/smoothstep.c \
$(srcroot)test/unit/spin.c \
$(srcroot)test/unit/stats.c \
$(srcroot)test/unit/stats_print.c \
$(srcroot)test/unit/ticker.c \
$(srcroot)test/unit/nstime.c \
$(srcroot)test/unit/tsd.c \
$(srcroot)test/unit/witness.c \
$(srcroot)test/unit/zero.c
ifeq (@enable_prof@, 1)
TESTS_UNIT += \
$(srcroot)test/unit/arena_reset_prof.c
endif
TESTS_INTEGRATION := $(srcroot)test/integration/aligned_alloc.c \
$(srcroot)test/integration/allocated.c \
$(srcroot)test/integration/extent.c \
$(srcroot)test/integration/mallocx.c \
$(srcroot)test/integration/MALLOCX_ARENA.c \
$(srcroot)test/integration/overflow.c \
$(srcroot)test/integration/posix_memalign.c \
$(srcroot)test/integration/rallocx.c \
$(srcroot)test/integration/sdallocx.c \
$(srcroot)test/integration/thread_arena.c \
$(srcroot)test/integration/thread_tcache_enabled.c \
$(srcroot)test/integration/xallocx.c
ifeq (@enable_cxx@, 1)
CPP_SRCS := $(srcroot)src/jemalloc_cpp.cpp
TESTS_INTEGRATION_CPP := $(srcroot)test/integration/cpp/basic.cpp
else
CPP_SRCS :=
TESTS_INTEGRATION_CPP :=
endif
TESTS_STRESS := $(srcroot)test/stress/microbench.c
TESTS := $(TESTS_UNIT) $(TESTS_INTEGRATION) $(TESTS_INTEGRATION_CPP) $(TESTS_STRESS)
PRIVATE_NAMESPACE_HDRS := $(objroot)include/jemalloc/internal/private_namespace.h $(objroot)include/jemalloc/internal/private_namespace_jet.h
PRIVATE_NAMESPACE_GEN_HDRS := $(PRIVATE_NAMESPACE_HDRS:%.h=%.gen.h)
C_SYM_OBJS := $(C_SRCS:$(srcroot)%.c=$(objroot)%.sym.$(O))
C_SYMS := $(C_SRCS:$(srcroot)%.c=$(objroot)%.sym)
C_OBJS := $(C_SRCS:$(srcroot)%.c=$(objroot)%.$(O))
CPP_OBJS := $(CPP_SRCS:$(srcroot)%.cpp=$(objroot)%.$(O))
C_PIC_OBJS := $(C_SRCS:$(srcroot)%.c=$(objroot)%.pic.$(O))
CPP_PIC_OBJS := $(CPP_SRCS:$(srcroot)%.cpp=$(objroot)%.pic.$(O))
C_JET_SYM_OBJS := $(C_SRCS:$(srcroot)%.c=$(objroot)%.jet.sym.$(O))
C_JET_SYMS := $(C_SRCS:$(srcroot)%.c=$(objroot)%.jet.sym)
C_JET_OBJS := $(C_SRCS:$(srcroot)%.c=$(objroot)%.jet.$(O))
C_TESTLIB_UNIT_OBJS := $(C_TESTLIB_SRCS:$(srcroot)%.c=$(objroot)%.unit.$(O))
C_TESTLIB_INTEGRATION_OBJS := $(C_TESTLIB_SRCS:$(srcroot)%.c=$(objroot)%.integration.$(O))
C_UTIL_INTEGRATION_OBJS := $(C_UTIL_INTEGRATION_SRCS:$(srcroot)%.c=$(objroot)%.integration.$(O))
C_TESTLIB_STRESS_OBJS := $(C_TESTLIB_SRCS:$(srcroot)%.c=$(objroot)%.stress.$(O))
C_TESTLIB_OBJS := $(C_TESTLIB_UNIT_OBJS) $(C_TESTLIB_INTEGRATION_OBJS) $(C_UTIL_INTEGRATION_OBJS) $(C_TESTLIB_STRESS_OBJS)
TESTS_UNIT_OBJS := $(TESTS_UNIT:$(srcroot)%.c=$(objroot)%.$(O))
TESTS_INTEGRATION_OBJS := $(TESTS_INTEGRATION:$(srcroot)%.c=$(objroot)%.$(O))
TESTS_INTEGRATION_CPP_OBJS := $(TESTS_INTEGRATION_CPP:$(srcroot)%.cpp=$(objroot)%.$(O))
TESTS_STRESS_OBJS := $(TESTS_STRESS:$(srcroot)%.c=$(objroot)%.$(O))
TESTS_OBJS := $(TESTS_UNIT_OBJS) $(TESTS_INTEGRATION_OBJS) $(TESTS_STRESS_OBJS)
TESTS_CPP_OBJS := $(TESTS_INTEGRATION_CPP_OBJS)
.PHONY: all dist build_doc_html build_doc_man build_doc
.PHONY: install_bin install_include install_lib
.PHONY: install_doc_html install_doc_man install_doc install
.PHONY: tests check clean distclean relclean
.SECONDARY : $(PRIVATE_NAMESPACE_GEN_HDRS) $(TESTS_OBJS) $(TESTS_CPP_OBJS)
# Default target.
all: build_lib
dist: build_doc
$(objroot)doc/%.html : $(objroot)doc/%.xml $(srcroot)doc/stylesheet.xsl $(objroot)doc/html.xsl
$(XSLTPROC) -o $@ $(objroot)doc/html.xsl $<
$(objroot)doc/%.3 : $(objroot)doc/%.xml $(srcroot)doc/stylesheet.xsl $(objroot)doc/manpages.xsl
$(XSLTPROC) -o $@ $(objroot)doc/manpages.xsl $<
build_doc_html: $(DOCS_HTML)
build_doc_man: $(DOCS_MAN3)
build_doc: $(DOCS)
#
# Include generated dependency files.
#
ifdef CC_MM
-include $(C_SYM_OBJS:%.$(O)=%.d)
-include $(C_OBJS:%.$(O)=%.d)
-include $(CPP_OBJS:%.$(O)=%.d)
-include $(C_PIC_OBJS:%.$(O)=%.d)
-include $(CPP_PIC_OBJS:%.$(O)=%.d)
-include $(C_JET_SYM_OBJS:%.$(O)=%.d)
-include $(C_JET_OBJS:%.$(O)=%.d)
-include $(C_TESTLIB_OBJS:%.$(O)=%.d)
-include $(TESTS_OBJS:%.$(O)=%.d)
-include $(TESTS_CPP_OBJS:%.$(O)=%.d)
endif
$(C_SYM_OBJS): $(objroot)src/%.sym.$(O): $(srcroot)src/%.c
$(C_SYM_OBJS): CPPFLAGS += -DJEMALLOC_NO_PRIVATE_NAMESPACE
$(C_SYMS): $(objroot)src/%.sym: $(objroot)src/%.sym.$(O)
$(C_OBJS): $(objroot)src/%.$(O): $(srcroot)src/%.c
$(CPP_OBJS): $(objroot)src/%.$(O): $(srcroot)src/%.cpp
$(C_PIC_OBJS): $(objroot)src/%.pic.$(O): $(srcroot)src/%.c
$(C_PIC_OBJS): CFLAGS += $(PIC_CFLAGS)
$(CPP_PIC_OBJS): $(objroot)src/%.pic.$(O): $(srcroot)src/%.cpp
$(CPP_PIC_OBJS): CXXFLAGS += $(PIC_CFLAGS)
$(C_JET_SYM_OBJS): $(objroot)src/%.jet.sym.$(O): $(srcroot)src/%.c
$(C_JET_SYM_OBJS): CPPFLAGS += -DJEMALLOC_JET -DJEMALLOC_NO_PRIVATE_NAMESPACE
$(C_JET_SYMS): $(objroot)src/%.jet.sym: $(objroot)src/%.jet.sym.$(O)
$(C_JET_OBJS): $(objroot)src/%.jet.$(O): $(srcroot)src/%.c
$(C_JET_OBJS): CPPFLAGS += -DJEMALLOC_JET
$(C_TESTLIB_UNIT_OBJS): $(objroot)test/src/%.unit.$(O): $(srcroot)test/src/%.c
$(C_TESTLIB_UNIT_OBJS): CPPFLAGS += -DJEMALLOC_UNIT_TEST
$(C_TESTLIB_INTEGRATION_OBJS): $(objroot)test/src/%.integration.$(O): $(srcroot)test/src/%.c
$(C_TESTLIB_INTEGRATION_OBJS): CPPFLAGS += -DJEMALLOC_INTEGRATION_TEST
$(C_UTIL_INTEGRATION_OBJS): $(objroot)src/%.integration.$(O): $(srcroot)src/%.c
$(C_TESTLIB_STRESS_OBJS): $(objroot)test/src/%.stress.$(O): $(srcroot)test/src/%.c
$(C_TESTLIB_STRESS_OBJS): CPPFLAGS += -DJEMALLOC_STRESS_TEST -DJEMALLOC_STRESS_TESTLIB
$(C_TESTLIB_OBJS): CPPFLAGS += -I$(srcroot)test/include -I$(objroot)test/include
$(TESTS_UNIT_OBJS): CPPFLAGS += -DJEMALLOC_UNIT_TEST
$(TESTS_INTEGRATION_OBJS): CPPFLAGS += -DJEMALLOC_INTEGRATION_TEST
$(TESTS_INTEGRATION_CPP_OBJS): CPPFLAGS += -DJEMALLOC_INTEGRATION_CPP_TEST
$(TESTS_STRESS_OBJS): CPPFLAGS += -DJEMALLOC_STRESS_TEST
$(TESTS_OBJS): $(objroot)test/%.$(O): $(srcroot)test/%.c
$(TESTS_CPP_OBJS): $(objroot)test/%.$(O): $(srcroot)test/%.cpp
$(TESTS_OBJS): CPPFLAGS += -I$(srcroot)test/include -I$(objroot)test/include
$(TESTS_CPP_OBJS): CPPFLAGS += -I$(srcroot)test/include -I$(objroot)test/include
ifneq ($(IMPORTLIB),$(SO))
$(CPP_OBJS) $(C_SYM_OBJS) $(C_OBJS) $(C_JET_SYM_OBJS) $(C_JET_OBJS): CPPFLAGS += -DDLLEXPORT
endif
# Dependencies.
ifndef CC_MM
HEADER_DIRS = $(srcroot)include/jemalloc/internal \
$(objroot)include/jemalloc $(objroot)include/jemalloc/internal
HEADERS = $(filter-out $(PRIVATE_NAMESPACE_HDRS),$(wildcard $(foreach dir,$(HEADER_DIRS),$(dir)/*.h)))
$(C_SYM_OBJS) $(C_OBJS) $(CPP_OBJS) $(C_PIC_OBJS) $(CPP_PIC_OBJS) $(C_JET_SYM_OBJS) $(C_JET_OBJS) $(C_TESTLIB_OBJS) $(TESTS_OBJS) $(TESTS_CPP_OBJS): $(HEADERS)
$(TESTS_OBJS) $(TESTS_CPP_OBJS): $(objroot)test/include/test/jemalloc_test.h
endif
$(C_OBJS) $(CPP_OBJS) $(C_PIC_OBJS) $(CPP_PIC_OBJS) $(C_TESTLIB_INTEGRATION_OBJS) $(C_UTIL_INTEGRATION_OBJS) $(TESTS_INTEGRATION_OBJS) $(TESTS_INTEGRATION_CPP_OBJS): $(objroot)include/jemalloc/internal/private_namespace.h
$(C_JET_OBJS) $(C_TESTLIB_UNIT_OBJS) $(C_TESTLIB_STRESS_OBJS) $(TESTS_UNIT_OBJS) $(TESTS_STRESS_OBJS): $(objroot)include/jemalloc/internal/private_namespace_jet.h
$(C_SYM_OBJS) $(C_OBJS) $(C_PIC_OBJS) $(C_JET_SYM_OBJS) $(C_JET_OBJS) $(C_TESTLIB_OBJS) $(TESTS_OBJS): %.$(O):
@mkdir -p $(@D)
$(CC) $(CFLAGS) -c $(CPPFLAGS) $(CTARGET) $<
ifdef CC_MM
@$(CC) -MM $(CPPFLAGS) -MT $@ -o $(@:%.$(O)=%.d) $<
endif
$(C_SYMS): %.sym:
@mkdir -p $(@D)
$(DUMP_SYMS) $< | $(AWK) -f $(objroot)include/jemalloc/internal/private_symbols.awk > $@
$(C_JET_SYMS): %.sym:
@mkdir -p $(@D)
$(DUMP_SYMS) $< | $(AWK) -f $(objroot)include/jemalloc/internal/private_symbols_jet.awk > $@
$(objroot)include/jemalloc/internal/private_namespace.gen.h: $(C_SYMS)
$(SHELL) $(srcroot)include/jemalloc/internal/private_namespace.sh $^ > $@
$(objroot)include/jemalloc/internal/private_namespace_jet.gen.h: $(C_JET_SYMS)
$(SHELL) $(srcroot)include/jemalloc/internal/private_namespace.sh $^ > $@
%.h: %.gen.h
@if ! `cmp -s $< $@` ; then echo "cp $< $<"; cp $< $@ ; fi
$(CPP_OBJS) $(CPP_PIC_OBJS) $(TESTS_CPP_OBJS): %.$(O):
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) -c $(CPPFLAGS) $(CTARGET) $<
ifdef CC_MM
@$(CXX) -MM $(CPPFLAGS) -MT $@ -o $(@:%.$(O)=%.d) $<
endif
ifneq ($(SOREV),$(SO))
%.$(SO) : %.$(SOREV)
@mkdir -p $(@D)
ln -sf $(<F) $@
endif
$(objroot)lib/$(LIBJEMALLOC).$(SOREV) : $(if $(PIC_CFLAGS),$(C_PIC_OBJS),$(C_OBJS)) $(if $(PIC_CFLAGS),$(CPP_PIC_OBJS),$(CPP_OBJS))
@mkdir -p $(@D)
$(CC) $(DSO_LDFLAGS) $(call RPATH,$(RPATH_EXTRA)) $(LDTARGET) $+ $(LDFLAGS) $(LIBS) $(EXTRA_LDFLAGS)
$(objroot)lib/$(LIBJEMALLOC)_pic.$(A) : $(C_PIC_OBJS) $(CPP_PIC_OBJS)
$(objroot)lib/$(LIBJEMALLOC).$(A) : $(C_OBJS) $(CPP_OBJS)
$(objroot)lib/$(LIBJEMALLOC)_s.$(A) : $(C_OBJS) $(CPP_OBJS)
$(STATIC_LIBS):
@mkdir -p $(@D)
$(AR) $(ARFLAGS)@AROUT@ $+
$(objroot)test/unit/%$(EXE): $(objroot)test/unit/%.$(O) $(C_JET_OBJS) $(C_TESTLIB_UNIT_OBJS)
@mkdir -p $(@D)
$(CC) $(LDTARGET) $(filter %.$(O),$^) $(call RPATH,$(objroot)lib) $(LDFLAGS) $(filter-out -lm,$(LIBS)) $(LM) $(EXTRA_LDFLAGS)
$(objroot)test/integration/%$(EXE): $(objroot)test/integration/%.$(O) $(C_TESTLIB_INTEGRATION_OBJS) $(C_UTIL_INTEGRATION_OBJS) $(objroot)lib/$(LIBJEMALLOC).$(IMPORTLIB)
@mkdir -p $(@D)
$(CC) $(TEST_LD_MODE) $(LDTARGET) $(filter %.$(O),$^) $(call RPATH,$(objroot)lib) $(LJEMALLOC) $(LDFLAGS) $(filter-out -lm,$(filter -lrt -lpthread -lstdc++,$(LIBS))) $(LM) $(EXTRA_LDFLAGS)
$(objroot)test/integration/cpp/%$(EXE): $(objroot)test/integration/cpp/%.$(O) $(C_TESTLIB_INTEGRATION_OBJS) $(C_UTIL_INTEGRATION_OBJS) $(objroot)lib/$(LIBJEMALLOC).$(IMPORTLIB)
@mkdir -p $(@D)
$(CXX) $(LDTARGET) $(filter %.$(O),$^) $(call RPATH,$(objroot)lib) $(objroot)lib/$(LIBJEMALLOC).$(IMPORTLIB) $(LDFLAGS) $(filter-out -lm,$(LIBS)) -lm $(EXTRA_LDFLAGS)
$(objroot)test/stress/%$(EXE): $(objroot)test/stress/%.$(O) $(C_JET_OBJS) $(C_TESTLIB_STRESS_OBJS) $(objroot)lib/$(LIBJEMALLOC).$(IMPORTLIB)
@mkdir -p $(@D)
$(CC) $(TEST_LD_MODE) $(LDTARGET) $(filter %.$(O),$^) $(call RPATH,$(objroot)lib) $(objroot)lib/$(LIBJEMALLOC).$(IMPORTLIB) $(LDFLAGS) $(filter-out -lm,$(LIBS)) $(LM) $(EXTRA_LDFLAGS)
build_lib_shared: $(DSOS)
build_lib_static: $(STATIC_LIBS)
build_lib: build_lib_shared build_lib_static
install_bin:
$(INSTALL) -d $(BINDIR)
@for b in $(BINS); do \
echo "$(INSTALL) -m 755 $$b $(BINDIR)"; \
$(INSTALL) -m 755 $$b $(BINDIR); \
done
install_include:
$(INSTALL) -d $(INCLUDEDIR)/jemalloc
@for h in $(C_HDRS); do \
echo "$(INSTALL) -m 644 $$h $(INCLUDEDIR)/jemalloc"; \
$(INSTALL) -m 644 $$h $(INCLUDEDIR)/jemalloc; \
done
install_lib_shared: $(DSOS)
$(INSTALL) -d $(LIBDIR)
$(INSTALL) -m 755 $(objroot)lib/$(LIBJEMALLOC).$(SOREV) $(LIBDIR)
ifneq ($(SOREV),$(SO))
ln -sf $(LIBJEMALLOC).$(SOREV) $(LIBDIR)/$(LIBJEMALLOC).$(SO)
endif
install_lib_static: $(STATIC_LIBS)
$(INSTALL) -d $(LIBDIR)
@for l in $(STATIC_LIBS); do \
echo "$(INSTALL) -m 755 $$l $(LIBDIR)"; \
$(INSTALL) -m 755 $$l $(LIBDIR); \
done
install_lib_pc: $(PC)
$(INSTALL) -d $(LIBDIR)/pkgconfig
@for l in $(PC); do \
echo "$(INSTALL) -m 644 $$l $(LIBDIR)/pkgconfig"; \
$(INSTALL) -m 644 $$l $(LIBDIR)/pkgconfig; \
done
install_lib: install_lib_shared install_lib_static install_lib_pc
install_doc_html:
$(INSTALL) -d $(DATADIR)/doc/jemalloc$(install_suffix)
@for d in $(DOCS_HTML); do \
echo "$(INSTALL) -m 644 $$d $(DATADIR)/doc/jemalloc$(install_suffix)"; \
$(INSTALL) -m 644 $$d $(DATADIR)/doc/jemalloc$(install_suffix); \
done
install_doc_man:
$(INSTALL) -d $(MANDIR)/man3
@for d in $(DOCS_MAN3); do \
echo "$(INSTALL) -m 644 $$d $(MANDIR)/man3"; \
$(INSTALL) -m 644 $$d $(MANDIR)/man3; \
done
install_doc: install_doc_html install_doc_man
install: install_bin install_include install_lib install_doc
tests_unit: $(TESTS_UNIT:$(srcroot)%.c=$(objroot)%$(EXE))
tests_integration: $(TESTS_INTEGRATION:$(srcroot)%.c=$(objroot)%$(EXE)) $(TESTS_INTEGRATION_CPP:$(srcroot)%.cpp=$(objroot)%$(EXE))
tests_stress: $(TESTS_STRESS:$(srcroot)%.c=$(objroot)%$(EXE))
tests: tests_unit tests_integration tests_stress
check_unit_dir:
@mkdir -p $(objroot)test/unit
check_integration_dir:
@mkdir -p $(objroot)test/integration
stress_dir:
@mkdir -p $(objroot)test/stress
check_dir: check_unit_dir check_integration_dir
check_unit: tests_unit check_unit_dir
$(SHELL) $(objroot)test/test.sh $(TESTS_UNIT:$(srcroot)%.c=$(objroot)%)
check_integration_prof: tests_integration check_integration_dir
ifeq ($(enable_prof), 1)
$(MALLOC_CONF)="prof:true" $(SHELL) $(objroot)test/test.sh $(TESTS_INTEGRATION:$(srcroot)%.c=$(objroot)%) $(TESTS_INTEGRATION_CPP:$(srcroot)%.cpp=$(objroot)%)
$(MALLOC_CONF)="prof:true,prof_active:false" $(SHELL) $(objroot)test/test.sh $(TESTS_INTEGRATION:$(srcroot)%.c=$(objroot)%) $(TESTS_INTEGRATION_CPP:$(srcroot)%.cpp=$(objroot)%)
endif
check_integration_decay: tests_integration check_integration_dir
$(MALLOC_CONF)="dirty_decay_ms:-1,muzzy_decay_ms:-1" $(SHELL) $(objroot)test/test.sh $(TESTS_INTEGRATION:$(srcroot)%.c=$(objroot)%) $(TESTS_INTEGRATION_CPP:$(srcroot)%.cpp=$(objroot)%)
$(MALLOC_CONF)="dirty_decay_ms:0,muzzy_decay_ms:0" $(SHELL) $(objroot)test/test.sh $(TESTS_INTEGRATION:$(srcroot)%.c=$(objroot)%) $(TESTS_INTEGRATION_CPP:$(srcroot)%.cpp=$(objroot)%)
check_integration: tests_integration check_integration_dir
$(SHELL) $(objroot)test/test.sh $(TESTS_INTEGRATION:$(srcroot)%.c=$(objroot)%) $(TESTS_INTEGRATION_CPP:$(srcroot)%.cpp=$(objroot)%)
stress: tests_stress stress_dir
$(SHELL) $(objroot)test/test.sh $(TESTS_STRESS:$(srcroot)%.c=$(objroot)%)
check: check_unit check_integration check_integration_decay check_integration_prof
clean:
rm -f $(PRIVATE_NAMESPACE_HDRS)
rm -f $(PRIVATE_NAMESPACE_GEN_HDRS)
rm -f $(C_SYM_OBJS)
rm -f $(C_SYMS)
rm -f $(C_OBJS)
rm -f $(CPP_OBJS)
rm -f $(C_PIC_OBJS)
rm -f $(CPP_PIC_OBJS)
rm -f $(C_JET_SYM_OBJS)
rm -f $(C_JET_SYMS)
rm -f $(C_JET_OBJS)
rm -f $(C_TESTLIB_OBJS)
rm -f $(C_SYM_OBJS:%.$(O)=%.d)
rm -f $(C_OBJS:%.$(O)=%.d)
rm -f $(CPP_OBJS:%.$(O)=%.d)
rm -f $(C_PIC_OBJS:%.$(O)=%.d)
rm -f $(CPP_PIC_OBJS:%.$(O)=%.d)
rm -f $(C_JET_SYM_OBJS:%.$(O)=%.d)
rm -f $(C_JET_OBJS:%.$(O)=%.d)
rm -f $(C_TESTLIB_OBJS:%.$(O)=%.d)
rm -f $(TESTS_OBJS:%.$(O)=%$(EXE))
rm -f $(TESTS_OBJS)
rm -f $(TESTS_OBJS:%.$(O)=%.d)
rm -f $(TESTS_OBJS:%.$(O)=%.out)
rm -f $(TESTS_CPP_OBJS:%.$(O)=%$(EXE))
rm -f $(TESTS_CPP_OBJS)
rm -f $(TESTS_CPP_OBJS:%.$(O)=%.d)
rm -f $(TESTS_CPP_OBJS:%.$(O)=%.out)
rm -f $(DSOS) $(STATIC_LIBS)
distclean: clean
rm -f $(objroot)bin/jemalloc-config
rm -f $(objroot)bin/jemalloc.sh
rm -f $(objroot)bin/jeprof
rm -f $(objroot)config.log
rm -f $(objroot)config.status
rm -f $(objroot)config.stamp
rm -f $(cfghdrs_out)
rm -f $(cfgoutputs_out)
relclean: distclean
rm -f $(objroot)configure
rm -f $(objroot)VERSION
rm -f $(DOCS_HTML)
rm -f $(DOCS_MAN3)
#===============================================================================
# Re-configuration rules.
ifeq ($(enable_autogen), 1)
$(srcroot)configure : $(srcroot)configure.ac
cd ./$(srcroot) && $(AUTOCONF)
$(objroot)config.status : $(srcroot)configure
./$(objroot)config.status --recheck
$(srcroot)config.stamp.in : $(srcroot)configure.ac
echo stamp > $(srcroot)config.stamp.in
$(objroot)config.stamp : $(cfgoutputs_in) $(cfghdrs_in) $(srcroot)configure
./$(objroot)config.status
@touch $@
# There must be some action in order for make to re-read Makefile when it is
# out of date.
$(cfgoutputs_out) $(cfghdrs_out) : $(objroot)config.stamp
@true
endif

20
jemalloc/README Normal file
View File

@ -0,0 +1,20 @@
jemalloc is a general purpose malloc(3) implementation that emphasizes
fragmentation avoidance and scalable concurrency support. jemalloc first came
into use as the FreeBSD libc allocator in 2005, and since then it has found its
way into numerous applications that rely on its predictable behavior. In 2010
jemalloc development efforts broadened to include developer support features
such as heap profiling and extensive monitoring/tuning hooks. Modern jemalloc
releases continue to be integrated back into FreeBSD, and therefore versatility
remains critical. Ongoing development efforts trend toward making jemalloc
among the best allocators for a broad range of demanding applications, and
eliminating/mitigating weaknesses that have practical repercussions for real
world applications.
The COPYING file contains copyright and licensing information.
The INSTALL file contains information on how to configure, build, and install
jemalloc.
The ChangeLog file contains a brief summary of changes for each release.
URL: http://jemalloc.net/

17
jemalloc/autogen.sh Executable file
View File

@ -0,0 +1,17 @@
#!/bin/sh
for i in autoconf; do
echo "$i"
$i
if [ $? -ne 0 ]; then
echo "Error $? in $i"
exit 1
fi
done
echo "./configure --enable-autogen $@"
./configure --enable-autogen $@
if [ $? -ne 0 ]; then
echo "Error $? in ./configure"
exit 1
fi

View File

@ -0,0 +1,83 @@
#!/bin/sh
usage() {
cat <<EOF
Usage:
@BINDIR@/jemalloc-config <option>
Options:
--help | -h : Print usage.
--version : Print jemalloc version.
--revision : Print shared library revision number.
--config : Print configure options used to build jemalloc.
--prefix : Print installation directory prefix.
--bindir : Print binary installation directory.
--datadir : Print data installation directory.
--includedir : Print include installation directory.
--libdir : Print library installation directory.
--mandir : Print manual page installation directory.
--cc : Print compiler used to build jemalloc.
--cflags : Print compiler flags used to build jemalloc.
--cppflags : Print preprocessor flags used to build jemalloc.
--cxxflags : Print C++ compiler flags used to build jemalloc.
--ldflags : Print library flags used to build jemalloc.
--libs : Print libraries jemalloc was linked against.
EOF
}
prefix="@prefix@"
exec_prefix="@exec_prefix@"
case "$1" in
--help | -h)
usage
exit 0
;;
--version)
echo "@jemalloc_version@"
;;
--revision)
echo "@rev@"
;;
--config)
echo "@CONFIG@"
;;
--prefix)
echo "@PREFIX@"
;;
--bindir)
echo "@BINDIR@"
;;
--datadir)
echo "@DATADIR@"
;;
--includedir)
echo "@INCLUDEDIR@"
;;
--libdir)
echo "@LIBDIR@"
;;
--mandir)
echo "@MANDIR@"
;;
--cc)
echo "@CC@"
;;
--cflags)
echo "@CFLAGS@"
;;
--cppflags)
echo "@CPPFLAGS@"
;;
--cxxflags)
echo "@CXXFLAGS@"
;;
--ldflags)
echo "@LDFLAGS@ @EXTRA_LDFLAGS@"
;;
--libs)
echo "@LIBS@"
;;
*)
usage
exit 1
esac

View File

@ -0,0 +1,9 @@
#!/bin/sh
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
@LD_PRELOAD_VAR@=${libdir}/libjemalloc.@SOREV@
export @LD_PRELOAD_VAR@
exec "$@"

5622
jemalloc/bin/jeprof.in Normal file

File diff suppressed because it is too large Load Diff

1462
jemalloc/build-aux/config.guess vendored Executable file

File diff suppressed because it is too large Load Diff

1825
jemalloc/build-aux/config.sub vendored Executable file

File diff suppressed because it is too large Load Diff

250
jemalloc/build-aux/install-sh Executable file
View File

@ -0,0 +1,250 @@
#! /bin/sh
#
# install - install a program, script, or datafile
# This comes from X11R5 (mit/util/scripts/install.sh).
#
# Copyright 1991 by the Massachusetts Institute of Technology
#
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation, and that the name of M.I.T. not be used in advertising or
# publicity pertaining to distribution of the software without specific,
# written prior permission. M.I.T. makes no representations about the
# suitability of this software for any purpose. It is provided "as is"
# without express or implied warranty.
#
# Calling this script install-sh is preferred over install.sh, to prevent
# `make' implicit rules from creating a file called install from it
# when there is no Makefile.
#
# This script is compatible with the BSD install script, but was written
# from scratch. It can only install one file at a time, a restriction
# shared with many OS's install programs.
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}"
# put in absolute paths if you don't have them in your path; or use env. vars.
mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
mkdirprog="${MKDIRPROG-mkdir}"
transformbasename=""
transform_arg=""
instcmd="$mvprog"
chmodcmd="$chmodprog 0755"
chowncmd=""
chgrpcmd=""
stripcmd=""
rmcmd="$rmprog -f"
mvcmd="$mvprog"
src=""
dst=""
dir_arg=""
while [ x"$1" != x ]; do
case $1 in
-c) instcmd="$cpprog"
shift
continue;;
-d) dir_arg=true
shift
continue;;
-m) chmodcmd="$chmodprog $2"
shift
shift
continue;;
-o) chowncmd="$chownprog $2"
shift
shift
continue;;
-g) chgrpcmd="$chgrpprog $2"
shift
shift
continue;;
-s) stripcmd="$stripprog"
shift
continue;;
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
shift
continue;;
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
shift
continue;;
*) if [ x"$src" = x ]
then
src=$1
else
# this colon is to work around a 386BSD /bin/sh bug
:
dst=$1
fi
shift
continue;;
esac
done
if [ x"$src" = x ]
then
echo "install: no input file specified"
exit 1
else
true
fi
if [ x"$dir_arg" != x ]; then
dst=$src
src=""
if [ -d $dst ]; then
instcmd=:
else
instcmd=mkdir
fi
else
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if [ -f $src -o -d $src ]
then
true
else
echo "install: $src does not exist"
exit 1
fi
if [ x"$dst" = x ]
then
echo "install: no destination specified"
exit 1
else
true
fi
# If destination is a directory, append the input filename; if your system
# does not like double slashes in filenames, you may need to add some logic
if [ -d $dst ]
then
dst="$dst"/`basename $src`
else
true
fi
fi
## this sed command emulates the dirname command
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
# Make sure that the destination directory exists.
# this part is taken from Noah Friedman's mkinstalldirs script
# Skip lots of stat calls in the usual case.
if [ ! -d "$dstdir" ]; then
defaultIFS='
'
IFS="${IFS-${defaultIFS}}"
oIFS="${IFS}"
# Some sh's can't handle IFS=/ for some reason.
IFS='%'
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
IFS="${oIFS}"
pathcomp=''
while [ $# -ne 0 ] ; do
pathcomp="${pathcomp}${1}"
shift
if [ ! -d "${pathcomp}" ] ;
then
$mkdirprog "${pathcomp}"
else
true
fi
pathcomp="${pathcomp}/"
done
fi
if [ x"$dir_arg" != x ]
then
$doit $instcmd $dst &&
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
else
# If we're going to rename the final executable, determine the name now.
if [ x"$transformarg" = x ]
then
dstfile=`basename $dst`
else
dstfile=`basename $dst $transformbasename |
sed $transformarg`$transformbasename
fi
# don't allow the sed command to completely eliminate the filename
if [ x"$dstfile" = x ]
then
dstfile=`basename $dst`
else
true
fi
# Make a temp file name in the proper directory.
dsttmp=$dstdir/#inst.$$#
# Move or copy the file name to the temp name
$doit $instcmd $src $dsttmp &&
trap "rm -f ${dsttmp}" 0 &&
# and set any options; do chmod last to preserve setuid bits
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $instcmd $src $dsttmp" command.
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
# Now rename the file to the real destination.
$doit $rmcmd -f $dstdir/$dstfile &&
$doit $mvcmd $dsttmp $dstdir/$dstfile
fi &&
exit 0

0
jemalloc/config.stamp.in Normal file
View File

2189
jemalloc/configure.ac Normal file

File diff suppressed because it is too large Load Diff

5
jemalloc/doc/html.xsl.in Normal file
View File

@ -0,0 +1,5 @@
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:import href="@XSLROOT@/html/docbook.xsl"/>
<xsl:import href="@abs_srcroot@doc/stylesheet.xsl"/>
<xsl:output method="xml" encoding="utf-8"/>
</xsl:stylesheet>

3264
jemalloc/doc/jemalloc.xml.in Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,4 @@
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:import href="@XSLROOT@/manpages/docbook.xsl"/>
<xsl:import href="@abs_srcroot@doc/stylesheet.xsl"/>
</xsl:stylesheet>

View File

@ -0,0 +1,10 @@
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:param name="funcsynopsis.style">ansi</xsl:param>
<xsl:param name="function.parens" select="0"/>
<xsl:template match="function">
<xsl:call-template name="inline.monoseq"/>
</xsl:template>
<xsl:template match="mallctl">
<quote><xsl:call-template name="inline.monoseq"/></quote>
</xsl:template>
</xsl:stylesheet>

View File

@ -0,0 +1,96 @@
#ifndef JEMALLOC_INTERNAL_ARENA_EXTERNS_H
#define JEMALLOC_INTERNAL_ARENA_EXTERNS_H
#include "jemalloc/internal/extent_dss.h"
#include "jemalloc/internal/pages.h"
#include "jemalloc/internal/size_classes.h"
#include "jemalloc/internal/stats.h"
extern ssize_t opt_dirty_decay_ms;
extern ssize_t opt_muzzy_decay_ms;
extern const arena_bin_info_t arena_bin_info[NBINS];
extern percpu_arena_mode_t opt_percpu_arena;
extern const char *percpu_arena_mode_names[];
extern const uint64_t h_steps[SMOOTHSTEP_NSTEPS];
extern malloc_mutex_t arenas_lock;
void arena_stats_large_nrequests_add(tsdn_t *tsdn, arena_stats_t *arena_stats,
szind_t szind, uint64_t nrequests);
void arena_stats_mapped_add(tsdn_t *tsdn, arena_stats_t *arena_stats,
size_t size);
void arena_basic_stats_merge(tsdn_t *tsdn, arena_t *arena,
unsigned *nthreads, const char **dss, ssize_t *dirty_decay_ms,
ssize_t *muzzy_decay_ms, size_t *nactive, size_t *ndirty, size_t *nmuzzy);
void arena_stats_merge(tsdn_t *tsdn, arena_t *arena, unsigned *nthreads,
const char **dss, ssize_t *dirty_decay_ms, ssize_t *muzzy_decay_ms,
size_t *nactive, size_t *ndirty, size_t *nmuzzy, arena_stats_t *astats,
malloc_bin_stats_t *bstats, malloc_large_stats_t *lstats);
void arena_extents_dirty_dalloc(tsdn_t *tsdn, arena_t *arena,
extent_hooks_t **r_extent_hooks, extent_t *extent);
#ifdef JEMALLOC_JET
size_t arena_slab_regind(extent_t *slab, szind_t binind, const void *ptr);
#endif
extent_t *arena_extent_alloc_large(tsdn_t *tsdn, arena_t *arena,
size_t usize, size_t alignment, bool *zero);
void arena_extent_dalloc_large_prep(tsdn_t *tsdn, arena_t *arena,
extent_t *extent);
void arena_extent_ralloc_large_shrink(tsdn_t *tsdn, arena_t *arena,
extent_t *extent, size_t oldsize);
void arena_extent_ralloc_large_expand(tsdn_t *tsdn, arena_t *arena,
extent_t *extent, size_t oldsize);
ssize_t arena_dirty_decay_ms_get(arena_t *arena);
bool arena_dirty_decay_ms_set(tsdn_t *tsdn, arena_t *arena, ssize_t decay_ms);
ssize_t arena_muzzy_decay_ms_get(arena_t *arena);
bool arena_muzzy_decay_ms_set(tsdn_t *tsdn, arena_t *arena, ssize_t decay_ms);
void arena_decay(tsdn_t *tsdn, arena_t *arena, bool is_background_thread,
bool all);
void arena_reset(tsd_t *tsd, arena_t *arena);
void arena_destroy(tsd_t *tsd, arena_t *arena);
void arena_tcache_fill_small(tsdn_t *tsdn, arena_t *arena, tcache_t *tcache,
tcache_bin_t *tbin, szind_t binind, uint64_t prof_accumbytes);
void arena_alloc_junk_small(void *ptr, const arena_bin_info_t *bin_info,
bool zero);
typedef void (arena_dalloc_junk_small_t)(void *, const arena_bin_info_t *);
extern arena_dalloc_junk_small_t *JET_MUTABLE arena_dalloc_junk_small;
void *arena_malloc_hard(tsdn_t *tsdn, arena_t *arena, size_t size,
szind_t ind, bool zero);
void *arena_palloc(tsdn_t *tsdn, arena_t *arena, size_t usize,
size_t alignment, bool zero, tcache_t *tcache);
void arena_prof_promote(tsdn_t *tsdn, const void *ptr, size_t usize);
void arena_dalloc_promoted(tsdn_t *tsdn, void *ptr, tcache_t *tcache,
bool slow_path);
void arena_dalloc_bin_junked_locked(tsdn_t *tsdn, arena_t *arena,
extent_t *extent, void *ptr);
void arena_dalloc_small(tsdn_t *tsdn, void *ptr);
bool arena_ralloc_no_move(tsdn_t *tsdn, void *ptr, size_t oldsize, size_t size,
size_t extra, bool zero);
void *arena_ralloc(tsdn_t *tsdn, arena_t *arena, void *ptr, size_t oldsize,
size_t size, size_t alignment, bool zero, tcache_t *tcache);
dss_prec_t arena_dss_prec_get(arena_t *arena);
bool arena_dss_prec_set(arena_t *arena, dss_prec_t dss_prec);
ssize_t arena_dirty_decay_ms_default_get(void);
bool arena_dirty_decay_ms_default_set(ssize_t decay_ms);
ssize_t arena_muzzy_decay_ms_default_get(void);
bool arena_muzzy_decay_ms_default_set(ssize_t decay_ms);
unsigned arena_nthreads_get(arena_t *arena, bool internal);
void arena_nthreads_inc(arena_t *arena, bool internal);
void arena_nthreads_dec(arena_t *arena, bool internal);
size_t arena_extent_sn_next(arena_t *arena);
arena_t *arena_new(tsdn_t *tsdn, unsigned ind, extent_hooks_t *extent_hooks);
void arena_boot(void);
void arena_prefork0(tsdn_t *tsdn, arena_t *arena);
void arena_prefork1(tsdn_t *tsdn, arena_t *arena);
void arena_prefork2(tsdn_t *tsdn, arena_t *arena);
void arena_prefork3(tsdn_t *tsdn, arena_t *arena);
void arena_prefork4(tsdn_t *tsdn, arena_t *arena);
void arena_prefork5(tsdn_t *tsdn, arena_t *arena);
void arena_prefork6(tsdn_t *tsdn, arena_t *arena);
void arena_postfork_parent(tsdn_t *tsdn, arena_t *arena);
void arena_postfork_child(tsdn_t *tsdn, arena_t *arena);
#endif /* JEMALLOC_INTERNAL_ARENA_EXTERNS_H */

View File

@ -0,0 +1,57 @@
#ifndef JEMALLOC_INTERNAL_ARENA_INLINES_A_H
#define JEMALLOC_INTERNAL_ARENA_INLINES_A_H
static inline unsigned
arena_ind_get(const arena_t *arena) {
return base_ind_get(arena->base);
}
static inline void
arena_internal_add(arena_t *arena, size_t size) {
atomic_fetch_add_zu(&arena->stats.internal, size, ATOMIC_RELAXED);
}
static inline void
arena_internal_sub(arena_t *arena, size_t size) {
atomic_fetch_sub_zu(&arena->stats.internal, size, ATOMIC_RELAXED);
}
static inline size_t
arena_internal_get(arena_t *arena) {
return atomic_load_zu(&arena->stats.internal, ATOMIC_RELAXED);
}
static inline bool
arena_prof_accum(tsdn_t *tsdn, arena_t *arena, uint64_t accumbytes) {
cassert(config_prof);
if (likely(prof_interval == 0)) {
return false;
}
return prof_accum_add(tsdn, &arena->prof_accum, accumbytes);
}
static inline void
percpu_arena_update(tsd_t *tsd, unsigned cpu) {
assert(have_percpu_arena);
arena_t *oldarena = tsd_arena_get(tsd);
assert(oldarena != NULL);
unsigned oldind = arena_ind_get(oldarena);
if (oldind != cpu) {
unsigned newind = cpu;
arena_t *newarena = arena_get(tsd_tsdn(tsd), newind, true);
assert(newarena != NULL);
/* Set new arena/tcache associations. */
arena_migrate(tsd, oldind, newind);
tcache_t *tcache = tcache_get(tsd);
if (tcache != NULL) {
tcache_arena_reassociate(tsd_tsdn(tsd), tcache,
newarena);
}
}
}
#endif /* JEMALLOC_INTERNAL_ARENA_INLINES_A_H */

View File

@ -0,0 +1,361 @@
#ifndef JEMALLOC_INTERNAL_ARENA_INLINES_B_H
#define JEMALLOC_INTERNAL_ARENA_INLINES_B_H
#include "jemalloc/internal/jemalloc_internal_types.h"
#include "jemalloc/internal/mutex.h"
#include "jemalloc/internal/rtree.h"
#include "jemalloc/internal/size_classes.h"
#include "jemalloc/internal/sz.h"
#include "jemalloc/internal/ticker.h"
static inline szind_t
arena_bin_index(arena_t *arena, arena_bin_t *bin) {
szind_t binind = (szind_t)(bin - arena->bins);
assert(binind < NBINS);
return binind;
}
JEMALLOC_ALWAYS_INLINE prof_tctx_t *
arena_prof_tctx_get(tsdn_t *tsdn, const void *ptr, alloc_ctx_t *alloc_ctx) {
cassert(config_prof);
assert(ptr != NULL);
/* Static check. */
if (alloc_ctx == NULL) {
const extent_t *extent = iealloc(tsdn, ptr);
if (unlikely(!extent_slab_get(extent))) {
return large_prof_tctx_get(tsdn, extent);
}
} else {
if (unlikely(!alloc_ctx->slab)) {
return large_prof_tctx_get(tsdn, iealloc(tsdn, ptr));
}
}
return (prof_tctx_t *)(uintptr_t)1U;
}
JEMALLOC_ALWAYS_INLINE void
arena_prof_tctx_set(tsdn_t *tsdn, const void *ptr, size_t usize,
alloc_ctx_t *alloc_ctx, prof_tctx_t *tctx) {
cassert(config_prof);
assert(ptr != NULL);
/* Static check. */
if (alloc_ctx == NULL) {
extent_t *extent = iealloc(tsdn, ptr);
if (unlikely(!extent_slab_get(extent))) {
large_prof_tctx_set(tsdn, extent, tctx);
}
} else {
if (unlikely(!alloc_ctx->slab)) {
large_prof_tctx_set(tsdn, iealloc(tsdn, ptr), tctx);
}
}
}
static inline void
arena_prof_tctx_reset(tsdn_t *tsdn, const void *ptr, prof_tctx_t *tctx) {
cassert(config_prof);
assert(ptr != NULL);
extent_t *extent = iealloc(tsdn, ptr);
assert(!extent_slab_get(extent));
large_prof_tctx_reset(tsdn, extent);
}
JEMALLOC_ALWAYS_INLINE void
arena_decay_ticks(tsdn_t *tsdn, arena_t *arena, unsigned nticks) {
tsd_t *tsd;
ticker_t *decay_ticker;
if (unlikely(tsdn_null(tsdn))) {
return;
}
tsd = tsdn_tsd(tsdn);
decay_ticker = decay_ticker_get(tsd, arena_ind_get(arena));
if (unlikely(decay_ticker == NULL)) {
return;
}
if (unlikely(ticker_ticks(decay_ticker, nticks))) {
arena_decay(tsdn, arena, false, false);
}
}
JEMALLOC_ALWAYS_INLINE void
arena_decay_tick(tsdn_t *tsdn, arena_t *arena) {
malloc_mutex_assert_not_owner(tsdn, &arena->decay_dirty.mtx);
malloc_mutex_assert_not_owner(tsdn, &arena->decay_muzzy.mtx);
arena_decay_ticks(tsdn, arena, 1);
}
JEMALLOC_ALWAYS_INLINE void *
arena_malloc(tsdn_t *tsdn, arena_t *arena, size_t size, szind_t ind, bool zero,
tcache_t *tcache, bool slow_path) {
assert(!tsdn_null(tsdn) || tcache == NULL);
assert(size != 0);
if (likely(tcache != NULL)) {
if (likely(size <= SMALL_MAXCLASS)) {
return tcache_alloc_small(tsdn_tsd(tsdn), arena,
tcache, size, ind, zero, slow_path);
}
if (likely(size <= tcache_maxclass)) {
return tcache_alloc_large(tsdn_tsd(tsdn), arena,
tcache, size, ind, zero, slow_path);
}
/* (size > tcache_maxclass) case falls through. */
assert(size > tcache_maxclass);
}
return arena_malloc_hard(tsdn, arena, size, ind, zero);
}
JEMALLOC_ALWAYS_INLINE arena_t *
arena_aalloc(tsdn_t *tsdn, const void *ptr) {
return extent_arena_get(iealloc(tsdn, ptr));
}
JEMALLOC_ALWAYS_INLINE size_t
arena_salloc(tsdn_t *tsdn, const void *ptr) {
assert(ptr != NULL);
rtree_ctx_t rtree_ctx_fallback;
rtree_ctx_t *rtree_ctx = tsdn_rtree_ctx(tsdn, &rtree_ctx_fallback);
szind_t szind = rtree_szind_read(tsdn, &extents_rtree, rtree_ctx,
(uintptr_t)ptr, true);
assert(szind != NSIZES);
return sz_index2size(szind);
}
JEMALLOC_ALWAYS_INLINE size_t
arena_vsalloc(tsdn_t *tsdn, const void *ptr) {
/*
* Return 0 if ptr is not within an extent managed by jemalloc. This
* function has two extra costs relative to isalloc():
* - The rtree calls cannot claim to be dependent lookups, which induces
* rtree lookup load dependencies.
* - The lookup may fail, so there is an extra branch to check for
* failure.
*/
rtree_ctx_t rtree_ctx_fallback;
rtree_ctx_t *rtree_ctx = tsdn_rtree_ctx(tsdn, &rtree_ctx_fallback);
extent_t *extent;
szind_t szind;
if (rtree_extent_szind_read(tsdn, &extents_rtree, rtree_ctx,
(uintptr_t)ptr, false, &extent, &szind)) {
return 0;
}
if (extent == NULL) {
return 0;
}
assert(extent_state_get(extent) == extent_state_active);
/* Only slab members should be looked up via interior pointers. */
assert(extent_addr_get(extent) == ptr || extent_slab_get(extent));
assert(szind != NSIZES);
return sz_index2size(szind);
}
static inline void
arena_dalloc_no_tcache(tsdn_t *tsdn, void *ptr) {
assert(ptr != NULL);
rtree_ctx_t rtree_ctx_fallback;
rtree_ctx_t *rtree_ctx = tsdn_rtree_ctx(tsdn, &rtree_ctx_fallback);
szind_t szind;
bool slab;
rtree_szind_slab_read(tsdn, &extents_rtree, rtree_ctx, (uintptr_t)ptr,
true, &szind, &slab);
if (config_debug) {
extent_t *extent = rtree_extent_read(tsdn, &extents_rtree,
rtree_ctx, (uintptr_t)ptr, true);
assert(szind == extent_szind_get(extent));
assert(szind < NSIZES);
assert(slab == extent_slab_get(extent));
}
if (likely(slab)) {
/* Small allocation. */
arena_dalloc_small(tsdn, ptr);
} else {
extent_t *extent = iealloc(tsdn, ptr);
large_dalloc(tsdn, extent);
}
}
JEMALLOC_ALWAYS_INLINE void
arena_dalloc(tsdn_t *tsdn, void *ptr, tcache_t *tcache,
alloc_ctx_t *alloc_ctx, bool slow_path) {
assert(!tsdn_null(tsdn) || tcache == NULL);
assert(ptr != NULL);
if (unlikely(tcache == NULL)) {
arena_dalloc_no_tcache(tsdn, ptr);
return;
}
szind_t szind;
bool slab;
rtree_ctx_t *rtree_ctx;
if (alloc_ctx != NULL) {
szind = alloc_ctx->szind;
slab = alloc_ctx->slab;
assert(szind != NSIZES);
} else {
rtree_ctx = tsd_rtree_ctx(tsdn_tsd(tsdn));
rtree_szind_slab_read(tsdn, &extents_rtree, rtree_ctx,
(uintptr_t)ptr, true, &szind, &slab);
}
if (config_debug) {
rtree_ctx = tsd_rtree_ctx(tsdn_tsd(tsdn));
extent_t *extent = rtree_extent_read(tsdn, &extents_rtree,
rtree_ctx, (uintptr_t)ptr, true);
assert(szind == extent_szind_get(extent));
assert(szind < NSIZES);
assert(slab == extent_slab_get(extent));
}
if (likely(slab)) {
/* Small allocation. */
tcache_dalloc_small(tsdn_tsd(tsdn), tcache, ptr, szind,
slow_path);
} else {
if (szind < nhbins) {
if (config_prof && unlikely(szind < NBINS)) {
arena_dalloc_promoted(tsdn, ptr, tcache,
slow_path);
} else {
tcache_dalloc_large(tsdn_tsd(tsdn), tcache, ptr,
szind, slow_path);
}
} else {
extent_t *extent = iealloc(tsdn, ptr);
large_dalloc(tsdn, extent);
}
}
}
static inline void
arena_sdalloc_no_tcache(tsdn_t *tsdn, void *ptr, size_t size) {
assert(ptr != NULL);
assert(size <= LARGE_MAXCLASS);
szind_t szind;
bool slab;
if (!config_prof || !opt_prof) {
/*
* There is no risk of being confused by a promoted sampled
* object, so base szind and slab on the given size.
*/
szind = sz_size2index(size);
slab = (szind < NBINS);
}
if ((config_prof && opt_prof) || config_debug) {
rtree_ctx_t rtree_ctx_fallback;
rtree_ctx_t *rtree_ctx = tsdn_rtree_ctx(tsdn,
&rtree_ctx_fallback);
rtree_szind_slab_read(tsdn, &extents_rtree, rtree_ctx,
(uintptr_t)ptr, true, &szind, &slab);
assert(szind == sz_size2index(size));
assert((config_prof && opt_prof) || slab == (szind < NBINS));
if (config_debug) {
extent_t *extent = rtree_extent_read(tsdn,
&extents_rtree, rtree_ctx, (uintptr_t)ptr, true);
assert(szind == extent_szind_get(extent));
assert(slab == extent_slab_get(extent));
}
}
if (likely(slab)) {
/* Small allocation. */
arena_dalloc_small(tsdn, ptr);
} else {
extent_t *extent = iealloc(tsdn, ptr);
large_dalloc(tsdn, extent);
}
}
JEMALLOC_ALWAYS_INLINE void
arena_sdalloc(tsdn_t *tsdn, void *ptr, size_t size, tcache_t *tcache,
alloc_ctx_t *alloc_ctx, bool slow_path) {
assert(!tsdn_null(tsdn) || tcache == NULL);
assert(ptr != NULL);
assert(size <= LARGE_MAXCLASS);
if (unlikely(tcache == NULL)) {
arena_sdalloc_no_tcache(tsdn, ptr, size);
return;
}
szind_t szind;
bool slab;
UNUSED alloc_ctx_t local_ctx;
if (config_prof && opt_prof) {
if (alloc_ctx == NULL) {
/* Uncommon case and should be a static check. */
rtree_ctx_t rtree_ctx_fallback;
rtree_ctx_t *rtree_ctx = tsdn_rtree_ctx(tsdn,
&rtree_ctx_fallback);
rtree_szind_slab_read(tsdn, &extents_rtree, rtree_ctx,
(uintptr_t)ptr, true, &local_ctx.szind,
&local_ctx.slab);
assert(local_ctx.szind == sz_size2index(size));
alloc_ctx = &local_ctx;
}
slab = alloc_ctx->slab;
szind = alloc_ctx->szind;
} else {
/*
* There is no risk of being confused by a promoted sampled
* object, so base szind and slab on the given size.
*/
szind = sz_size2index(size);
slab = (szind < NBINS);
}
if (config_debug) {
rtree_ctx_t *rtree_ctx = tsd_rtree_ctx(tsdn_tsd(tsdn));
rtree_szind_slab_read(tsdn, &extents_rtree, rtree_ctx,
(uintptr_t)ptr, true, &szind, &slab);
extent_t *extent = rtree_extent_read(tsdn,
&extents_rtree, rtree_ctx, (uintptr_t)ptr, true);
assert(szind == extent_szind_get(extent));
assert(slab == extent_slab_get(extent));
}
if (likely(slab)) {
/* Small allocation. */
tcache_dalloc_small(tsdn_tsd(tsdn), tcache, ptr, szind,
slow_path);
} else {
if (szind < nhbins) {
if (config_prof && unlikely(szind < NBINS)) {
arena_dalloc_promoted(tsdn, ptr, tcache,
slow_path);
} else {
tcache_dalloc_large(tsdn_tsd(tsdn),
tcache, ptr, szind, slow_path);
}
} else {
extent_t *extent = iealloc(tsdn, ptr);
large_dalloc(tsdn, extent);
}
}
}
#endif /* JEMALLOC_INTERNAL_ARENA_INLINES_B_H */

View File

@ -0,0 +1,11 @@
#ifndef JEMALLOC_INTERNAL_ARENA_STRUCTS_A_H
#define JEMALLOC_INTERNAL_ARENA_STRUCTS_A_H
#include "jemalloc/internal/bitmap.h"
struct arena_slab_data_s {
/* Per region allocated/deallocated bitmap. */
bitmap_t bitmap[BITMAP_GROUPS_MAX];
};
#endif /* JEMALLOC_INTERNAL_ARENA_STRUCTS_A_H */

Some files were not shown because too many files have changed in this diff Show More