From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755080Ab2GRVgR (ORCPT ); Wed, 18 Jul 2012 17:36:17 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:43861 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753824Ab2GRVgO (ORCPT ); Wed, 18 Jul 2012 17:36:14 -0400 Date: Wed, 18 Jul 2012 14:36:12 -0700 From: Andrew Morton To: Wanpeng Li Cc: linux-mm@kvack.org, Michal Hocko , Johannes Weiner , KAMEZAWA Hiroyuki , Gavin Shan , linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/memcg: wrap mem_cgroup_from_css function Message-Id: <20120718143612.e34dd3f3.akpm@linux-foundation.org> In-Reply-To: <1342580730-25703-1-git-send-email-liwanp@linux.vnet.ibm.com> References: <1342580730-25703-1-git-send-email-liwanp@linux.vnet.ibm.com> X-Mailer: Sylpheed 3.0.2 (GTK+ 2.20.1; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 18 Jul 2012 11:05:30 +0800 Wanpeng Li wrote: > wrap mem_cgroup_from_css function to clarify get mem cgroup > from cgroup_subsys_state. This certainly adds clarity. But it also adds a little more type-safety - these container_of() calls can be invoked against *any* struct which has a field called "css". With your patch, we add a check that the code is indeed using a cgroup_subsys_state*. A small thing, but it's all good. I changed the patch title to the more idiomatic "memcg: add mem_cgroup_from_css() helper" and rewrote the changelog to : Add a mem_cgroup_from_css() helper to replace open-coded invokations of : container_of(). To clarify the code and to add a little more type safety. > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -396,6 +396,12 @@ static void mem_cgroup_put(struct mem_cgroup *memcg); > #include > #include > > +static inline > +struct mem_cgroup *mem_cgroup_from_css(struct cgroup_subsys_state *s) > +{ > + return container_of(s, struct mem_cgroup, css); > +} And with great self-control, I avoided renaming this to memcg_from_css(). Sigh. I guess all that extra typing has cardio benefits.