Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758856AbXHTIVm (ORCPT ); Mon, 20 Aug 2007 04:21:42 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754112AbXHTIVd (ORCPT ); Mon, 20 Aug 2007 04:21:33 -0400 Received: from mailhub.sw.ru ([195.214.233.200]:34265 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752661AbXHTIVc (ORCPT ); Mon, 20 Aug 2007 04:21:32 -0400 Date: Mon, 20 Aug 2007 12:20:54 +0400 From: Alexey Dobriyan To: Balbir Singh Cc: Andrew Morton , Nick Piggin , Peter Zijlstra , Dhaval Giani , YAMAMOTO Takashi , Linux Kernel Mailing List , Linux MM Mailing List , Linux Containers Subject: Re: [Devel] [-mm PATCH 1/9] Memory controller resource counters (v6) Message-ID: <20070820082054.GA6926@localhost.sw.ru> References: <20070817084228.26003.12568.sendpatchset@balbir-laptop> <20070817084238.26003.7733.sendpatchset@balbir-laptop> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20070817084238.26003.7733.sendpatchset@balbir-laptop> User-Agent: Mutt/1.5.11 Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2448 Lines: 97 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 from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/