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.133.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 DE0561B3743 for ; Thu, 20 Jun 2024 16:52:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718902327; cv=none; b=jJ8ThTJUptjff4p6StprtzZ5KYJdA4soryy2hnaj+U13T2MYGfaUt9Y4au6rNBk3UcuVsvwDZHqynb6zyrydDtI7idw+urCllT0fYXViO2IYB1tyjyMN3odSl63A1mjuYJgDp397Z39WL4lllDdZM3GlCDdqmDE9lPl1OalSrRE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718902327; c=relaxed/simple; bh=V9G1TuLObH+hBuA1XVHFOx9/aQg59AkUqLikVHdJ4js=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Wdg/YTzNQhAtwfGIkG69sTjG5+biGYDfLRy3yMYN/gQlhRUld0oXM/DX+QRY04SY38vea8Jl5ZAHrBxE8NqyZT0MyRjMv7hRc5q8W5VP1BlIYfQ7VBtIxtAPWK14KKqPGWs1tdPo9MqL+KHsLFnSR4F5xpINyDA/s2hduqRWlpA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=g7UWdsEn; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="g7UWdsEn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718902324; 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=wmT/TfqWZIcOIEydAuy+1NX1w0tpwKPG8r51Xm9pXoo=; b=g7UWdsEnIQCTw73kHR5Mib433D6r3nMLYvXCTzwF9bBe1EVFbj2oxrVHVJXgterau/ZXEs 08LPsIqabfUzVw2KsPD5uqq1HFmsuU/KsYwjDWuyMkmamsEwpeEEL/11npEn4Uu2aLBTvg viLSLz0+2r4tpqWCAcOnFAMbeAgdOcA= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-478-KdW3CWfgPnKgAiq4ptPhEQ-1; Thu, 20 Jun 2024 12:52:03 -0400 X-MC-Unique: KdW3CWfgPnKgAiq4ptPhEQ-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-423034c6119so7664535e9.2 for ; Thu, 20 Jun 2024 09:52:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718902320; x=1719507120; h=content-transfer-encoding:in-reply-to:organization: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=wmT/TfqWZIcOIEydAuy+1NX1w0tpwKPG8r51Xm9pXoo=; b=gmbkCKbhCZ+tBoCzCvDa1TFHLXa27chveZ/VcjEEsgmTzfbjYnVZVu4SlljeRbzL+k Ovtx+qkHC+WHpHOAXQZcBtx4AaQYMIKhGV5nHiDBqpS6hhp2Xhu+SVaXNxGjtkZzstGr 95KmZEwUI1kfQRPkZXvjVhFtRwHhe+FS+qw6TJkiwzcL+YQM849kbpY179+kUfPmdsaI A7SR32Bp/lB2HkdyDGWviNGyyk8KuC1i3cldVpOIWTVaXdFajz9INWDIZ8lHzcxEnPjz xwIwWWxVz8kP3oOVBYl6rrpk56aQIV81duBqTBbHslbManz+XqF4cVY+vzjRcTsOEjmp Aa5A== X-Forwarded-Encrypted: i=1; AJvYcCWd/P1/lJprjRERNyDjJuCAMed4p83NLwT+wPLKheB6Q4HWawpidCZUjgBXwx2WXXma/w4jGzhl9IVvdm5DBYj754y5t/szCNULRls/ X-Gm-Message-State: AOJu0YzgP33Bc4N42rSU9fhUEuN8yEeub4SD3K/Ipob3Ne0Mz4HIMNgO yRaNLWZseUmz5adfZW5SAhQW3dPt0sbOAlzbeJ3IPBESBKlbrPNjk/b1bkvwZVRFkkIrpY2vt15 9RwNjijyrK+TBNDduXhkHm5Jhq6zEdB7lc3F70CPP3uoK7XOTenQ9UwgfOWk1GA== X-Received: by 2002:a7b:cc13:0:b0:424:784c:b13b with SMTP id 5b1f17b1804b1-424784cb209mr34286525e9.13.1718902320395; Thu, 20 Jun 2024 09:52:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGkU9eW+awitjJjD5GfqBhhuJt0IBeYp1kZXJAiUgDhww7y86Wx3yzlGriaKMbYnwqURbX5rg== X-Received: by 2002:a7b:cc13:0:b0:424:784c:b13b with SMTP id 5b1f17b1804b1-424784cb209mr34286355e9.13.1718902319937; Thu, 20 Jun 2024 09:51:59 -0700 (PDT) Received: from ?IPV6:2003:cb:c719:5b00:61af:900f:3aef:3af3? (p200300cbc7195b0061af900f3aef3af3.dip0.t-ipconnect.de. [2003:cb:c719:5b00:61af:900f:3aef:3af3]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4247d0b634asm32104925e9.1.2024.06.20.09.51.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Jun 2024 09:51:59 -0700 (PDT) Message-ID: <1cdf6a43-9599-4e34-8f70-29ed16295a60@redhat.com> Date: Thu, 20 Jun 2024 18:51:58 +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 v2 0/9] support large folio swap-out and swap-in for shmem To: Hugh Dickins Cc: Andrew Morton , Barry Song , Baolin Wang , willy@infradead.org, wangkefeng.wang@huawei.com, chrisl@kernel.org, ying.huang@intel.com, 21cnbao@gmail.com, ryan.roberts@arm.com, shy828301@gmail.com, ziy@nvidia.com, ioworker0@gmail.com, da.gomez@samsung.com, p.raghav@samsung.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20240618130538.ffab3ce1b4e66e3ba095d8cf@linux-foundation.org> <475f0f2c-afc7-4225-809f-93c93f45c830@linux.alibaba.com> <2683b71d-aebd-5527-348c-18c0e021b653@google.com> <25ae21b4-23d5-73ba-2e0a-e642ec4b69a0@google.com> <2a358ff4-4219-4262-9225-d9aab14445f6@redhat.com> From: David Hildenbrand Content-Language: en-US Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdB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wlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 20.06.24 18:27, Hugh Dickins wrote: > On Thu, 20 Jun 2024, David Hildenbrand wrote: > >>> >>> (I do have doubts about Barry's: the "_new" in folio_add_new_anon_rmap() >>> was all about optimizing a known-exclusive case, so it surprises me >>> to see it being extended to non-exclusive; and I worry over how its >>> atomic_set(&page->_mapcount, 0)s can be safe when non-exclusive (but >>> I've never caught up with David's exclusive changes, I'm out of date). >> >> We discussed that a while ago: if we wouldn't be holding the folio lock in the >> "folio == swapcache" at that point (which we do for both do_swap_page() and >> unuse_pte()) things would already be pretty broken. > > You're thinking of the non-atomic-ness of atomic_set(): I agree that > the folio lock makes that safe (against other adds; but not against > concurrent removes, which could never occur with the old "_new" usage). > > But what I'm worried about is the 0 in atomic_set(&page->_mapcount, 0): > once the folio lock has been dropped, another non-exclusive add could > come in and set _mapcount again to 0 instead of to 1 (mapcount 1 when > it should be 2)? That would mean that we have someone checking folio_test_anon() before doing the folio_add_new*, and *not* performing that check under folio lock such that we can race with another folio_add_new*() call. (or not checking for folio_test_anon() at all, which would be similarly broken) When thinking about this in the past I concluded that such code would be inherently racy and wrong already and the existing VM_WARN_ON_FOLIO() would have revealed that race. Whoever calls folio_add_new*() either (a) just allocated that thing and can be sure that nobody else does something concurrently -- no need for the folio lock; or (b) calls it only when !folio_test_anon(), and synchronizes against any other possible races using the folio lock. swapin code falls into category (b), everything else we have in the tree into category (a). So far my thinking :) > >> >> That's I added a while ago: >> >> if (unlikely(!folio_test_anon(folio))) { >> VM_WARN_ON_FOLIO(!folio_test_locked(folio), folio); >> /* >> * For a PTE-mapped large folio, we only know that the single >> * PTE is exclusive. Further, __folio_set_anon() might not get >> * folio->index right when not given the address of the head >> * page. >> */ >> ... >> >> We should probably move that VM_WARN_ON_FOLIO() to folio_add_new_anon_rmap() >> and document that it's required in the non-exclusive case. >> >>> >>> But even if those are wrong, I'd expect them to tend towards a mapped >>> page becoming unreclaimable, then "Bad page map" when munmapped, >>> not to any of the double-free symptoms I've actually seen.) >> >> What's the first known-good commit? > > I cannot answer that with any certainty: we're on the shifting sands > of next and mm-unstable, and the bug itself is looking rather like > something which gets amplified or masked by other changes - witness > my confident arrival at Barry's series as introducing the badness, > only for a longer run then to contradict that conclusion. > > There was no sign of a problem in a 20-hour run of the same load on > rc3-based next-2024-06-13 (plus my posted fixes); there has been no > sign of this problem on 6.10-rc1, rc2, rc3 (but I've not tried rc4 > itself, mm.git needing the more urgent attention). mm-everything- > 2024-06-15 (minus Chris's mTHP swap) did not show this problem, but > did show filemap_get_folio() hang. mm-everything-2024-06-18 (minus > Baolin's mTHP shmem swap) is where I'm hunting it. Good, as long as we suspect only something very recent is affected. There was this report against rc3 upstream: https://lore.kernel.org/all/CA+G9fYvKmr84WzTArmfaypKM9+=Aw0uXCtuUKHQKFCNMGJyOgQ@mail.gmail.com/ It's only been observed once, and who knows what's happening in that NFS setup. I suspected NUMA hinting code, but I am not sure if that really explains the issue ... -- Cheers, David / dhildenb