From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B9AD258ED9 for ; Mon, 1 Sep 2025 07:52:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756713146; cv=none; b=fcoFBc9aNIQOUeZk3o6jTdD+DT2suaqHBkQB/+R1+CNaCYsDqVUqp3eaR4qFhpDkvRMO33Z6jMEQxcz9KPY14+52eQt/bpYEgCH+yEOt8C4wmoObCppEnghD13nYZ1EkmVJizr63Ld/hNC+QBgNkNXYp7WoGXgtxCToG7CA/jQw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756713146; c=relaxed/simple; bh=i+1qCp3beBG8hR67Ml0uTTncFl+n66M6KTgqSeRW5mk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=J2h9EJo7V8kclS6Nu2Po/YJzP33ojf4O53G99Z3r4oIQyWXDCVDwj8eHxfG9vCm8AxtoeObU8PHBbUZ78UavGpReTFO9liyUC8c7nnTmMWAJki2Wq2Q29sCHgbD82jF7iZnXmJ6drBFRzI5VHfJaxHQfCRF9ifte2HIp3KBTcq0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=d2neTr1z; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="d2neTr1z" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1756713143; 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:autocrypt:autocrypt; bh=HllG5yxgEuvgobHZe1WNgsnnNNSMr0+x2czShD/v46g=; b=d2neTr1z+lW0Qw0mpjusjwmEJ9Xzkm0mPaGe+TaAhCkVtSnvohJ9Thi+rtbXYT0XRCV8Ej NcL5R2llg+4LOkVEkO4HB1nbSgvPIxhC9Ge217sf9kMtLCu0YYkPa/eaLUzlAOAPETtLtq XXm/3xXY61FkXRRwsWAJboi86022sck= 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-1-8O_En15hNUSoPE5c6_7gZA-1; Mon, 01 Sep 2025 03:52:22 -0400 X-MC-Unique: 8O_En15hNUSoPE5c6_7gZA-1 X-Mimecast-MFC-AGG-ID: 8O_En15hNUSoPE5c6_7gZA_1756713141 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3ce059e3d42so2358702f8f.2 for ; Mon, 01 Sep 2025 00:52:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756713141; x=1757317941; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:cc:to:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=HllG5yxgEuvgobHZe1WNgsnnNNSMr0+x2czShD/v46g=; b=B+IBVz43M5wAyht5VxiVDVJf/6befdATCMIP2pr9Oejy7y+mICk38/G4DMbWQc1MEP uVZN1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3d4:d572:b8ea with SMTP id ffacd0b85a97d-3d4d582029dmr3197729f8f.34.1756713140933; Mon, 01 Sep 2025 00:52:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEkxrzk0lP+lzTzium88rZISj1JP6wQQDJHhaGn2DR4npJJgvliAA7HY6y8ULZXDuQ1rwzhPw== X-Received: by 2002:a05:6000:22c8:b0:3d4:d572:b8ea with SMTP id ffacd0b85a97d-3d4d582029dmr3197620f8f.34.1756713139105; Mon, 01 Sep 2025 00:52:19 -0700 (PDT) Received: from ?IPV6:2003:d8:2f37:2b00:948c:dd9f:29c8:73f4? (p200300d82f372b00948cdd9f29c873f4.dip0.t-ipconnect.de. [2003:d8:2f37:2b00:948c:dd9f:29c8:73f4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3d0a1f807f9sm13185017f8f.38.2025.09.01.00.52.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 01 Sep 2025 00:52:18 -0700 (PDT) Message-ID: <92def216-ca9c-402d-8643-226592ca1a85@redhat.com> Date: Mon, 1 Sep 2025 09:52:16 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/7] mm: fix folio_expected_ref_count() when PG_private_2 To: Hugh Dickins , Matthew Wilcox Cc: Andrew Morton , Will Deacon , Shivank Garg , Christoph Hellwig , Keir Fraser , Jason Gunthorpe , John Hubbard , Frederick Mayle , Peter Xu , "Aneesh Kumar K.V" , Johannes Weiner , Vlastimil Babka , Alexander Krabler , Ge Yang , Li Zhe , Chris Li , Yu Zhao , Axel Rasmussen , Yuanchu Xie , Wei Xu , Konstantin Khlebnikov , linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <52da6c6a-e568-38bd-775b-eff74f87215b@google.com> From: David Hildenbrand Content-Language: en-US Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEA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QWcwRuj1m73D sq8DEFBdZ5eEkj1dCyx+t/ga6x2rHyc8Sl86oK1tvAkwBNsfKou3v+jP/l14a7DGBvrmlYjO 59o3t6inu6H7pt7OL6u6BQj7DoMAEQEAAcLBfAQYAQgAJgIbDBYhBBvZyq1zXEw6Rg38yk3e EPcA/4NaBQJonNqrBQkmWAihAAoJEE3eEPcA/4NaKtMQALAJ8PzprBEXbXcEXwDKQu+P/vts IfUb1UNMfMV76BicGa5NCZnJNQASDP/+bFg6O3gx5NbhHHPeaWz/VxlOmYHokHodOvtL0WCC 8A5PEP8tOk6029Z+J+xUcMrJClNVFpzVvOpb1lCbhjwAV465Hy+NUSbbUiRxdzNQtLtgZzOV Zw7jxUCs4UUZLQTCuBpFgb15bBxYZ/BL9MbzxPxvfUQIPbnzQMcqtpUs21CMK2PdfCh5c4gS sDci6D5/ZIBw94UQWmGpM/O1ilGXde2ZzzGYl64glmccD8e87OnEgKnH3FbnJnT4iJchtSvx yJNi1+t0+qDti4m88+/9IuPqCKb6Stl+s2dnLtJNrjXBGJtsQG/sRpqsJz5x1/2nPJSRMsx9 5YfqbdrJSOFXDzZ8/r82HgQEtUvlSXNaXCa95ez0UkOG7+bDm2b3s0XahBQeLVCH0mw3RAQg r7xDAYKIrAwfHHmMTnBQDPJwVqxJjVNr7yBic4yfzVWGCGNE4DnOW0vcIeoyhy9vnIa3w1uZ 3iyY2Nsd7JxfKu1PRhCGwXzRw5TlfEsoRI7V9A8isUCoqE2Dzh3FvYHVeX4Us+bRL/oqareJ CIFqgYMyvHj7Q06kTKmauOe4Nf0l0qEkIuIzfoLJ3qr5UyXc2hLtWyT9Ir+lYlX9efqh7mOY qIws/H2t In-Reply-To: <52da6c6a-e568-38bd-775b-eff74f87215b@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 01.09.25 03:17, Hugh Dickins wrote: > On Mon, 1 Sep 2025, Matthew Wilcox wrote: >> On Sun, Aug 31, 2025 at 02:01:16AM -0700, Hugh Dickins wrote: >>> 6.16's folio_expected_ref_count() is forgetting the PG_private_2 flag, >>> which (like PG_private, but not in addition to PG_private) counts for >>> 1 more reference: it needs to be using folio_has_private() in place of >>> folio_test_private(). >> >> No, it doesn't. I know it used to, but no filesystem was actually doing >> that. So I changed mm to match how filesystems actually worked. >> I'm not sure if there's still documentation lying around that gets >> this wrong or if you're remembering how things used to be documented, >> but it's never how any filesystem has ever worked. >> >> We're achingly close to getting rid of PG_private_2. I think it's just >> ceph and nfs that still use it. > > I knew you were trying to get rid of it (hurrah! thank you), so when I > tried porting my lru_add_drainage to 6.12 I was careful to check whether > folio_expected_ref_count() would need to add it to the accounting there: > apparently yes; but then I was surprised to find that it's still present > in 6.17-rc, I'd assumed it gone long ago. > > I didn't try to read the filesystems (which could easily have been > inconsistent about it) to understand: what convinced me amidst all > the confusion was this comment and code in mm/filemap.c: > > /** > * folio_end_private_2 - Clear PG_private_2 and wake any waiters. > * @folio: The folio. > * > * Clear the PG_private_2 bit on a folio and wake up any sleepers waiting for > * it. The folio reference held for PG_private_2 being set is released. > * > * This is, for example, used when a netfs folio is being written to a local > * disk cache, thereby allowing writes to the cache for the same folio to be > * serialised. > */ > void folio_end_private_2(struct folio *folio) > { > VM_BUG_ON_FOLIO(!folio_test_private_2(folio), folio); > clear_bit_unlock(PG_private_2, folio_flags(folio, 0)); > folio_wake_bit(folio, PG_private_2); > folio_put(folio); > } > EXPORT_SYMBOL(folio_end_private_2); > > That seems to be clear that PG_private_2 is matched by a folio reference, > but perhaps you can explain it away - worth changing the comment if so. > > I was also anxious to work out whether PG_private with PG_private_2 > would mean +1 or +2: I don't think I found any decisive statement, > but traditional use of page_has_private() implied +1; and I expect > there's no filesystem which actually could have both on the same folio. I think it's "+1", like we used to have. I was seriously confused when discovering (iow, concerned about false positives): PG_fscache = PG_private_2, But in the end PG_fscache is only used in comments and e.g., __fscache_clear_page_bits() calls folio_end_private_2(). So both are really just aliases. [Either PG_fscache should be dropped and referred to as PG_private_2, or PG_private_2 should be dropped and PG_fscache used instead. It's even inconsistently used in that fscache. file. Or both should be dropped, of course, once we can actually get rid of it ...] So PG_private_2 should not be used for any other purpose. folio_start_private_2() / folio_end_private_2() indeed pair the flag with a reference. There are no other callers that would set/clear the flag without involving a reference. The usage of private_2 is declared deprecated all over the place. So the question is if we really still care. The ceph usage is guarded by CONFIG_CEPH_FSCACHE, the NFS one by NFS_FSCACHE, nothing really seems to prevent it from getting configured in easily. Now, one problem would be if migration / splitting / ... code where we use folio_expected_ref_count() cannot deal with that additional reference properly, in which case this patch would indeed cause harm. If all folio_expected_ref_count() callers can deal with updating that reference, all good. nfs_migrate_folio(), for example, has folio_test_private_2() handling in there (just wait until it is gone). ceph handles it during ceph_writepages_start(), but uses ordinary filemap_migrate_folio. Long story short: this patch is problematic if one folio_expected_ref_count() users is not aware of how to handle that additional reference. -- Cheers David / dhildenb