From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760704AbbLCQ1X (ORCPT ); Thu, 3 Dec 2015 11:27:23 -0500 Received: from mail-wm0-f54.google.com ([74.125.82.54]:35239 "EHLO mail-wm0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760320AbbLCQ1V (ORCPT ); Thu, 3 Dec 2015 11:27:21 -0500 Date: Thu, 3 Dec 2015 17:27:18 +0100 From: Michal Hocko To: Geliang Tang Cc: Johannes Weiner , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry Message-ID: <20151203162718.GK9264@dhcp22.suse.cz> References: <9e62e3006561653fcbf0c49cf0b9c2b653a8ed0e.1449152124.git.geliangtang@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9e62e3006561653fcbf0c49cf0b9c2b653a8ed0e.1449152124.git.geliangtang@163.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 03-12-15 22:16:55, Geliang Tang wrote: > To make the intention clearer, use list_{first,next}_entry instead > of list_entry. Does this really help readability? This function simply uncharges the given list of pages. Why cannot we simply use list_for_each_entry instead... > Signed-off-by: Geliang Tang > --- > mm/memcontrol.c | 9 +++------ > 1 file changed, 3 insertions(+), 6 deletions(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 79a29d5..a6301ea 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -5395,16 +5395,12 @@ static void uncharge_list(struct list_head *page_list) > unsigned long nr_file = 0; > unsigned long nr_huge = 0; > unsigned long pgpgout = 0; > - struct list_head *next; > struct page *page; > > - next = page_list->next; > + page = list_first_entry(page_list, struct page, lru); > do { > unsigned int nr_pages = 1; > > - page = list_entry(next, struct page, lru); > - next = page->lru.next; > - > VM_BUG_ON_PAGE(PageLRU(page), page); > VM_BUG_ON_PAGE(page_count(page), page); > > @@ -5440,7 +5436,8 @@ static void uncharge_list(struct list_head *page_list) > page->mem_cgroup = NULL; > > pgpgout++; > - } while (next != page_list); > + } while (!list_is_last(&page->lru, page_list) && > + (page = list_next_entry(page, lru))); > > if (memcg) > uncharge_batch(memcg, pgpgout, nr_anon, nr_file, > -- > 2.5.0 > -- Michal Hocko SUSE Labs From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f54.google.com (mail-wm0-f54.google.com [74.125.82.54]) by kanga.kvack.org (Postfix) with ESMTP id B6B9E6B025B for ; Thu, 3 Dec 2015 11:27:21 -0500 (EST) Received: by wmww144 with SMTP id w144so28393298wmw.1 for ; Thu, 03 Dec 2015 08:27:21 -0800 (PST) Received: from mail-wm0-f41.google.com (mail-wm0-f41.google.com. [74.125.82.41]) by mx.google.com with ESMTPS id x11si6061043wju.95.2015.12.03.08.27.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Dec 2015 08:27:20 -0800 (PST) Received: by wmww144 with SMTP id w144so28392724wmw.1 for ; Thu, 03 Dec 2015 08:27:20 -0800 (PST) Date: Thu, 3 Dec 2015 17:27:18 +0100 From: Michal Hocko Subject: Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry Message-ID: <20151203162718.GK9264@dhcp22.suse.cz> References: <9e62e3006561653fcbf0c49cf0b9c2b653a8ed0e.1449152124.git.geliangtang@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9e62e3006561653fcbf0c49cf0b9c2b653a8ed0e.1449152124.git.geliangtang@163.com> Sender: owner-linux-mm@kvack.org List-ID: To: Geliang Tang Cc: Johannes Weiner , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org On Thu 03-12-15 22:16:55, Geliang Tang wrote: > To make the intention clearer, use list_{first,next}_entry instead > of list_entry. Does this really help readability? This function simply uncharges the given list of pages. Why cannot we simply use list_for_each_entry instead... > Signed-off-by: Geliang Tang > --- > mm/memcontrol.c | 9 +++------ > 1 file changed, 3 insertions(+), 6 deletions(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 79a29d5..a6301ea 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -5395,16 +5395,12 @@ static void uncharge_list(struct list_head *page_list) > unsigned long nr_file = 0; > unsigned long nr_huge = 0; > unsigned long pgpgout = 0; > - struct list_head *next; > struct page *page; > > - next = page_list->next; > + page = list_first_entry(page_list, struct page, lru); > do { > unsigned int nr_pages = 1; > > - page = list_entry(next, struct page, lru); > - next = page->lru.next; > - > VM_BUG_ON_PAGE(PageLRU(page), page); > VM_BUG_ON_PAGE(page_count(page), page); > > @@ -5440,7 +5436,8 @@ static void uncharge_list(struct list_head *page_list) > page->mem_cgroup = NULL; > > pgpgout++; > - } while (next != page_list); > + } while (!list_is_last(&page->lru, page_list) && > + (page = list_next_entry(page, lru))); > > if (memcg) > uncharge_batch(memcg, pgpgout, nr_anon, nr_file, > -- > 2.5.0 > -- Michal Hocko SUSE Labs -- 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: Michal Hocko Subject: Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry Date: Thu, 3 Dec 2015 17:27:18 +0100 Message-ID: <20151203162718.GK9264@dhcp22.suse.cz> References: <9e62e3006561653fcbf0c49cf0b9c2b653a8ed0e.1449152124.git.geliangtang@163.com> Mime-Version: 1.0 Return-path: Content-Disposition: inline In-Reply-To: <9e62e3006561653fcbf0c49cf0b9c2b653a8ed0e.1449152124.git.geliangtang-9Onoh4P/yGk@public.gmane.org> Sender: cgroups-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Geliang Tang Cc: Johannes Weiner , cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org On Thu 03-12-15 22:16:55, Geliang Tang wrote: > To make the intention clearer, use list_{first,next}_entry instead > of list_entry. Does this really help readability? This function simply uncharges the given list of pages. Why cannot we simply use list_for_each_entry instead... > Signed-off-by: Geliang Tang > --- > mm/memcontrol.c | 9 +++------ > 1 file changed, 3 insertions(+), 6 deletions(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 79a29d5..a6301ea 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -5395,16 +5395,12 @@ static void uncharge_list(struct list_head *page_list) > unsigned long nr_file = 0; > unsigned long nr_huge = 0; > unsigned long pgpgout = 0; > - struct list_head *next; > struct page *page; > > - next = page_list->next; > + page = list_first_entry(page_list, struct page, lru); > do { > unsigned int nr_pages = 1; > > - page = list_entry(next, struct page, lru); > - next = page->lru.next; > - > VM_BUG_ON_PAGE(PageLRU(page), page); > VM_BUG_ON_PAGE(page_count(page), page); > > @@ -5440,7 +5436,8 @@ static void uncharge_list(struct list_head *page_list) > page->mem_cgroup = NULL; > > pgpgout++; > - } while (next != page_list); > + } while (!list_is_last(&page->lru, page_list) && > + (page = list_next_entry(page, lru))); > > if (memcg) > uncharge_batch(memcg, pgpgout, nr_anon, nr_file, > -- > 2.5.0 > -- Michal Hocko SUSE Labs