Changeset: 47ad11127c89 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=47ad11127c89 Modified Files: gdk/gdk_utils.c Branch: default Log Message:
Merged with linear-hashing 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 @@ -404,9 +404,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 * @@ -440,8 +479,7 @@ MT_init(void) if (strncmp(buf, "0::", 3) == 0) { /* cgroup v2 entry */ l = strconcat_len(pth, sizeof(pth), - "/sys/fs/cgroup", - buf + 3, "/", NULL); + cgr2, buf + 3, "/", NULL); /* hard limit */ strcpy(pth + l, "memory.max"); f = fopen(pth, "r"); @@ -489,8 +527,7 @@ MT_init(void) if (strstr(q, "memory") == NULL) continue; l = strconcat_len(pth, sizeof(pth), - "/sys/fs/cgroup/", q, - p, "/", NULL); + cgr1, p, "/", NULL); /* limit of memory usage */ strcpy(pth + l, "memory.limit_in_bytes"); f = fopen(pth, "r"); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list