From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60751C433F5 for ; Fri, 22 Apr 2022 08:57:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA00A6B0074; Fri, 22 Apr 2022 04:57:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A4F546B0075; Fri, 22 Apr 2022 04:57:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 917396B0078; Fri, 22 Apr 2022 04:57:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id 7E0D56B0074 for ; Fri, 22 Apr 2022 04:57:47 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 4F5DE80DF8 for ; Fri, 22 Apr 2022 08:57:47 +0000 (UTC) X-FDA: 79383912174.03.3E2705D Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf11.hostedemail.com (Postfix) with ESMTP id 496D140017 for ; Fri, 22 Apr 2022 08:57:44 +0000 (UTC) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Kl7X90KbtzFqfD; Fri, 22 Apr 2022 16:55:05 +0800 (CST) Received: from dggpemm100007.china.huawei.com (7.185.36.116) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 22 Apr 2022 16:57:21 +0800 Received: from dggpemm500022.china.huawei.com (7.185.36.162) by dggpemm100007.china.huawei.com (7.185.36.116) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 22 Apr 2022 16:57:21 +0800 Received: from dggpemm500022.china.huawei.com ([7.185.36.162]) by dggpemm500022.china.huawei.com ([7.185.36.162]) with mapi id 15.01.2375.024; Fri, 22 Apr 2022 16:57:21 +0800 From: liusongtang To: Andrew Morton CC: "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , Nixiaoming , "Liuyang (Young,C)" , liusongtang , "mgorman@suse.de" Subject: Thread-Index: AdhWJvbUleEgbnxeQpScQoDlY7nhUA== Date: Fri, 22 Apr 2022 08:57:21 +0000 Message-ID: <388eaecb1ceb46bf8eb861055e64d399@huawei.com> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.67.110.243] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-CFilter-Loop: Reflected X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 496D140017 X-Rspam-User: Authentication-Results: imf11.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf11.hostedemail.com: domain of liusongtang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=liusongtang@huawei.com X-Stat-Signature: i33mad3ow3pxmkkpka7i3qtef8t7azej X-HE-Tag: 1650617864-962885 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: liusongtang Date: Thu, 21 Apr 2022 17:44:07 +0800 Subject: [PATCH] mm: reduce Committed_AS if memory protection is changed to PROT_NONE If PROT_WRITE is set, the size of vm area will be added to Committed_AS. However, if memory protection is changed to PROT_NONE, the corresponding physical memory will not be used, but Committed_AS still count the size of the PROT_NONE memory. This patch reduce Committed_AS and free the corresponding memory if memory protection is changed to PROT_NONE. Signed-off-by: liusongtang --- mm/mprotect.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/mprotect.c b/mm/mprotect.c index b69ce7a..c3121e6 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -497,6 +497,12 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_a= rea_struct **pprev, } success: + if ((newflags & (VM_READ | VM_WRITE | VM_EXEC | VM_LOCKED | VM_ACCO= UNT)) =3D=3D VM_ACCOUNT) { + zap_page_range(vma, start, end - start); + newflags &=3D ~VM_ACCOUNT; + vm_unacct_memory((end - start) >> PAGE_SHIFT); + } + /* * vm_flags and vm_page_prot are protected by the mmap_lock * held in write mode. -- 2.12.3