linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Alexey Dobriyan <adobriyan@sw.ru>
To: Balbir Singh <balbir@linux.vnet.ibm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Nick Piggin <npiggin@suse.de>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Dhaval Giani <dhaval@linux.vnet.ibm.com>,
	YAMAMOTO Takashi <yamamoto@valinux.co.jp>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Linux MM Mailing List <linux-mm@kvack.org>,
	Linux Containers <containers@lists.osdl.org>
Subject: Re: [Devel] [-mm PATCH 1/9] Memory controller resource counters (v6)
Date: Mon, 20 Aug 2007 12:20:54 +0400	[thread overview]
Message-ID: <20070820082054.GA6926@localhost.sw.ru> (raw)
In-Reply-To: <20070817084238.26003.7733.sendpatchset@balbir-laptop>

On Fri, Aug 17, 2007 at 02:12:38PM +0530, Balbir Singh wrote:
> --- /dev/null
> +++ linux-2.6.23-rc2-mm2-balbir/kernel/res_counter.c
> +void res_counter_init(struct res_counter *counter)
> +{
> +	spin_lock_init(&counter->lock);
> +	counter->limit = (unsigned long)LONG_MAX;

why cast?

> +int res_counter_charge_locked(struct res_counter *counter, unsigned long val)
> +{
> +	if (counter->usage > (counter->limit - val)) {

() aren't needed.

> +		counter->failcnt++;
> +		return -ENOMEM;
> +	}
> +
> +	counter->usage += val;
> +	return 0;
> +}
> +
> +int res_counter_charge(struct res_counter *counter, unsigned long val)
> +{
> +	int ret;
> +	unsigned long flags;
> +
> +	spin_lock_irqsave(&counter->lock, flags);
> +	ret = res_counter_charge_locked(counter, val);
> +	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))
> +		val = counter->usage;

explicit if and WARN_ON(1) is clearer. I should send a patch banning such
type of usage soon.

> +
> +	counter->usage -= val;
> +}
> +
> +void res_counter_uncharge(struct res_counter *counter, unsigned long val)
> +{
> +	unsigned long flags;
> +
> +	spin_lock_irqsave(&counter->lock, flags);
> +	res_counter_uncharge_locked(counter, val);
> +	spin_unlock_irqrestore(&counter->lock, flags);
> +}

> +ssize_t res_counter_write(struct res_counter *counter, int member,
> +		const char __user *userbuf, size_t nbytes, loff_t *pos)
> +{
> +	int ret;
> +	char *buf, *end;
> +	unsigned long tmp, *val;
> +
> +	buf = kmalloc(nbytes + 1, GFP_KERNEL);

please, switch to fixed buffer, allocating memory depending on size
told by userspace will beat later. Ditto for other proc writing
functions.

> +	ret = -ENOMEM;
> +	if (buf == NULL)
> +		goto out;
> +
> +	buf[nbytes] = '\0';
> +	ret = -EFAULT;
> +	if (copy_from_user(buf, userbuf, nbytes))
> +		goto out_free;
> +
> +	ret = -EINVAL;
> +	tmp = simple_strtoul(buf, &end, 10);
> +	if (*end != '\0')
> +		goto out_free;
> +
> +	val = res_counter_member(counter, member);
> +	*val = tmp;
> +	ret = nbytes;
> +out_free:
> +	kfree(buf);
> +out:
> +	return ret;
> +}

--
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>

  reply	other threads:[~2007-08-20  8:20 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-17  8:42 [-mm PATCH 0/9] Memory controller introduction (v6) Balbir Singh
2007-08-17  8:42 ` [-mm PATCH 1/9] Memory controller resource counters (v6) Balbir Singh
2007-08-20  8:20   ` Alexey Dobriyan [this message]
2007-08-20  9:01     ` [Devel] " Balbir Singh
2007-09-11  0:42   ` Paul Menage
2007-09-12 10:05     ` Balbir Singh
2007-08-17  8:42 ` [-mm PATCH 2/9] Memory controller containers setup (v6) Balbir Singh
2007-08-17  8:42 ` [-mm PATCH 3/9] Memory controller accounting " Balbir Singh
2007-08-17  8:43 ` [-mm PATCH 4/9] Memory controller memory accounting (v6) Balbir Singh
2007-08-17  8:43 ` [-mm PATCH 5/9] Memory controller task migration (v6) Balbir Singh
2007-08-17  8:43 ` [-mm PATCH 6/9] Memory controller add per container LRU and reclaim (v6) Balbir Singh
2007-08-17  8:43 ` [-mm PATCH 7/9] Memory controller OOM handling (v6) Balbir Singh
2007-08-17  8:43 ` [-mm PATCH 8/9] Memory controller add switch to control what type of pages to limit (v6) Balbir Singh
2007-08-17  8:44 ` [-mm PATCH 9/9] Memory controller make page_referenced() container aware (v6) Balbir Singh
2007-08-17 15:49 ` [-mm PATCH 0/9] Memory controller introduction (v6) Dhaval Giani

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=20070820082054.GA6926@localhost.sw.ru \
    --to=adobriyan@sw.ru \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=balbir@linux.vnet.ibm.com \
    --cc=containers@lists.osdl.org \
    --cc=dhaval@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=npiggin@suse.de \
    --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