folly icon indicating copy to clipboard operation
folly copied to clipboard

redefinition of ‘struct extent_hooks_s’

Open ftiasch opened this issue 6 years ago • 15 comments

Building on Archlinux gives me the following error:

Building CXX object CMakeFiles/folly_base.dir/folly/experimental/JemallocHugePageAllocator.cpp.o
/home/ftiasch/Documents/folly/src/folly-2018.09.24.00/folly/experimental/JemallocHugePageAllocator.cpp:52:8: error: redefinition of ‘struct extent_hooks_s’
 struct extent_hooks_s {
        ^~~~~~~~~~~~~~
In file included from /home/ftiasch/Documents/folly/src/folly-2018.09.24.00/folly/memory/Malloc.h:32,
                 from /home/ftiasch/Documents/folly/src/folly-2018.09.24.00/folly/experimental/JemallocHugePageAllocator.h:22,
                 from /home/ftiasch/Documents/folly/src/folly-2018.09.24.00/folly/experimental/JemallocHugePageAllocator.cpp:17:
/usr/include/jemalloc/jemalloc.h:339:8: note: previous definition of ‘struct extent_hooks_s’
 struct extent_hooks_s {
        ^~~~~~~~~~~~~~

Is the jemalloc installed too new?

ftiasch avatar Sep 29 '18 08:09 ftiasch

I have exactly the same problem too. os: Manjaro (Archlinux) jemalloc version: 5.1

detective7th avatar Oct 10 '18 20:10 detective7th

The intention is that for jemalloc version > 5, that definition should not be compiled (see folly/experimental/JemallocHugePageAllocator.cpp:27). Can you check what JEMALLOC_VERSION_MAJOR reports?

gdankel avatar Oct 10 '18 23:10 gdankel

@gdankel my JEMALLOC_VERSION_MAJOR is 5. Checked with the following code:

#include <cstdio>
#include <jemalloc/jemalloc.h>

int main()
{
    printf("%d\n", JEMALLOC_VERSION_MAJOR);
}

It prints "5".

ftiasch avatar Oct 11 '18 03:10 ftiasch

@ftiasch Thanks! Could you also please try commenting out line 26 and see if anything changes:

//#include <jemalloc/jemalloc.h>

It's likely the case that jemalloc.h is getting included via one of the other headers.

gdankel avatar Oct 11 '18 04:10 gdankel

@gdankel it still presents the same error.

ftiasch avatar Oct 11 '18 04:10 ftiasch

OK, you can try this patch to JemallocHugePageAllocator.cpp:

@@ -40,6 +40,8 @@
 #define MALLOCX_ARENA(x) 0
 #define MALLOCX_TCACHE_NONE 0
 #define MADV_HUGEPAGE 0
+
+#ifndef JEMALLOC_VERSION_MAJOR
 typedef struct extent_hooks_s extent_hooks_t;
 typedef void*(extent_alloc_t)(
     extent_hooks_t*,
@@ -52,6 +54,8 @@
 struct extent_hooks_s {
   extent_alloc_t* alloc;
 };
+#endif // JEMALLOC_VERSION_MAJOR
+
 bool folly::JemallocHugePageAllocator::hugePagesSupported{false};
 #endif // FOLLY_JEMALLOC_HUGE_PAGE_ALLOCATOR_SUPPORTED

gdankel avatar Oct 11 '18 05:10 gdankel

it works!

ftiasch avatar Oct 11 '18 05:10 ftiasch

I'll submit a proper patch - there might be an issue with jemalloc version < 5 as well if the header is included via another header.

By the way, just to make it clear (if you're trying to use this allocator) - with this part of the code compiled if won't actually back the memory by huge pages.

gdankel avatar Oct 11 '18 17:10 gdankel

There seems to be an issue with the FOLLY_HAVE_LIBJEMALLOC as well. You can try to replace that with FOLLY_USE_JEMALLOC (in the same file). This is probably the better fix in your case.

gdankel avatar Oct 12 '18 17:10 gdankel

We're working on this internally :)

Orvid avatar Oct 12 '18 17:10 Orvid

Building folly in an Ubuntu 18.04 docker container with jemalloc from head is giving me this same error. I was able to resolve it with the patch here on this issue. Is there a reason the patch can't be merged? Thanks

mechanyx avatar Feb 06 '19 22:02 mechanyx

We did merge a different patch that seems to have worked for most folks. I will also merge the above.

gdankel avatar Feb 20 '19 00:02 gdankel

Great, thank you. I'm currently applying the patch after checking out folly in our build script. I imagine there are others who will also benefit from having this merged. Thanks!

mechanyx avatar Feb 20 '19 01:02 mechanyx

Sorry, I meant to follow up here. It appears that part of the problem is that jemalloc isn't setting its version when building from source. The configure script checks for a file called VERSION in the root of its checkout and, in my instance, that file was not there. I needed to create such a file with an appropriate version number inside to get this to work. Thanks

mechanyx avatar Apr 19 '19 22:04 mechanyx

This happens if jemalloc was built from source without the --with-version option set properly.

dutor avatar Sep 13 '23 05:09 dutor