tags 1072831 patch
thanks

On Tue 11 Jun 2024, Craig Small wrote:

> Could you check to see if in the container that lxcfs has overwritten
> the /proc/meminfo file? They sometimes do this for /proc/uptime. They
> might have messed one of the lines up and choked procps; I'm thinking
> like a tab/space at the end of the line or something that looks right
> to a human but not a computer.

The /proc/meminfo in the lxc container is basically the same as that of
the host, except the total memory reflects the limit imposed on the
container. So

-MemTotal:        7914164 kB$
+MemTotal:        2097152 kB$

and the Slab / SReclaimable / SUnreclaim lines show 0 kB.

> I think we'll need to either run a strace on free or a debugger to see
> where exactly the issue is.

I've been doing this.
Apparently the /proc/meminfo inside the lxc container is not seekable,
errno is ESPIPE.
The code does some seeks to reset to the beginning in preparation for
rereading the file.

I've changed the code to not do an lseek() just after opening the file
(as we should be at the start of the file then anyway), and if the file
is already open, try lseek() and if that returns errno == ESPIPE, then
close and reopen the file.

This works for me. Patch attached.

I don't know whether configure needs to test for existence of ESPIPE;
I do believe it's POSIX.


Paul
--- library/meminfo.c.orig	2023-07-11 11:09:18.436786212 +0200
+++ library/meminfo.c	2024-06-11 10:41:41.643438234 +0200
@@ -646,12 +646,18 @@
     // clear out the soon to be 'current' values
     memset(&info->hist.new, 0, sizeof(struct meminfo_data));
 
-    if (-1 == info->meminfo_fd
-    && (-1 == (info->meminfo_fd = open(MEMINFO_FILE, O_RDONLY))))
-        return 1;
-
-    if (lseek(info->meminfo_fd, 0L, SEEK_SET) == -1)
-        return 1;
+    if (-1 == info->meminfo_fd) {
+    	if (-1 == (info->meminfo_fd = open(MEMINFO_FILE, O_RDONLY)))
+	    return 1;
+    }
+    else {
+	if (lseek(info->meminfo_fd, 0L, SEEK_SET) == -1)
+	    if (ESPIPE == errno) {
+		close(info->meminfo_fd);
+		if (-1 == (info->meminfo_fd = open(MEMINFO_FILE, O_RDONLY)))
+		    return 1;
+	    }
+    }
 
     for (;;) {
         if ((size = read(info->meminfo_fd, buf, sizeof(buf)-1)) < 0) {

Reply via email to