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 D806BC54E41 for ; Mon, 4 Mar 2024 21:03:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4DC3B6B0089; Mon, 4 Mar 2024 16:03:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 465736B008A; Mon, 4 Mar 2024 16:03:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2DF4D6B008C; Mon, 4 Mar 2024 16:03:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 14F686B0089 for ; Mon, 4 Mar 2024 16:03:02 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id DD787140444 for ; Mon, 4 Mar 2024 21:03:01 +0000 (UTC) X-FDA: 81860581362.23.E989938 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 69B201C001D for ; Mon, 4 Mar 2024 21:02:59 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=WcboNZol; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709586179; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=cese54POTivQZ+W5GHwwAwK3ptv9CAQYY/x9CSNE4fs=; b=7wEAP3NxIFiv6XbfhCoVNLS6tF6Vau84/ye2QDFWAVqPaz2KJaYiBDt02qAGw2qWhoecbf e8T1QTcZXgjSLSt0dU6iRbKz+0UCFIthmoYbDYJxxkaX/mU9PP75GPubX8acyEUMUN3eBc Veji+l54IpLtc86yPtpv64lzClu0IUo= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=WcboNZol; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709586179; a=rsa-sha256; cv=none; b=onxkMTq6JJf/nfKTX6KGgoJTJ8LLZFaqU0xxQYJ8wIKbGdNPWzoHjAR79CJG9ujLQrFJcu Eb3hdCi6K/8pEDXOkbma0JzzrUk6jPeSMFMC4RjSurqI4gWcaVMUo8zKEU2lYovs+XuXuj nx2Ww04lwe6gGE3KtYDFDcTbddx4eWw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709586178; 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=cese54POTivQZ+W5GHwwAwK3ptv9CAQYY/x9CSNE4fs=; b=WcboNZolgEHxAdRvI2VDixEJ4cyfQvYJLSnZBZ1NCPNllN+FY5ia3Ma1vZWqn9vHK6d8Qs p+VfbXSeSKa1THQ8PYV1EtYy2uoR+G1GwFH52vPZSMISrv0cnsCsae1PsWcvnQdVVyh7Vq PZZLevNdy5m1GXJJ4/sIxgmyLg1L2DM= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-30-putI35ZnMrWL1KKosU6bBw-1; Mon, 04 Mar 2024 16:02:56 -0500 X-MC-Unique: putI35ZnMrWL1KKosU6bBw-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-33d1d766f83so1675609f8f.3 for ; Mon, 04 Mar 2024 13:02:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709586175; x=1710190975; h=content-transfer-encoding:in-reply-to:organization:autocrypt: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=cese54POTivQZ+W5GHwwAwK3ptv9CAQYY/x9CSNE4fs=; b=YZqeKwvqbqo/tCSBn/b6u3hgtrYtZ5ZusKQ/cahkLXxUd7ojZJQPsvCrpOVnVwOt77 AeOyFmrIbyZXz0jpMwn2rfeuzqTmuZbIC4ALP6otIqFsgMFFCgVHaeiqClALmDb26lkk 0Oj4msYrjdH2IqY7YL3xUzaok6gtFJUV9TXOkl2Nj0z0RnYzOkDILXHDOj4agOsBYuoe LQZu3INiV0+I4W7Ob95kCjkZJJNQObV82mSfFqqhIvuoDVU2e0PNAoU25p119JyCVpmT bTTlzzEKyDoFYqu634tGDaXkJLvfeDddeRUmapACM2P//KDtKQNHtfMc0g3mXkDxsbLy w9sg== X-Forwarded-Encrypted: i=1; AJvYcCWUcc7UpeVHxO6aOUl4oMxN9bR7/K6SYOhV/sLz/8w3P40ipMP8hCj1mwgF7A7V0Yv3erFEKvalZEQK+M2pllqxnOA= X-Gm-Message-State: AOJu0YygI7WcTi1c1YD0U8FltZkSVrbAc1adhXbemXUixCu77D1GG8Ds HdCNvSxMeU/sUUMwKF1tegkgkA71hR+3CiKCB3r7upUtuBFzVv47QIcKYI4jWBLjwAcSN4r/T0i 02aa0uk2kj3qpFfRpjn7Sx7K0O/EvkvNc1S4A6UcN927paX3H X-Received: by 2002:a05:6000:400c:b0:33e:3055:366c with SMTP id cp12-20020a056000400c00b0033e3055366cmr4738374wrb.51.1709586175528; Mon, 04 Mar 2024 13:02:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IG9Ow4Gg01zZ5Z5RUfqHK6uq+IV49G+BPhDqRY1aOg7hJUg2sVqmBmk1nes7yhjSkc5kR+D6A== X-Received: by 2002:a05:6000:400c:b0:33e:3055:366c with SMTP id cp12-20020a056000400c00b0033e3055366cmr4738358wrb.51.1709586175086; Mon, 04 Mar 2024 13:02:55 -0800 (PST) Received: from ?IPV6:2003:cb:c733:f100:75e7:a0a4:9ac2:1abb? (p200300cbc733f10075e7a0a49ac21abb.dip0.t-ipconnect.de. [2003:cb:c733:f100:75e7:a0a4:9ac2:1abb]) by smtp.gmail.com with ESMTPSA id q9-20020adf9dc9000000b0033e192a5852sm10972816wre.30.2024.03.04.13.02.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Mar 2024 13:02:54 -0800 (PST) Message-ID: <882fcbdd-5392-4dbf-99e4-b35defd9e3dc@redhat.com> Date: Mon, 4 Mar 2024 22:02:53 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH] mm: hold PTL from the first PTE while reclaiming a large folio To: Barry Song <21cnbao@gmail.com> Cc: Ryan Roberts , akpm@linux-foundation.org, linux-mm@kvack.org, chrisl@kernel.org, yuzhao@google.com, hanchuanhua@oppo.com, linux-kernel@vger.kernel.org, willy@infradead.org, ying.huang@intel.com, xiang@kernel.org, mhocko@suse.com, shy828301@gmail.com, wangkefeng.wang@huawei.com, Barry Song , Hugh Dickins References: <20240304103757.235352-1-21cnbao@gmail.com> <706b7129-85f6-4470-9fd9-f955a8e6bd7c@arm.com> <37f1e6da-412b-4bb4-88b7-4c49f21f5fe9@redhat.com> <10f9542e-f3d8-42b0-9de4-9867cab997b9@arm.com> <17b4527c-3782-4eab-8b33-e0c6ff57139f@redhat.com> From: David Hildenbrand 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//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURfIdKSb B3JfpUqcWwE7vUaYrHG1nw54pLUoPG6sAA7Mehl3nd4pZUALHwARAQABzSREYXZpZCBIaWxk ZW5icmFuZCA8ZGF2aWRAcmVkaGF0LmNvbT7CwZgEEwEIAEICGwMGCwkIBwMCBhUIAgkKCwQW AgMBAh4BAheAAhkBFiEEG9nKrXNcTDpGDfzKTd4Q9wD/g1oFAl8Ox4kFCRKpKXgACgkQTd4Q 9wD/g1oHcA//a6Tj7SBNjFNM1iNhWUo1lxAja0lpSodSnB2g4FCZ4R61SBR4l/psBL73xktp rDHrx4aSpwkRP6Epu6mLvhlfjmkRG4OynJ5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Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 69B201C001D X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 46z1rbayiapug9gzry5wxbmcpuw4p1k8 X-HE-Tag: 1709586179-386229 X-HE-Meta: U2FsdGVkX1+tteLov49h82+eepKa2vaNcpx9vybwwD22eqGt58a6LM1NgdCIslEvVCn6ViH20qlKv8Aevb1SSSKWYnh/xXoLjz3rdA+TAwaMxkyyB2tQR1W3PrtE1f0f/V2eShg/TAY259nv7Ulk4t6tyl9KDJ7/BLHOdDXZ5z5DdtHbhTim0TvqOx4OFWUFnV5RgoTJSrQY+8vscopfDkjvZmDMS1+/vGO5n2QtRflZj02O7XZ755OGHmJaetKMbOEBgDYqi2K2G4v4koaUa2Jqc1ecrXcZjkcjUGf0sM8P0q6LbvPyoNKzy/XuRddeRsb+JcwjLhW93RNAOonhhuW0DhH+jt3BnkjNQVNlR9/VtbED6/smtnd6KqmKtnnyPU8aEGCFgigJQy6dd/EDVRgsBhVPew5ZNNlZZlE7M1fGyqLKBbO98nNuMExr9PCH1bW3czFN1XfOw77BLyZTQzVJre03xMs6a3GN4XO8dBghI9l9BCgJ6Q9gwNUfp0OMguv4x4HDV8eWW7fGk779NK4zzcnY0S5XPupkoCo4VpFLuq2rgN9yxxGq672ueHr5mOd22Q8/CARxm7NksmWvtgE9sStTeJf96b4N9ADxfSgS1JlsODtZ+u39FvUkazxr3hJWJBviIuEDPtP3B+pi1HYK1iHMP8ra5CdkDfQCD5VfZ/RZZ+1qK9zDAorzJ9tuyyJwlKy/N4XjfKkJPCVFaEJoiJlo6RkXeGOfTtcaWBqEAxAKzG99WkUtYXdVg0gyI6t/FfdCXXz1MJnbG/vNl+8baCyEuSbxbWsAQDHPsnit9V4qoLyPUl/f62LSikUrE4i8kehBIO6RqkKOFUEBT7HV5LsB61EAKPT0Hv8CPlUqc2OgdHf64Gkd4r5r2v9Ax+3TTgP7M6/ZY9fSyo+gkZ+vUCYEi3oWrOY0vXRqBv9Lie+UbK4YtISjpbAFFcSDB3cM45kh67PhU4XAXlg U723Y0ce BxYs7BVUHzxIBcjHWC4SUUWPoIF8aPW84e0IywcHgCNYnXxWzKSBbbAaQslfNHDBGIKO49DTChRv65J/AI49y2GBq87l66iBKnyDoz9Ugxkc3NGZk1XRei8pdIqBGbls5/zcDk9yI1w3m2eyGwX1RIwxGN5S0Kb0PvzhqWqhQ8WH7c8KWlu9KoNDoKflZdrdL7ufvU/c2txB1ms8+pjf/U/tCS8FKssU+tSOw8AHcBTzXTWPxFqJ5IXOjqTg8WA/aa5+atcGNS/9MYU+Hm7hKVfKYw+/XSVVS4lITmGlAIoVRExE4r2e6E65upf+cGH8atumPWlImEh9Qs/RTFAC+/GQ867CeqkOrvvsqWxxlr3fIfBr7nX67U3jwaJGYWSAzfUmEXURe/TP9/lKZWe1NIuKG9R5na4Vv9IqMwYFsZJWI8//rD1jI2SJ01YG82Gb0KFjDG2M25GtbbpguGdqJcS1Is8SiCQNtLaukq4wg1hg65Fls69SUTo6IvQ/FiK2z9nW0mv1nlFMla2QBiGQLFRYXLgTxj2VN+KOKKNavDaqGK8k= 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 04.03.24 21:42, Barry Song wrote: > On Tue, Mar 5, 2024 at 3:27 AM David Hildenbrand wrote: >> >> On 04.03.24 14:03, Ryan Roberts wrote: >>> On 04/03/2024 12:41, David Hildenbrand wrote: >>>> On 04.03.24 13:20, Ryan Roberts wrote: >>>>> Hi Barry, >>>>> >>>>> On 04/03/2024 10:37, Barry Song wrote: >>>>>> From: Barry Song >>>>>> >>>>>> page_vma_mapped_walk() within try_to_unmap_one() races with other >>>>>> PTEs modification such as break-before-make, while iterating PTEs >>>>>> of a large folio, it will only begin to acquire PTL after it gets >>>>>> a valid(present) PTE. break-before-make intermediately sets PTEs >>>>>> to pte_none. Thus, a large folio's PTEs might be partially skipped >>>>>> in try_to_unmap_one(). >>>>> >>>>> I just want to check my understanding here - I think the problem occurs for >>>>> PTE-mapped, PMD-sized folios as well as smaller-than-PMD-size large folios? Now >>>>> that I've had a look at the code and have a better understanding, I think that >>>>> must be the case? And therefore this problem exists independently of my work to >>>>> support swap-out of mTHP? (From your previous report I was under the impression >>>>> that it only affected mTHP). >>>>> >>>>> Its just that the problem is becoming more pronounced because with mTHP, >>>>> PTE-mapped large folios are much more common? >>>> >>>> That is my understanding. >>>> >>>>> >>>>>> For example, for an anon folio, after try_to_unmap_one(), we may >>>>>> have PTE0 present, while PTE1 ~ PTE(nr_pages - 1) are swap entries. >>>>>> So folio will be still mapped, the folio fails to be reclaimed. >>>>>> What’s even more worrying is, its PTEs are no longer in a unified >>>>>> state. This might lead to accident folio_split() afterwards. And >>>>>> since a part of PTEs are now swap entries, accessing them will >>>>>> incur page fault - do_swap_page. >>>>>> It creates both anxiety and more expense. While we can't avoid >>>>>> userspace's unmap to break up unified PTEs such as CONT-PTE for >>>>>> a large folio, we can indeed keep away from kernel's breaking up >>>>>> them due to its code design. >>>>>> This patch is holding PTL from PTE0, thus, the folio will either >>>>>> be entirely reclaimed or entirely kept. On the other hand, this >>>>>> approach doesn't increase PTL contention. Even w/o the patch, >>>>>> page_vma_mapped_walk() will always get PTL after it sometimes >>>>>> skips one or two PTEs because intermediate break-before-makes >>>>>> are short, according to test. Of course, even w/o this patch, >>>>>> the vast majority of try_to_unmap_one still can get PTL from >>>>>> PTE0. This patch makes the number 100%. >>>>>> The other option is that we can give up in try_to_unmap_one >>>>>> once we find PTE0 is not the first entry we get PTL, we call >>>>>> page_vma_mapped_walk_done() to end the iteration at this case. >>>>>> This will keep the unified PTEs while the folio isn't reclaimed. >>>>>> The result is quite similar with small folios with one PTE - >>>>>> either entirely reclaimed or entirely kept. >>>>>> Reclaiming large folios by holding PTL from PTE0 seems a better >>>>>> option comparing to giving up after detecting PTL begins from >>>>>> non-PTE0. >>>>>> >>>> >>>> I'm sure that wall of text can be formatted in a better way :) . Also, I think >>>> we can drop some of the details, >>>> >>>> If you need some inspiration, I can give it a shot. >>>> >>>>>> Cc: Hugh Dickins >>>>>> Signed-off-by: Barry Song >>>>> >>>>> Do we need a Fixes tag? >>>>> >>>> >>>> What would be the description of the problem we are fixing? >>>> >>>> 1) failing to unmap? >>>> >>>> That can happen with small folios as well IIUC. >>>> >>>> 2) Putting the large folio on the deferred split queue? >>>> >>>> That sounds more reasonable. >>> >>> Isn't the real problem today that we can end up writng a THP to the swap file >>> (so 2M more IO and space used) but we can't remove it from memory, so no actual >>> reclaim happens? Although I guess your (2) is really just another way of saying >>> that. >> >> The same could happen with small folios I believe? We might end up >> running into the >> >> folio_mapped() >> >> after the try_to_unmap(). >> >> Note that the actual I/O does not happen during add_to_swap(), but >> during the pageout() call when we find the folio to be dirty. >> >> So there would not actually be more I/O. Only swap space would be >> reserved, that would be used later when not running into the race. > > I am not worried about small folios at all as they have only one PTE. > so the PTE is either completely unmapped or completely mapped. > > In terms of large folios, it is a different story. for example, a large > folio with 16 PTEs with CONT-PTE, we will have > > 1. unfolded CONT-PTE, eg. PTE0 present, PTE1-PTE15 swap entries > > 2. page faults on PTE1-PTE15 after try_to_unmap if we access them. > > This is totally useless PF and can be avoided if we can try_to_unmap > properly at the beginning. > > 3. potential need to split a large folio afterwards. for example, MADV_PAGEOUT, > MADV_FREE might split it after finding it is not completely mapped. > > For small folios, we don't have any concern on the above issues. Right, but when we talk about "Fixes:", what exactly are we consider "really broken" above and what is "undesired"? (a) is there a correctness issue? I don't think so. (b) is there a real performance issue? I'd like to understand. After all, we've been living with that ever since we supported THP_SWAP, correct? "something does not work ideally in some corner cases" might be reasonable to handle here (and I really think we should), but might not be worth a "Fixes:". So if we could clarify that, it would be great. -- Cheers, David / dhildenb