mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrea Righi <righi.andrea@gmail.com>
To: balbir@linux.vnet.ibm.com
Cc: menage@google.com, kamezawa.hiroyu@jp.fujitsu.com,
	kosaki.motohiro@jp.fujitsu.com, xemul@openvz.org,
	linux-kernel@vger.kernel.org, containers@lists.osdl.org,
	Andrea Righi <righi.andrea@gmail.com>
Subject: [RFC PATCH 3/5] mgmcg VM overcommit interface
Date: Tue, 10 Jun 2008 01:33:01 +0200	[thread overview]
Message-ID: <1213054383-18137-4-git-send-email-righi.andrea@gmail.com> (raw)
In-Reply-To: <>

Per-cgroup overcommit_memory and overcommit_ratio parameters can be shown
and/or manipulated using the files "memory.overcommit_memory" and
"memory.overcommit_ratio" in the cgroup filesystem.

The file "overcommit_as" can be used to retrieve the current committed space
and limit of each cgroup.

Signed-off-by: Andrea Righi <righi.andrea@gmail.com>
---
 mm/memcontrol.c |  116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 115 insertions(+), 1 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 4100e24..e3e34e9 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -36,6 +36,8 @@
 
 #include <asm/uaccess.h>
 
+#define K(x) ((x) << (PAGE_SHIFT - 10))
+
 struct cgroup_subsys mem_cgroup_subsys;
 static const int MEM_CGROUP_RECLAIM_RETRIES = 5;
 static struct kmem_cache *page_cgroup_cache;
@@ -47,7 +49,7 @@ enum mem_cgroup_stat_index {
 	/*
 	 * For MEM_CONTAINER_TYPE_ALL, usage = pagecache + rss.
 	 */
-	MEM_CGROUP_STAT_CACHE, 	   /* # of pages charged as cache */
+	MEM_CGROUP_STAT_CACHE,	   /* # of pages charged as cache */
 	MEM_CGROUP_STAT_RSS,	   /* # of pages charged as rss */
 	MEM_CGROUP_STAT_PGPGIN_COUNT,	/* # of pages paged in */
 	MEM_CGROUP_STAT_PGPGOUT_COUNT,	/* # of pages paged out */
@@ -55,6 +57,11 @@ enum mem_cgroup_stat_index {
 	MEM_CGROUP_STAT_NSTATS,
 };
 
+enum mem_cgroup_vmacct_index {
+	MEM_CGROUP_OVERCOMMIT_MEMORY,
+	MEM_CGROUP_OVERCOMMIT_RATIO,
+};
+
 struct mem_cgroup_stat_cpu {
 	s64 count[MEM_CGROUP_STAT_NSTATS];
 } ____cacheline_aligned_in_smp;
@@ -995,6 +1002,97 @@ static ssize_t mem_cgroup_write(struct cgroup *cont, struct cftype *cft,
 				mem_cgroup_write_strategy);
 }
 
+static ssize_t mem_cgroup_committed_read(struct cgroup *cont,
+					 struct cftype *cft,
+					 struct file *file,
+					 char __user *userbuf,
+					 size_t nbytes,
+					 loff_t *ppos)
+{
+	struct mem_cgroup *mem;
+	char *page;
+	unsigned long total, committed, allowed;
+	ssize_t count;
+	int ret;
+
+	page = (char *)__get_free_page(GFP_TEMPORARY);
+	if (unlikely(!page))
+		return -ENOMEM;
+
+	cgroup_lock();
+	if (cgroup_is_removed(cont)) {
+		cgroup_unlock();
+		ret = -ENODEV;
+		goto out;
+	}
+
+	mem = mem_cgroup_from_cont(cont);
+	committed = atomic_long_read(&mem->vmacct.vm_committed_space);
+
+	total = (long)(mem->res.limit >> PAGE_SHIFT) + 1L;
+	if (total > (totalram_pages - hugetlb_total_pages()))
+		allowed = ((totalram_pages - hugetlb_total_pages())
+			* mem->vmacct.overcommit_ratio / 100)
+			+ total_swap_pages;
+	else
+		allowed = total * mem->vmacct.overcommit_ratio / 100
+			+ total_swap_pages;
+	cgroup_unlock();
+
+	count = sprintf(page, "CommitLimit:  %8lu kB\n"
+			      "Committed_AS: %8lu kB\n",
+			      K(allowed), K(committed));
+	ret = simple_read_from_buffer(userbuf, nbytes, ppos, page, count);
+out:
+	free_page((unsigned long)page);
+	return ret;
+}
+
+static s64 mem_cgroup_vmacct_read_s64(struct cgroup *cont, struct cftype *cft)
+{
+	struct mem_cgroup *mem = mem_cgroup_from_cont(cont);
+	enum mem_cgroup_vmacct_index type = cft->private;
+
+	switch (type) {
+	case MEM_CGROUP_OVERCOMMIT_MEMORY:
+		return mem->vmacct.overcommit_memory;
+	case MEM_CGROUP_OVERCOMMIT_RATIO:
+		return mem->vmacct.overcommit_ratio;
+	default:
+		BUG();
+	}
+}
+
+static int mem_cgroup_vmacct_write_s64(struct cgroup *cont, struct cftype *cft,
+				       s64 val)
+{
+	struct mem_cgroup *mem = mem_cgroup_from_cont(cont);
+	enum mem_cgroup_vmacct_index type = cft->private;
+	int ret = 0;
+
+	cgroup_lock();
+	if (cgroup_is_removed(cont)) {
+		cgroup_unlock();
+		return -ENODEV;
+	}
+
+	switch (type) {
+	case MEM_CGROUP_OVERCOMMIT_MEMORY:
+		mem->vmacct.overcommit_memory = (int)val;
+		break;
+	case MEM_CGROUP_OVERCOMMIT_RATIO:
+		mem->vmacct.overcommit_ratio = (int)val;
+		break;
+	default:
+		ret = -EINVAL;
+		break;
+	}
+	cgroup_unlock();
+
+	return ret;
+
+}
+
 static int mem_cgroup_reset(struct cgroup *cont, unsigned int event)
 {
 	struct mem_cgroup *mem;
@@ -1086,6 +1184,22 @@ static struct cftype mem_cgroup_files[] = {
 		.name = "stat",
 		.read_map = mem_control_stat_show,
 	},
+	{
+		.name = "overcommit_memory",
+		.private = MEM_CGROUP_OVERCOMMIT_MEMORY,
+		.read_s64 = mem_cgroup_vmacct_read_s64,
+		.write_s64 = mem_cgroup_vmacct_write_s64,
+	},
+	{
+		.name = "overcommit_ratio",
+		.private = MEM_CGROUP_OVERCOMMIT_RATIO,
+		.read_s64 = mem_cgroup_vmacct_read_s64,
+		.write_s64 = mem_cgroup_vmacct_write_s64,
+	},
+	{
+		.name = "overcommit_as",
+		.read = mem_cgroup_committed_read,
+	},
 };
 
 static int alloc_mem_cgroup_per_zone_info(struct mem_cgroup *mem, int node)
-- 
1.5.4.3


             reply	other threads:[~2008-06-09 23:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-09 23:33 Andrea Righi [this message]
2008-06-10 17:42 ` Dave Hansen
2008-06-11 10:43   ` Andrea Righi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1213054383-18137-4-git-send-email-righi.andrea@gmail.com \
    --to=righi.andrea@gmail.com \
    --cc=balbir@linux.vnet.ibm.com \
    --cc=containers@lists.osdl.org \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=menage@google.com \
    --cc=xemul@openvz.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®