From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx107.postini.com [74.125.245.107]) by kanga.kvack.org (Postfix) with SMTP id 00B826B004D for ; Tue, 26 Jun 2012 18:25:23 -0400 (EDT) Date: Tue, 26 Jun 2012 15:25:22 -0700 From: Andrew Morton Subject: Re: [PATCH 1/2] fix bad behavior in use_hierarchy file Message-Id: <20120626152522.c7161b5a.akpm@linux-foundation.org> In-Reply-To: <1340725634-9017-2-git-send-email-glommer@parallels.com> References: <1340725634-9017-1-git-send-email-glommer@parallels.com> <1340725634-9017-2-git-send-email-glommer@parallels.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Glauber Costa Cc: cgroups@vger.kernel.org, linux-mm@kvack.org, kamezawa.hiroyu@jp.fujitsu.com, Michal Hocko , Johannes Weiner , Dhaval Giani , Tejun Heo On Tue, 26 Jun 2012 19:47:13 +0400 Glauber Costa wrote: > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -3989,6 +3989,10 @@ static int mem_cgroup_hierarchy_write(struct cgroup *cont, struct cftype *cft, > parent_memcg = mem_cgroup_from_cont(parent); > > cgroup_lock(); > + > + if (memcg->use_hierarchy == val) > + goto out; > + > /* > * If parent's use_hierarchy is set, we can't make any modifications > * in the child subtrees. If it is unset, then the change can > @@ -4005,6 +4009,8 @@ static int mem_cgroup_hierarchy_write(struct cgroup *cont, struct cftype *cft, > retval = -EBUSY; > } else > retval = -EINVAL; > + > +out: > cgroup_unlock(); > > return retval; hm. The various .write_u64() implementations go and return zero on success and cgroup_write_X64() sees this and rewrites the return value to `nbytes'. That was a bit naughty of us - it prevents a .write_u64() instance from being able to fully implement a partial write. We can *partially* implement a partial write, by returning a value between 1 and nbytes-1, but we can't return zero. It's a weird interface, it's a surprising interface and it was quite unnecessary to do it this way. Someone please slap Paul. It's hardly a big problem I, but that's why the unix write() interface was designed the way it is. -- 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: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Morton Subject: Re: [PATCH 1/2] fix bad behavior in use_hierarchy file Date: Tue, 26 Jun 2012 15:25:22 -0700 Message-ID: <20120626152522.c7161b5a.akpm@linux-foundation.org> References: <1340725634-9017-1-git-send-email-glommer@parallels.com> <1340725634-9017-2-git-send-email-glommer@parallels.com> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1340725634-9017-2-git-send-email-glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org> Sender: cgroups-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-ID: Content-Type: text/plain; charset="us-ascii" To: Glauber Costa Cc: cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org, kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org, Michal Hocko , Johannes Weiner , Dhaval Giani , Tejun Heo On Tue, 26 Jun 2012 19:47:13 +0400 Glauber Costa wrote: > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -3989,6 +3989,10 @@ static int mem_cgroup_hierarchy_write(struct cgroup *cont, struct cftype *cft, > parent_memcg = mem_cgroup_from_cont(parent); > > cgroup_lock(); > + > + if (memcg->use_hierarchy == val) > + goto out; > + > /* > * If parent's use_hierarchy is set, we can't make any modifications > * in the child subtrees. If it is unset, then the change can > @@ -4005,6 +4009,8 @@ static int mem_cgroup_hierarchy_write(struct cgroup *cont, struct cftype *cft, > retval = -EBUSY; > } else > retval = -EINVAL; > + > +out: > cgroup_unlock(); > > return retval; hm. The various .write_u64() implementations go and return zero on success and cgroup_write_X64() sees this and rewrites the return value to `nbytes'. That was a bit naughty of us - it prevents a .write_u64() instance from being able to fully implement a partial write. We can *partially* implement a partial write, by returning a value between 1 and nbytes-1, but we can't return zero. It's a weird interface, it's a surprising interface and it was quite unnecessary to do it this way. Someone please slap Paul. It's hardly a big problem I, but that's why the unix write() interface was designed the way it is.