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

Make compilecache atomic #30174

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ Language changes
to the `Core` module ([#29968]).
* Using the same name for both a local variable and a static parameter is now an error instead
of a warning ([#29429]).
* Precompilation cache files are now created atomically ([#30174]). Note that
invoking _n_ `julia` processes simultaneously may creates _n_ temporary
tkf marked this conversation as resolved.
Show resolved Hide resolved
copies of cache files.

New library functions
---------------------
Expand Down
27 changes: 20 additions & 7 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1185,18 +1185,31 @@ function compilecache(pkg::PkgId, path::String)
else
@logmsg verbosity "Precompiling $pkg"
end
p = create_expr_cache(path, cachefile, concrete_deps, pkg.uuid)
if success(p)
# append checksum to the end of the .ji file:
open(cachefile, "a+") do f
write(f, _crc32c(seekstart(f)))
# create a temporary file in `cachepath` directory, write the cache in it,
# write the checksum, _and then_ atomically move the file to `cachefile`.
tmppath, tmpio = mktemp(cachepath)
local p
try
close(tmpio)
p = create_expr_cache(path, tmppath, concrete_deps, pkg.uuid)
if success(p)
# append checksum to the end of the .ji file:
open(tmppath, "a+") do f
write(f, _crc32c(seekstart(f)))
end
# this is atomic according to POSIX:
rename(tmppath, cachefile)
return cachefile
end
elseif p.exitcode == 125
finally
# not using `mktemp() do ...` to pass `force=true` to `rm`
rm(tmppath, force=true)
end
if p.exitcode == 125
return PrecompilableError()
else
error("Failed to precompile $pkg to $cachefile.")
end
return cachefile
end

module_build_id(m::Module) = ccall(:jl_module_build_id, UInt64, (Any,), m)
Expand Down
16 changes: 16 additions & 0 deletions doc/src/manual/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,22 @@ a scalar can participate in linear algebra operations such as `2 * rand(2,2)`,
but the analogous operation with a zero-dimensional array
`fill(2) * rand(2,2)` is an error.

## Computing cluster

### How do I manage precompilation cache files in distributed file systems?

When using `julia` in high-performance computing (HPC) facilities, invoking
_n_ `julia` processes simultaneously creates at most _n_ temporary copies of
cache files. It may become a major issue in slow and/or small distributed
file systems. There are a few possible workarounds:

1. Use `julia` with `--compilecache=no` flag to turn off precompilation.
Copy link

Choose a reason for hiding this comment

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

This option has been renamed: https://github.com/JuliaLang/julia/pull/23616/files

compilecache -> compiled-modules

2. Configure a private writable depot using `pushfirst!(DEPOT_PATH, private_path)`
where `private_path` is a path unique to this `julia` process. This
can also be done by setting environment variable `JULIA_DEPOT_PATH` to
`$private_path:$HOME/.julia`.
3. Create a symlink from `~/.julia/compiled` to a directory in a scratch space.

## Julia Releases

### Do I want to use a release, beta, or nightly version of Julia?
Expand Down