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 62499C433F5 for ; Tue, 15 Feb 2022 23:21:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A32F36B0078; Tue, 15 Feb 2022 18:21:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E41A6B007B; Tue, 15 Feb 2022 18:21:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8AB2C6B007D; Tue, 15 Feb 2022 18:21:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0178.hostedemail.com [216.40.44.178]) by kanga.kvack.org (Postfix) with ESMTP id 7BE816B0078 for ; Tue, 15 Feb 2022 18:21:23 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 39B17181AC9C6 for ; Tue, 15 Feb 2022 23:21:23 +0000 (UTC) X-FDA: 79146587646.25.BDE1983 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf26.hostedemail.com (Postfix) with ESMTP id A2ED014000A for ; Tue, 15 Feb 2022 23:21:22 +0000 (UTC) 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=zctHsFYI39kKpZ65pfZtOmz6zeTwXvzzS07zdKOR0As=; b=XRl94yyNGudaG33KxxsztMkolj KUoRGCrUdxQi9s/OmlDMn77OJz7JmGQIGinlkXhDHnUD6UKq7Rk0K5skenCKjwCsMav7Fgn5rhk8N 2OhjaQMZlSs0HWJPKLJum0MyuveiRSFzOF4UXGW/+3z5eXSC9tWB2atNS8jehM0avk3WWv9IZ/WRd q4S7IsIZK4wk/8mS0gPEtN0n+dbxHfjwFGka+ylGVxTtNP34c7Rl6Kh3IQgu+0NABC+sdGbrC/+JW xT3EK69m8tSaTBAh0x/MkLmj0sGVjROHclQ0STdUNXp+/z3bEDowXnkXntdbQNsNxbkPvcoYnhVzN GAjPQ9uA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nK78A-00EFfc-G7; Tue, 15 Feb 2022 23:21:10 +0000 Date: Tue, 15 Feb 2022 23:21:10 +0000 From: Matthew Wilcox To: Hugh Dickins Cc: Andrew Morton , Michal Hocko , Vlastimil Babka , "Kirill A. Shutemov" , David Hildenbrand , Alistair Popple , Johannes Weiner , Rik van Riel , Suren Baghdasaryan , Yu Zhao , Greg Thelen , Shakeel Butt , Yang Li , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v2 04/13] mm/munlock: rmap call mlock_vma_page() munlock_vma_page() Message-ID: References: <55a49083-37f9-3766-1de9-9feea7428ac@google.com> <501673c-a5a-6c5f-ab65-38545dfb723d@google.com> <3c6097a7-df8c-f39c-36e8-8b5410e76c8a@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3c6097a7-df8c-f39c-36e8-8b5410e76c8a@google.com> X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: A2ED014000A X-Stat-Signature: fkckqbo57mf5ym53peacjnp9k7s1343h Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=XRl94yyN; spf=none (imf26.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-HE-Tag: 1644967282-497828 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, Feb 15, 2022 at 01:38:20PM -0800, Hugh Dickins wrote: > On Tue, 15 Feb 2022, Matthew Wilcox wrote: > > On Mon, Feb 14, 2022 at 06:26:39PM -0800, Hugh Dickins wrote: > > > Add vma argument to mlock_vma_page() and munlock_vma_page(), make them > > > inline functions which check (vma->vm_flags & VM_LOCKED) before calling > > > mlock_page() and munlock_page() in mm/mlock.c. > > > > > > Add bool compound to mlock_vma_page() and munlock_vma_page(): this is > > > because we have understandable difficulty in accounting pte maps of THPs, > > > and if passed a PageHead page, mlock_page() and munlock_page() cannot > > > tell whether it's a pmd map to be counted or a pte map to be ignored. > > > > > [...] > > > > > > Mlock accounting on THPs has been hard to define, differed between anon > > > and file, involved PageDoubleMap in some places and not others, required > > > clear_page_mlock() at some points. Keep it simple now: just count the > > > pmds and ignore the ptes, there is no reason for ptes to undo pmd mlocks. > > > > How would you suggest we handle the accounting for folios which are > > intermediate in size between PMDs and PTEs? eg, an order-4 page? > > Would it make sense to increment mlock_count by HUGE_PMD_NR for > > each PMD mapping and by 1 for each PTE mapping? > > I think you're asking the wrong question here, but perhaps you've > already decided there's only one satisfactory answer to the right question. Or I've gravely misunderstood the situation. Or explained my concern badly. The possibilities are endless! My concern is that a filesystem may create an order-4 folio, an application mmaps the folio and then calls mlock() (either over a portion or the entirety of the folio). As far as I can tell, we then do not move the folio onto the unevictable list because it is of order >0 and is only mapped by PTEs. This presumably then has performance problems (or we wouldn't need to have an unevictable list in the first place). > The question I thought you should be asking is about how to count them > in Mlocked. That's tough; but I take it for granted that you would not > want per-subpage flags and counts involved (or not unless forced to do > so by some regression that turns out to matter). And I think the only > satisfactory answer is to count the whole compound_nr() as Mlocked > when any part of it (a single pte, a series of ptes, a pmd) is mlocked; > and (try to) move folio to Unevictable whenever any part of it is mlocked. I think that makes sense. As with so many other things, we choose to manage memory in >PAGE_SIZE chunks. If you mlock() a part of a folio, we lock the whole folio in memory, and it all counts as being locked.