.getLong(
TTConfig.TT_SLEEP_TIME_BEFORE_SIG_KILL,
ProcessTree.DEFAULT_SLEEPTIME_BEFORE_SIGKILL);
// create process tree object
ProcfsBasedProcessTree pt =
new ProcfsBasedProcessTree(pId,
ProcessTree.isSetsidAvailable, sleeptimeBeforeSigkill);
LOG.debug("Tracking ProcessTree " + pId + " for the first time");
ptInfo.setPid(pId);
ptInfo.setProcessTree(pt);
}
}
// End of initializing any uninitialized processTrees
if (pId == null) {
continue; // processTree cannot be tracked
}
if (taskTracker.runningTasks.get(tid).wasKilled()) {
continue; // this task has been killed already
}
LOG.debug("Constructing ProcessTree for : PID = " + pId + " TID = "
+ tid);
ProcfsBasedProcessTree pTree = ptInfo.getProcessTree();
pTree = pTree.getProcessTree(); // get the updated process-tree
ptInfo.setProcessTree(pTree); // update ptInfo with proces-tree of
// updated state
long currentMemUsage = pTree.getCumulativeVmem();
long currentRssMemUsage = pTree.getCumulativeRssmem();
// as processes begin with an age 1, we want to see if there
// are processes more than 1 iteration old.
long curMemUsageOfAgedProcesses = pTree.getCumulativeVmem(1);
long curRssMemUsageOfAgedProcesses = pTree.getCumulativeRssmem(1);
long limit = ptInfo.getMemLimit();
long limitPhysical = ptInfo.getMemLimitPhysical();
LOG.info(String.format(MEMORY_USAGE_STRING,
pId, tid.toString(), currentMemUsage, limit,
currentRssMemUsage, limitPhysical));
boolean isMemoryOverLimit = false;
String msg = "";
if (doCheckVirtualMemory() &&
isProcessTreeOverLimit(tid.toString(), currentMemUsage,
curMemUsageOfAgedProcesses, limit)) {
// Task (the root process) is still alive and overflowing memory.
// Dump the process-tree and then clean it up.
msg = "TaskTree [pid=" + pId + ",tipID=" + tid
+ "] is running beyond memory-limits. Current usage : "
+ currentMemUsage + "bytes. Limit : " + limit
+ "bytes. Killing task. \nDump of the process-tree for "
+ tid + " : \n" + pTree.getProcessTreeDump();
isMemoryOverLimit = true;
} else if (doCheckPhysicalMemory() &&
isProcessTreeOverLimit(tid.toString(), currentRssMemUsage,
curRssMemUsageOfAgedProcesses, limitPhysical)) {
// Task (the root process) is still alive and overflowing memory.
// Dump the process-tree and then clean it up.
msg = "TaskTree [pid=" + pId + ",tipID=" + tid
+ "] is running beyond physical memory-limits."
+ " Current usage : "
+ currentRssMemUsage + "bytes. Limit : " + limitPhysical
+ "bytes. Killing task. \nDump of the process-tree for "
+ tid + " : \n" + pTree.getProcessTreeDump();
isMemoryOverLimit = true;
}
if (isMemoryOverLimit) {
// Virtual or physical memory over limit. Fail the task and remove
// the corresponding process tree
LOG.warn(msg);
taskTracker.cleanUpOverMemoryTask(tid, true, msg);
// Now destroy the ProcessTree, remove it from monitoring map.
pTree.destroy(true/*in the background*/);
it.remove();
LOG.info("Removed ProcessTree with root " + pId);
} else {
// Accounting the total memory in usage for all tasks that are still
// alive and within limits.