Skip to content

Fix build on GNU/Hurd - #2443

Open
sthibaul wants to merge 2 commits into
jemalloc:devfrom
sthibaul:dev
Open

sthibaul wants to merge 2 commits into
jemalloc:devfrom
sthibaul:dev

Conversation

@sthibaul

Copy link
Copy Markdown

No description provided.

paravoid added 2 commits May 16, 2023 17:02
GNU/Hurd has the cpuset types and macros, but no pthread_getaffinity_np
yet.
@paravoid

Copy link
Copy Markdown
Contributor

I maintain the Debian packages for jemalloc, and @sthibaul is also with the Debian project, and one of the GNU Hurd porters. Samuel also had to submit a couple of changes (1, 2) to glibc for jemalloc to work on Hurd; he's definitely the subject-matter expert here!

I've included the changes in this PR in our jemalloc (5.3.0) Debian package, and it has built successfully (build log) on Hurd, and is passing the test suite with no warnings.

I doubt Hurd is a priority for jemalloc, but given this works and the changes are trivial and not invasive at all, nor hurt any other ports, I was hoping you'd just merge it, so that we don't have to carry any downstream patches. Thanks!

@interwq interwq left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sharing the context @paravoid and @sthibaul. Added some questions.

Comment thread src/background_thread.c
#if defined(JEMALLOC_HAVE_SCHED_SETAFFINITY)
cpu_set_t cpuset;
#else
#elif defined(JEMALLOC_HAVE_PTHREAD_GETAFFINITY_NP)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: does Hurd have pthread_getaffinity_np but not pthread_setaffinity_np? Asking because L116 have the defined(JEMALLOC_HAVE_PTHREAD_SETAFFINITY_NP) check.

This section of the code is assuming background thread is supported, so we should not have unsupported cases workaround here. See L86 around #ifndef JEMALLOC_BACKGROUND_THREAD. If it's not possible to support bg thds on hurd, let's make it explicitly so. Maybe through:

if test "x${have_pthread}" = "x1" -a "x${je_cv_os_unfair_lock}" != "xyes" -a \

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does Hurd have pthread_getaffinity_np but not pthread_setaffinity_np?

No, it has none of the two (and not sched_setaffinity either)

This section of the code is assuming background thread is supported

Mmm, ok, but is thread binding really necessary for background thread support?

Comment thread src/jemalloc.c
# elif defined(JEMALLOC_HAVE_PTHREAD_GETAFFINITY_NP)
pthread_getaffinity_np(pthread_self(), sizeof(set), &set);
# else
CPU_ZERO(&set);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause jemalloc to detect wrong number of CPUs, and likely will not perform well, even defeating the purpose of using jemalloc. Is there no way to do so on hurd?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SMP support is still WIP, so it's actually the correct number of CPUs :)
That said, sysconf(_SC_NPROCESSORS_ONLN) will properly report 1, so perhaps it's the #elif defined(CPU_COUNT) above that should rather be #elif defined(CPU_COUNT) && (defined(JEMALLOC_HAVE_SCHED_SETAFFINITY) || defined(JEMALLOC_HAVE_PTHREAD_GETAFFINITY_NP)

@paravoid

Copy link
Copy Markdown
Contributor

Hi! Any news here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants