@@ -523,7 +523,10 @@ def cleanUpSlurmResources(def pipeline, SlurmCluster cluster, String clusterName
523523 Utils . exec(pipeline, script : " echo Sleeping to allow Slurm job termination; sleep 30" )
524524
525525 def cleanupCommands = [
526- " rm -rf ${ cluster.scratchPath} /users/svc_tensorrt/containers/container-${ slurmJobID} .sqsh || true" ,
526+ // .sqsh is shared across jobs (named by image digest), so age-prune
527+ // instead of deleting per job; reused images keep a refreshed mtime.
528+ " find ${ cluster.scratchPath} /users/svc_tensorrt/containers -maxdepth 1 -name 'container-*.sqsh' -mtime +3 -delete 2>/dev/null || true" ,
529+ " find ${ cluster.scratchPath} /users/svc_tensorrt/containers -maxdepth 1 \\ ( -name 'container-*.tmp' -o -name 'container-*.lock' \\ ) -mtime +1 -delete 2>/dev/null || true" ,
527530 " rm -rf ${ jobWorkspace} || true" ,
528531 ]. join(" ; " )
529532 Utils . exec(
@@ -562,7 +565,10 @@ def cleanUpNodeResources(def pipeline, SlurmCluster cluster, String clusterName,
562565 def entrypoint = SlurmConfig . containerRuntimeToEntrypoint[cluster. containerRuntime]
563566 def cleanupCommands = [
564567 " rm -rf /home/svc_tensorrt/bloom/scripts/agent-${ nodeName} .jar /home/svc_tensorrt/bloom/scripts/${ nodeName} -${ entrypoint} || true" ,
565- " rm -rf ${ cluster.scratchPath} /users/svc_tensorrt/containers/container-${ slurmJobID} .sqsh || true" ,
568+ // .sqsh is shared across jobs (named by image digest), so age-prune
569+ // instead of deleting per job; reused images keep a refreshed mtime.
570+ " find ${ cluster.scratchPath} /users/svc_tensorrt/containers -maxdepth 1 -name 'container-*.sqsh' -mtime +3 -delete 2>/dev/null || true" ,
571+ " find ${ cluster.scratchPath} /users/svc_tensorrt/containers -maxdepth 1 \\ ( -name 'container-*.tmp' -o -name 'container-*.lock' \\ ) -mtime +1 -delete 2>/dev/null || true" ,
566572 ]. join(" ; " )
567573 Utils . exec(
568574 pipeline,
@@ -1108,37 +1114,69 @@ def runLLMTestlistWithSbatch(pipeline, platform, testList, config=VANILLA_CONFIG
11081114 def containerImageArg = container
11091115 def srunPrologue = " "
11101116 if (cluster. containerRuntime. toString() == " ENROOT" ) {
1111- def enrootImagePath = " ${ cluster.scratchPath} /users/svc_tensorrt/containers/container-\$ {SLURM_JOB_ID}.sqsh"
1112- containerImageArg = enrootImagePath
1117+ def containerDir = " ${ cluster.scratchPath} /users/svc_tensorrt/containers"
1118+ // Name the .sqsh by image digest (not job ID) so jobs sharing
1119+ // an image reuse one .sqsh instead of re-running `enroot import`
1120+ // per job. Path is resolved at runtime into ${enrootImagePath}.
1121+ containerImageArg = " \$ {enrootImagePath}"
11131122
11141123 srunPrologue = """
11151124 export ENROOT_CACHE_PATH='/home/svc_tensorrt/.cache/enroot'
11161125
1126+ containerDir="$containerDir "
1127+ mkdir -p "\$ containerDir"
1128+ imageDigest=\$ (printf '%s' "$container " | sha256sum | cut -d' ' -f1)
1129+ export enrootImagePath="\$ containerDir/container-\$ {imageDigest}.sqsh"
1130+
11171131 importContainerWithRetries() {
11181132 local docker_uri=\$ 1
11191133 local output_path=\$ 2
11201134 local max_attempts=\$ {3:-3}
11211135 local delay=\$ {4:-60}
11221136 local attempt=1
1137+ local tmp_path
1138+
1139+ # Best-effort lock so racing jobs don't all import the same
1140+ # image. flock may be a no-op on some shared filesystems;
1141+ # correctness still holds since the import publishes atomically.
1142+ exec 9>"\$ {output_path}.lock" || true
1143+ flock 9 || true
1144+
1145+ if [ -f "\$ output_path" ]
1146+ then
1147+ echo "Reusing cached container image: \$ output_path"
1148+ # Refresh mtime so reused images survive age-based pruning.
1149+ touch "\$ output_path" || true
1150+ flock -u 9 || true
1151+ return 0
1152+ fi
11231153
1124- rm -f "\$ output_path"
1154+ # Import to a temp path, then mv to publish atomically so
1155+ # other jobs never see a partial .sqsh.
1156+ tmp_path="\$ {output_path}.\$ {SLURM_JOB_ID}.tmp"
1157+ rm -f "\$ tmp_path"
11251158
1126- until enroot import -o "\$ output_path " -- "docker://\$ docker_uri"
1159+ until enroot import -o "\$ tmp_path " -- "docker://\$ docker_uri"
11271160 do
11281161 if ((attempt >= max_attempts))
11291162 then
11301163 echo "enroot import failed after \$ max_attempts attempts"
1164+ rm -f "\$ tmp_path"
1165+ flock -u 9 || true
11311166 return 1
11321167 fi
11331168
11341169 echo "enroot import failed (attempt \$ attempt of \$ max_attempts). Retrying in \$ {delay}s..."
1135- rm -f "\$ output_path "
1170+ rm -f "\$ tmp_path "
11361171 sleep \$ delay
1137- ((attempt++ ))
1172+ attempt= \$ ((attempt + 1 ))
11381173 done
1174+
1175+ mv -f "\$ tmp_path" "\$ output_path"
1176+ flock -u 9 || true
11391177 }
11401178
1141- importContainerWithRetries "$container " "$enrootImagePath "
1179+ importContainerWithRetries "$container " "\ $ enrootImagePath"
11421180 """ . replaceAll(" (?m)^\\ s*" , " " )
11431181 }
11441182
0 commit comments