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 3593AC433EF for ; Mon, 30 May 2022 23:02:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5FFDD6B0071; Mon, 30 May 2022 19:02:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5ADB46B0073; Mon, 30 May 2022 19:02:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 49DC66B0074; Mon, 30 May 2022 19:02:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 37B266B0071 for ; Mon, 30 May 2022 19:02:28 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id F0565603EE for ; Mon, 30 May 2022 23:02:27 +0000 (UTC) X-FDA: 79523935134.19.92B374F Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf17.hostedemail.com (Postfix) with ESMTP id 0E92B40050 for ; Mon, 30 May 2022 23:01:52 +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 ams.source.kernel.org (Postfix) with ESMTPS id 0FAC9B80E6F; Mon, 30 May 2022 23:02:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83B34C385B8; Mon, 30 May 2022 23:02:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1653951744; bh=xT7SaWtqN0EyC8Ek+r//2xD54BrdZFRp3T/MnlYFo6c=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=JsZKHYbTdUBqgiZITdHz43jCUoLaE3I/SSm4wI2HJRLGm1NJ5/7VTODYUHsdpw9JH zr04i6bh+G97yzowRs1GvfypPXgTbSyL8xHtoxSh912xauWbamHe/28g/GAFgRyemA rnbkL9VL0omoNo9JFAddoxEomXdl6+iR724ATj0c= Date: Mon, 30 May 2022 16:02:23 -0700 From: Andrew Morton To: Miaohe Lin Cc: , Subject: Re: [PATCH 1/3] mm/swapfile: make security_vm_enough_memory_mm() work as expected Message-Id: <20220530160223.63ae3bdef7420f252d7366ed@linux-foundation.org> In-Reply-To: <20220527092626.31883-2-linmiaohe@huawei.com> References: <20220527092626.31883-1-linmiaohe@huawei.com> <20220527092626.31883-2-linmiaohe@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-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 0E92B40050 X-Stat-Signature: 73iunt79ied15r3a71eijm4mnkx5bma7 Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=JsZKHYbT; dmarc=none; spf=pass (imf17.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-HE-Tag: 1653951712-857881 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 Fri, 27 May 2022 17:26:24 +0800 Miaohe Lin wrote: > security_vm_enough_memory_mm() checks whether a process has enough memory > to allocate a new virtual mapping. And total_swap_pages is considered as > available memory while swapoff tries to make sure there's enough memory > that can hold the swapped out memory. But total_swap_pages contains the > swap space that is being swapoff. So security_vm_enough_memory_mm() will > success even if there's no memory to hold the swapped out memory because > total_swap_pages always greater than or equal to p->pages. > > In order to fix it, p->pages should be retracted from total_swap_pages > first and then check whether there's enough memory for inuse swap pages. User-visible impact? If I'm understanding correctly, there's a risk that this fix will cause existing setups to newly fail when attempting swapoff()?