From 05d7fa7e3796ce9dbec946a1c0694d08b03d0d15 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Thu, 5 Feb 2026 11:40:20 -0500 Subject: [PATCH] Implement parallel SMART data collection for faster execution SMART queries are now run in parallel using background jobs: 1. First pass launches background jobs for all devices 2. Each job writes to a temp file in SMART_CACHE_DIR 3. Wait for all jobs to complete 4. Second pass reads cached data for display This significantly reduces script runtime when multiple drives are present, as SMART queries can take 1-2 seconds each. Cache directory is automatically cleaned up after use. Fixes: https://code.lotusguild.org/LotusGuild/driveAtlas/issues/15 Co-Authored-By: Claude Opus 4.5 --- driveAtlas.sh | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/driveAtlas.sh b/driveAtlas.sh index a7a7b69..5f75012 100644 --- a/driveAtlas.sh +++ b/driveAtlas.sh @@ -855,12 +855,32 @@ done # Sort drives by bay position (numeric bays first, then m2 slots) # Combine numeric bays (sorted numerically) with m2 slots (sorted alphanumerically) all_bays=$(printf '%s\n' "${!DRIVE_MAP[@]}" | grep -E '^[0-9]+$' | sort -n; printf '%s\n' "${!DRIVE_MAP[@]}" | grep -E '^m2-' | sort) + +# Parallel SMART data collection for faster execution +# Collect SMART data in background jobs, store in temp files +if [[ "$SKIP_SMART" != true ]]; then + SMART_CACHE_DIR="$(mktemp -d)" + log_info "Collecting SMART data in parallel..." + + for bay in $all_bays; do + device="${DRIVE_MAP[$bay]}" + if [[ -n "$device" && "$device" != "EMPTY" && -b "/dev/$device" ]]; then + # Launch background job for each device + (get_drive_smart_info "$device" > "$SMART_CACHE_DIR/$device") & + fi + done + + # Wait for all background SMART queries to complete + wait + log_info "SMART data collection complete" +fi + for bay in $all_bays; do device="${DRIVE_MAP[$bay]}" if [[ -n "$device" && "$device" != "EMPTY" && -b "/dev/$device" ]]; then size="$(lsblk -d -n -o SIZE "/dev/$device" 2>/dev/null)" - # Get SMART info (or defaults if skipped) + # Get SMART info from cache (or defaults if skipped) if [[ "$SKIP_SMART" == true ]]; then type="-" temp="-" @@ -869,7 +889,12 @@ for bay in $all_bays; do serial="-" warnings="" else - smart_info="$(get_drive_smart_info "$device")" + # Read from cached SMART data + if [[ -f "$SMART_CACHE_DIR/$device" ]]; then + smart_info="$(cat "$SMART_CACHE_DIR/$device")" + else + smart_info="" + fi IFS='|' read -r type temp health model serial warnings <<< "$smart_info" fi @@ -926,6 +951,11 @@ for bay in $all_bays; do fi done +# Clean up SMART cache directory +if [[ -n "${SMART_CACHE_DIR:-}" && -d "$SMART_CACHE_DIR" ]]; then + rm -rf "$SMART_CACHE_DIR" +fi + # NVMe drives (only show unmapped ones - mapped NVMe drives appear in main table) nvme_devices=$(lsblk -d -n -o NAME,SIZE | grep "^nvme" 2>/dev/null) if [[ -n "$nvme_devices" ]]; then