as doing:
kill -s USR1 $(pidof lxcfs)
+
+## Using with Docker
+
+```
+docker run -it -m 256m --memory-swap 256m \
+ -v /var/lib/lxcfs/proc/cpuinfo:/proc/cpuinfo:rw \
+ -v /var/lib/lxcfs/proc/diskstats:/proc/diskstats:rw \
+ -v /var/lib/lxcfs/proc/meminfo:/proc/meminfo:rw \
+ -v /var/lib/lxcfs/proc/stat:/proc/stat:rw \
+ -v /var/lib/lxcfs/proc/swaps:/proc/swaps:rw \
+ -v /var/lib/lxcfs/proc/uptime:/proc/uptime:rw \
+ ubuntu:18.04 /bin/bash
+ ```
+
+ In a system with swap enabled, the parameter "-u" can be used to set all values in "meminfo" that refer to the swap to 0.
+
+ sudo lxcfs -u /var/lib/lxcfs
struct fuse_file_info *fi)
{
struct fuse_context *fc = fuse_get_context();
+ struct lxcfs_opts *opts = (struct lxcfs_opts *) fuse_get_context()->private_data;
struct file_info *d = (struct file_info *)fi->fh;
char *cg;
char *memusage_str = NULL, *memstat_str = NULL,
} else if (startswith(line, "MemAvailable:")) {
snprintf(lbuf, 100, "MemAvailable: %8lu kB\n", memlimit - memusage + cached);
printme = lbuf;
- } else if (startswith(line, "SwapTotal:") && memswlimit > 0) {
+ } else if (startswith(line, "SwapTotal:") && memswlimit > 0 && opts->swap_off == false) {
sscanf(line+sizeof("SwapTotal:")-1, "%lu", &hostswtotal);
if (hostswtotal < memswlimit)
memswlimit = hostswtotal;
snprintf(lbuf, 100, "SwapTotal: %8lu kB\n", memswlimit);
printme = lbuf;
- } else if (startswith(line, "SwapFree:") && memswlimit > 0 && memswusage > 0) {
+ } else if (startswith(line, "SwapTotal:") && opts->swap_off == true) {
+ snprintf(lbuf, 100, "SwapTotal: %8lu kB\n", 0UL);
+ printme = lbuf;
+ } else if (startswith(line, "SwapFree:") && memswlimit > 0 && memswusage > 0 && opts->swap_off == false) {
unsigned long swaptotal = memswlimit,
swapusage = memswusage - memusage,
swapfree = swapusage < swaptotal ? swaptotal - swapusage : 0;
snprintf(lbuf, 100, "SwapFree: %8lu kB\n", swapfree);
printme = lbuf;
+ } else if (startswith(line, "SwapFree:") && opts->swap_off == true) {
+ snprintf(lbuf, 100, "SwapFree: %8lu kB\n", 0UL);
+ printme = lbuf;
} else if (startswith(line, "Slab:")) {
snprintf(lbuf, 100, "Slab: %8lu kB\n", 0UL);
printme = lbuf;
#define BASEDIR RUNTIME_PATH "/lxcfs/controllers"
#define ROOTDIR RUNTIME_PATH "/lxcfs/root"
+struct lxcfs_opts {
+ bool swap_off;
+};
+
extern int cg_write(const char *path, const char *buf, size_t size, off_t offset,
struct fuse_file_info *fi);
extern int cg_mkdir(const char *path, mode_t mode);
{
fprintf(stderr, "Usage:\n");
fprintf(stderr, "\n");
- fprintf(stderr, "lxcfs [-f|-d] -l [-p pidfile] mountpoint\n");
+ fprintf(stderr, "lxcfs [-f|-d] -u -l -n [-p pidfile] mountpoint\n");
fprintf(stderr, " -f running foreground by default; -d enable debug output \n");
fprintf(stderr, " -l use loadavg \n");
+ fprintf(stderr, " -u no swap \n");
fprintf(stderr, " Default pidfile is %s/lxcfs.pid\n", RUNTIME_PATH);
fprintf(stderr, "lxcfs -h\n");
exit(1);
int nargs = 5, cnt = 0;
char *newargv[6];
+ struct lxcfs_opts *opts;
+ opts = malloc(sizeof(struct lxcfs_opts));
+ if (opts == NULL) {
+ fprintf(stderr, "Error allocating memory for options.\n");
+ goto out;
+ }
+ opts->swap_off = false;
+
/* accomodate older init scripts */
swallow_arg(&argc, argv, "-s");
swallow_arg(&argc, argv, "-f");
if (swallow_arg(&argc, argv, "-l")) {
load_use = true;
}
+ if (swallow_arg(&argc, argv, "-u")) {
+ opts->swap_off = true;
+ }
if (swallow_option(&argc, argv, "-o", &v)) {
/* Parse multiple values */
for (; (token = strtok_r(v, ",", &saveptr)); v = NULL) {
if (load_use && start_loadavg() != 0)
goto out;
- if (!fuse_main(nargs, newargv, &lxcfs_ops, NULL))
+ if (!fuse_main(nargs, newargv, &lxcfs_ops, opts))
ret = EXIT_SUCCESS;
if (load_use)
stop_loadavg();