From 4ed15def79ad397a84c287b1deab83b8aa138ae9 Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Thu, 1 Aug 2019 10:44:54 +0100 Subject: [PATCH 01/12] [NFC] Remove some code duplication in the PALs. Pull out a generic POSIX PAL as a superclass for the Linux and generic BSD PALs. Now we have FreeBSD and Linux adding OS-specific behaviour, OpenBSD as a named subclass of the generic BSD PAL that doesn't add any behaviour. I believe a NetBSD PAL should now be identical to the OpenBSD one - patches welcome if anyone wants to test one! --- src/pal/pal_bsd.h | 85 +++++++--------------------- src/pal/pal_freebsd.h | 14 +++-- src/pal/pal_linux.h | 67 ++++++---------------- src/pal/pal_openbsd.h | 17 +++++- src/pal/pal_posix.h | 125 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 185 insertions(+), 123 deletions(-) create mode 100644 src/pal/pal_posix.h diff --git a/src/pal/pal_bsd.h b/src/pal/pal_bsd.h index cc996c2..25ba3bd 100644 --- a/src/pal/pal_bsd.h +++ b/src/pal/pal_bsd.h @@ -3,6 +3,7 @@ #if (defined(__FreeBSD__) || defined(__OpenBSD__)) && !defined(_KERNEL) # include "../ds/bits.h" # include "../mem/allocconfig.h" +# include "pal_posix.h" # include # include @@ -10,84 +11,36 @@ namespace snmalloc { - class PALBSD + /** + * Generic *BSD PAL mixin. This provides features that are common to the BSD + * family. + */ + template + class PALBSD : public PALPOSIX { public: /** * Bitmap of PalFeatures flags indicating the optional features that this * PAL supports. + * + * The generic BSD PAL does not add any features that are not supported by + * generic POSIX systems, but explicitly declares this variable to remind + * anyone who extends this class that they may need to modify this field. */ - static constexpr uint64_t pal_features = 0; - static void error(const char* const str) - { - puts(str); - abort(); - } + static constexpr uint64_t pal_features = PALPOSIX::pal_features; - /// Notify platform that we will not be using these pages + /** + * Notify platform that we will not be using these pages. + * + * BSD systems provide the `MADV_FREE` flag to `madvise`, which allows the + * operating system to replace the pages with CoW copies of a zero page at + * any point between the call and the next write to that page. + */ void notify_not_using(void* p, size_t size) noexcept { assert(bits::is_aligned_block(p, size)); madvise(p, size, MADV_FREE); } - - /// Notify platform that we will be using these pages - template - void notify_using(void* p, size_t size) noexcept - { - assert( - bits::is_aligned_block(p, size) || (zero_mem == NoZero)); - if constexpr (zero_mem == YesZero) - { - zero(p, size); - } - else - { - UNUSED(size); - UNUSED(p); - } - } - - /// OS specific function for zeroing memory - template - void zero(void* p, size_t size) noexcept - { - if (page_aligned || bits::is_aligned_block(p, size)) - { - assert(bits::is_aligned_block(p, size)); - void* r = mmap( - p, - size, - PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, - -1, - 0); - - if (r != MAP_FAILED) - return; - } - - bzero(p, size); - } - - template - void* reserve(const size_t* size) noexcept - { - size_t request = *size; - - void* p = mmap( - nullptr, - request, - PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, - -1, - 0); - - if (p == MAP_FAILED) - error("Out of memory"); - - return p; - } }; } // namespace snmalloc #endif diff --git a/src/pal/pal_freebsd.h b/src/pal/pal_freebsd.h index 2924fa4..b853281 100644 --- a/src/pal/pal_freebsd.h +++ b/src/pal/pal_freebsd.h @@ -11,19 +11,25 @@ namespace snmalloc { - class PALFBSD : public PALBSD + class PALFBSD : public PALBSD { public: /** * Bitmap of PalFeatures flags indicating the optional features that this * PAL supports. */ - static constexpr uint64_t pal_features = AlignedAllocation | LazyCommit; + static constexpr uint64_t pal_features = + AlignedAllocation | PALBSD::pal_features; + /** + * Reserve memory. + * + * FreeBSD supports requesting pages at an arbitrary alignment, which + * improves efficiency of snmalloc. + */ template void* reserve(const size_t* size, size_t align) noexcept { - size_t request = *size; // Alignment must be a power of 2. assert(align == bits::next_pow2(align)); @@ -33,7 +39,7 @@ namespace snmalloc void* p = mmap( nullptr, - request, + *size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_ALIGNED(log2align), -1, diff --git a/src/pal/pal_linux.h b/src/pal/pal_linux.h index dcb75dd..e159831 100644 --- a/src/pal/pal_linux.h +++ b/src/pal/pal_linux.h @@ -3,6 +3,7 @@ #if defined(__linux__) # include "../ds/bits.h" # include "../mem/allocconfig.h" +# include "pal_posix.h" # include # include @@ -11,47 +12,28 @@ extern "C" int puts(const char* str); namespace snmalloc { - class PALLinux + class PALLinux : public PALPOSIX { public: /** * Bitmap of PalFeatures flags indicating the optional features that this * PAL supports. + * + * Linux does not support any features other than those in a generic POSIX + * platform. This field is declared explicitly to remind anyone who + * extends this PAL that they may need to extend the set of advertised + * features. */ - static constexpr uint64_t pal_features = LazyCommit; - static void error(const char* const str) - { - puts(str); - abort(); - } + static constexpr uint64_t pal_features = PALPOSIX::pal_features; - /// Notify platform that we will not be using these pages - void notify_not_using(void* p, size_t size) noexcept - { - assert(bits::is_aligned_block(p, size)); - // Do nothing. Don't call madvise here, as the system call slows the - // allocator down too much. - UNUSED(p); - UNUSED(size); - } - - /// Notify platform that we will be using these pages - template - void notify_using(void* p, size_t size) noexcept - { - assert( - bits::is_aligned_block(p, size) || (zero_mem == NoZero)); - - if constexpr (zero_mem == YesZero) - zero(p, size); - else - { - UNUSED(p); - UNUSED(size); - } - } - - /// OS specific function for zeroing memory + /** + * OS specific function for zeroing memory. + * + * Linux implements an unusual interpretation of `MADV_DONTNEED`, which + * immediately resets the pages to the zero state (rather than marking them + * as sensible ones to swap out in high memory pressure). We use this to + * clear the underlying memory range. + */ template void zero(void* p, size_t size) noexcept { @@ -65,23 +47,6 @@ namespace snmalloc ::memset(p, 0, size); } } - - template - void* reserve(const size_t* size) noexcept - { - void* p = mmap( - nullptr, - *size, - PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, - -1, - 0); - - if (p == MAP_FAILED) - error("Out of memory"); - - return p; - } }; } // namespace snmalloc #endif diff --git a/src/pal/pal_openbsd.h b/src/pal/pal_openbsd.h index fb1dbc0..0daf4ca 100644 --- a/src/pal/pal_openbsd.h +++ b/src/pal/pal_openbsd.h @@ -11,10 +11,23 @@ namespace snmalloc { - class PALOBSD : public PALBSD + /** + * OpenBSD platform abstraction layer. + * + * OpenBSD behaves exactly like a generic BSD platform but this class exists + * as a place to add OpenBSD-specific behaviour later, if required. + */ + class PALOBSD : public PALBSD { public: - static constexpr uint64_t pal_features = LazyCommit; + /** + * The features exported by this PAL. + * + * Currently, these are identical to the generic BSD PAL. This field is + * declared explicitly to remind anyone who modifies this class that they + * should add any required features. + */ + static constexpr uint64_t pal_features = PALBSD; }; } // namespace snmalloc #endif diff --git a/src/pal/pal_posix.h b/src/pal/pal_posix.h new file mode 100644 index 0000000..4cf1e62 --- /dev/null +++ b/src/pal/pal_posix.h @@ -0,0 +1,125 @@ +#pragma once + +#include "../ds/bits.h" +#include "../mem/allocconfig.h" + +#include +#include + +extern "C" int puts(const char* str); + +namespace snmalloc +{ + template + class PALPOSIX + { + public: + /** + * Bitmap of PalFeatures flags indicating the optional features that this + * PAL supports. + * + * POSIX systems are assumed to support lazy commit. + */ + static constexpr uint64_t pal_features = LazyCommit; + static void error(const char* const str) noexcept + { + puts(str); + abort(); + } + + /** + * Notify platform that we will not be using these pages. + * + * This does nothing in a generic POSIX implementation. Most POSIX systems + * provide an `madvise` call that can be used to return pages to the OS in + * high memory pressure conditions, though on Linux this seems to impose + * too much of a performance penalty. + */ + void notify_not_using(void* p, size_t size) noexcept + { + assert(bits::is_aligned_block(p, size)); + UNUSED(p); + UNUSED(size); + } + + /** + * Notify platform that we will be using these pages. + * + * On POSIX platforms, lazy commit means that this is a no-op, unless we + * are also zeroing the pages in which case we call the platform's `zero` + * function. + */ + template + void notify_using(void* p, size_t size) noexcept + { + assert( + bits::is_aligned_block(p, size) || (zero_mem == NoZero)); + + if constexpr (zero_mem == YesZero) + static_cast(this)->template zero(p, size); + else + { + UNUSED(p); + UNUSED(size); + } + } + + /** + * OS specific function for zeroing memory. + * + * The generic POSIX implementation uses mmap to map anonymous memory over + * the range for ranges larger than a page. The underlying OS is assumed + * to provide new CoW copies of the zero page. + * + * Note: On most systems it is faster for a single page to zero the memory + * explicitly than do this, we should probably tweak the threshold for + * calling bzero at some point. + */ + template + void zero(void* p, size_t size) noexcept + { + if (page_aligned || bits::is_aligned_block(p, size)) + { + assert(bits::is_aligned_block(p, size)); + void* r = mmap( + p, + size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, + -1, + 0); + + if (r != MAP_FAILED) + return; + } + + bzero(p, size); + } + + /** + * Reserve memory. + * + * POSIX platforms support lazy commit, and so this also puts the memory in + * the lazy commit state (i.e. pages will be allocated on first use). + * + * POSIX does not define a portable interface for specifying alignment + * greater than a page. + */ + template + void* reserve(const size_t* size) noexcept + { + void* p = mmap( + nullptr, + *size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, + -1, + 0); + + if (p == MAP_FAILED) + OS::error("Out of memory"); + + return p; + } + }; +} // namespace snmalloc From d257f6073197e4b2a6e97f708c7049b405442ba0 Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Thu, 1 Aug 2019 11:03:22 +0100 Subject: [PATCH 02/12] [NFC] Add missing doc comments. --- src/pal/pal_freebsd.h | 6 ++++++ src/pal/pal_posix.h | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/pal/pal_freebsd.h b/src/pal/pal_freebsd.h index b853281..bb58966 100644 --- a/src/pal/pal_freebsd.h +++ b/src/pal/pal_freebsd.h @@ -11,6 +11,12 @@ namespace snmalloc { + /** + * FreeBSD-specific platform abstraction layer. + * + * This adds FreeBSD-specific aligned allocation to the generic BSD + * implementation. + */ class PALFBSD : public PALBSD { public: diff --git a/src/pal/pal_posix.h b/src/pal/pal_posix.h index 4cf1e62..1e909bb 100644 --- a/src/pal/pal_posix.h +++ b/src/pal/pal_posix.h @@ -10,6 +10,18 @@ extern "C" int puts(const char* str); namespace snmalloc { + /** + * Platform abstraction layer for generic POSIX systems. + * + * This provides the lowest common denominator for POSIX systems. It should + * work on pretty much any POSIX system, but won't necessarily be the most + * efficient implementation. Subclasses should provide more efficient + * implementations using platform-specific functionality. + * + * The template parameter for this is the subclass and is used for explicit + * up casts to allow this class to call non-virtual methods on the templated + * version. + */ template class PALPOSIX { @@ -21,6 +33,10 @@ namespace snmalloc * POSIX systems are assumed to support lazy commit. */ static constexpr uint64_t pal_features = LazyCommit; + + /** + * Report a fatal error an exit. + */ static void error(const char* const str) noexcept { puts(str); From 0497993d235891b6325340fc51737ac353d6833f Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Thu, 1 Aug 2019 11:20:05 +0100 Subject: [PATCH 03/12] Fix typo in OpenBSD PAL. --- src/pal/pal_openbsd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pal/pal_openbsd.h b/src/pal/pal_openbsd.h index 0daf4ca..7fb832c 100644 --- a/src/pal/pal_openbsd.h +++ b/src/pal/pal_openbsd.h @@ -27,7 +27,7 @@ namespace snmalloc * declared explicitly to remind anyone who modifies this class that they * should add any required features. */ - static constexpr uint64_t pal_features = PALBSD; + static constexpr uint64_t pal_features = PALBSD::pal_features; }; } // namespace snmalloc #endif From 54cbf8b2bb41d7dcd58115574fe1b5259adcdbbd Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Thu, 1 Aug 2019 11:20:37 +0100 Subject: [PATCH 04/12] [NFC] Remove unused headers from OpenBSD PAL. --- src/pal/pal_openbsd.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/pal/pal_openbsd.h b/src/pal/pal_openbsd.h index 7fb832c..69651a9 100644 --- a/src/pal/pal_openbsd.h +++ b/src/pal/pal_openbsd.h @@ -1,14 +1,8 @@ #pragma once #if defined(__OpenBSD__) && !defined(_KERNEL) -# include "../ds/bits.h" -# include "../mem/allocconfig.h" # include "pal_bsd.h" -# include -# include -# include - namespace snmalloc { /** From cf6fca65144a3640ece5da2e9699f1c3630b9869 Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Thu, 1 Aug 2019 11:21:32 +0100 Subject: [PATCH 05/12] [NFC] Make the Apple PAL use the generic BSD code. --- src/pal/pal_apple.h | 86 +++++++-------------------------------------- 1 file changed, 12 insertions(+), 74 deletions(-) diff --git a/src/pal/pal_apple.h b/src/pal/pal_apple.h index 97f72bb..cc9a96d 100644 --- a/src/pal/pal_apple.h +++ b/src/pal/pal_apple.h @@ -1,89 +1,27 @@ #pragma once #ifdef __APPLE__ -# include "../ds/bits.h" -# include "../mem/allocconfig.h" - -# include -# include -# include - -extern "C" int puts(const char* str); +# include "pal_bsd.h" namespace snmalloc { /** * PAL implementation for Apple systems (macOS, iOS, watchOS, tvOS...). + * + * XNU behaves exactly like a generic BSD platform but this class exists + * as a place to add XNU-specific behaviour later, if required. */ - class PALApple + class PALApple : public PALBSD { public: /** - * Bitmap of PalFeatures flags indicating the optional features that this - * PAL supports. + * The features exported by this PAL. + * + * Currently, these are identical to the generic BSD PAL. This field is + * declared explicitly to remind anyone who modifies this class that they + * should add any required features. */ - static constexpr uint64_t pal_features = LazyCommit; - static void error(const char* const str) - { - puts(str); - abort(); - } - - /// Notify platform that we will not be using these pages - void notify_not_using(void* p, size_t size) noexcept - { - assert(bits::is_aligned_block(p, size)); - madvise(p, size, MADV_FREE); - } - - /// Notify platform that we will be using these pages - template - void notify_using(void* p, size_t size) noexcept - { - assert( - bits::is_aligned_block(p, size) || (zero_mem == NoZero)); - if constexpr (zero_mem == YesZero) - zero(p, size); - } - - /// OS specific function for zeroing memory - template - void zero(void* p, size_t size) noexcept - { - if (page_aligned || bits::is_aligned_block(p, size)) - { - assert(bits::is_aligned_block(p, size)); - void* r = mmap( - p, - size, - PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, - -1, - 0); - - if (r != MAP_FAILED) - return; - } - - bzero(p, size); - } - - template - void* reserve(size_t* size) noexcept - { - void* p = mmap( - NULL, - *size, - PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, - -1, - 0); - - if (p == MAP_FAILED) - error("Out of memory"); - - return p; - } + static constexpr uint64_t pal_features = PALBSD::pal_features; }; -} +} // namespace snmalloc #endif From fd88b8464bea9727b036e5194ccbf9d030d65d4f Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Thu, 1 Aug 2019 11:37:00 +0100 Subject: [PATCH 06/12] [NFC] Separate out support for aligned allocation from the FreeBSD PAL. NetBSD also supports `MAP_ALIGNED()` in `mmap` (according to the man page, at least). --- src/pal/pal_bsd_aligned.h | 55 +++++++++++++++++++++++++++++++++++++++ src/pal/pal_freebsd.h | 46 +++++--------------------------- 2 files changed, 62 insertions(+), 39 deletions(-) create mode 100644 src/pal/pal_bsd_aligned.h diff --git a/src/pal/pal_bsd_aligned.h b/src/pal/pal_bsd_aligned.h new file mode 100644 index 0000000..48b5989 --- /dev/null +++ b/src/pal/pal_bsd_aligned.h @@ -0,0 +1,55 @@ +#pragma once + +#if defined(__FreeBSD__) && !defined(_KERNEL) +# include "pal_bsd.h" + +namespace snmalloc +{ + /** + * FreeBSD-specific platform abstraction layer. + * + * This adds aligned allocation using `MAP_ALIGNED` to the generic BSD + * implementation. This flag is supported by NetBSD and FreeBSD. + */ + template + class PALBSD_Aligned : public PALBSD + { + public: + /** + * Bitmap of PalFeatures flags indicating the optional features that this + * PAL supports. + * + * This class adds support for aligned allocation. + */ + static constexpr uint64_t pal_features = + AlignedAllocation | PALBSD::pal_features; + + /** + * Reserve memory at a specific alignment. + */ + template + void* reserve(const size_t* size, size_t align) noexcept + { + // Alignment must be a power of 2. + assert(align == bits::next_pow2(align)); + + align = bits::max(4096, align); + + size_t log2align = bits::next_pow2_bits(align); + + void* p = mmap( + nullptr, + *size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_ALIGNED(log2align), + -1, + 0); + + if (p == MAP_FAILED) + error("Out of memory"); + + return p; + } + }; +} // namespace snmalloc +#endif diff --git a/src/pal/pal_freebsd.h b/src/pal/pal_freebsd.h index bb58966..10eec07 100644 --- a/src/pal/pal_freebsd.h +++ b/src/pal/pal_freebsd.h @@ -1,13 +1,7 @@ #pragma once #if defined(__FreeBSD__) && !defined(_KERNEL) -# include "../ds/bits.h" -# include "../mem/allocconfig.h" -# include "pal_bsd.h" - -# include -# include -# include +# include "pal_bsd_aligned.h" namespace snmalloc { @@ -17,45 +11,19 @@ namespace snmalloc * This adds FreeBSD-specific aligned allocation to the generic BSD * implementation. */ - class PALFBSD : public PALBSD + class PALFBSD : public PALBSD_Aligned { public: /** * Bitmap of PalFeatures flags indicating the optional features that this * PAL supports. - */ - static constexpr uint64_t pal_features = - AlignedAllocation | PALBSD::pal_features; - - /** - * Reserve memory. * - * FreeBSD supports requesting pages at an arbitrary alignment, which - * improves efficiency of snmalloc. + * The FreeBSD PAL does not currently add any features beyond those of a + * generic BSD with support for arbitrary alignment from `mmap`. This + * field is declared explicitly to remind anyone modifying this class to + * add new features that they should add any required feature flags. */ - template - void* reserve(const size_t* size, size_t align) noexcept - { - // Alignment must be a power of 2. - assert(align == bits::next_pow2(align)); - - align = bits::max(4096, align); - - size_t log2align = bits::next_pow2_bits(align); - - void* p = mmap( - nullptr, - *size, - PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS | MAP_ALIGNED(log2align), - -1, - 0); - - if (p == MAP_FAILED) - error("Out of memory"); - - return p; - } + static constexpr uint64_t pal_features = PALBSD_Aligned::pal_features; }; } // namespace snmalloc #endif From 2b44b6b5ea8f56742e107a6e16e855ff8daec4af Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Thu, 1 Aug 2019 11:41:08 +0100 Subject: [PATCH 07/12] Add a NetBSD PAL. Currently untested, but identical to the FreeBSD one so should work... The NetBSD man pages for `madvise` and `mmap` mention the flags that we use. --- src/pal/pal.h | 3 +++ src/pal/pal_netbsd.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/pal/pal_netbsd.h diff --git a/src/pal/pal.h b/src/pal/pal.h index 6cec451..ad74b77 100644 --- a/src/pal/pal.h +++ b/src/pal/pal.h @@ -13,6 +13,7 @@ namespace snmalloc # include "pal_free_bsd_kernel.h" # include "pal_freebsd.h" # include "pal_linux.h" +# include "pal_netbsd.h" # include "pal_openbsd.h" # include "pal_windows.h" #endif @@ -33,6 +34,8 @@ namespace snmalloc PALFreeBSDKernel; # elif defined(__FreeBSD__) PALFBSD; +# elif defined(__NetBSD__) + PALNetBSD; # elif defined(__OpenBSD__) PALOBSD; # else diff --git a/src/pal/pal_netbsd.h b/src/pal/pal_netbsd.h new file mode 100644 index 0000000..0c7cb68 --- /dev/null +++ b/src/pal/pal_netbsd.h @@ -0,0 +1,29 @@ +#pragma once + +#ifdef __NetBSD__ +# include "pal_bsd_aligned.h" + +namespace snmalloc +{ + /** + * NetBSD-specific platform abstraction layer. + * + * This adds NetBSD-specific aligned allocation to the generic BSD + * implementation. + */ + class PALNetBSD : public PALBSD_Aligned + { + public: + /** + * Bitmap of PalFeatures flags indicating the optional features that this + * PAL supports. + * + * The NetBSD PAL does not currently add any features beyond those of a + * generic BSD with support for arbitrary alignment from `mmap`. This + * field is declared explicitly to remind anyone modifying this class to + * add new features that they should add any required feature flags. + */ + static constexpr uint64_t pal_features = PALBSD_Aligned::pal_features; + }; +} // namespace snmalloc +#endif From 896cc9cf6f76e1bdab9185a370db3fa026cb7374 Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Thu, 1 Aug 2019 11:43:40 +0100 Subject: [PATCH 08/12] [NFC] Rename some PALs to make the naming more consistent. --- src/pal/pal.h | 6 +++--- src/pal/pal_freebsd.h | 2 +- src/pal/{pal_free_bsd_kernel.h => pal_freebsd_kernel.h} | 0 src/pal/pal_openbsd.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) rename src/pal/{pal_free_bsd_kernel.h => pal_freebsd_kernel.h} (100%) diff --git a/src/pal/pal.h b/src/pal/pal.h index ad74b77..85d41e8 100644 --- a/src/pal/pal.h +++ b/src/pal/pal.h @@ -10,7 +10,7 @@ namespace snmalloc // If simultating OE, then we need the underlying platform #if !defined(OPEN_ENCLAVE) || defined(OPEN_ENCLAVE_SIMULATION) # include "pal_apple.h" -# include "pal_free_bsd_kernel.h" +# include "pal_freebsd_kernel.h" # include "pal_freebsd.h" # include "pal_linux.h" # include "pal_netbsd.h" @@ -33,11 +33,11 @@ namespace snmalloc # elif defined(FreeBSD_KERNEL) PALFreeBSDKernel; # elif defined(__FreeBSD__) - PALFBSD; + PALFreeBSD; # elif defined(__NetBSD__) PALNetBSD; # elif defined(__OpenBSD__) - PALOBSD; + PALOpenBSD; # else # error Unsupported platform # endif diff --git a/src/pal/pal_freebsd.h b/src/pal/pal_freebsd.h index 10eec07..13d74ae 100644 --- a/src/pal/pal_freebsd.h +++ b/src/pal/pal_freebsd.h @@ -11,7 +11,7 @@ namespace snmalloc * This adds FreeBSD-specific aligned allocation to the generic BSD * implementation. */ - class PALFBSD : public PALBSD_Aligned + class PALFreeBSD : public PALBSD_Aligned { public: /** diff --git a/src/pal/pal_free_bsd_kernel.h b/src/pal/pal_freebsd_kernel.h similarity index 100% rename from src/pal/pal_free_bsd_kernel.h rename to src/pal/pal_freebsd_kernel.h diff --git a/src/pal/pal_openbsd.h b/src/pal/pal_openbsd.h index 69651a9..fa15750 100644 --- a/src/pal/pal_openbsd.h +++ b/src/pal/pal_openbsd.h @@ -11,7 +11,7 @@ namespace snmalloc * OpenBSD behaves exactly like a generic BSD platform but this class exists * as a place to add OpenBSD-specific behaviour later, if required. */ - class PALOBSD : public PALBSD + class PALOpenBSD : public PALBSD { public: /** From d11f09e4eca4c6e06b8071f7e87ee57fb98d9cd7 Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Thu, 1 Aug 2019 11:48:42 +0100 Subject: [PATCH 09/12] [NFC] Remove incorrect guard and some unused includes. --- src/pal/pal_bsd.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/pal/pal_bsd.h b/src/pal/pal_bsd.h index 25ba3bd..8a9691e 100644 --- a/src/pal/pal_bsd.h +++ b/src/pal/pal_bsd.h @@ -1,11 +1,7 @@ #pragma once -#if (defined(__FreeBSD__) || defined(__OpenBSD__)) && !defined(_KERNEL) -# include "../ds/bits.h" -# include "../mem/allocconfig.h" # include "pal_posix.h" -# include # include # include @@ -43,4 +39,3 @@ namespace snmalloc } }; } // namespace snmalloc -#endif From 81a0f0aed83182128bf7850413f30b0db68b3c32 Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Thu, 1 Aug 2019 11:50:03 +0100 Subject: [PATCH 10/12] [NFC] Remove one more unneeded include. --- src/pal/pal_bsd.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pal/pal_bsd.h b/src/pal/pal_bsd.h index 8a9691e..df3b846 100644 --- a/src/pal/pal_bsd.h +++ b/src/pal/pal_bsd.h @@ -2,7 +2,6 @@ # include "pal_posix.h" -# include # include namespace snmalloc From d24ad45abed5d5201f841f552076bf62e933d071 Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Thu, 1 Aug 2019 12:03:35 +0100 Subject: [PATCH 11/12] [NFC] clangformat. --- src/pal/pal.h | 2 +- src/pal/pal_bsd.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pal/pal.h b/src/pal/pal.h index 85d41e8..5a866a6 100644 --- a/src/pal/pal.h +++ b/src/pal/pal.h @@ -10,8 +10,8 @@ namespace snmalloc // If simultating OE, then we need the underlying platform #if !defined(OPEN_ENCLAVE) || defined(OPEN_ENCLAVE_SIMULATION) # include "pal_apple.h" -# include "pal_freebsd_kernel.h" # include "pal_freebsd.h" +# include "pal_freebsd_kernel.h" # include "pal_linux.h" # include "pal_netbsd.h" # include "pal_openbsd.h" diff --git a/src/pal/pal_bsd.h b/src/pal/pal_bsd.h index df3b846..f373825 100644 --- a/src/pal/pal_bsd.h +++ b/src/pal/pal_bsd.h @@ -1,8 +1,8 @@ #pragma once -# include "pal_posix.h" +#include "pal_posix.h" -# include +#include namespace snmalloc { From caec12c5456df4dccd213b9df26998a0084f281e Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Thu, 1 Aug 2019 12:53:03 +0100 Subject: [PATCH 12/12] Reduce the parallelism in Windows Release build tests. Hopefully this will stop the CI machines from running out of memory... --- azure-pipelines.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 728baab..f7ce06c 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -112,7 +112,7 @@ jobs: 64-bit Release: BuildType: Release CMakeArgs: '-G"Visual Studio 15 2017 Win64"' - JFlag: '-j 4' + JFlag: '-j 2' 64-bit Release Windows8Compat: BuildType: Release @@ -127,7 +127,7 @@ jobs: 32-bit Release: BuildType: Release CMakeArgs: '-G"Visual Studio 15 2017"' - JFlag: '-j 4' + JFlag: '-j 2' steps: - task: CMake@1