From patchwork Wed Oct 28 14:16:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hui Su X-Patchwork-Id: 11862797 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 275FB14B2 for ; Wed, 28 Oct 2020 14:17:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B882424734 for ; Wed, 28 Oct 2020 14:17:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="euYbvd4e" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B882424734 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=163.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 875ED6B0062; Wed, 28 Oct 2020 10:17:47 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 84D596B0068; Wed, 28 Oct 2020 10:17:47 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 73CAF6B006C; Wed, 28 Oct 2020 10:17:47 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0198.hostedemail.com [216.40.44.198]) by kanga.kvack.org (Postfix) with ESMTP id 47B5A6B0062 for ; Wed, 28 Oct 2020 10:17:47 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id E3270181AC9C6 for ; Wed, 28 Oct 2020 14:17:46 +0000 (UTC) X-FDA: 77421537732.20.star11_350503d27285 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id A9481180C07A3 for ; Wed, 28 Oct 2020 14:17:46 +0000 (UTC) X-Spam-Summary: 1,0,0,3d5fd32a51e940df,d41d8cd98f00b204,sh_def@163.com,,RULES_HIT:41:355:379:582:800:960:973:988:989:1152:1260:1277:1312:1313:1314:1345:1381:1516:1518:1519:1534:1541:1593:1594:1595:1596:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3151:3352:3866:3870:3871:4321:4605:5007:6261:6653:10004:10400:10450:10455:11026:11334:11658:11914:12043:12048:12296:12297:12438:12555:12895:13069:13311:13357:13439:13895:14181:14394:14721:19904:19999:21080:21600:21627:21990:30054,0,RBL:220.181.12.15:@163.com:.lbl8.mailshell.net-66.100.201.100 62.50.2.100;04yg35eqadmn54hzjfdmaco64p8r1ypsub795j8tk8is7ng4o4d7kzdbguih1yg.a7ms1czxjw1acesysso1mohegsnsb467u1t8ef758bp417ig1n1sa9y4jbzd1ih.w-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:71,LUA_SUMMARY:none X-HE-Tag: star11_350503d27285 X-Filterd-Recvd-Size: 3209 Received: from m12-15.163.com (m12-15.163.com [220.181.12.15]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Wed, 28 Oct 2020 14:17:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=Date:From:Subject:Message-ID:MIME-Version; bh=gmYDL NcOnzaaetAj3ChK//hLyFrS3pOYHO5vlGIygw4=; b=euYbvd4e9rHp3GuAqTD2O x6FZp+nfNLqNKZ/NG4kUSsy/OcpZ8ZKOD+JcZUgHXTnI+NsOVpNgxNxpfMuKPAGv sgrsEaPDT1K2zxXtYf3S/q5t1OdOWQTfWu6wsAUaDaXC052OIARMzMlpfqJFsydi YaqAZq27pVaHAlfNp+soUA= Received: from localhost (unknown [101.86.209.121]) by smtp11 (Coremail) with SMTP id D8CowAAXMSlOfZlfeJU+FQ--.17491S2; Wed, 28 Oct 2020 22:16:46 +0800 (CST) Date: Wed, 28 Oct 2020 22:16:46 +0800 From: Hui Su To: akpm@linux-foundation.org, gustavo@embeddedor.com, songmuchun@bytedance.com, vbabka@suse.cz, sh_def@163.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2] mm/list_lru: optimize condition of exiting the loop Message-ID: <20201028141646.GA75933@rlk> MIME-Version: 1.0 Content-Disposition: inline X-CM-TRANSID: D8CowAAXMSlOfZlfeJU+FQ--.17491S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7ArW3AryrGFyxGrWDJr47urg_yoW8Wry5pa 1Y9ry7KFWxXF4ru348J39ruF10gr48CrW7Kr47uw1jy343tFZxJwsFkrW2qFy5GFWxWryf GryDCF1UuF4UGwUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UJpndUUUUU= X-Originating-IP: [101.86.209.121] X-CM-SenderInfo: xvkbvvri6rljoofrz/1tbifw7LX1r6mWtOJwAAse X-Bogosity: Ham, tests=bogofilter, spamicity=0.434788, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Acked-by: Vlastimil Babka Acked-by: Pankaj Gupta Reviewed-by: Muchun Song --- include/linux/list_lru.h | 2 +- mm/list_lru.c | 4 ++-- 2 files changed, 3 insertions(+), 3 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..35be4de9fd77 100644 --- 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]; @@ -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; } }