-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmem.c
66 lines (57 loc) · 1.49 KB
/
mem.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* mem.c
*
* Copyright (C) 2018 < Daniel Finneran, [email protected] >
* All rights reserved.
*
* This software may be modified and distributed under the terms
* of the GPL license. See the LICENSE file for details.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "utils.h"
#include "log.h"
long urchinMemorySize;
char *urchinMemory;
void setMem(long mem) {
urchinMemorySize = mem;
}
long getMemSize() {
return urchinMemorySize;
}
int allocateMemory() {
urchinMemory = malloc(sizeof(char) * urchinMemorySize);
// if c is allocated then populate the memory
if(urchinMemory)
{
logInfo("Operating System allowed allocation of memory\n");
memset(urchinMemory, 1, sizeof(char) * urchinMemorySize);
return 0;
}
else
{
logError("Operatings system denied memory allocation\n");
return 1;
}
}
void freeMemory() {
free(urchinMemory);
}
char* getMemoryConfiguration() {
char *oom;
oom = readFile("/proc/sys/vm/overcommit_memory");
if (oom == 0) {
logWarn("Unable to read OOM settings\n");
return "Couldn't Read file [/proc/sys/vm/overcommit_memory]";
}
if (oom[0] == '0' ) {
return("OOM Enabled (Mode 0)\n");
}
if (oom[0] == '1' ) {
return("OOM Enabled (Mode 1)\n");
}
if (oom[0] == '2' ) {
return("OOM Disabled\n");
}
return "Unknown Memory Configuration in kernel"; // If Nil then there was an error reading the file
}