Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp223230pxb; Wed, 20 Oct 2021 20:44:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwScL23ejGzvuGhXPFbc/EfE7hM3TFtebdUagvPTDS6AqcT2rm2q0ro4WLVywHZE8cixHxE X-Received: by 2002:a17:906:7a0c:: with SMTP id d12mr4144711ejo.442.1634787850703; Wed, 20 Oct 2021 20:44:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634787850; cv=none; d=google.com; s=arc-20160816; b=ekp1uoemdW4gjw1ixfag9vOhyuXxKaYd+bbwmZyOI+pZyygoONTB/vidheONKU3uTO YyJqq1MJABHEzVTh6iKoL+bgQSKR+hJ3PqraJ9qLM4qPOODltgijykoJQSJ3r1Jzomn4 RdphZ3Z4vvB6yV9OVTazI1RFEdnnhSwCO1LgjaV2NI2aeXnt3ZUE0+GpQXsAhLY4NS6f ufCRNPxgbdlfgEMoYivNp3g0xK+8G2S0QyTGUCXoBt8R2mvA8iFi6ID9PQfp1ny4YFc4 Zv++TkXlaC6AaVjn0KFz6cRmPivbUUmSipEetCbOM7L72Znmbh0auEwv8uc0pFmw1+eK AddA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=LkSc+D3ywBVNEW2yS5dRaNNpzJHLuD3cI0EvXUMOVQw=; b=IJwLxX1SAam7kim78nBFMx7w4lGph3R0Hd3solXgB8VqWFd0SLu5yAfTPeAV5oXe3g Tt8jiGA6TlDvEyTOF29rFDCo67nfb9OBvASif2/vLx7BpR3+A+lVNIwtlNRSNYdn1Kv1 lLyWgIZo8QZwl///rvH1Ks1+JiWKvwU3CgboFfKOG1rEzwddIeKZb+4NVyzLqI1OKS6A kr9NCgfg5XrNlyDZEIjoCHQwcooJe6Jv5Ji1vBOHKkJwjAlCsU9UdCb+OoUnMAofhya8 xRpBp0xqvv/FdxnMTD1U0pdd8q03UkWLECtQRt1cUT09uAboTzHw0UEzNgnl7F9doktp 8fMQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f8si9136092edd.594.2021.10.20.20.43.47; Wed, 20 Oct 2021 20:44:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230378AbhJUDn3 (ORCPT + 99 others); Wed, 20 Oct 2021 23:43:29 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:26106 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231295AbhJUDn2 (ORCPT ); Wed, 20 Oct 2021 23:43:28 -0400 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 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch uses clamp() to simplify code in init_per_zone_wmark_min(). Signed-off-by: Wang ShaoBo --- 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(); -- 2.25.1