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 334E9C54798 for ; Tue, 5 Mar 2024 08:54:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BCDA56B0080; Tue, 5 Mar 2024 03:54:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B7D116B0081; Tue, 5 Mar 2024 03:54:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A6BE46B0082; Tue, 5 Mar 2024 03:54:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 946996B0080 for ; Tue, 5 Mar 2024 03:54:49 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6ACE41C0E1C for ; Tue, 5 Mar 2024 08:54:49 +0000 (UTC) X-FDA: 81862375098.22.4DBE65D Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf17.hostedemail.com (Postfix) with ESMTP id B945F4000E for ; Tue, 5 Mar 2024 08:54:46 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf17.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709628886; 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; bh=lHpsogBzysUNiksKZNiBz3d5OPKuMBwqpf72lstjgkA=; b=BTTvglDKhNQaJlzLcwnvnueQ+5FRgLA3dotI7TkCcxZGJzz2MmRXTKMJZx+OlOT+PW6JEo AIBR0NVGyzToMbdt/0K6lNKKXIRcxbNrly7WmmFMFDKSqlIijElcE1W8Rv/YUvvD8Diw4F oRrYwRZD7julZxYYUQXtAJHNH7gSmAo= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf17.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709628886; a=rsa-sha256; cv=none; b=PumNjSpXwL273RgBzXAhCvGk0DM4cXdLs7dZxtZ6WV64LNSEYW72Fl6irJ62tKtNXu8g8Q 1OMiPzQ9nm4CcC4BOQlnPvD4bIhpz+TqTETUhrEGcQKb7UKfYmhH+bK4nKLQh8xJwlbPJo gr6oIsKvIc2hRIaG1JG8DETcQlt5wbY= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 495B41FB; Tue, 5 Mar 2024 00:55:22 -0800 (PST) Received: from [10.57.68.162] (unknown [10.57.68.162]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4CF103F762; Tue, 5 Mar 2024 00:54:43 -0800 (PST) Message-ID: Date: Tue, 5 Mar 2024 08:54:41 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH] mm: hold PTL from the first PTE while reclaiming a large folio Content-Language: en-GB To: Barry Song <21cnbao@gmail.com> Cc: akpm@linux-foundation.org, linux-mm@kvack.org, david@redhat.com, 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> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: B945F4000E X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: uqtufksn6t44nzqkj43ckrtzwciftzaf X-HE-Tag: 1709628886-374482 X-HE-Meta: U2FsdGVkX18MRbHM21cQ7t6NWwPqMJn2JPIRV344e4mEUKl30Zh011uJcB3oA2FZBoIWzk99EeprnurtoST9Nlq2QInSW6DKYyNNZTZ6RSbuojx6Jli3jUy+QTbesNABy/0l+PJ2HneOUKbxlMtGbDTXBmdFHVwmj1LUR+LRv2Pal8IoahgUB7jppc10JZqPMAtTu0mVYTW3bIFiKIrUea5V0yQjTtUFNMZVno3d42RHWgRXwP5j2q7keOqTvyarwa1vVOGie0qRcVmGZ975ObPWyC6OTE2o6SKXSoGra+TIDEaxoTCR26lFpxtufrLGg9+UbJxLf9CBHoVOSJRm6nNEaxzdki6AKUcecprlWMuLqQLmhsPXhJ35phwThLzeeAO3CRPqrP6xq6IdAtL06qN1FphqTpS3LOZQGxaMmM6x+hiwoUJzVJM/Y++78ABK4gWdUqaIbt23ShoV4yPN/DpZcJzVrCbWXrrCoJ2R7lccW8iMouWT255VwjJe+PA1bb8wzGvg2pyQjN0ot6cW+ckxTZfRtFYXCIwYTr6rNrgNpBVaYshb/OXwXsdQ7q6eCd/a00xIVJInYIn4ZmnjM/RzUJhWmdRNQovtAyjyBnQLXLV9sVukf+tOItadX4okCxATR5pl50oqvW1igj29fu9a9O2GEAV7qTo8t6mjiamFywErFP15loDRhDtpnGwYHCAkeiyODkWj9YPhjEH0tqb5mwI6OTB2mxF9LiANXkTHZv0ZA6tHea17gnGqRmCZUbJHAfhs6kKfHsS1YTGcYVc8BvA8dqeny9R2SOzwIODlMMdzRIZ8i+0HlsypSvZeuVGcc73bOqDGoGOc/HlMZZ952s2ymOpajuJxu9cvJGOVvvSaYitqShf4I1d8jPo4xhWBQCUbt4p9SbGQz56ZhvhWvUyNxA+LrEfX7ZCJtOPwOpxbGNI8otBeEps1CwbYtE/qE86estSj9E8v8zY PgG2YHxk sJzR0V78cl2Elk15+j64kicZiR8pT+Rm3fS0f/mcm2HiGat2T9smEqfoZgfJCXU99bsVamFDrlTobWe8F74Qnj56TWl9ne7pn8xwi+0GavB2UYck9eJzXBTE8Plu2iJGwbaTrhe6oCaNPF+gJEHZJOcF0Qq3E2LCP/SruTW9cU65VQbmzL+Y9cT6FSobDAGJG4sgW5/bp6TU+RZ439D3G8BkiQlGEzmwZJ9gp2fw2umdj1z2kZm2MyM82n0hfVbKzwvybnGsNAAq4ZIwEUzWelYG9Z06Q3j+G+MGE 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/2024 21:57, Barry Song wrote: > On Tue, Mar 5, 2024 at 1:21 AM 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). > > I think this affects all large folios with PTEs entries more than 1. but hugeTLB > is handled as a whole in try_to_unmap_one and its rmap is removed all > together, i feel hugeTLB doesn't have this problem. > >> >> Its just that the problem is becoming more pronounced because with mTHP, >> PTE-mapped large folios are much more common? > > right. as now large folios become a more common case, and it is my case > running in millions of phones. > > BTW, I feel we can somehow learn from hugeTLB, for example, we can reclaim > all PTEs all together rather than iterating PTEs one by one. This will improve > performance. for example, a batched > set_ptes_to_swap_entries() > { > } > then we only need to loop once for a large folio, right now we are looping > nr_pages times. You still need a pte-pte loop somewhere. In hugetlb's case it's in the arch implementation. HugeTLB ptes are all a fixed size for a given VMA, which makes things a bit easier too, whereas in the regular mm, they are now a variable size. David and I introduced folio_pte_batch() to help gather batches of ptes, and it uses the contpte bit to avoid iterating over intermediate ptes. And I'm adding swap_pte_batch() which does a similar thing for swap entry batching in v4 of my swap-out series. For your set_ptes_to_swap_entries() example, I'm not sure what it would do other than loop over the PTEs setting an incremented swap entry to each one? How is that more performant? Thanks, Ryan