Use fewer header files
Removing some includes to reduce the code that is dragged in.
This commit is contained in:
committed by
Matthew Parkinson
parent
30ad9722a7
commit
4faf9f3bee
@@ -452,5 +452,17 @@ namespace snmalloc
|
|||||||
return (size_t)1 << (m_e + LOW_BITS);
|
return (size_t)1 << (m_e + LOW_BITS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr inline T min(T t1, T t2)
|
||||||
|
{
|
||||||
|
return t1 < t2 ? t1 : t2;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr inline T max(T t1, T t2)
|
||||||
|
{
|
||||||
|
return t1 > t2 ? t1 : t2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "bits.h"
|
#include "bits.h"
|
||||||
|
#include "helpers.h"
|
||||||
#include <stdlib.h>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
namespace snmalloc
|
namespace snmalloc
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,8 +21,6 @@
|
|||||||
#include "sizeclasstable.h"
|
#include "sizeclasstable.h"
|
||||||
#include "slab.h"
|
#include "slab.h"
|
||||||
|
|
||||||
#include <array>
|
|
||||||
|
|
||||||
namespace snmalloc
|
namespace snmalloc
|
||||||
{
|
{
|
||||||
enum Boundary
|
enum Boundary
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ namespace snmalloc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_SNMALLOC_STATS
|
||||||
void print_all_stats(std::ostream& o, uint64_t dumpid = 0)
|
void print_all_stats(std::ostream& o, uint64_t dumpid = 0)
|
||||||
{
|
{
|
||||||
auto alloc = Parent::iterate();
|
auto alloc = Parent::iterate();
|
||||||
@@ -59,6 +60,12 @@ namespace snmalloc
|
|||||||
alloc = Parent::iterate(alloc);
|
alloc = Parent::iterate(alloc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
void print_all_stats(void*& o, uint64_t dumpid = 0)
|
||||||
|
{
|
||||||
|
UNUSED(o); UNUSED(dumpid);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void cleanup_unused()
|
void cleanup_unused()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,8 +8,6 @@
|
|||||||
#include "baseslab.h"
|
#include "baseslab.h"
|
||||||
#include "sizeclass.h"
|
#include "sizeclass.h"
|
||||||
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
namespace snmalloc
|
namespace snmalloc
|
||||||
{
|
{
|
||||||
template<class PAL>
|
template<class PAL>
|
||||||
@@ -61,7 +59,7 @@ namespace snmalloc
|
|||||||
size_t bump;
|
size_t bump;
|
||||||
size_t remaining;
|
size_t remaining;
|
||||||
|
|
||||||
std::pair<void*, size_t> reserve_block() noexcept
|
void new_block()
|
||||||
{
|
{
|
||||||
size_t size = SUPERSLAB_SIZE;
|
size_t size = SUPERSLAB_SIZE;
|
||||||
void* r = reserve<false>(&size, SUPERSLAB_SIZE);
|
void* r = reserve<false>(&size, SUPERSLAB_SIZE);
|
||||||
@@ -70,14 +68,9 @@ namespace snmalloc
|
|||||||
error("out of memory");
|
error("out of memory");
|
||||||
|
|
||||||
((PAL*)this)->template notify_using<NoZero>(r, OS_PAGE_SIZE);
|
((PAL*)this)->template notify_using<NoZero>(r, OS_PAGE_SIZE);
|
||||||
return std::make_pair(r, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void new_block()
|
bump = (size_t)r;
|
||||||
{
|
remaining = size;
|
||||||
auto r_size = reserve_block();
|
|
||||||
bump = (size_t)r_size.first;
|
|
||||||
remaining = r_size.second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../ds/bits.h"
|
#include "../ds/bits.h"
|
||||||
|
#include "../ds/helpers.h"
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace snmalloc
|
namespace snmalloc
|
||||||
{
|
{
|
||||||
@@ -274,7 +275,7 @@ namespace snmalloc
|
|||||||
auto leaf_ix = get_leaf_index<true>(p, success);
|
auto leaf_ix = get_leaf_index<true>(p, success);
|
||||||
size_t ix = leaf_ix.second;
|
size_t ix = leaf_ix.second;
|
||||||
|
|
||||||
auto last = std::min(LEAF_MASK + 1, ix + length);
|
auto last = bits::min(LEAF_MASK + 1, ix + length);
|
||||||
|
|
||||||
auto diff = last - ix;
|
auto diff = last - ix;
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ namespace snmalloc
|
|||||||
bits::from_exp_mant<INTERMEDIATE_BITS, MIN_ALLOC_BITS>(sizeclass);
|
bits::from_exp_mant<INTERMEDIATE_BITS, MIN_ALLOC_BITS>(sizeclass);
|
||||||
|
|
||||||
size_t alignment =
|
size_t alignment =
|
||||||
std::min((size_t)1 << bits::ctz_const(size[sizeclass]), OS_PAGE_SIZE);
|
bits::min((size_t)1 << bits::ctz_const(size[sizeclass]), OS_PAGE_SIZE);
|
||||||
cache_friendly_mask[sizeclass] = (alignment - 1);
|
cache_friendly_mask[sizeclass] = (alignment - 1);
|
||||||
inverse_cache_friendly_mask[sizeclass] = ~(alignment - 1);
|
inverse_cache_friendly_mask[sizeclass] = ~(alignment - 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,7 @@
|
|||||||
#include "../ds/helpers.h"
|
#include "../ds/helpers.h"
|
||||||
#include "allocslab.h"
|
#include "allocslab.h"
|
||||||
#include "metaslab.h"
|
#include "metaslab.h"
|
||||||
|
#include <new>
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
namespace snmalloc
|
namespace snmalloc
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,6 +7,10 @@
|
|||||||
#error At most one out of SNMALLOC_USE_THREAD_CLEANUP and SNMALLOC_USE_THREAD_DESTRUCTOR may be defined.
|
#error At most one out of SNMALLOC_USE_THREAD_CLEANUP and SNMALLOC_USE_THREAD_DESTRUCTOR may be defined.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined(_WIN32) && !defined(FreeBSD_KERNEL)
|
||||||
|
# include "pthread.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace snmalloc
|
namespace snmalloc
|
||||||
{
|
{
|
||||||
extern "C" void _malloc_thread_cleanup(void);
|
extern "C" void _malloc_thread_cleanup(void);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "../snmalloc.h"
|
#include "../snmalloc.h"
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
using namespace snmalloc;
|
using namespace snmalloc;
|
||||||
|
|
||||||
@@ -89,7 +90,7 @@ extern "C"
|
|||||||
if (p != nullptr)
|
if (p != nullptr)
|
||||||
{
|
{
|
||||||
assert(p == Alloc::external_pointer<Start>(p));
|
assert(p == Alloc::external_pointer<Start>(p));
|
||||||
sz = (std::min)(size, sz);
|
sz = bits::min(size, sz);
|
||||||
memcpy(p, ptr, sz);
|
memcpy(p, ptr, sz);
|
||||||
SNMALLOC_NAME_MANGLE(free)(ptr);
|
SNMALLOC_NAME_MANGLE(free)(ptr);
|
||||||
}
|
}
|
||||||
@@ -135,7 +136,7 @@ extern "C"
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
size = (std::max)(size, alignment);
|
size = bits::max(size, alignment);
|
||||||
uint8_t sc = size_to_sizeclass(size);
|
uint8_t sc = size_to_sizeclass(size);
|
||||||
if (sc >= NUM_SIZECLASSES)
|
if (sc >= NUM_SIZECLASSES)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,10 +5,11 @@
|
|||||||
# include "../mem/allocconfig.h"
|
# include "../mem/allocconfig.h"
|
||||||
|
|
||||||
# include <pthread.h>
|
# include <pthread.h>
|
||||||
# include <stdio.h>
|
|
||||||
# include <strings.h>
|
# include <strings.h>
|
||||||
# include <sys/mman.h>
|
# include <sys/mman.h>
|
||||||
|
|
||||||
|
int puts ( const char * str );
|
||||||
|
|
||||||
namespace snmalloc
|
namespace snmalloc
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
# include "../ds/bits.h"
|
# include "../ds/bits.h"
|
||||||
# include "../mem/allocconfig.h"
|
# include "../mem/allocconfig.h"
|
||||||
|
|
||||||
# include <pthread.h>
|
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
# include <strings.h>
|
# include <strings.h>
|
||||||
# include <sys/mman.h>
|
# include <sys/mman.h>
|
||||||
|
|||||||
@@ -4,10 +4,11 @@
|
|||||||
# include "../ds/bits.h"
|
# include "../ds/bits.h"
|
||||||
# include "../mem/allocconfig.h"
|
# include "../mem/allocconfig.h"
|
||||||
|
|
||||||
# include <stdio.h>
|
|
||||||
# include <string.h>
|
# include <string.h>
|
||||||
# include <sys/mman.h>
|
# include <sys/mman.h>
|
||||||
|
|
||||||
|
int puts ( const char * str );
|
||||||
|
|
||||||
namespace snmalloc
|
namespace snmalloc
|
||||||
{
|
{
|
||||||
class PALLinux
|
class PALLinux
|
||||||
|
|||||||
Reference in New Issue
Block a user