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 C41E3C433F5 for ; Tue, 26 Apr 2022 20:34:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5BCAA6B0074; Tue, 26 Apr 2022 16:34:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5453A6B0075; Tue, 26 Apr 2022 16:34:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E7186B0078; Tue, 26 Apr 2022 16:34:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id 3018C6B0074 for ; Tue, 26 Apr 2022 16:34:04 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 081D46129A for ; Tue, 26 Apr 2022 20:34:04 +0000 (UTC) X-FDA: 79400182008.18.8DEB62B Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf30.hostedemail.com (Postfix) with ESMTP id C23B68004B for ; Tue, 26 Apr 2022 20:33:56 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B9C336119C; Tue, 26 Apr 2022 20:34:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8AB7C385A0; Tue, 26 Apr 2022 20:34:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1651005242; bh=1nLv2uonWidEFj1pcSTMshyTONddZm1b5bjnp+01fFQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Gf0gHdt2okkMpp8c3Tx2/ENbPLTud5mAngEc563OHINdGlX00/CeEy71BKhr5D90G RVheA6Z6zLvlXxnCmGuoIWUPr0FbXthZk67HezG33K0HZY7ZRy/J3qJoUWlSdqGUs/ 7trds2YehtZeWFn+DTjtjNLZSzjGuplwtaWt1Xh0= Date: Tue, 26 Apr 2022 13:34:01 -0700 From: Andrew Morton To: liusongtang Cc: , , , , Subject: Re: [PATCH] mm/mprotect: reduce Committed_AS if memory protection is changed to PROT_NONE Message-Id: <20220426133401.9404190c5a5c6ff58b694c59@linux-foundation.org> In-Reply-To: <20220426112705.3323-1-liusongtang@huawei.com> References: <20220426112705.3323-1-liusongtang@huawei.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Stat-Signature: cp17ne19uj6w6k1b8k4pherwd8mn3bet Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=Gf0gHdt2; spf=pass (imf30.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: C23B68004B X-HE-Tag: 1651005236-597930 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: On Tue, 26 Apr 2022 19:27:05 +0800 liusongtang wrote: > 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. > > ... > > --- 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. Surprised. If userspace does mprotect(addr, len. PROT_NONE) then mprotect(addr, len. PROT_READ), what is now at *addr? Zeroes?