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 0545CC77B73 for ; Tue, 2 May 2023 15:53:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 80B476B0074; Tue, 2 May 2023 11:53:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7E22F6B0075; Tue, 2 May 2023 11:53:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D14E6B0078; Tue, 2 May 2023 11:53:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by kanga.kvack.org (Postfix) with ESMTP id 4FBE76B0074 for ; Tue, 2 May 2023 11:53:12 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683042792; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2u65LuYPb7QHnSkAdm0mclaHTsGhn661RhJYVq6qWaA=; b=TBofuVd9s7MR0muCEh4nOHeSAzY1WukKjh4Hr7Jzgrdl4Ner+tyYU2yCgwdpKwgZb7nNsT 24aFNH64gS7cK7lLeXkXhFWj5A+xjLJ1nRNgZprsm6rVc8QrP+Bmf1cKbm6m1eF9CJzzNJ 6wVA4NW9koSMOQHuCvLu0WWAOQ1uMHA= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-626-JhfR6_0INKCcDWF8oBopqA-1; Tue, 02 May 2023 11:53:11 -0400 X-MC-Unique: JhfR6_0INKCcDWF8oBopqA-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-2fbb99cb2easo1092087f8f.1 for ; Tue, 02 May 2023 08:53:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683042790; x=1685634790; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2u65LuYPb7QHnSkAdm0mclaHTsGhn661RhJYVq6qWaA=; b=M+96FyrCJlbSMV/MSteZNifxcSLrt4l7jivAOJ/mdwH19NfkwuKcVUZDkuAdUTdHrE f3x8Vf2Q1OusMxCYsglG35D4mcW2oy2S5jPvM+G5l8oqaTgA8K4YiZPOz0XvLnyiqXKF sUgFebYsCkQ0bCYLT6GLHCaALXwj53vS3IHVlLwNiBSarK3/dxpOyy8vEjtN/oxIxTqQ ygZ9vKYsowC0xqO/g8PVqFdN8z9+EDJHimcqRyvdZ0hQyJsQrED/Z0OeOheQnV2y3IfD /UNmO7ffa/5shaKwu+qgWeJEFCSDpB48it5q7zVXkcm3jpCEf8ItdULkXROxgVX2bpJ/ 3C1A== X-Gm-Message-State: AC+VfDx6g4Z+3HlXDXfEvkt2idKwpRx/TbPMn2vLq3xcfbw/uvqQY8D6 UOU3scpvNECyy9zw+IPAhAlZzI2e2AU7IJhGRofKwo0YuPkqcKV3bP99LEe9hHqpAjIX7P0CeLK XK5Wt5mhVF/g= X-Received: by 2002:a05:6000:108f:b0:306:379e:d161 with SMTP id y15-20020a056000108f00b00306379ed161mr1871463wrw.5.1683042789937; Tue, 02 May 2023 08:53:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5gFmAybutFB9eQ9Tbxlz4qEY/FJ8V5M2LIv21wHOxibkY6Uc3HukKMzqNz7cKtw+U3w+TVgw== X-Received: by 2002:a05:6000:108f:b0:306:379e:d161 with SMTP id y15-20020a056000108f00b00306379ed161mr1871456wrw.5.1683042789546; Tue, 02 May 2023 08:53:09 -0700 (PDT) Received: from ?IPV6:2003:cb:c700:2400:6b79:2aa:9602:7016? (p200300cbc70024006b7902aa96027016.dip0.t-ipconnect.de. [2003:cb:c700:2400:6b79:2aa:9602:7016]) by smtp.gmail.com with ESMTPSA id t13-20020a7bc3cd000000b003f173c566b5sm35982711wmj.5.2023.05.02.08.53.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 02 May 2023 08:53:09 -0700 (PDT) Message-ID: <42b80e03-fc72-dfa0-f18d-d6006ea48e76@redhat.com> Date: Tue, 2 May 2023 17:53:08 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH] mm: Do not reclaim private data from pinned page To: Peter Xu Cc: Jan Kara , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Lorenzo Stoakes , Andrew Morton , Christoph Hellwig References: <20230428124140.30166-1-jack@suse.cz> <8dba1912-4120-cb3d-6e10-5fc18459e2ac@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 02.05.23 17:48, Peter Xu wrote: > On Tue, May 02, 2023 at 05:33:22PM +0200, David Hildenbrand wrote: >> On 02.05.23 17:26, Peter Xu wrote: >>> On Fri, Apr 28, 2023 at 02:41:40PM +0200, 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(+) >>>> >>>> This was the non-controversial part of my series [1] dealing with pinned pages >>>> in filesystems. It is already a win as it avoids crashes in the filesystem and >>>> we can drop workarounds for this in ext4. Can we merge it please? >>>> >>>> [1] https://lore.kernel.org/all/20230209121046.25360-1-jack@suse.cz/ >>>> >>>> diff --git a/mm/vmscan.c b/mm/vmscan.c >>>> index bf3eedf0209c..401a379ea99a 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 as that may upset the filesystem. >>>> + */ >>>> + if (folio_maybe_dma_pinned(folio)) >>>> + goto activate_locked; >>>> + >>>> mapping = folio_mapping(folio); >>>> if (folio_test_dirty(folio)) { >>>> /* >>>> -- >>>> 2.35.3 >>>> >>>> >>> >>> IIUC we have similar handling for anon (feb889fb40fafc). Should we merge >>> the two sites and just move the check earlier? Thanks, >>> >> >> feb889fb40fafc introduced a best-effort check that is racy, as the page is >> still mapped (can still get pinned). Further, we get false positives most >> only if a page is shared very often (1024 times), which happens rarely with >> anon pages. Now that we handle COW+pinning correctly using >> PageAnonExclusive, that check only optimizes for the "already pinned" case. >> But it's not required for correctness anymore (so it can be racy). >> >> Here, however, we want more precision, and not false positives simply >> because a page is mapped many times (which can happen easily) or can still >> get pinned while mapped. > > Ah makes sense, thanks. > > Acked-by: Peter Xu > > This seems not obvious, though, if we simply read the two commits. It'll be > great if we mention it somewhere in either comment or commit message on the > relationship of the two checks. I once had a patch lying around to document the existing check: https://github.com/davidhildenbrand/linux/commit/abb01d42a99b56e2c5e707ba80ddc8b05ad7d618 -- Thanks, David / dhildenb