// create process tree object
long sleeptimeBeforeSigkill = taskTracker.getJobConf().getLong(
"mapred.tasktracker.tasks.sleeptime-before-sigkill",
ProcessTree.DEFAULT_SLEEPTIME_BEFORE_SIGKILL);
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
}
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 process-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 limit = ptInfo.getMemLimit();
String user = taskTracker.getUserName(ptInfo.tid);
if (user == null) {
// If user is null the task is deleted from the TT memory
continue;
}
// Log RSS and virtual memory usage of all tasks
LOG.debug((String.format("Memory usage of ProcessTree %s : " +
"[USER,TID,RSS,VMEM,VLimit,TotalRSSLimit]"
+ "=[%s,%s,%s,%s,%s,%s]",
pId, user, ptInfo.tid, currentRssMemUsage,
currentMemUsage, limit, maxRssMemoryAllowedForAllTasks)));
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.
String 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();
LOG.warn(msg);
taskTracker.cleanUpOverMemoryTask(tid, true, msg);
LinuxSystemCall.killProcessGroup(Integer.parseInt(pId));
it.remove();