Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
feat: renice copy-ignored to lowest OS priority (#1916)
Maximilian Roos7bc0805e7ef2
diff --git a/docs/content/step.md b/docs/content/step.mdindex c1b9eef56..bef1fb78d 100644--- a/docs/content/step.md+++ b/docs/content/step.md@@ -358,7 +358,7 @@ Reflink copies share disk blocks until modified — no data is actually copied.| `cp -R` (full copy) | 2m || `cp -Rc` / `wt step copy-ignored` | 20s |-Uses per-file reflink (like `cp -Rc`) — copy time scales with file count.+Uses per-file reflink (like `cp -Rc`) — copy time scales with file count. On Unix, the process is automatically reniced to lowest priority (nice 19) so it yields to interactive work.Use the `post-start` hook so the copy runs in the background. Use `pre-start` instead if subsequent hooks or `--execute` command need the copied files immediately.diff --git a/skills/worktrunk/reference/step.md b/skills/worktrunk/reference/step.mdindex 4def81fc8..f771cdd1e 100644--- a/skills/worktrunk/reference/step.md+++ b/skills/worktrunk/reference/step.md@@ -373,7 +373,7 @@ Reflink copies share disk blocks until modified — no data is actually copied.| `cp -R` (full copy) | 2m || `cp -Rc` / `wt step copy-ignored` | 20s |-Uses per-file reflink (like `cp -Rc`) — copy time scales with file count.+Uses per-file reflink (like `cp -Rc`) — copy time scales with file count. On Unix, the process is automatically reniced to lowest priority (nice 19) so it yields to interactive work.Use the `post-start` hook so the copy runs in the background. Use `pre-start` instead if subsequent hooks or `--execute` command need the copied files immediately.diff --git a/src/cli/step.rs b/src/cli/step.rsindex 39f965f0d..81d1afd9b 100644--- a/src/cli/step.rs+++ b/src/cli/step.rs@@ -288,7 +288,7 @@ Reflink copies share disk blocks until modified — no data is actually copied.| `cp -R` (full copy) | 2m || `cp -Rc` / `wt step copy-ignored` | 20s |-Uses per-file reflink (like `cp -Rc`) — copy time scales with file count.+Uses per-file reflink (like `cp -Rc`) — copy time scales with file count. On Unix, the process is automatically reniced to lowest priority (nice 19) so it yields to interactive work.Use the `post-start` hook so the copy runs in the background. Use `pre-start` instead if subsequent hooks or `--execute` command need the copied files immediately.diff --git a/src/commands/step_commands.rs b/src/commands/step_commands.rsindex 4d08d3424..d3ba741d5 100644--- a/src/commands/step_commands.rs+++ b/src/commands/step_commands.rs@@ -707,6 +707,7 @@ pub fn step_copy_ignored(dry_run: bool,force: bool,) -> anyhow::Result<()> {+ worktrunk::copy::lower_process_priority();let repo = Repository::current()?;let copy_ignored_config = resolve_copy_ignored_config(&repo)?;diff --git a/src/copy.rs b/src/copy.rsindex 8cea86eb6..118dffba7 100644--- a/src/copy.rs+++ b/src/copy.rs@@ -7,6 +7,9 @@//! All copy I/O runs in a dedicated 4-thread pool rather than the global rayon//! pool (which is sized at 2× CPU cores for network I/O) to avoid saturating//! the CPU on a background operation.+//!+//! Callers that want low-priority I/O (e.g. `step_copy_ignored`) should call+//! [`lower_process_priority`] before starting work.use std::fs;use std::io::ErrorKind;@@ -40,6 +43,25 @@ pub fn copy_pool_install<R: Send>(f: impl FnOnce() -> R + Send) -> R {COPY_POOL.install(f)}+/// Lower the current process's scheduling priority so copy I/O doesn't+/// compete with interactive foreground work.+///+/// Uses `renice` rather than a direct `nice(2)` syscall to stay within the+/// `forbid(unsafe_code)` lint. Non-fatal: if `renice` is missing or fails,+/// copies proceed at normal priority.+pub fn lower_process_priority() {+ #[cfg(unix)]+ {+ use std::process::{Command, Stdio};+ let _ = Command::new("renice")+ .args(["-n", "19", "-p", &std::process::id().to_string()])+ .stdin(Stdio::null())+ .stdout(Stdio::null())+ .stderr(Stdio::null())+ .status();+ }+}+/// Copy a directory tree recursively using reflink (COW) per file.////// Handles regular files, directories, and symlinks. Non-regular files (sockets,