Example #1
0
extern int jobacct_gather_set_mem_limit(uint32_t job_id, uint32_t step_id,
					uint32_t mem_limit)
{
	if (!plugin_polling)
		return SLURM_SUCCESS;

	if ((job_id == 0) || (mem_limit == 0)) {
		error("jobacct_gather_set_mem_limit: jobid:%u mem_limit:%u",
		      job_id, mem_limit);
		return SLURM_ERROR;
	}

	jobacct_job_id      = job_id;
	jobacct_step_id     = step_id;
	jobacct_mem_limit   = mem_limit * 1024;	/* MB to KB */
	jobacct_vmem_limit  = jobacct_mem_limit;
	jobacct_vmem_limit *= (slurm_get_vsize_factor() / 100.0);
	return SLURM_SUCCESS;
}
Example #2
0
int set_user_limits(stepd_step_rec_t *job)
{
#ifdef RLIMIT_AS
#define SLURM_RLIMIT_VSIZE RLIMIT_AS
#define SLURM_RLIMIT_VNAME "RLIMIT_AS"
#elif defined(RLIMIT_DATA)
/* RLIMIT_DATA is useless on many systems which provide anonymous
 * mmap()'s in addition to brk(), use it here only as a fallback for
 * oddball systems lacking RLIMIT_AS. */
#define SLURM_RLIMIT_VSIZE RLIMIT_DATA
#define SLURM_RLIMIT_VNAME "RLIMIT_DATA"
#endif
	slurm_rlimits_info_t *rli;
	struct rlimit r;
	rlim_t task_mem_bytes;
#ifdef SLURM_RLIMIT_VSIZE
	uint16_t vsize_factor;
#endif

	if (getrlimit(RLIMIT_CPU, &r) == 0) {
		if (r.rlim_max != RLIM_INFINITY) {
			error("SLURM process CPU time limit is %d seconds",
			      (int) r.rlim_max);
		}
	}

	for (rli = get_slurm_rlimits_info(); rli->name; rli++)
		_set_limit( job->env, rli );

	/* Set soft and hard rss and vsize limit for this process,
	 * handle job limit (for all spawned processes) in slurmd */
	task_mem_bytes  = job->step_mem;	/* MB */
	task_mem_bytes *= (1024 * 1024);

	/* Many systems, Linux included, ignore RSS limits, but set it
	 * here anyway for consistency and to provide a way for
	 * applications to interrogate what the RSS limit is (with the
	 * caveat that the real RSS limit is over all job tasks on the
	 * node and not per process, but hopefully this is better than
	 * nothing).  */
#ifdef RLIMIT_RSS
	if ((task_mem_bytes) && (getrlimit(RLIMIT_RSS, &r) == 0) &&
	    (r.rlim_max > task_mem_bytes)) {
		r.rlim_max =  r.rlim_cur = task_mem_bytes;
		if (setrlimit(RLIMIT_RSS, &r)) {
			/* Indicates that limit has already been exceeded */
			fatal("setrlimit(RLIMIT_RSS, %u MB): %m",
			      job->step_mem);
		} else
			debug2("Set task rss(%u MB)", job->step_mem);
#if 0
		getrlimit(RLIMIT_RSS, &r);
		info("task RSS limits: %u %u", r.rlim_cur, r.rlim_max);
#endif
	}
#endif

#ifdef SLURM_RLIMIT_VSIZE
	if ((task_mem_bytes) &&
	    ((vsize_factor = slurm_get_vsize_factor()) != 0) &&
	    (getrlimit(SLURM_RLIMIT_VSIZE, &r) == 0) &&
	    (r.rlim_max > task_mem_bytes)) {
		r.rlim_max = task_mem_bytes * (vsize_factor / 100.0);
		r.rlim_cur = r.rlim_max;
		if (setrlimit(SLURM_RLIMIT_VSIZE, &r)) {
			/* Indicates that limit has already been exceeded */
			fatal("setrlimit(%s, %u MB): %m", 
			      SLURM_RLIMIT_VNAME, job->step_mem);
		} else
			debug2("Set task vsize(%u MB)", job->step_mem);
#if 0
		getrlimit(SLURM_RLIMIT_VSIZE, &r);
		info("task VSIZE limits:   %u %u", r.rlim_cur, r.rlim_max);
#endif
	}
#endif

	return SLURM_SUCCESS;
}