[COMMIT osv master] procfs: add meminfo pseudo-file

9 views
Skip to first unread message

Commit Bot

unread,
Jan 9, 2020, 11:28:56 PM1/9/20
to osv...@googlegroups.com, Waldemar Kozaczuk
From: Waldemar Kozaczuk <jwkoz...@gmail.com>
Committer: Waldemar Kozaczuk <jwkoz...@gmail.com>
Branch: master

procfs: add meminfo pseudo-file

Signed-off-by: Waldemar Kozaczuk <jwkoz...@gmail.com>

---
diff --git a/fs/procfs/procfs_vnops.cc b/fs/procfs/procfs_vnops.cc
--- a/fs/procfs/procfs_vnops.cc
+++ b/fs/procfs/procfs_vnops.cc
@@ -182,6 +182,7 @@ procfs_mount(mount* mp, const char *dev, int flags,
const void* data)
root->add("sys", sys);

root->add("cpuinfo", inode_count++, [] { return
processor::features_str(); });
+ root->add("meminfo", inode_count++, [] { return
pseudofs::meminfo("MemTotal:\t%ld kB\nMemFree: \t%ld kB\n"); });

vp->v_data = static_cast<void*>(root);

diff --git a/fs/pseudofs/pseudofs.cc b/fs/pseudofs/pseudofs.cc
--- a/fs/pseudofs/pseudofs.cc
+++ b/fs/pseudofs/pseudofs.cc
@@ -8,6 +8,7 @@

#include "pseudofs.hh"
#include <osv/sched.hh>
+#include <sys/sysinfo.h>

namespace pseudofs {

@@ -191,4 +192,14 @@ string cpumap()
}
return os.str();
}
+
+string meminfo(const char* format)
+{
+ struct sysinfo info;
+ sysinfo(&info);
+
+ std::ostringstream os;
+ osv::fprintf(os, format, info.totalram >> 10, info.freeram >> 10);
+ return os.str();
+}
}
diff --git a/fs/pseudofs/pseudofs.hh b/fs/pseudofs/pseudofs.hh
--- a/fs/pseudofs/pseudofs.hh
+++ b/fs/pseudofs/pseudofs.hh
@@ -146,6 +146,8 @@ int readdir(vnode *vp, file *fp, dirent *dir);
int getattr(vnode *vp, vattr *attr);

string cpumap();
+
+string meminfo(const char* format);
}

#endif
diff --git a/fs/sysfs/sysfs_vnops.cc b/fs/sysfs/sysfs_vnops.cc
--- a/fs/sysfs/sysfs_vnops.cc
+++ b/fs/sysfs/sysfs_vnops.cc
@@ -8,7 +8,6 @@
#include <unistd.h>
#include <osv/mount.h>
#include <mntent.h>
-#include <sys/sysinfo.h>

#include "fs/pseudofs/pseudofs.hh"

@@ -21,18 +20,6 @@ static uint64_t inode_count = 1; /* inode 0 is reserved
to root */

static mutex_t sysfs_mutex;

-static string sysfs_meminfo()
-{
- struct sysinfo info;
- sysinfo(&info);
-
- char total_line[200];
- sprintf(total_line, "Node 0 MemTotal:\t%ld kB\nNode 0 MemFree: \t%ld
kB\n",
- info.totalram >> 10, info.freeram >> 10);
-
- return std::string(total_line);
-}
-
static string sysfs_cpumap()
{
return pseudofs::cpumap() + "\n";
@@ -49,7 +36,7 @@ sysfs_mount(mount* mp, const char *dev, int flags, const
void* data)
auto* vp = mp->m_root->d_vnode;

auto node0 = make_shared<pseudo_dir_node>(inode_count++);
- node0->add("meminfo", inode_count++, sysfs_meminfo);
+ node0->add("meminfo", inode_count++, [] { return
pseudofs::meminfo("Node 0 MemTotal:\t%ld kB\nNode 0 MemFree: \t%ld kB\n");
});
node0->add("cpumap", inode_count++, sysfs_cpumap);
node0->add("distance", inode_count++, sysfs_distance);

Nadav Har'El

unread,
Jan 12, 2020, 5:43:48 AM1/12/20
to Waldemar Kozaczuk, Osv Dev

On Fri, Jan 10, 2020 at 6:28 AM Commit Bot <b...@cloudius-systems.com> wrote:
From: Waldemar Kozaczuk <jwkoz...@gmail.com>
Committer: Waldemar Kozaczuk <jwkoz...@gmail.com>
Branch: master

procfs: add meminfo pseudo-file

Can you please say a few words on the motivation of this change?
Apparently we already had /proc/meminfo, so what benefit does this change bring?

--
You received this message because you are subscribed to the Google Groups "OSv Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osv-dev/0000000000004b63eb059bc19023%40google.com.

Waldek Kozaczuk

unread,
Jan 14, 2020, 11:42:08 AM1/14/20
to OSv Development


On Sunday, January 12, 2020 at 5:43:48 AM UTC-5, Nadav Har'El wrote:

On Fri, Jan 10, 2020 at 6:28 AM Commit Bot <b...@cloudius-systems.com> wrote:
From: Waldemar Kozaczuk <jwkoz...@gmail.com>
Committer: Waldemar Kozaczuk <jwkoz...@gmail.com>
Branch: master

procfs: add meminfo pseudo-file

Can you please say a few words on the motivation of this change?
Needed for nodejs 12. 
Apparently we already had /proc/meminfo, so what benefit does this change bring?
We had sysfs meminfo version but not /proc/meminfo.

To unsubscribe from this group and stop receiving emails from it, send an email to osv...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages