Changeset: c40e94930c9b for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c40e94930c9b
Modified Files:
gdk/gdk_utils.c
Branch: Nov2019
Log Message:
Parse /proc/self/mountinfo to find out mount point of cgroups hierarchies.
diffs (73 lines):
diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -405,9 +405,48 @@ MT_init(void)
#ifdef __linux__
/* limit values to whatever cgroups gives us */
FILE *fc;
+ char buf[1024];
+ char cgr1[1024] = "/sys/fs/cgroup/memory";
+ char cgr2[1024] = "/sys/fs/cgroup";
+ fc = fopen("/proc/self/mountinfo", "r");
+ if (fc != NULL) {
+ while (fgets(buf, (int) sizeof(buf), fc) != NULL) {
+ char *p, *cgr;
+ if ((p = strstr(buf, " - cgroup ")) != NULL &&
+ strstr(p, "memory") != NULL)
+ cgr = cgr1;
+ else if (strstr(buf, " - cgroup2 ") != NULL)
+ cgr = cgr2;
+ else
+ continue;
+ /* buf point at mount ID */
+ p = strchr(buf, ' ');
+ if (p++ == NULL)
+ break;
+ /* p points at parent ID */
+ p = strchr(p, ' ');
+ if (p++ == NULL)
+ break;
+ /* p points at major:minor */
+ p = strchr(p, ' ');
+ if (p++ == NULL)
+ break;
+ /* p points at root */
+ p = strchr(p, ' ');
+ if (p++ == NULL)
+ break;
+ /* p points at mount point */
+ char *dir = p;
+ p = strchr(p, ' ');
+ if (p == NULL)
+ break;
+ *p = 0;
+ strcpy(cgr, dir);
+ }
+ fclose(fc);
+ }
fc = fopen("/proc/self/cgroup", "r");
if (fc != NULL) {
- char buf[1024];
/* each line is of the form:
* hierarchy-ID:controller-list:cgroup-path
*
@@ -439,8 +478,7 @@ MT_init(void)
*p = 0;
if (strncmp(buf, "0::", 3) == 0) {
/* cgroup v2 entry */
- q = stpconcat(pth, "/sys/fs/cgroup",
- buf + 3, "/", NULL);
+ q = stpconcat(pth, cgr2, buf + 3, "/", NULL);
/* hard limit */
strcpy(q, "memory.max");
f = fopen(pth, "r");
@@ -487,8 +525,7 @@ MT_init(void)
*p++ = 0;
if (strstr(q, "memory") == NULL)
continue;
- q = stpconcat(pth, "/sys/fs/cgroup/", q,
- p, "/", NULL);
+ q = stpconcat(pth, cgr1, p, "/", NULL);
/* limit of memory usage */
strcpy(q, "memory.limit_in_bytes");
f = fopen(pth, "r");
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list