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 5958EC7EE23 for ; Mon, 29 May 2023 00:32:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 931F4900003; Sun, 28 May 2023 20:32:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8BBEF900002; Sun, 28 May 2023 20:32:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 75BDA900003; Sun, 28 May 2023 20:32:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 617E8900002 for ; Sun, 28 May 2023 20:32:17 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 3EAC94036E for ; Mon, 29 May 2023 00:32:16 +0000 (UTC) X-FDA: 80841415872.16.B50AB2E Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf12.hostedemail.com (Postfix) with ESMTP id 2AC8C40009 for ; Mon, 29 May 2023 00:32:13 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=JoONvPpu; dmarc=none; spf=none (imf12.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685320334; a=rsa-sha256; cv=none; b=3wSo+2I37Kc3IXEIfPu54JE1LIK5jKxmClzseczRuqsikyUL8ne9YhLvFIxalSJd5ymqQa az+0t885Db1/JgmIHQDUHdCaFYekma995PgFgmTOv4hzp72rDMbuPjLyv52ch/aAFDO18f NIfL56Jyhbx/9gXGvnWvlwz7VRrJisA= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=JoONvPpu; dmarc=none; spf=none (imf12.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685320334; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=oPq+aPazMa0RW6CoOUWsQ8ZgZfRmLufbWHh8kTVH4tk=; b=0DfeQK6sdfyXikTXQZWKGh8KHNZp5hkKwoFxH+3n7PSHschAGqv64WIxnix0LQLQDBn8I/ fRggh5vSFzb+JCljfOFR7TRynSy6FBcicxnEhd0pij2KnILUtnSN8fS7iIrxiyZ26AEm0g ydWwuhP3BspxczVGByIpbJW1nWof0go= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=oPq+aPazMa0RW6CoOUWsQ8ZgZfRmLufbWHh8kTVH4tk=; b=JoONvPpux0XMSl3QUMbjmEZJTV cIpIIDiWtZgjaLPMnw9Du1/urlvdvLMVvinUl/nef3kE1y89kW+/Fz49ITG4JVg3y2UYz5UEQ+wjH QlFQXH3IkF0J8XY4JZ3pIlvuXBTDUUwNVrTIXAtwlFk1Ikc6bSpYMqTHWD0chY38uZPryFsnT8kZe +jvIXKPaCZSp4xeZuTI54o+tHpV843DY8c7PdI4xsHSG80UVNBMkQnvku7sesRu3c5y/Z8EMHoCYQ huR+XA4sey0UJoRKYupm3HY+NtA52l0wyU1FFRBW43a1sPkYtoFJq1MX5w3JansfdqNx3aBHFzJNQ oTEryqLA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1q3Qnd-004ube-2L; Mon, 29 May 2023 00:31:49 +0000 Date: Mon, 29 May 2023 01:31:49 +0100 From: Matthew Wilcox To: John Hubbard Cc: David Hildenbrand , Khalid Aziz , Steven Sistare , akpm@linux-foundation.org, ying.huang@intel.com, mgorman@techsingularity.net, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Khalid Aziz Subject: Re: [PATCH v4] mm, compaction: Skip all non-migratable pages during scan Message-ID: References: <60367660-f4a3-06dc-4d17-4dbdc733ef74@oracle.com> <846b770c-9f63-90a2-0435-ec82484e3f74@nvidia.com> <9821bd9c-7c30-8f0c-68e4-6b1d312bc032@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9821bd9c-7c30-8f0c-68e4-6b1d312bc032@nvidia.com> X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 2AC8C40009 X-Stat-Signature: dz1nn7gzrxnu67c9fuju376rc11fqx6g X-HE-Tag: 1685320333-835760 X-HE-Meta: U2FsdGVkX1/XBX5xhC9qJWqGAwQv1BjaztPAyXRWFOTTkRd5ydD9tn66AcaPC+OQEEkLs1ZenwNsuw3dNoSSQl4Z3Upb5/nBIAXaS3cIGWC90nw2ScBbr0ItGyRca84n5VJkDxy3Dq98jZcWQ6oMWzg3L6FUE6rBvvAGu3PPR+3LsCLQ7vUUVnk53ehHm74nceYRyTeh8HmscCmmuscIX3MeXnOvhB32MmGnUyLgfCFAlZn/AWfn+r8I37O8bbev9UfBJ8MJn0IdByMItylIMcUz63mxljHzSszkpCsxZzGu8lS9JWA5eCyFi8VE8ui5QmsjwqGiop+17yOGD5qQnFlaxGWjhvmhejYgCdqpvI3klbiiVhxBEnSADI48SKgLGseJLlA9vtdyfOiwYBukLyK91ff6SGQfJSrRdtrhL2BePkNCkRDwyNUZbuh0e0zPrFUJAW9WNoSemibPEzcJn+CfDWT4fT2yl1FgyDoSEtolb7OsbIMROGUVqhEDgeGyoAU4tV8tuiLcbSUCPCDchhd6zb5+ZtqDNjBhCwG1LBRtCtoaY4VLUSw4RE2k+B0+rnQyYaq5RaBFjEd0M9dPA5HSuuZ7bkudtg2v26bd5nR58XrgubPro3dJmBZCSzHJJrUDKvoKbiSKEaT4gB2tcyt2YfCHjkuROqoATbaALQRDiBX+qaRnQiYhvcCssP2K0D8Pg/OTawRgXmiWb9WKc++zsUbkx4nk8UZeLoDtCZ0yL2Ze5BAoeowpY0fdsPQqZj3Kx/IdcWiIq2gq4i33h+sBuBaL7qQcFIouMYnOL8UHyKCRPvE9zJycLuZ8BNkoX+UVn9X+DZMmBG+HDQ2+BNTIOBnXGTb2kVNcSaCGZ5EnHYn8RkeXYwYIHT5qiRk6azVwWApPR63eoLxXjnxB8slSZOp39XP77VlWqaagUwuV1v5TTeueY0wj79444W2oy/Kfrgmoa4tGfie/KyV pOlFqYHj PPQynGsHsoGgGxn8toXRxEARBp+ikj12FVlBuEwUEi0RDXokQwCiCAVc8DusZf65abPnaqBcbHiH4YjynUrHhVENlw7r7LAFwB5drZHyTSJUiV+wXPNVm6e5qcLQGbRD+lTcPhowII7xVOwQ= 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 Sun, May 28, 2023 at 04:49:52PM -0700, John Hubbard wrote: > On 5/26/23 20:18, Matthew Wilcox wrote: > > On Fri, May 26, 2023 at 07:11:05PM -0700, John Hubbard wrote: > > > > So any user with 1024 processes can fragment physical memory? :/ > > > > > > > > Sorry, I'd like to minimize the usage of folio_maybe_dma_pinned(). > > > > > > I was actually thinking that we should minimize any more cases of > > > fragile mapcount and refcount comparison, which then leads to > > > Matthew's approach here! > > > > I was wondering if we shouldn't make folio_maybe_dma_pinned() a little > > more accurate. eg: > > > > if (folio_test_large(folio)) > > return atomic_read(&folio->_pincount) > 0; > > return (unsigned)(folio_ref_count(folio) - folio_mapcount(folio)) >= > > GUP_PIN_COUNTING_BIAS; > > I'm trying to figure out what might be wrong with that, but it seems > OK. We must have talked about this earlier, but I recall vaguely that > there was not a lot of concern about the case of a page being mapped > > 1024 times. Because pinned or not, it's likely to be effectively > locked into memory due to LRU effects. As mentioned here, too. That was my point of view, but David convinced me that a hostile process can effectively lock its own memory into place. > Anyway, sure. > > A detail: > > The unsigned cast, I'm not sure that helps or solves anything, right? > That is, other than bugs, is it possible to get refcount < mapcount? > > And if it's only due to bugs, then the casting, again, isn't likely to > going to mitigate the fallout from whatever mess the bug caused. I wasn't thinking too hard about the cast. If the caller has the folio lock, I don't think it's possible for refcount < mapcount. This caller has a refcount, but doesn't hold the lock, so it is possible for them to read mapcount first, then have both mapcount and refcount decremented and see refcount < mapcount. I don't think it matters too much. We don't hold the folio lock, so it might transition from pinned to unpinned as much as a refcount might be decremented or a mapcount incremented. What's important is that a hostile process can't prevent memory from being moved indefinitely. David, have I missed something else?