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

Change default temp on Linux to /var/tmp. #19038

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

averms
Copy link

@averms averms commented Jan 5, 2025

Previously, the default temporary directory was /tmp on Linux and /private/tmp on macOS. On many Linux distros, including at least Fedora, /tmp is stored in RAM. This diverges from the behavior on macOS and has led to bugs, most notably the inability to install large bottles on memory-limited machines.

This fixes #19037.

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

Please let me know if there's anything else I need to change.

averms added 2 commits January 4, 2025 21:31
Previously, the default temporary directory was /tmp on Linux and
/private/tmp on macOS. On many Linux distros, including at least Fedora,
/tmp is stored in RAM. This diverges from the behavior on macOS and has
led to bugs, most notably the inability to install large bottles on
memory-limited machines.

This fixes Homebrew#19037.
@MikeMcQuaid
Copy link
Member

To me it makes more sense to scope this to either just Fedora or just when /tmp is tmpfs. I'm open to input from @Homebrew/maintainers, though.

@SMillerDev
Copy link
Member

Can we detect where to put this somehow?

@fxcoudert
Copy link
Member

I don't think we want to detect it every time we run the brew script. And Debian is moving to having in-RAM /tmp, like most distros already do: https://linuxiac.com/debian-13-moves-to-tmpfs-for-tmp-directory/

However, I would note that moving the temporary directory to /var/tmp means that things will be slower for most users. That's a significant downside.

@averms
Copy link
Author

averms commented Jan 5, 2025

just when /tmp is tmpfs.

Can we detect where to put this somehow?

This can be done with findmnt --target /tmp --output fstype --noheadings. It uses findmnt(8), which is in util-linux.

However, I agree with @fxcoudert. This is already the default behavior in just about every RPM-based distro and in Arch Linux and it will be soon in Debian

However, I would note that moving the temporary directory to /var/tmp means that things will be slower for most users. That's a significant downside.

Could you explain why for those of us not familiar with Homebrew internals?

@fxcoudert
Copy link
Member

moving the temporary directory to /var/tmp means that things will be slower for most users

The reason why /tmp is faster than /var/tmp is that it is RAM-based, rather than disk-based.

@iMichka
Copy link
Member

iMichka commented Jan 7, 2025

moving the temporary directory to /var/tmp means that things will be slower for most users

The reason why /tmp is faster than /var/tmp is that it is RAM-based, rather than disk-based.

Agreed. That's a pretty bad downside.

I see three solutions:

  • catch the "No space left on device" error, and fallback to /var/tmp for a second attempt
  • check the installed size upfront and if it will use too much RAM fallback to /var/tmp before installing
  • ignore this edge-case (maybe document it as unsupported) / or require 8 Gb? of RAM to use Hombrew on Linux for those systems?

@fxcoudert
Copy link
Member

How about: catch the ENOSPC and suggest the user set HOMEBREW_TEMP to a suitable space?

@averms
Copy link
Author

averms commented Jan 7, 2025

The reason why /tmp is faster than /var/tmp is that it is RAM-based, rather than disk-based.

I would be cautious about assuming that applies to all operations without supporting evidence. While I’m not familiar with every use of HOMEBREW_TEMP, based on my benchmarking, I’ve found that the performance of brew install is identical whether using /var/tmp or /tmp.

Untarring and decompressing from disk into memory and then writing those files back to disk doesn’t result in any performance improvement compared to simply untarring directly onto disk and renaming afterward — at least when both the source and destination are on the same file system.

@MikeMcQuaid
Copy link
Member

I would be cautious about assuming that applies to all operations without supporting evidence. While I’m not familiar with every use of HOMEBREW_TEMP, based on my benchmarking, I’ve found that the performance of brew install is identical whether using /var/tmp or /tmp.

Maintaining the status quo doesn't require supporting evidence, proposing a change does.

@MikeMcQuaid
Copy link
Member

An argument in favour of this change: this makes things more similar to macOS and we've never had serious complaints about the status-quo there.

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.

Can't pour large bottles on Fedora Linux
5 participants