Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4360730ioa; Wed, 27 Apr 2022 01:56:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzts90Ull6BpKLpFq5FT11Fuh9bBv8uaEgpt/p6/Hec2L+Q4f8tOPGQLmZaeweif+qva5sn X-Received: by 2002:a05:6a00:b4d:b0:50d:7e9f:1ff0 with SMTP id p13-20020a056a000b4d00b0050d7e9f1ff0mr2901998pfo.80.1651049785750; Wed, 27 Apr 2022 01:56:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651049785; cv=none; d=google.com; s=arc-20160816; b=rlvW+wNVsO33YZe4ayhUbs+rgs8lLVNoShL8Y7ry2D1fyDFEkw5dfk0peHo6mmWHeo uu2cX0fG3y1jA0b3o5mxbSENSdOdFiL7tBqXfd3eaYwcJYXB9cjgSLf8qdR0GkWjsdRt DnQ3wCMQMFmaBmdZE1CqmyLPuyonzfB9Dg4jhCJs5lBseQ5ZQvKT6BgTzukoe1Y0bPzQ 5dQE7r3XzVqy/GruPbr44Fq8LLuvGOBxVSRC6F7sjiWW3TtPdWFGAamgoN6+C2hsAYKh o0h6OzVEhQexr1ojJBBq5W1FD0RIp8ayzp286Xx9M9O2+JIy3JbX+uRT1eJ6HSpkBDIZ wr5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=IfUkEJsbzGHDSlWA4OKvVJaiMRr2eQNxb0JWcTHI/0I=; b=ltSrkPIInLIYUwDuP1nRi7apHLyiIXiRfeJivh//1FmGN/e9RbfMn2fyXYzM1tAI9P /JUwGQiXOf091iOMID39smcdkX/Zn5bDrYUCVUEIGKHSYhlGZizbgAzLgjOBgq+FceFL U5nwJQMscMjr+bl2XM1czbHKAk6fJP/U2y4yadMxvTm9Qo9TKXbD48slbMG+xEf/Zzwr 7n5UMLQ8wafqpoCYyH5NkfQnIJrvOgyQ4jEP1/mwLqyg7kxktOunAvoOMdFwJmWlj5Of uZxDp/wKk3CMVwm+isWuxOirIZdm0GQRdrPIe0qlaQq7Q/rjEYF0eFkHkQ+fgK8BMHVV WUwQ== 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:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id y127-20020a626485000000b0050a9b3e1c5fsi721971pfb.333.2022.04.27.01.56.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 01:56:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DF2F91ACD30; Wed, 27 Apr 2022 01:53:01 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245083AbiDZLaX (ORCPT + 99 others); Tue, 26 Apr 2022 07:30:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238693AbiDZLaW (ORCPT ); Tue, 26 Apr 2022 07:30:22 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 413A242A2D for ; Tue, 26 Apr 2022 04:27:15 -0700 (PDT) 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 Content-Type: text/plain 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-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE autolearn=no 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 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_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. -- 2.12.3