[CRIU] [PATCH 6/7] kdat: Add fetching files stat
Cyrill Gorcunov
gorcunov at openvz.org
Mon May 29 13:15:04 PDT 2017
From: Cyrill Gorcunov <gorcunov at virtuozzo.com>
Will need it to unlimit the files allocation
for service fd reserving and later for parasite code run
(which is implemented in vz7 instance and soon will be
ported into vanilla).
Signed-off-by: Cyrill Gorcunov <gorcunov at virtuozzo.com>
---
criu/include/kerndat.h | 3 +++
criu/kerndat.c | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/criu/include/kerndat.h b/criu/include/kerndat.h
index da184c0542a2..2d39f13010ac 100644
--- a/criu/include/kerndat.h
+++ b/criu/include/kerndat.h
@@ -14,6 +14,7 @@ extern int kerndat_init(void);
extern int kerndat_get_dirty_track(void);
extern int kerndat_fdinfo_has_lock(void);
extern int kerndat_loginuid(void);
+extern int kerndat_files_stat(void);
enum pagemap_func {
PM_UNKNOWN,
@@ -52,6 +53,8 @@ struct kerndat_s {
bool has_nspid;
bool has_ns_get_userns;
bool has_ns_get_parent;
+ unsigned int sysctl_nr_open;
+ unsigned long files_stat_max_files;
};
extern struct kerndat_s kdat;
diff --git a/criu/kerndat.c b/criu/kerndat.c
index 3204d4bc1d12..bc3416a2c6f5 100644
--- a/criu/kerndat.c
+++ b/criu/kerndat.c
@@ -149,6 +149,40 @@ static void kerndat_mmap_min_addr(void)
(unsigned long)kdat.mmap_min_addr);
}
+int kerndat_files_stat(void)
+{
+ uint64_t max_files;
+ uint32_t nr_open;
+
+ struct sysctl_req req[] = {
+ {
+ .name = "fs/file-max",
+ .arg = &max_files,
+ .type = CTL_U64,
+ },
+ {
+ .name = "fs/nr_open",
+ .arg = &nr_open,
+ .type = CTL_U32,
+ },
+ };
+
+ if (sysctl_op(req, ARRAY_SIZE(req), CTL_READ, 0)) {
+ pr_warn("Can't fetch file_stat, using kernel defaults\n");
+ nr_open = 1024 * 1024;
+ max_files = 8192;
+ }
+
+ kdat.sysctl_nr_open = nr_open;
+ kdat.files_stat_max_files = max_files;
+
+ pr_debug("files stat: %s %lu, %s %u\n",
+ req[0].name, kdat.files_stat_max_files,
+ req[1].name, kdat.sysctl_nr_open);
+
+ return 0;
+}
+
static int kerndat_get_shmemdev(void)
{
void *map;
@@ -823,6 +857,7 @@ int kerndat_init(void)
kerndat_lsm();
kerndat_mmap_min_addr();
+ kerndat_files_stat();
if (!ret)
kerndat_save_cache();
--
2.7.4
More information about the CRIU
mailing list