64 lines
2.6 KiB
Python
64 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Lab holder, v3: the same queue protocol as ~/work/gpu-runs/holder/kar_holder2.py, but the sealed memfd is NOT filled here.
|
|
|
|
`single-copy-holder.sh` runs `leleka seal-exec --file ARCHIVE -- python3 single-copy-holder.py {FD} JOBS`: the Rust sealer copies the archive with large
|
|
O_DIRECT blocks on many threads (docs: unattended "fast cold load"; 600 MB/s and up against 8-35 MB/s for a buffered 16 MiB read loop on this NVMe) and never
|
|
leaves the 55 GB in the page cache, which kar_holder2.py's buffered read does (a second copy of the archive in RAM, ~50 GB, until something evicts it).
|
|
This process only inherits the descriptor and runs the job scripts exactly as kar_holder2.py does:
|
|
|
|
* queue: names listed in JOBS/PRIORITY (top first), then the oldest *.sh first; the queue is re-read after every job; files younger than 3 s are skipped;
|
|
* a job runs as `bash JOB` with LELEKA_STRA169_KAR_FD=<fd> and the fd passed; JOB.running while it runs, JOB.done (rc) after;
|
|
* JOBS/STOP (checked between jobs) ends the holder; JOBS/READY holds the fd number.
|
|
"""
|
|
import glob, os, subprocess, sys, time
|
|
|
|
fd = int(sys.argv[1])
|
|
jobs = sys.argv[2]
|
|
st = os.fstat(fd)
|
|
print(f"holder3 ready fd={fd} bytes={st.st_size} allocated={st.st_blocks * 512}", flush=True)
|
|
open(os.path.join(jobs, "READY"), "w").write(str(fd))
|
|
|
|
|
|
def pending():
|
|
out = []
|
|
for job in glob.glob(os.path.join(jobs, "*.sh")):
|
|
base = job[:-3]
|
|
if os.path.exists(base + ".done") or os.path.exists(base + ".running"):
|
|
continue
|
|
try:
|
|
if time.time() - os.path.getmtime(job) < 3:
|
|
continue
|
|
out.append((os.path.getmtime(job), job))
|
|
except OSError:
|
|
pass
|
|
return out
|
|
|
|
|
|
def pick():
|
|
p = pending()
|
|
if not p:
|
|
return None
|
|
try:
|
|
prio = [l.strip() for l in open(os.path.join(jobs, "PRIORITY")) if l.strip() and not l.startswith("#")]
|
|
except OSError:
|
|
prio = []
|
|
byname = {os.path.basename(j)[:-3]: j for _, j in p}
|
|
for name in prio:
|
|
if name in byname:
|
|
return byname[name]
|
|
return min(p)[1]
|
|
|
|
|
|
while not os.path.exists(os.path.join(jobs, "STOP")):
|
|
job = pick()
|
|
if job is None:
|
|
time.sleep(2)
|
|
continue
|
|
base = job[:-3]
|
|
open(base + ".running", "w").close()
|
|
env = dict(os.environ, LELEKA_STRA169_KAR_FD=str(fd))
|
|
with open(base + ".log", "wb") as log:
|
|
rc = subprocess.run(["bash", job], stdout=log, stderr=subprocess.STDOUT, env=env, pass_fds=[fd]).returncode
|
|
os.remove(base + ".running")
|
|
open(base + ".done", "w").write(str(rc))
|