From patchwork Fri Nov 5 20:40:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12605603 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 4ABD7C433FE for ; Fri, 5 Nov 2021 20:40:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 032C5611C0 for ; Fri, 5 Nov 2021 20:40:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 032C5611C0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 91601940074; Fri, 5 Nov 2021 16:40:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C5FC940049; Fri, 5 Nov 2021 16:40:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B50E940074; Fri, 5 Nov 2021 16:40:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0189.hostedemail.com [216.40.44.189]) by kanga.kvack.org (Postfix) with ESMTP id 6A377940049 for ; Fri, 5 Nov 2021 16:40:57 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 34E6218494E94 for ; Fri, 5 Nov 2021 20:40:57 +0000 (UTC) X-FDA: 78776045796.01.A0FF9FB Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf15.hostedemail.com (Postfix) with ESMTP id E5577D0000AC for ; Fri, 5 Nov 2021 20:40:45 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id E905E61262; Fri, 5 Nov 2021 20:40:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1636144856; bh=NOCP50HYKMSoBePJ/HR1LDAyXYJlPTqLctXom3vTXos=; h=Date:From:To:Subject:In-Reply-To:From; b=Qqr7byP2j+c7GM/LyIh4imPabe34S8W3py0u1RlTX8IeHjhXhJojV3ZXkfbn88T1R nmjx+enlzFMNgNMhs+eeL3k/fYLmCqMmkUOz8qn8tdZ1RiJylJfN9SHUhnqZwhNFzE XZ/qZ1KyFn3UbOb7qH8VRGHuKSTBLte+jCAAtU28= Date: Fri, 05 Nov 2021 13:40:55 -0700 From: Andrew Morton To: akpm@linux-foundation.org, bobo.shaobowang@huawei.com, david@redhat.com, huawei.libin@huawei.com, linux-mm@kvack.org, mm-commits@vger.kernel.org, torvalds@linux-foundation.org, weiyongjun1@huawei.com Subject: [patch 120/262] mm/page_alloc: use clamp() to simplify code Message-ID: <20211105204055.6P3hBKyWJ%akpm@linux-foundation.org> In-Reply-To: <20211105133408.cccbb98b71a77d5e8430aba1@linux-foundation.org> User-Agent: s-nail v14.8.16 Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=Qqr7byP2; dmarc=none; spf=pass (imf15.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E5577D0000AC X-Stat-Signature: 39if89uryth8s43co1ykzoy34afch8k4 X-HE-Tag: 1636144845-131535 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: From: Wang ShaoBo Subject: mm/page_alloc: use clamp() to simplify code This patch uses clamp() to simplify code in init_per_zone_wmark_min(). Link: https://lkml.kernel.org/r/20211021034830.1049150-1-bobo.shaobowang@huawei.com Signed-off-by: Wang ShaoBo Reviewed-by: David Hildenbrand Cc: Wei Yongjun Cc: Li Bin Signed-off-by: Andrew Morton --- mm/page_alloc.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) --- a/mm/page_alloc.c~mm-page_alloc-use-clamp-to-simplify-code +++ a/mm/page_alloc.c @@ -8477,16 +8477,12 @@ int __meminit init_per_zone_wmark_min(vo 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();