Skip to content

Commit d0dc5ef

Browse files
committed
fix(deploy): genie-drop-caches.sh self-elevates via sudo tee
The script required running the whole thing as root and wrote the root-owned proc files with a plain redirect. Drop the root requirement and write through `sudo sync` + `echo N | sudo tee /proc/sys/vm/{drop_caches,compact_memory}` so it can be invoked as a normal user without `sudo bash` — only the privileged writes elevate.
1 parent 19879c5 commit d0dc5ef

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

deploy/scripts/genie-drop-caches.sh

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,17 @@
88
# free-memory headroom. It is safe (caches just re-warm from disk), so the only
99
# cost is a brief slowdown as hot files are re-read.
1010
#
11-
# Usage (on the Jetson, as root):
12-
# sudo bash /opt/geniepod/bin/genie-drop-caches.sh # drop everything (3)
13-
# sudo bash /opt/geniepod/bin/genie-drop-caches.sh 1 # page cache only
14-
# sudo bash /opt/geniepod/bin/genie-drop-caches.sh 2 # dentries + inodes
11+
# Usage (on the Jetson — uses sudo internally, so no need to run the whole
12+
# script as root):
13+
# bash /opt/geniepod/bin/genie-drop-caches.sh # drop everything (3)
14+
# bash /opt/geniepod/bin/genie-drop-caches.sh 1 # page cache only
15+
# bash /opt/geniepod/bin/genie-drop-caches.sh 2 # dentries + inodes
1516
#
1617
# Levels follow /proc/sys/vm/drop_caches: 1=pagecache, 2=slab (dentries/inodes),
1718
# 3=both (default).
1819

1920
set -euo pipefail
2021

21-
if [[ $EUID -ne 0 ]]; then
22-
echo "This script must run as root. Re-run with: sudo $0 $*" >&2
23-
exit 1
24-
fi
25-
2622
level="${1:-3}"
2723
case "$level" in
2824
1 | 2 | 3) ;;
@@ -36,13 +32,16 @@ avail_mb() { free -m | awk '/^Mem:/ {print $7}'; }
3632

3733
before="$(avail_mb)"
3834

39-
# Flush dirty pages first so they are reclaimable, then drop the requested caches.
40-
sync
41-
echo "$level" > /proc/sys/vm/drop_caches
35+
# Flush dirty pages first so they are reclaimable, then drop the requested
36+
# caches. Only the privileged writes use sudo: the proc files are root-owned, and
37+
# a plain `echo 3 > /proc/...` runs the redirect as the calling user and fails —
38+
# so write through `sudo tee` instead.
39+
sudo sync
40+
echo "$level" | sudo tee /proc/sys/vm/drop_caches > /dev/null
4241

4342
# Best-effort: compact free memory so large contiguous allocations (model load /
4443
# KV cache) are easier to satisfy. Not present on every kernel — ignore failures.
45-
echo 1 > /proc/sys/vm/compact_memory 2>/dev/null || true
44+
echo 1 | sudo tee /proc/sys/vm/compact_memory > /dev/null 2>&1 || true
4645

4746
after="$(avail_mb)"
4847

0 commit comments

Comments
 (0)