From patchwork Thu Oct 21 03:48:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wangshaobo (bobo)" X-Patchwork-Id: 12573709 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E6DDC433EF for ; Thu, 21 Oct 2021 03:41:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6075961183 for ; Thu, 21 Oct 2021 03:41:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6075961183 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 02ED26B0072; Wed, 20 Oct 2021 23:41:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F215C6B0073; Wed, 20 Oct 2021 23:41:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE8EE900002; Wed, 20 Oct 2021 23:41:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0130.hostedemail.com [216.40.44.130]) by kanga.kvack.org (Postfix) with ESMTP id D0A716B0072 for ; Wed, 20 Oct 2021 23:41:15 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 91CF62DD77 for ; Thu, 21 Oct 2021 03:41:15 +0000 (UTC) X-FDA: 78719044110.24.AA88BE3 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf19.hostedemail.com (Postfix) with ESMTP id B97C7B0000AA for ; Thu, 21 Oct 2021 03:41:11 +0000 (UTC) Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4HZYBM4SSNz1DHlQ; Thu, 21 Oct 2021 11:39:23 +0800 (CST) Received: from dggpemm500015.china.huawei.com (7.185.36.181) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.15; Thu, 21 Oct 2021 11:41:10 +0800 Received: from huawei.com (10.175.103.91) by dggpemm500015.china.huawei.com (7.185.36.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.15; Thu, 21 Oct 2021 11:41:10 +0800 From: Wang ShaoBo To: CC: , , , Subject: [PATCH] mm/page_alloc: use clamp() to simplify code Date: Thu, 21 Oct 2021 11:48:30 +0800 Message-ID: <20211021034830.1049150-1-bobo.shaobowang@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500015.china.huawei.com (7.185.36.181) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: B97C7B0000AA X-Stat-Signature: s549xqe7c79tjfxyikbp44obixp646gx Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=huawei.com; spf=pass (imf19.hostedemail.com: domain of bobo.shaobowang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=bobo.shaobowang@huawei.com X-HE-Tag: 1634787671-99705 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This patch uses clamp() to simplify code in init_per_zone_wmark_min(). Signed-off-by: Wang ShaoBo Reviewed-by: David Hildenbrand --- mm/page_alloc.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index b37435c274cf..d0449212a824 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -8460,16 +8460,12 @@ int __meminit init_per_zone_wmark_min(void) lowmem_kbytes = nr_free_buffer_pages() * (PAGE_SIZE >> 10); new_min_free_kbytes = int_sqrt(lowmem_kbytes * 16); - if (new_min_free_kbytes > user_min_free_kbytes) { - min_free_kbytes = new_min_free_kbytes; - if (min_free_kbytes < 128) - min_free_kbytes = 128; - if (min_free_kbytes > 262144) - min_free_kbytes = 262144; - } else { + if (new_min_free_kbytes > user_min_free_kbytes) + min_free_kbytes = clamp(new_min_free_kbytes, 128, 262144); + else pr_warn("min_free_kbytes is not updated to %d because user defined value %d is preferred\n", new_min_free_kbytes, user_min_free_kbytes); - } + setup_per_zone_wmarks(); refresh_zone_stat_thresholds(); setup_per_zone_lowmem_reserve();