From patchwork Tue Apr 26 11:27:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liusongtang X-Patchwork-Id: 12826950 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 EC764C433F5 for ; Tue, 26 Apr 2022 11:27:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4072B6B0073; Tue, 26 Apr 2022 07:27:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3B6536B0074; Tue, 26 Apr 2022 07:27:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 27E576B0075; Tue, 26 Apr 2022 07:27:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 143046B0073 for ; Tue, 26 Apr 2022 07:27:19 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id DF79C210AC for ; Tue, 26 Apr 2022 11:27:18 +0000 (UTC) X-FDA: 79398804156.18.0DB9A98 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf07.hostedemail.com (Postfix) with ESMTP id 11F3340045 for ; Tue, 26 Apr 2022 11:27:15 +0000 (UTC) Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Knfcd2GYgzCs0Z; Tue, 26 Apr 2022 19:22:41 +0800 (CST) Received: from linux-suspe12sp5.huawei.com (10.67.133.42) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 26 Apr 2022 19:27:12 +0800 From: liusongtang To: CC: , , , , , Subject: [PATCH] mm/mprotect: reduce Committed_AS if memory protection is changed to PROT_NONE Date: Tue, 26 Apr 2022 19:27:05 +0800 Message-ID: <20220426112705.3323-1-liusongtang@huawei.com> X-Mailer: git-send-email 2.12.3 MIME-Version: 1.0 X-Originating-IP: [10.67.133.42] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500022.china.huawei.com (7.185.36.162) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 11F3340045 X-Stat-Signature: cwfbt7tiqi43871jf6thupy9fqsgjer7 X-Rspam-User: Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf07.hostedemail.com: domain of liusongtang@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=liusongtang@huawei.com X-Rspamd-Server: rspam09 X-HE-Tag: 1650972435-785077 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: 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 Reported-by: kernel test robot --- 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_area_struct **pprev, } success: + if ((newflags & (VM_READ | VM_WRITE | VM_EXEC | VM_LOCKED | VM_ACCOUNT)) == VM_ACCOUNT) { + zap_page_range(vma, start, end - start); + newflags &= ~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.