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 7B773C05027 for ; Tue, 14 Feb 2023 13:00:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 044016B0073; Tue, 14 Feb 2023 08:00:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F36476B0074; Tue, 14 Feb 2023 08:00:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DFDA66B0075; Tue, 14 Feb 2023 08:00:06 -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 D0DD56B0073 for ; Tue, 14 Feb 2023 08:00:06 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 91DABC072C for ; Tue, 14 Feb 2023 13:00:06 +0000 (UTC) X-FDA: 80465905212.22.4E55168 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf04.hostedemail.com (Postfix) with ESMTP id 0F8394001C for ; Tue, 14 Feb 2023 13:00:02 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=AZmiSRVQ; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=YpBWRY9Z; spf=pass (imf04.hostedemail.com: domain of jack@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=jack@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676379603; a=rsa-sha256; cv=none; b=aGEm/B5BKAVIS1apFhrTmRMKOLG0efxarsJG8s7dqWzDTHmvMbhYFMHU39XQzP5dUQEkAE CZ03JfO0cv9IkFnVDIlhhJkv+qJ8pGnskqrsYxFvs4lUX4Y70xPGcI6QbLG6QK2RaawM47 lRVv0KbSxwUnBSzkehopCtfb8SaoqGU= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=AZmiSRVQ; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=YpBWRY9Z; spf=pass (imf04.hostedemail.com: domain of jack@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=jack@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676379603; 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=gz+b6Xt8mJ3ak48xss4fFkdb+QBvNTstPHhtjW5QbEw=; b=a9SGzMSbzlnwU5SR6LmAr0lf+LhRFwlIkOLns7+wUYRNXqxNt2c+GXBTA6jTjlgEL/p/GD mhzF+fOVEeyoJHT8ZVW5Q+/if4fXDejAeH45O+xmJtr0tvQa6vEuHc2PkJ3wXVlmFNycNv XrbmjlRS9Df+AvDzM/7MWe4bo0Wp7KQ= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 65BD81F37F; Tue, 14 Feb 2023 13:00:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1676379601; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gz+b6Xt8mJ3ak48xss4fFkdb+QBvNTstPHhtjW5QbEw=; b=AZmiSRVQDfTJgkiUJSdU0mEi40Pv39uPOe93WKQbinXAnR11U4sFoMSpVveB2j5ui8LioA TJKFRMhop3IfGy7gjALJ7MOKmk5A7MK5vJQwZGISDT2b41WFfo1BrTFI6nl6BzobuQH1iq ps1fL1TLqalfcPs30O5TTVnGXX/SLZE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1676379601; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gz+b6Xt8mJ3ak48xss4fFkdb+QBvNTstPHhtjW5QbEw=; b=YpBWRY9ZWWcMyQOKgAtNfVetBte+Wt4r+HM2bZe9L88SY5sib75nPRyO3s2u8o89tIZ94H tnarVEyxu2ImUODg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 570B6138E3; Tue, 14 Feb 2023 13:00:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id HVgcFdGF62NBKQAAMHmgww (envelope-from ); Tue, 14 Feb 2023 13:00:01 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 14F89A06D8; Tue, 14 Feb 2023 14:00:00 +0100 (CET) Date: Tue, 14 Feb 2023 14:00:00 +0100 From: Jan Kara To: David Hildenbrand Cc: Jan Kara , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org, John Hubbard , David Howells Subject: Re: [PATCH 1/5] mm: Do not reclaim private data from pinned page Message-ID: <20230214130000.s5kynjhjiyrpvzxx@quack3> References: <20230209121046.25360-1-jack@suse.cz> <20230209123206.3548-1-jack@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Queue-Id: 0F8394001C X-Rspamd-Server: rspam01 X-Stat-Signature: xxydq3ha3zjpjcms7maxfzjj7ar68rnb X-HE-Tag: 1676379602-815315 X-HE-Meta: U2FsdGVkX19e5BfPCqq8JoqqDFLKQnb0CG3TFrqIFn/Uyftl+3SAmcrIwDw1LCAxrhX4k0fkeHSgNEXgoSp1EtO78Snk3mmELlKRI+ICM7HATQHi42uGNb4l8Dld3iCfh8WvCjrgM/mATmaKLd0RcLvXJUEDczpB/A9zUG0TLWRQSbGQD23KRYcjR4XaFyjzPZZV1DkbCP3/U655eVYUpIb8ud4y2XyoZ8ksYBX8hAli1em0GIjSGeC5B/gvNz4jyev49BWmV85ankP1MMUuRhLl+sJMqDUF6kLcb9rebehjwu/JrSHDajQmDpIUvd31cQt07lmf07VcyQlXR0mgRDRe6SkWKuZYd6BnJoCbUB6q2ww8y39HeOefSWQBF9Z0VibmLcWI21nml97y38R8yYpYQ/i86mwmjQnZ/m+EikmMlCnV10ytWYMSQbfOyRWx9IDxmyQMb7PunQGRrKlfSbirnYWfGTvGAqzM44FJonXRRITEStkdQFKfcbs91OE2td5mWDcEqU/6ApYa9+tAHUwbHFzMS7VbWiNXBION1i5mJunfAzkBgIjFZdp+dRJr6OjjwDJiUDezjsuuD9gyHHgB4tpLncNyGiQFXUfoBoDghi43DXuxSQ42ANWjyju8BrQ8HaUAOoksMj32JIh1sVhylw5iX6DmE8DngL/XT4DEZnd1mO5b6gB8RWAnnt4+ofkECmQg3G3EFHndGe9vxMTVbM4VVJwryV+lIf6m0uC0fAa2ubeGi0Icopfugy141MNNiGVeGzcJz+TQTgUiqUao4gSGKuh+O33nKjVXyHX7aINYcoMOGfkpGk5puXNvJ1CLay6UoRw8w7KwS070Hzitfilnp26TMOpCK5aOuh68xKuYnKK3GNj7dsEijpPis6PU3Z9Q6kdn3EmVfz9iFsUxywIDk8YYGC+IVSrVqG6bvRy7uhN0kSeahfVwSsVs0AkO5pG0m5o4Dl0sb6x G+MUVgrM DoSBhQxucOPEHuosxn/e7kWaDbrFM6oULxGJoU+HVgFkwmJE3xyGO+sHfbEE+O5AMvUvfydENK1liy0te0E8qsl47vXyMIIoCoq9ZixH7cLuz+dV/SQrtYZhzFqsoa5TKH6DcsrirTaWv1lGt9pzyb+7ESpE3SQ+AjcRVygSeRanVRg8/Fz6BiAvMykVA0NLk2kgXmEhbYac6BMMwgq9CR/eYq5rjqTLOcf0/xxbAYiY+j28fH6CnuToFNUJI1hacafAKqng3TEarbfATlCem79BOI24wadoqmjqDeeJjnWHPLxw8cLwfxYERUjIgc2XtxFMapFFnxkoZ/DA= 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 Mon 13-02-23 10:01:35, David Hildenbrand wrote: > On 09.02.23 13:31, Jan Kara wrote: > > If the page is pinned, there's no point in trying to reclaim it. > > Furthermore if the page is from the page cache we don't want to reclaim > > fs-private data from the page because the pinning process may be writing > > to the page at any time and reclaiming fs private info on a dirty page > > can upset the filesystem (see link below). > > > > Link: https://lore.kernel.org/linux-mm/20180103100430.GE4911@quack2.suse.cz > > Signed-off-by: Jan Kara > > --- > > mm/vmscan.c | 10 ++++++++++ > > 1 file changed, 10 insertions(+) > > > > diff --git a/mm/vmscan.c b/mm/vmscan.c > > index bf3eedf0209c..ab3911a8b116 100644 > > --- a/mm/vmscan.c > > +++ b/mm/vmscan.c > > @@ -1901,6 +1901,16 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, > > } > > } > > + /* > > + * Folio is unmapped now so it cannot be newly pinned anymore. > > + * No point in trying to reclaim folio if it is pinned. > > + * Furthermore we don't want to reclaim underlying fs metadata > > + * if the folio is pinned and thus potentially modified by the > > + * pinning process is that may upset the filesystem. > > + */ > > + if (folio_maybe_dma_pinned(folio)) > > + goto activate_locked; > > + > > mapping = folio_mapping(folio); > > if (folio_test_dirty(folio)) { > > /* > > At this point, we made sure that the folio is completely unmapped. However, > we specify "TTU_BATCH_FLUSH", so rmap code might defer a TLB flush and > consequently defer an IPI sync. > > I remember that this check here is fine regarding GUP-fast: even if > concurrent GUP-fast pins the page after our check here, it should observe > the changed PTE and unpin it again. > > Checking after unmapping makes sense: we reduce the likelyhood of false > positives when a file-backed page is mapped many times (>= 1024). OTOH, we > might unmap pinned pages because we cannot really detect it early. > > For anon pages, we have an early (racy) check, which turned out "ok" in > practice, because we don't frequently have that many anon pages that are > shared by that many processes. I assume we don't want something similar for > pagecache pages, because having a single page mapped by many processes can > happen easily and would prevent reclaim. Yeah, I think pagecache pages shared by many processes are more likely. Furthermore I think pinned pagecache pages are rather rare so unmapping them before checking seems fine to me. Obviously we can reconsider if reality would prove me wrong ;). > I once had a patch lying around that documented for the existing > folio_maybe_dma_pinned() for anon pages exactly that (racy+false positives > with many mappings). > > Long story short, I assume this change is fine. Thanks for the throughout verification :) Honza -- Jan Kara SUSE Labs, CR