Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have homebrew use system jemalloc and hwloc #23366

Merged
merged 4 commits into from
Sep 14, 2023

Conversation

stonea
Copy link
Contributor

@stonea stonea commented Sep 13, 2023

Our nightly testing is encountering an issue we're linking to a system version of jemalloc despite configuring Chapel to use a bundled version (ultimately resulting in unsightly linker errors):

Undefined symbols for architecture arm64:
  "_chpl_je_dallocx", referenced from:
      _chpl_free in chpl__module.o
      _chpl_realloc in chpl__module.o
      _chpl_mem_layerInit in libchpl.a(mem-jemalloc.o)
      _qio_readv in libchpl.a(qio.o)
      _chpl_mem_free in libchpl.a(qio.o)
      _qio_writev in libchpl.a(qio.o)
      _qio_preadv in libchpl.a(qio.o)

I believe this is the same issue as: #18955

In order to get nightly testing back on track I think we should use the system version of jemalloc (and hwloc, which I think would run into a similar issue).

---
Signed-off-by: Andy Stone <stonea@users.noreply.github.com>
---
Signed-off-by: Andy Stone <stonea@users.noreply.github.com>
@@ -22,6 +22,7 @@ class Chapel < Formula
depends_on "llvm@14"
depends_on "python@3.10"
depends_on "cmake"
depends_on "hwloc"

Copy link
Contributor

Choose a reason for hiding this comment

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

Need depends_on jemalloc too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems like we should add it (it does depend on it after all).

For whatever reason things build fine without it but don't build fine if it's missing hwloc.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would guess that's just since jemalloc happens to be installed on our test machine already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nah, it would error out even with hwloc installed, here:

exists, retcode, my_out, my_err = try_run_command(
['pkg-config', '--atleast-version=2.1', 'hwloc'])
if exists and retcode != 0:
err = "CHPL_HWLOC=system requires hwloc >= 2.1"
error(err, ValueError)

That pkg-config command would work from the root shell but not whatever environment homebrew puts itself in during the install.

@@ -56,6 +57,11 @@ def install
(libexec/"chplconfig").write <<~EOS
CHPL_RE2=bundled
CHPL_GMP=system
CHPL_MEM=jemalloc
CHPL_HOST_MEM=jemalloc
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that CHPL_HOST_MEM defaults to cstdlib on mac. Not sure we need/want to set it here.

Also don't see any reason to explicitly set CHPL_MEM=jemalloc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the CHPL_HOST_MEM line because without it I was running into this (confusing) error message:

Error: CHPL_JEMALLOC must be 'none' when CHPL_MEM is not jemalloc

Confusing because this is despite the fact that I explicitly did set CHPL_MEM to jemalloc.

Taking a look at chpl_jemalloc.get:

def get(flag='target'):

it can be called with its flag parameter as either host or target. If it's host then the mem_val on this line is really referring to CHPL_HOST_MEM and jemalloc_val is really referring to CHPL_HOST_JEMALLOC:

if mem_val != 'jemalloc' and jemalloc_val != 'none':
error("CHPL_JEMALLOC must be 'none' when CHPL_MEM is not jemalloc")

Maybe we should have the error print CHPL_HOST_JEMALLOC/CHPL_TARGET_JEMALLOC and CHPL_HOST_MEM/CHPL_TARGET_MEM mem as appropriate. Though that might be confusing if the user really did set CHPL_MEM directly and this line in our doc makes me thing maybe it's going to be a moot point in a release or two anyway:

CHPL_TARGET_MEM will be replacing CHPL_MEM in the future. CHPL_TARGET_MEM takes precedence over CHPL_MEM.

In terms of what to do for this homebrew formula: now that I write this out, it seems like a better fix than setting CHPL_HOST_MEM=jemalloc would be to remove the CHPL_HOST_JEMALLOC=system line (in which case I think it defaults to none?). Trying it out this seems to build fine.

Also don't see any reason to explicitly set CHPL_MEM=jemalloc

Yep, looks like that one's not needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

In terms of what to do for this homebrew formula: now that I write this out, it seems like a better fix than setting CHPL_HOST_MEM=jemalloc would be to remove the CHPL_HOST_JEMALLOC=system line (in which case I think it defaults to none?). Trying it out this seems to build fine.

👍

Since we now require jemalloc to be system installed for mac homebrew

---
Signed-off-by: Andy Stone <stonea@users.noreply.github.com>
---
Signed-off-by: Andy Stone <stonea@users.noreply.github.com>
@stonea stonea merged commit 46cc8df into chapel-lang:main Sep 14, 2023
7 checks passed
stonea added a commit that referenced this pull request Sep 15, 2023
In #23366, I updated the
Homebrew formula to use system versions of jemalloc and hwloc.

Unfortunately, this change runs into issues. Some of which may be fixed
later by this PR
(#23409 (comment)).

There's also this issue about the bundled jemalloc makefile being run and
failing despite the fact that we're supposed to be using the system one
#23409 (comment)).

Given all this, and how close we are to the release, we decided to have
the formula use cstdlib for memory management instead.

[Reviewed by @ronawho]
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.

None yet

2 participants