linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: "linux-mm@kvack.org" <linux-mm@kvack.org>,
	"balbir@linux.vnet.ibm.com" <balbir@linux.vnet.ibm.com>,
	"xemul@openvz.org" <xemul@openvz.org>,
	"nishimura@mxp.nes.nec.co.jp" <nishimura@mxp.nes.nec.co.jp>,
	"yamamoto@valinux.co.jp" <yamamoto@valinux.co.jp>,
	"hugh@veritas.com" <hugh@veritas.com>,
	"kosaki.motohiro@jp.fujitsu.com" <kosaki.motohiro@jp.fujitsu.com>
Subject: [RFC][-mm] [6/7] res_counter distance to limit
Date: Wed, 2 Jul 2008 21:15:10 +0900	[thread overview]
Message-ID: <20080702211510.6f1fe470.kamezawa.hiroyu@jp.fujitsu.com> (raw)
In-Reply-To: <20080702210322.518f6c43.kamezawa.hiroyu@jp.fujitsu.com>

I wonder wheher there is better name rather than "distance"...
give me a hint ;)
==
Charge the val to res_counter and returns distance to the limit.

Useful when a controller (memory controller) want to implement background
feedback ops depends on the rest of resource.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>

 include/linux/res_counter.h |   21 ++++++++++++++++++++-
 kernel/res_counter.c        |   27 +++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 1 deletion(-)

Index: test-2.6.26-rc5-mm3++/include/linux/res_counter.h
===================================================================
--- test-2.6.26-rc5-mm3++.orig/include/linux/res_counter.h
+++ test-2.6.26-rc5-mm3++/include/linux/res_counter.h
@@ -104,7 +104,8 @@ int __must_check res_counter_charge_lock
 		unsigned long val);
 int __must_check res_counter_charge(struct res_counter *counter,
 		unsigned long val);
-
+int __must_check res_counter_charge_distance(struct res_counter *counter,
+	unsigned long val, unsigned long long *distance);
 /*
  * uncharge - tell that some portion of the resource is released
  *
@@ -173,4 +174,22 @@ static inline int res_counter_set_limit(
 	spin_unlock_irqrestore(&cnt->lock, flags);
 	return ret;
 }
+
+/*
+ * Returns limit - usage. if usage > limit, returns 0.
+ */
+
+static inline unsigned long long
+res_counter_distance_to_limit(struct res_counter *cnt)
+{
+	unsigned long flags;
+	unsigned long long distance = 0;
+
+	spin_lock_irqsave(&cnt->lock, flags);
+	if (cnt->usage < cnt->limit)
+		distance = cnt->limit - cnt->usage;
+	spin_unlock_irqrestore(&cnt->lock, flags);
+	return distance;
+}
+
 #endif
Index: test-2.6.26-rc5-mm3++/kernel/res_counter.c
===================================================================
--- test-2.6.26-rc5-mm3++.orig/kernel/res_counter.c
+++ test-2.6.26-rc5-mm3++/kernel/res_counter.c
@@ -44,6 +44,33 @@ int res_counter_charge(struct res_counte
 	return ret;
 }
 
+/*
+ * res_counter_charge_distance - do res_counter_charge and returns distance to
+ * limit.
+ * @counter: the counter
+ * @val: the amount of the resource. each controller defines its own units.
+ * @distance: the rest of resource to the limit.
+ *
+ * returns 0 on success and <0 if the counter->usage will exceed the
+ * counter->limit.
+ */
+
+int res_counter_charge_distance(struct res_counter *counter, unsigned long val,
+	unsigned long long *distance)
+{
+	int ret;
+	unsigned long flags;
+
+	spin_lock_irqsave(&counter->lock, flags);
+	ret = res_counter_charge_locked(counter, val);
+	if (!ret)
+		*distance = counter->limit - counter->usage;
+	spin_unlock_irqrestore(&counter->lock, flags);
+	return ret;
+}
+
+
+
 void res_counter_uncharge_locked(struct res_counter *counter, unsigned long val)
 {
 	if (WARN_ON(counter->usage < val))

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2008-07-02 12:15 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-02 12:03 [RFC][-mm] [0/7] misc memcg patch set KAMEZAWA Hiroyuki
2008-07-02 12:07 ` [RFC][-mm] [1/7] shmem swapcache fix KAMEZAWA Hiroyuki
2008-07-02 12:08 ` [RFC][-mm] [2/7] delete FLAG_CACHE KAMEZAWA Hiroyuki
2008-07-02 12:10 ` [RFC][-mm] [3/7] add shmem page to active list KAMEZAWA Hiroyuki
2008-07-03  0:11   ` KAMEZAWA Hiroyuki
2008-07-03  4:27     ` KAMEZAWA Hiroyuki
2008-07-03  7:03       ` Hugh Dickins
2008-07-03  7:43         ` KAMEZAWA Hiroyuki
2008-07-03 22:28           ` Hugh Dickins
2008-07-04  0:47             ` KAMEZAWA Hiroyuki
2008-07-02 12:12 ` [RFC][-mm] [4/7] handle limit change KAMEZAWA Hiroyuki
2008-07-02 12:13 ` [RFC][-mm] [5/7] reduce usage at " KAMEZAWA Hiroyuki
2008-07-02 12:15 ` KAMEZAWA Hiroyuki [this message]
2008-07-02 19:19   ` [RFC][-mm] [6/7] res_counter distance to limit Paul Menage
2008-07-02 23:57     ` KAMEZAWA Hiroyuki
2008-07-02 12:17 ` [RFC][-mm] [7/7] background job for memcg KAMEZAWA Hiroyuki
2008-07-02 14:23 ` [RFC][-mm] [0/7] misc memcg patch set Daisuke Nishimura
2008-07-02 16:31   ` KOSAKI Motohiro
2008-07-02 23:56   ` KAMEZAWA Hiroyuki
2008-07-03  2:38 ` KAMEZAWA Hiroyuki
2008-07-03  3:06 ` KAMEZAWA Hiroyuki
2008-07-03  9:07 ` Balbir Singh
2008-07-03  9:54   ` KAMEZAWA Hiroyuki
2008-07-11  8:38 ` KAMEZAWA Hiroyuki

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=20080702211510.6f1fe470.kamezawa.hiroyu@jp.fujitsu.com \
    --to=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=balbir@linux.vnet.ibm.com \
    --cc=hugh@veritas.com \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=linux-mm@kvack.org \
    --cc=nishimura@mxp.nes.nec.co.jp \
    --cc=xemul@openvz.org \
    --cc=yamamoto@valinux.co.jp \
    /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