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 67362C5478C for ; Tue, 27 Feb 2024 15:27:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D322D6B012B; Tue, 27 Feb 2024 10:27:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CBB4528001D; Tue, 27 Feb 2024 10:27:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5CAE6B012D; Tue, 27 Feb 2024 10:27:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 91DBA6B012B for ; Tue, 27 Feb 2024 10:27:24 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3D040140C20 for ; Tue, 27 Feb 2024 15:27:24 +0000 (UTC) X-FDA: 81837962808.03.7F3EE0F Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf26.hostedemail.com (Postfix) with ESMTP id 827A2140008 for ; Tue, 27 Feb 2024 15:27:20 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=bnx2+Zze; dmarc=none; 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709047642; a=rsa-sha256; cv=none; b=iJJA99fP301ajesG60kJ/p02eBXVuPnYJ/mFSPe/GU/PMzAyCPXIk68DrqVE0TH9pCdD9m 4hDzEokdV2kJ28EeJAIE3+tTdW6WIVQUcdLXXNyY4gYvOfHFJKNSNVRJHw/gaMZMNoYI65 1KVoHALBdjeUrZxoPR0BWb61e4V9sXA= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=bnx2+Zze; dmarc=none; 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709047642; 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=GaUbM6bqN08OMdLhbJnuxGOqey6Y7OVLpt4cMrcB0fU=; b=7hvRV07Itw2oIpqZVD7NR2DWmRIExWksZbUnVWt9E79xxUTXW3qh6fwPJvjutRwvzeG8Mh L5+RgtF6gok+a8446VOiNigKixX1zYT67DruUL6rN9rL/kpF0MmmjpYW1WCQNXGIvmtudT vEgVHjMgp9N9yCVBAjyDEQmJ7eP44G8= 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=GaUbM6bqN08OMdLhbJnuxGOqey6Y7OVLpt4cMrcB0fU=; b=bnx2+ZzeZUZXwd+CL9uMuyRenA 0YW9CXDzxwKtZAmYivJzi2dIfK3H6HWxhbtgXa22P7Ih3EXrWm6fqMy5xV5TwOn13L779uLEuokr7 nFo1NLBPFbq7UQ+wPNvKrRGUEfE8y/ixEt9iauL96ctekuStaO8CyJLVWZa4/2xBjFVwm+oMuw01L 7MfawEytTWr51W1fF/enq/CMGRPR0ZwohP+VBnOfHH0T3iBMt82CUl+DsrjGve8CiefoFfQe41Btf xbFMQDdIg/O8vK9AKQZlD4CSJDqQAaH42yuo2pr2598zWf4rtiVrU3nzBw/2MN920DOx6mBtnSGr+ QwakEwBg==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rezMS-00000002iZA-2Ys0; Tue, 27 Feb 2024 15:27:16 +0000 Date: Tue, 27 Feb 2024 15:27:16 +0000 From: Matthew Wilcox To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton Subject: Re: [PATCH v2 1/2] mm/memfd: refactor memfd_tag_pins() and memfd_wait_for_pins() Message-ID: References: <20240226141324.278526-1-david@redhat.com> <20240226141324.278526-2-david@redhat.com> <02e4e497-d70f-4f4b-8b2c-55fe3a0b726e@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <02e4e497-d70f-4f4b-8b2c-55fe3a0b726e@redhat.com> X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 827A2140008 X-Stat-Signature: ijkwa93yeyijefjji8hp37udkqdfb6zn X-HE-Tag: 1709047640-869790 X-HE-Meta: U2FsdGVkX189Uxkw1CX5drRclRQ8Os3NGlhrMlOqyfjwAWrL1uY8XbWn6UIYh9IyCe8xjlOE/8Ulx6y0p2EfWZkn+0aHZU/QPqWVLquUJWHGhejG84G75nXAlC72wUu52nqwrBBcUFzxt+RzjmRtO9EyB5JqfZDDl4f7KmX0CHa/lhOPuYGwlNls9N5L7RMUXbzetp9ukQ9pQ3XDD108zIpElFgYT3Lkii/mO4ST/ZMxD+iF0D7rJ8fXlg22X392Q3zskFkD5lfEG39bBxAlA+KBklxyN5SHtx3BzP2FUI7R+NrpoT0BUNCjmSwzpBHM28XPaylGSEiUJnN+QL4gMmSgJlGgwOZCk6E7llDeajpWbKf6UEwE3BqK8js3DFpsuvkjYrTQY2lLy/doT6oeanpVs/O+O9jq/7MJcPoKWXgM6UXJD7uIA6VyQDtoHJbgBgcacw8DpNBUrKNsI6EyzBLEEZwEa0ySyac7UT/nx5jN6lrLdJ0V/s637wrHBz5SBGs/6JMy38TdCAf1Z3YEzfLQP6tisKrOkjxwWhKd7hEsGNBre9883PJxWRmWpgNhOIDHS/52EQcsozYCL0pTVTP+SFldAwEZhCyfIfj2D6TQZhJTOwX5CzK7m71EYe86/uZH73vyr7pkq3lX/ELhDzdwTC0K+KhRBJbBDBQPEuZAaE57jD3WdBwHZDy6qiqilBX4j0IH7Quon0MbVODEKX+bwooI+60Fb199yfBbWK4dPq9GDhn6GmZvDidFie0Y9MhhYDLhS/VYFHkB1MYfzOGoCvIo2S3YQHco/eE083LLNM6iFmDHNsdqPJLt3l1hq5h+SAsu6UprGJHDz/Tg+jZZ5g8N6m9gp3flJQcw+/oABMcjG92D1dDVKYVrEKzA 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: List-Subscribe: List-Unsubscribe: On Mon, Feb 26, 2024 at 05:56:09PM +0100, David Hildenbrand wrote: > > > @@ -95,20 +90,15 @@ static int memfd_wait_for_pins(struct address_space *mapping) > > > xas_set(&xas, 0); > > > xas_lock_irq(&xas); > > > - xas_for_each_marked(&xas, page, ULONG_MAX, MEMFD_TAG_PINNED) { > > > + xas_for_each_marked(&xas, folio, ULONG_MAX, MEMFD_TAG_PINNED) { > > > bool clear = true; > > > - cache_count = 1; > > > - if (!xa_is_value(page) && > > > - PageTransHuge(page) && !PageHuge(page)) > > > - cache_count = HPAGE_PMD_NR; > > > - > > > - if (!xa_is_value(page) && cache_count != > > > - page_count(page) - total_mapcount(page)) { > > > + if (!xa_is_value(folio) && > > > + memfd_folio_has_extra_refs(folio)) { > > > > ... so we don't need to test it here because we'll never see any value > > entries. No? > > I was not able to convince myself that swapout code would clear the mark > when replacing the entry. > > shmem_writepage()->shmem_delete_from_page_cache()->shmem_replace_entry() > > will perform a xas_store() with swp_to_radix_entry(swap) under > xa_lock_irq(). > > Reading the doc, and staring at the code for a bit too long, I think > xas_store() would only clear tags when deleting an entry (passing NULL). > > But maybe xas_store() will always clear tags? No, xas_store() will leave the tag alone ... this is the right thing to do for the pagecache because we always clear the tags before removing a folio from the cache. > In memfd code, I think we could see swapout between memfd_tag_pins() and the > check for tags, where we drop the xa_lock. Unless some other lock (inode > lock?) protects us. ... and if it does happen, we see the value entry tagged and clear the tag on it. OK. Reviewed-by: Matthew Wilcox (Oracle)