Repository navigation
Shortcut already-hardlinked files - #251
Conversation
If an inode in the Nix store has more than 1 link, it probably means that it was linked into .links/ by us. If so, skip. There's a possibility that something else hardlinked the file, so it would be nice to be able to override this. Also, by looking at the number of hardlinks for each of the files in .links/, you can get deduplication numbers and space savings.
|
I like this. Perhaps we can unlink any hard links in |
|
Another way would be to load all .links inode numbers and hashes into memory at optimization start. Then there's no guessing necessary... Shouldn't be a problem memory-wise right? |
|
So is there anything preventing a merge? Worst case, some files don't get deduplicated, and this greatly speeds up optimization runs, to where it's a no-brainer to enable auto-optimise |
|
Only @edolstra can merge this. |
|
Well, it's not entirely correct, since it prevents some files from being deduplicated. In particular, if you run the optimiser and then delete the .links directory (which is allowed), then you'll have a lot of files with multiple links which are not in .links. I think scanning the inode numbers in .links is a better approach. |
By preloading all inodes in the /nix/store/.links directory, we can quickly determine of a hardlinked file was already linked to the hashed links. This is tolerant of removing the .links directory, it will simply recalculate all hashes in the store.
|
@edolstra how about this? |
|
I left out the hash loading for the auto-optimize case, because I reasoned those files would be new to the store anyway, right? It does cache the newly linked files so it can skip hardlinks of those. |
|
And another thing that would be nice-ish is looking at the .links directory to get accurate deduplication statistics (size and count); however that takes time to calculate and isn't very useful... Perhaps only in the --optimize case because then the user is not worried about execution time? |
|
@edolstra indeed that's much better. Done. |
|
I just realized that the same thing applies to walking the store itself. I'll add that. |
readdir() already returns the inode numbers, so we don't need to call lstat to know if a file was already linked or not.
|
@edolstra I can't think of ways to make it faster now :) ...although I wonder if the unordered_set should instead be an ordered set, perhaps it uses less memory through range compression. I don't know. |
|
Merged, thanks! |
…ns/cachix/install-nix-action-17 chore(deps): bump cachix/install-nix-action from 16 to 17
Fixes NixOS#251. We aren't using them. Change-Id: Ib24da6e0277bdd6afa9103c553c743a610f7b4e1
Move cargo.sh to the top level
…rt-url Tell our users to file issues with us, not upstream
…OS#259, fixes ledger Independent whole-branch audit (22 agents -> dedup -> per-finding adversarial verify): 70 findings, 63 confirmed, 7 refuted. Catalog corrections (counts/claims re-derived against master): - NixOS#65: recorded grep was malformed (anchored `builtins\."` returns 2, not 79); restored the unanchored form, noted the 87-name-anchored alternative is a different set (F014). - NixOS#18: B3's grep returns 24 lines / 23 hand-written, not 17; added the six omitted names (F016). - NixOS#169/NixOS#217/N33: friend count is 11 Expr* lines / 10 distinct, not "10 / 9" (F013). - NixOS#103/N6 + verified/05: RewritingSink no longer "tracks match positions"; matches is dead and HashModuloSink::finish's loop is inert since 3ebe134 (F019). - NixOS#138: eval.cc read-site is copyPathToStore, not the nonexistent "addToStore" (F006). - NixOS#218 + STATUS: placeholder inventory undercounted (6 -> 7-8); the wire-marker is the BuildResult compat StringMap, not a DrvOutput serialisation; nix-store.cc misfiled as a "legitimate constant" (F007-F011). - README U7b/U7c + N1: migratable cache count and per-site exclusion reasons (F017/F018). - verified/19: nix_get_external is a functional bug, not a "quirk"; nix_store_path_hash missing-preamble outlier (F003/F052). - verified/17: tree glyphs live in libutil util.hh, not "libcmd headers" (F035). - NixOS#11-legacy NixOS#222/NixOS#231 + FOLLOWUPS: --max-freed mechanism and the --priority getArg mis-recommendation (F001/F002). New candidates NixOS#241-NixOS#259 filed into their topical sections (per the catalog's group-by-symptom principle): 03 (NixOS#244), 07 (NixOS#246), 08 (NixOS#243), 10 (NixOS#253,NixOS#255), 12 (NixOS#241,NixOS#242,NixOS#259), 13 (NixOS#248,NixOS#249,NixOS#251), 16 (NixOS#245,NixOS#247), 17 (NixOS#254,NixOS#256), 20 (NixOS#250,NixOS#252), 23 (NixOS#257,NixOS#258). NixOS#122: re-verified the stackOverflowHandler symbol-mangle caveat is correct as written (F062). The audit is recorded as a STATUS.md "Recently completed" event (it subsumes the per-finding report; no standalone report file is kept). The corresponding code fixes are uncommitted on the cleanup worktrees. Also converted the macOS /Users/cbaker2 paths in HANDOFF.md/STATUS.md to the Linux /home/cbaker2 paths used on this machine. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
/NixOS#252/NixOS#258/NixOS#259, NixOS#251 deferred Records the first single-shard foundation batch landed on the cleanup branches (one commit per candidate, all nix build -L . green): - NixOS#259 (libutil): LocalSigner moves the SecretKey; publicKey derived from the member to avoid use-of-moved-from without a member reorder. - NixOS#243 (libutil): git size/mode parses use checked helpers throwing SerialisationError instead of std::stoi's std::logic_error (latent bug for >=2GiB objects / malformed headers). - NixOS#244 (libutil): MemorySink::openForCreate prelude extracted; both diagnostic nouns preserved byte-for-byte. - NixOS#252 (libexpr): setTagged collapses the three tag-only AttrDb setters. - NixOS#258 (libflake): applyLockMode + mode table for the C entry points (ABI-preserving); fixed the stale nix_flake_lock_flags_new comments. NixOS#251 (libexpr queryMetaTyped) marked deferred-not-landed: re-judged marginal against the churn standard (template threads two callables per site, legacy path, no extra caller). Tip-SHA table refreshed (libutil a16c0a7, libexpr 411cc11, libflake b29de94) with per-branch push modes (fast-forward vs force). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
If an inode in the Nix store has more than 1 link, it probably means that it was linked into .links/ by us. If so, skip. This results in super-fast optimization runs.
There's a possibility that something else hardlinked the file, so it would be nice to be able to override this.
Note: by looking at the number of hardlinks for each of the files in .links/, you can get accurate deduplication numbers and space savings. This requires going through all files in the .links/ directory, but that may be a good idea anyway, to remove the ones that have only one link.