From nobody Fri Jun 19 15:50:26 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2A99C433EF for ; Sat, 2 Apr 2022 03:22:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344854AbiDBDX4 (ORCPT ); Fri, 1 Apr 2022 23:23:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345214AbiDBDXw (ORCPT ); Fri, 1 Apr 2022 23:23:52 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 449FB1FA5A for ; Fri, 1 Apr 2022 20:21:59 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4KVj4c6bTfz1HBQN; Sat, 2 Apr 2022 11:21:36 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Sat, 2 Apr 2022 11:21:57 +0800 From: Miaohe Lin To: CC: , , Subject: [PATCH] mm/mmap.c: use helper mlock_future_check() Date: Sat, 2 Apr 2022 11:22:31 +0800 Message-ID: <20220402032231.64974-1-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use helper mlock_future_check() to check whether it's safe to enlarge the locked_vm to simplify the code. Minor readability improvement. Signed-off-by: Miaohe Lin --- mm/mmap.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index d62598dc2fdd..36914ef6f338 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2348,15 +2348,8 @@ static int acct_stack_growth(struct vm_area_struct *= vma, return -ENOMEM; =20 /* mlock limit tests */ - if (vma->vm_flags & VM_LOCKED) { - unsigned long locked; - unsigned long limit; - locked =3D mm->locked_vm + grow; - limit =3D rlimit(RLIMIT_MEMLOCK); - limit >>=3D PAGE_SHIFT; - if (locked > limit && !capable(CAP_IPC_LOCK)) - return -ENOMEM; - } + if (mlock_future_check(mm, vma->vm_flags, grow << PAGE_SHIFT)) + return -ENOMEM; =20 /* Check to ensure the stack will not grow into a hugetlb-only region */ new_start =3D (vma->vm_flags & VM_GROWSUP) ? vma->vm_start : --=20 2.23.0