View | Details | Raw Unified | Return to ticket 4635
Collapse All | Expand All

(-)slurm-17.11.6/src/slurmd/slurmd/get_mach_stat.c (-3 / +26 lines)
Lines 41-46 Link Here
41
41
42
#include "config.h"
42
#include "config.h"
43
43
44
#define MEMINFO_FILE "/proc/meminfo"
45
44
#ifdef HAVE_SYS_SYSTEMCFG_H
46
#ifdef HAVE_SYS_SYSTEMCFG_H
45
# include <sys/systemcfg.h>
47
# include <sys/systemcfg.h>
46
#endif
48
#endif
Lines 287-303 extern int get_cpu_load(uint32_t *cpu_lo Link Here
287
extern int get_free_mem(uint64_t *free_mem)
289
extern int get_free_mem(uint64_t *free_mem)
288
{
290
{
289
#if defined(__APPLE__) || defined(__NetBSD__) || defined(__FreeBSD__)
291
#if defined(__APPLE__) || defined(__NetBSD__) || defined(__FreeBSD__)
290
	/* Not sure how to get CPU load on above systems.
292
	/* Not sure how to get free memory on above systems.
291
	 * Perhaps some method below works. */
293
	 * Perhaps some method below works. */
292
	*free_mem = 0;
294
	*free_mem = 0;
293
#else
295
#else
294
	struct sysinfo info;
296
	/* Patch for bug #4635 (https://bugs.schedmd.com/show_bug.cgi?id=4635)
297
	 * This will only work (in Linux ?) if the line "MemAvailable" is
298
	 * present in /proc/meminfo. That should be the case in kernel >= 3.13.0
299
	 * but it looks like some distributions have backported this to earlier
300
	 * versions as well. Red Hat/CentOS is one of those. */
301
	
302
	/* Get the available memory if possible. */
303
	FILE *meminfo;
304
	if ((meminfo = fopen(MEMINFO_FILE, "r")) != NULL) {
305
		char line[256];
306
		while (fgets(line, sizeof(line), meminfo) != NULL) {
307
			unsigned long availram;
308
			if (sscanf(line, "MemAvailable: %lu kB", &availram)) {
309
				fclose(meminfo);
310
				*free_mem = (uint64_t)(availram/1024);
311
				return 0;
312
			}
313
		}
314
		fclose(meminfo);
315
	}
295
316
317
	/* If we couldn't find the amount of available memory in proc, fall back to
318
	 * the standard Slurm algorithm and just return amount of free RAM. */
319
	struct sysinfo info;
296
	if (sysinfo(&info) < 0) {
320
	if (sysinfo(&info) < 0) {
297
		*free_mem = 0;
321
		*free_mem = 0;
298
		return errno;
322
		return errno;
299
	}
323
	}
300
301
	*free_mem = (((uint64_t )info.freeram)*info.mem_unit)/(1024*1024);
324
	*free_mem = (((uint64_t )info.freeram)*info.mem_unit)/(1024*1024);
302
#endif
325
#endif
303
	return 0;
326
	return 0;

Return to ticket 4635