From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.4 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 114FDC388F9 for ; Tue, 27 Oct 2020 18:45:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4833520760 for ; Tue, 27 Oct 2020 18:45:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4833520760 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B7A896B005C; Tue, 27 Oct 2020 14:45:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B2A8B6B005D; Tue, 27 Oct 2020 14:45:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A409B6B0062; Tue, 27 Oct 2020 14:45:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0166.hostedemail.com [216.40.44.166]) by kanga.kvack.org (Postfix) with ESMTP id 751496B005C for ; Tue, 27 Oct 2020 14:45:57 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 1234B1EE6 for ; Tue, 27 Oct 2020 18:45:57 +0000 (UTC) X-FDA: 77418584754.16.river31_4d1320b2727e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id D6C4F100E6903 for ; Tue, 27 Oct 2020 18:45:56 +0000 (UTC) X-HE-Tag: river31_4d1320b2727e X-Filterd-Recvd-Size: 2957 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf13.hostedemail.com (Postfix) with ESMTP for ; Tue, 27 Oct 2020 18:45:56 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id C6937ABA2; Tue, 27 Oct 2020 18:45:54 +0000 (UTC) Subject: Re: [PATCH] mm/list_lru: optimize condition of exiting the loop To: Hui Su , akpm@linux-foundation.org, gustavo@embeddedor.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20201027170420.GA61326@rlk> From: Vlastimil Babka Message-ID: Date: Tue, 27 Oct 2020 19:45:53 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.3.3 MIME-Version: 1.0 In-Reply-To: <20201027170420.GA61326@rlk> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 10/27/20 6:04 PM, Hui Su wrote: > In list_lru_walk(), nr_to_walk type is 'unsigned long', > so nr_to_walk won't be '< 0'. > > In list_lru_walk_node(), nr_to_walk type is 'unsigned long', > so *nr_to_walk won't be '< 0' too. > > We can use '!nr_to_walk' instead of 'nr_to_walk <= 0', which > is more precise. > > Signed-off-by: Hui Su OK. Why not this too? --- a/mm/list_lru.c +++ b/mm/list_lru.c @@ -294,7 +294,7 @@ unsigned long list_lru_walk_node(struct list_lru *lru, int nid, isolated += list_lru_walk_one(lru, nid, NULL, isolate, cb_arg, nr_to_walk); - if (*nr_to_walk > 0 && list_lru_memcg_aware(lru)) { + if (*nr_to_walk && list_lru_memcg_aware(lru)) { for_each_memcg_cache_index(memcg_idx) { struct list_lru_node *nlru = &lru->node[nid]; > --- > include/linux/list_lru.h | 2 +- > mm/list_lru.c | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/include/linux/list_lru.h b/include/linux/list_lru.h > index 9dcaa3e582c9..b7bc4a2636b9 100644 > --- a/include/linux/list_lru.h > +++ b/include/linux/list_lru.h > @@ -214,7 +214,7 @@ list_lru_walk(struct list_lru *lru, list_lru_walk_cb isolate, > for_each_node_state(nid, N_NORMAL_MEMORY) { > isolated += list_lru_walk_node(lru, nid, isolate, > cb_arg, &nr_to_walk); > - if (nr_to_walk <= 0) > + if (!nr_to_walk) > break; > } > return isolated; > diff --git a/mm/list_lru.c b/mm/list_lru.c > index 5aa6e44bc2ae..39b8d467159d 100644 > --- a/mm/list_lru.c > +++ b/mm/list_lru.c > @@ -304,7 +304,7 @@ unsigned long list_lru_walk_node(struct list_lru *lru, int nid, > nr_to_walk); > spin_unlock(&nlru->lock); > > - if (*nr_to_walk <= 0) > + if (!*nr_to_walk) > break; > } > } >