|
@@ -73,11 +73,24 @@ fix_dirty_frag() {
|
|
|
done
|
|
done
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-# --- Function: Memory Sanitization ---
|
|
|
|
|
|
|
+# --- Function: Memory Sanitization with Timeout ---
|
|
|
clear_caches() {
|
|
clear_caches() {
|
|
|
- log_info "Dropping system caches to ensure memory purity..."
|
|
|
|
|
- sync
|
|
|
|
|
- echo 3 > /proc/sys/vm/drop_caches
|
|
|
|
|
|
|
+ log_info "Attempting to drop system caches safely..."
|
|
|
|
|
+
|
|
|
|
|
+ # 1. First, try to sync dirty buffers to disk with a timeout.
|
|
|
|
|
+ # If sync hangs, it indicates heavy I/O or storage issues.
|
|
|
|
|
+ if ! timeout 15s sync; then
|
|
|
|
|
+ log_warn "System sync timed out. There might be heavy I/O load. Skipping drop_caches."
|
|
|
|
|
+ return 0
|
|
|
|
|
+ fi
|
|
|
|
|
+
|
|
|
|
|
+ # 2. Write to drop_caches with a timeout.
|
|
|
|
|
+ # We use a subshell to prevent the main script from hanging if the kernel is unresponsive.
|
|
|
|
|
+ if ! timeout 5s sh -c "echo 3 > /proc/sys/vm/drop_caches" 2>/dev/null; then
|
|
|
|
|
+ log_warn "drop_caches operation timed out. Kernel is likely busy reclaiming Slabs."
|
|
|
|
|
+ else
|
|
|
|
|
+ log_info "Caches dropped successfully."
|
|
|
|
|
+ fi
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
# --- Main Execution ---
|
|
# --- Main Execution ---
|