From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753222AbbLCT2E (ORCPT ); Thu, 3 Dec 2015 14:28:04 -0500 Received: from gum.cmpxchg.org ([85.214.110.215]:47572 "EHLO gum.cmpxchg.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751633AbbLCT2C (ORCPT ); Thu, 3 Dec 2015 14:28:02 -0500 Date: Thu, 3 Dec 2015 14:27:50 -0500 From: Johannes Weiner To: Michal Hocko Cc: Geliang Tang , 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: <20151203192750.GA19242@cmpxchg.org> References: <9e62e3006561653fcbf0c49cf0b9c2b653a8ed0e.1449152124.git.geliangtang@163.com> <20151203162718.GK9264@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20151203162718.GK9264@dhcp22.suse.cz> 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, Dec 03, 2015 at 05:27:18PM +0100, Michal Hocko wrote: > 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... You asked the same thing when reviewing the patch for the first time. :-) I think it's time to add a comment. >>From e8ba3f31bb43ed4091b997b6ee8857dc8bbcd349 Mon Sep 17 00:00:00 2001 From: Johannes Weiner Date: Thu, 3 Dec 2015 14:21:45 -0500 Subject: [PATCH] mm: memcontrol: clarify the uncharge_list() loop uncharge_list() does an unusual list walk because the function can take regular lists with dedicated list_heads as well as singleton lists where a single page is passed via its page->lru list node. This can sometimes lead to confusion, as well as suggestions to replace the loop with a list_for_each_entry(), which wouldn't work. Signed-off-by: Johannes Weiner --- mm/memcontrol.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 9acfb16..f7ee1c0 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5422,6 +5422,10 @@ static void uncharge_list(struct list_head *page_list) struct list_head *next; struct page *page; + /* + * Note that the list can be a single page->lru; hence the + * do-while loop instead of a simple list_for_each_entry(). + */ next = page_list->next; do { unsigned int nr_pages = 1; -- 2.6.3 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f52.google.com (mail-wm0-f52.google.com [74.125.82.52]) by kanga.kvack.org (Postfix) with ESMTP id C2EB46B0255 for ; Thu, 3 Dec 2015 14:28:04 -0500 (EST) Received: by wmww144 with SMTP id w144so36195401wmw.0 for ; Thu, 03 Dec 2015 11:28:04 -0800 (PST) Received: from gum.cmpxchg.org (gum.cmpxchg.org. [85.214.110.215]) by mx.google.com with ESMTPS id k129si571892wma.26.2015.12.03.11.28.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Dec 2015 11:28:03 -0800 (PST) Date: Thu, 3 Dec 2015 14:27:50 -0500 From: Johannes Weiner Subject: Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry Message-ID: <20151203192750.GA19242@cmpxchg.org> References: <9e62e3006561653fcbf0c49cf0b9c2b653a8ed0e.1449152124.git.geliangtang@163.com> <20151203162718.GK9264@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20151203162718.GK9264@dhcp22.suse.cz> Sender: owner-linux-mm@kvack.org List-ID: To: Michal Hocko Cc: Geliang Tang , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org On Thu, Dec 03, 2015 at 05:27:18PM +0100, Michal Hocko wrote: > 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... You asked the same thing when reviewing the patch for the first time. :-) I think it's time to add a comment. From mboxrd@z Thu Jan 1 00:00:00 1970 From: Johannes Weiner Subject: Re: [PATCH] mm/memcontrol.c: use list_{first,next}_entry Date: Thu, 3 Dec 2015 14:27:50 -0500 Message-ID: <20151203192750.GA19242@cmpxchg.org> References: <9e62e3006561653fcbf0c49cf0b9c2b653a8ed0e.1449152124.git.geliangtang@163.com> <20151203162718.GK9264@dhcp22.suse.cz> Mime-Version: 1.0 Return-path: Content-Disposition: inline In-Reply-To: <20151203162718.GK9264@dhcp22.suse.cz> Sender: linux-kernel-owner@vger.kernel.org List-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Michal Hocko Cc: Geliang Tang , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org On Thu, Dec 03, 2015 at 05:27:18PM +0100, Michal Hocko wrote: > 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... You asked the same thing when reviewing the patch for the first time. :-) I think it's time to add a comment. >From e8ba3f31bb43ed4091b997b6ee8857dc8bbcd349 Mon Sep 17 00:00:00 2001 From: Johannes Weiner Date: Thu, 3 Dec 2015 14:21:45 -0500 Subject: [PATCH] mm: memcontrol: clarify the uncharge_list() loop uncharge_list() does an unusual list walk because the function can take regular lists with dedicated list_heads as well as singleton lists where a single page is passed via its page->lru list node. This can sometimes lead to confusion, as well as suggestions to replace the loop with a list_for_each_entry(), which wouldn't work. Signed-off-by: Johannes Weiner --- mm/memcontrol.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 9acfb16..f7ee1c0 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5422,6 +5422,10 @@ static void uncharge_list(struct list_head *page_list) struct list_head *next; struct page *page; + /* + * Note that the list can be a single page->lru; hence the + * do-while loop instead of a simple list_for_each_entry(). + */ next = page_list->next; do { unsigned int nr_pages = 1; -- 2.6.3