Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2855188pxp; Tue, 22 Mar 2022 07:18:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFDhAyRhmNMdOB22SvsJDSGvJdwazJx9yyMFyptY9IDKKwlt8JjvkSivc6klYsoOqNh3Sl X-Received: by 2002:a17:906:7745:b0:6b5:fe2b:4827 with SMTP id o5-20020a170906774500b006b5fe2b4827mr25370831ejn.628.1647958722361; Tue, 22 Mar 2022 07:18:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647958722; cv=none; d=google.com; s=arc-20160816; b=mjTpEkOn6fHQY8Afu2lE0sy1IcZ9KLBOLxlzPrSD0K2ct9vJ+t0Nl8JWXrgc9OXmCH lTvPD+6w9dLnv1L1MEkCk0YuOA21bKz4uT1ub4OzoN2OYFEksqGeJMoaqrpUOTFmXAmC AxUl+jxCVfTBCu4Fe1dvgsQDG2+sEyGWTzRk9i3Cr3bPWTNeLuuKwFGwqfGBnBwKsAG4 NVwIuKScC28htx+fEcujVi4uZ/qYqrUeBEoOktYpTDFe6lIbCrAeUFH5yYnqXZ4fjeMd BCTrEdNdyPyxxDVrhoQ1z2Mz53LvhEbJE6gF8pEkwj2ILqBPn4FHQIBhV53v7fU0m8zO yYiA== 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=FKePfno8WwvePYSEfOVar8idPWbwNO2lUwXVBooGFpk=; b=TEEi6tIfkV/WvugfkelTmnoa+C+TtAPr3KldeKY4kKTD/as+uOatWmmlcm5pG0Awgq qEOmoGvykIl4CoBeDcH0yTkokjmPn4GEK3y+9ZHhPDmqtvxatPU4EzOcGKFK4xWTabHn +Hq4PzVt0CADzkSlElG27ZIB7fyGCgHqIarv7K8of1NeKzq+1SsEIi8joZlw0ObsSOqq 0JxE7Rwp8FHXJX9gHkQ+QySDPZoA+Tb71iDZU/WHtehMgl+0XI+sIOGrPrCAjQtFkuJT LV0WV6c1WNX+W79xTVC8BxpYEAA4cGXHUkdSVg96s2Pmqsc1+BBdVQwbWgZyL/4sBc9A HeTg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 6-20020a170906008600b006df76385cafsi8748485ejc.335.2022.03.22.07.18.16; Tue, 22 Mar 2022 07:18:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234086AbiCVLU7 (ORCPT + 99 others); Tue, 22 Mar 2022 07:20:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231368AbiCVLUz (ORCPT ); Tue, 22 Mar 2022 07:20:55 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C20A726DB for ; Tue, 22 Mar 2022 04:19:27 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4KN89F3CX6zfZ6x; Tue, 22 Mar 2022 19:17:53 +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; Tue, 22 Mar 2022 19:19:25 +0800 From: Miaohe Lin To: CC: , , Subject: [PATCH] mm/mremap: use helper mlock_future_check Date: Tue, 22 Mar 2022 19:20:04 +0800 Message-ID: <20220322112004.27380-1-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use helper mlock_future_check to check whether it's safe to resize the locked_vm to simplify the code. Minor readability improvement. Signed-off-by: Miaohe Lin --- mm/mremap.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/mm/mremap.c b/mm/mremap.c index 9d76da79594d..e776d4c2345c 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -763,14 +763,8 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr, if (vma->vm_flags & (VM_DONTEXPAND | VM_PFNMAP)) return ERR_PTR(-EFAULT); - if (vma->vm_flags & VM_LOCKED) { - unsigned long locked, lock_limit; - locked = mm->locked_vm << PAGE_SHIFT; - lock_limit = rlimit(RLIMIT_MEMLOCK); - locked += new_len - old_len; - if (locked > lock_limit && !capable(CAP_IPC_LOCK)) - return ERR_PTR(-EAGAIN); - } + if (mlock_future_check(mm, vma->vm_flags, new_len - old_len)) + return ERR_PTR(-EAGAIN); if (!may_expand_vm(mm, vma->vm_flags, (new_len - old_len) >> PAGE_SHIFT)) -- 2.23.0