Skip to content

Try to reduce memory usage during sysimg build#50237

Merged
pchintalapudi merged 7 commits intomasterfrom
pc/32bit-memory
Jun 26, 2023
Merged

Try to reduce memory usage during sysimg build#50237
pchintalapudi merged 7 commits intomasterfrom
pc/32bit-memory

Conversation

@pchintalapudi
Copy link
Member

At least in the past, the most memory hungry step was emitting the system image to the object file. This is likely due to there being 3 or more copies of the sysimage live at that time, specifically:

  1. Inside the ios_t providing the system image buffer
  2. Inside the LLVMContext for the module
  3. Inside the object file being emitted

This PR tries to reduce the number of live copies to 2, by incrementally copying to the next stage of code generation and then explicitly freeing the previous stage's resources.

Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

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

Seems good to me

@vchuravy
Copy link
Member

Cross-compiling from 64bit to 32bit on Linux currently OOMs for me on master.
This lowers max VIRT memory usage from >4100M to ~3200M so a decent improvement.

@pchintalapudi
Copy link
Member Author

Note that we can't merge this until the windows builders are back online, there is still an unfixed win32 bug somewhere.

@vchuravy
Copy link
Member

Embedding test failed due to: Evaluated: "Triple is x86_64-unknown-linux-gnu" == "exception caught from C"

@vchuravy vchuravy added the priority This should be addressed urgently label Jun 23, 2023
@vchuravy vchuravy requested a review from vtjnash June 24, 2023 02:35
@pchintalapudi
Copy link
Member Author

@vchuravy could you confirm the memory benefits on the new implementation?

@maleadt
Copy link
Member

maleadt commented Jun 26, 2023

This PR fails to build for me, after VIRT memory usage crosses 4GB. So I guess not.

@pchintalapudi
Copy link
Member Author

That's odd, for me I'm not seeing it cross 3.7 virtual/3.3 reserved on a 64 bit build (default options, no multiversioning) with 1 thread.

@pchintalapudi
Copy link
Member Author

This PR fails to build for me, after VIRT memory usage crosses 4GB. So I guess not.

Resolved offline, peak memory usage varies fairly significantly between runs, but this PR does seem to reduce memory usage overall.

@pchintalapudi pchintalapudi merged commit 8630576 into master Jun 26, 2023
@pchintalapudi pchintalapudi deleted the pc/32bit-memory branch June 26, 2023 16:06
sysimgM.setDataLayout(DL);
sysimgM.setStackProtectorGuard(StackProtectorGuard);
sysimgM.setOverrideStackAlignment(OverrideStackAlignment);
Constant *data = ConstantDataArray::get(Context,
Copy link
Member

Choose a reason for hiding this comment

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

I think you also now could move the call to jl_create_system_image here, and avoid needing all of that extra memory (for z) until after LLVM is completely done and after we've freed most of the llvm::Module objects.

Copy link
Member Author

Choose a reason for hiding this comment

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

I suspect that change is more complicated, since we call jl_create_native as part of jl_create_system_image, and then I think we do a few more transformations on the module while generating z.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, but in that case the change might make more sense too, since the current organization sounds complicated also

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

Labels

priority This should be addressed urgently

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants