Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions docs/src/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ These algorithms also work with `--check`, using tags such as `BLAKE3-256` or
`du` allows `birth` and `creation` as values for the `--time` argument to show the creation time. It
also provides a `-v`/`--verbose` flag.

<!-- spell-checker:ignore FIEMAP reflink reflinks -->
On Linux, `--dedupe-reflinks` uses FIEMAP to count identical shared physical
extents only once. The first file encountered owns each extent. Directory
entries are processed in lexical order for deterministic results, while command
line operands retain their given order. Only exact extent matches are
deduplicated; partially overlapping CoW extents remain counted separately.
FIEMAP adds one or more system calls per regular file, so this mode can be
significantly slower. It conflicts with `--apparent-size`, `--bytes`, `--inodes`,
and `--count-links`. A file that `du` lacks permission to read, or that sits on
a filesystem without FIEMAP, is counted at its full size, as without the
option, so an unreadable reflink clone is not deduplicated. Any other failure
to open or query a regular file is reported once, the file and its other hard
links are omitted from the totals, and `du` exits nonzero.

## `env`

GNU `env` allows the empty string to be used as an environment variable name.
Expand Down
3 changes: 3 additions & 0 deletions src/uu/du/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ uucore = { workspace = true, features = [
[target.'cfg(all(unix, not(target_os = "redox")))'.dependencies]
uucore = { workspace = true, features = ["safe-traversal"] }

[target.'cfg(target_os = "linux")'.dependencies]
libc = { workspace = true }

[target.'cfg(windows)'.dependencies]
windows-sys = { workspace = true, features = [
"Win32_Storage_FileSystem",
Expand Down
75 changes: 75 additions & 0 deletions src/uu/du/benches/du_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ use tempfile::TempDir;
use uu_du::uumain;
use uucore::benchmark::{fs_tree, get_bench_args};

#[cfg(target_os = "linux")]
use std::{
fs,
process::{Command, Stdio},
};

/* too much variance
/// Benchmark default du on balanced tree
#[divan::bench(args = [(5, 4, 10)])]
Expand Down Expand Up @@ -120,6 +126,75 @@ fn du_summarize_balanced_tree(
.bench_values(|args| black_box(uumain(args)));
}

/// Benchmark du --dedupe-reflinks on wide tree.
/// Measures the per-file open and identity check added by the flag. Files in
/// `fs_tree` are empty, so FIEMAP itself is skipped here; see
/// `du_dedupe_reflink_clones` for the extent query cost.
#[cfg(target_os = "linux")]
#[divan::bench(args = [(5000, 500)])]
fn du_dedupe_reflinks_wide_tree(bencher: Bencher, (total_files, total_dirs): (usize, usize)) {
let temp_dir = TempDir::new().unwrap();
let temp_path = temp_dir.path();
fs_tree::create_wide_tree(temp_path, total_files, total_dirs);

bencher
.with_inputs(|| {
get_bench_args([OsStr::new("--dedupe-reflinks"), temp_path.as_os_str()]).into_iter()
})
.bench_values(|args| black_box(uumain(args)));
}

/// Benchmark populated deduplication state using real reflink clones.
///
/// Fixture creation is intentionally outside the timed closure. Filesystems
/// without reflink support do not produce a benchmark sample.
#[cfg(target_os = "linux")]
#[divan::bench]
fn du_dedupe_reflink_clones(bencher: Bencher) {
const CLONE_COUNT: usize = 256;
const FILE_SIZE: usize = 1024 * 1024;

let temp_dir = TempDir::new().unwrap();
let source = temp_dir.path().join("source");
let mut data = vec![0_u8; FILE_SIZE];
let mut random_state = 0x4d59_5df4_d0f3_3173_u64;
for byte in &mut data {
random_state ^= random_state << 13;
random_state ^= random_state >> 7;
random_state ^= random_state << 17;
*byte = random_state as u8;
}
fs::write(&source, data).unwrap();
fs::File::open(&source).unwrap().sync_all().unwrap();

for index in 0..CLONE_COUNT {
let destination = temp_dir.path().join(format!("clone-{index:04}"));
let status = Command::new("cp")
.arg("--reflink=always")
.arg(&source)
.arg(destination)
.stdout(Stdio::null())
.stderr(Stdio::null())
.status();
if !status.is_ok_and(|status| status.success()) {
eprintln!("skipping du_dedupe_reflink_clones: reflinks are unsupported");
return;
}
}

let temp_path = temp_dir.path();
let args =
|| get_bench_args([OsStr::new("--dedupe-reflinks"), temp_path.as_os_str()]).into_iter();
if uumain(args()) != 0 {
eprintln!("skipping du_dedupe_reflink_clones: FIEMAP validation failed");
return;
}

bencher
.with_inputs(args)
.bench_values(|args| black_box(uumain(args)));
}

fn main() {
divan::main();
}
6 changes: 6 additions & 0 deletions src/uu/du/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ du-help-si = like -h, but use powers of 1000 not 1024
du-help-one-file-system = skip directories on different file systems
du-help-threshold = exclude entries smaller than SIZE if positive, or entries greater than SIZE if negative
du-help-verbose = verbose mode (option not present in GNU/Coreutils)
du-help-dedupe-reflinks = count storage shared via reflinks (CoW copies) only once (Linux only; requires FIEMAP). Adds significant overhead.
du-help-exclude = exclude files that match PATTERN
du-help-exclude-from = exclude files that match any pattern in FILE
du-help-files0-from = summarize device usage of the NUL-terminated file names specified in file F; if F is -, then read names from standard input
Expand All @@ -57,6 +58,11 @@ du-error-invalid-time-style = invalid argument { $style } for 'time style'
Try '{ $help }' for more information.
du-error-invalid-time-arg = 'birth' and 'creation' arguments for --time are not supported on this platform.
du-error-invalid-glob = Invalid exclude syntax: { $error }
du-error-dedupe-reflinks-not-supported = --dedupe-reflinks is only supported on Linux
du-error-unknown-file-identity = could not determine file identity
du-error-file-changed-during-reflink-scan = file changed while collecting reflink extents
du-error-fiemap-no-progress = FIEMAP pagination made no progress
du-error-fiemap-too-many-extents = FIEMAP returned too many extents
du-error-cannot-read-directory = cannot read directory { $path }
du-error-cannot-access = cannot access { $path }
du-error-read-error-is-directory = { $file }: read error: Is a directory
Expand Down
6 changes: 6 additions & 0 deletions src/uu/du/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ du-help-si = comme -h, mais utiliser les puissances de 1000 et non 1024
du-help-one-file-system = ignorer les répertoires sur des systèmes de fichiers différents
du-help-threshold = exclure les entrées plus petites que TAILLE si positive, ou les entrées plus grandes que TAILLE si négative
du-help-verbose = mode verbeux (option non présente dans GNU/Coreutils)
du-help-dedupe-reflinks = compter le stockage partagé via des reflinks (copies CoW) une seule fois (Linux uniquement ; nécessite FIEMAP). Ajoute un surcoût important.
du-help-exclude = exclure les fichiers qui correspondent au MOTIF
du-help-exclude-from = exclure les fichiers qui correspondent à n'importe quel motif dans FICHIER
du-help-files0-from = résumer l'utilisation du périphérique des noms de fichiers terminés par NUL spécifiés dans le fichier F ; si F est -, alors lire les noms depuis l'entrée standard
Expand Down Expand Up @@ -70,6 +71,11 @@ du-error-invalid-suffix = suffixe invalide dans l'argument --{ $option } { $valu
du-error-invalid-argument = argument --{ $option } invalide { $value }
du-error-argument-too-large = argument --{ $option } { $value } trop grand
du-error-hyphen-file-name-not-allowed = le nom de fichier '-' n'est pas autorisé lors de la lecture de l'entrée standard
du-error-dedupe-reflinks-not-supported = --dedupe-reflinks n'est pris en charge que sous Linux
du-error-unknown-file-identity = impossible de déterminer l'identité du fichier
du-error-file-changed-during-reflink-scan = le fichier a changé pendant la collecte des extents reflink
du-error-fiemap-no-progress = la pagination FIEMAP n'a pas progressé
du-error-fiemap-too-many-extents = FIEMAP a renvoyé trop d'extents

# Messages verbeux/de statut
du-verbose-ignored = { $path } ignoré
Expand Down
Loading
Loading