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 8724EC4167B for ; Mon, 11 Dec 2023 16:29:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA5478D0002; Mon, 11 Dec 2023 11:29:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E55358D0001; Mon, 11 Dec 2023 11:29:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CCF4A8D0002; Mon, 11 Dec 2023 11:29:12 -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 B88858D0001 for ; Mon, 11 Dec 2023 11:29:12 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8110BC07BE for ; Mon, 11 Dec 2023 16:29:12 +0000 (UTC) X-FDA: 81555072144.05.9570C3E Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf10.hostedemail.com (Postfix) with ESMTP id 769E4C0020 for ; Mon, 11 Dec 2023 16:29:10 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702312150; 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=vo2qZt3ysnVXQVTospJiJAbqLL/zwId670Ca3iZhqfo=; b=b/NAswjNIyKou2UKmwaTb1izCAWiDY6NF3C3JPIW2sYDz1SYkpwzcJvezVYxK8CjTYLWBG IlcxwXO2NwodGW1mF28TFnl6MRFI7IKB8kx9bCG3ve8QPFbdq1r6uqJYAGLyNgmm/z8hmN z5+FeOzmy5v9VNwzpctaAI8ATa1CTKU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702312150; a=rsa-sha256; cv=none; b=ZiSgyl7MH1VxiRCrsUXJeBYqpMo2wjHzJk3RiWLUTYubMrxgqZHhB0cZ+cwFw3Z+31sFhg VUz40uOcMndxhbEPcnGIaasQoqqhS7Wve5SC/BzICYyujrgEQdGlnchZ7SWBUQGsOPD3Ts DBMtktVDXhc2iHgXWihXB3fqobyC3sA= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com 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 4249D1007; Mon, 11 Dec 2023 08:29:56 -0800 (PST) Received: from [10.57.73.30] (unknown [10.57.73.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 53B433F738; Mon, 11 Dec 2023 08:29:08 -0800 (PST) Message-ID: Date: Mon, 11 Dec 2023 16:29:06 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 05/39] mm/rmap: introduce and use hugetlb_try_share_anon_rmap() Content-Language: en-GB To: David Hildenbrand , linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, Andrew Morton , "Matthew Wilcox (Oracle)" , Hugh Dickins , Yin Fengwei , Mike Kravetz , Muchun Song , Peter Xu References: <20231211155652.131054-1-david@redhat.com> <20231211155652.131054-6-david@redhat.com> From: Ryan Roberts In-Reply-To: <20231211155652.131054-6-david@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Stat-Signature: jtns8k83ot9cko1akouxospwxnnteipd X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 769E4C0020 X-Rspam-User: X-HE-Tag: 1702312150-856140 X-HE-Meta: U2FsdGVkX18cyyIltlu7Vc/FzhsVLFGHuty9zDFJlHu5MKLubnCn769N/2iLwQ6BT1SjMRCgcMvGxmi1+h6ydBzezQ7ndXUjwp73WObjIfBBqhBzx6Y9un59ToWd4oTCYTtxm96ICXSZRKHuqDRiS8X69KvIgtltQ80NmgmIhxBpTGsY8UB70X93OTJRqx2asaNc5LpcaH1xku99F6dxTSz5r0HmIQiRxT/Urou5cIplBU3B9gDKCd+yEFOKhe81iPUUfS8CqM6n8cdRxX7VEl2PWFZry66dPA07B3/NmWLbl8UorJ5oesXKQKp7t5x7pgWCi6WgPNfuB7A0VGT/sScthyd41iwaVgdhaU6zpXJCrAWI82gNMsXQTNN9qhXvXf38rOdJxtxIvYwY1mGGsPB8pgOxwdWkYnZlRkJNeuX8jRP3Zrlr6GWYk4m2iJO63YOkwv9w1Ycds7BS0nTMlD+XvBKaskD6usNR8SA17dA2ws7NNW2oPrBdRs7ButZNkpDxOG903zvc5M5fpouoiCfR0udm+w4ien/t5BD/4Kz+w8wcxJEE3hXWsolvavw8ymwuFFHavJ1CSA2SmN9L//oae0noIYToUCV/T4uklOPWwdXrhd6I6JTGZPqg8gbv7Y9ttImDOYBPzB6yi66VgjBKoMJjruZnBHopOzQqJTucmO/JqUwEdq8EZVsvxZI8Bsy0oV1wEpPTNiJ0wTgLkdKDQagWBLX8U8NA4A+QuozYue8vlrsKXXPmSXjy99554/i4Trp1NxMNEYCqTb9E5VCphPatgp3Yo3ArqnNoPrPn7WKclulDX28cYYuh0A6oj4LiMHGKfYhDR6kiA8Rb7TPuDJHuUjPU7yUwcQz4+yYskPwKx0svuptOkNemwcUFRfSPuEV0n9rz7prWkfxTx0N5nSpXu/ZhGp6MORIFSLzV7jN896X+f32fPe5wzfkKbK66+koNS944AZyg6OE XNqYLaFS 0k4+qp3qqGcK+u+5mrtAMtm4aQV5MeCvuhSnditsKY1YDbsTnp2UsprlbUnvtobrwAMmgb097Wy5f1MAZd9KzDy0T8YkB4wkXDZECfrFXPV3m/ZhceFZSXaabgHFgONFqTrnuSRHF+Ub9fP38sTXHUI2K2L37gD2nHD7x14skY2nPZ5s6ztRmhq4WrTscmXf7r65glUR9UX2zg7NBazgpnPJu7hM1Sdf7bGqoCl8TcNjupB0kzsig+vIcEaLa5M66hPxzFRmrC2M5nQqBOYb9L9CDaMEadKV4vVLlgVruyw6wNeE= 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 11/12/2023 15:56, David Hildenbrand wrote: > hugetlb rmap handling differs quite a lot from "ordinary" rmap code. > For example, hugetlb currently only supports entire mappings, and treats > any mapping as mapped using a single "logical PTE". Let's move it out > of the way so we can overhaul our "ordinary" rmap. > implementation/interface. > > So let's introduce and use hugetlb_try_dup_anon_rmap() to make all > hugetlb handling use dedicated hugetlb_* rmap functions. > > Note that try_to_unmap_one() does not need care. Easy to spot because > among all that nasty hugetlb special-casing in that function, we're not > using set_huge_pte_at() on the anon path -- well, and that code assumes > that we would want to swapout. > > Reviewed-by: Yin Fengwei > Signed-off-by: David Hildenbrand Reviewed-by: Ryan Roberts > --- > include/linux/rmap.h | 23 +++++++++++++++++++++++ > mm/rmap.c | 15 ++++++++++----- > 2 files changed, 33 insertions(+), 5 deletions(-) > > diff --git a/include/linux/rmap.h b/include/linux/rmap.h > index ca42b3db5688..4c0650e9f6db 100644 > --- a/include/linux/rmap.h > +++ b/include/linux/rmap.h > @@ -228,6 +228,29 @@ static inline int hugetlb_try_dup_anon_rmap(struct folio *folio, > return 0; > } > > +/* See page_try_share_anon_rmap() */ > +static inline int hugetlb_try_share_anon_rmap(struct folio *folio) > +{ > + VM_WARN_ON_FOLIO(!folio_test_anon(folio), folio); > + VM_WARN_ON_FOLIO(!PageAnonExclusive(&folio->page), folio); > + > + /* Paired with the memory barrier in try_grab_folio(). */ > + if (IS_ENABLED(CONFIG_HAVE_FAST_GUP)) > + smp_mb(); > + > + if (unlikely(folio_maybe_dma_pinned(folio))) > + return -EBUSY; > + ClearPageAnonExclusive(&folio->page); > + > + /* > + * This is conceptually a smp_wmb() paired with the smp_rmb() in > + * gup_must_unshare(). > + */ > + if (IS_ENABLED(CONFIG_HAVE_FAST_GUP)) > + smp_mb__after_atomic(); > + return 0; > +} > + > static inline void hugetlb_add_file_rmap(struct folio *folio) > { > VM_WARN_ON_FOLIO(folio_test_anon(folio), folio); > diff --git a/mm/rmap.c b/mm/rmap.c > index 4e60c1f38eaa..e210ac1b73de 100644 > --- a/mm/rmap.c > +++ b/mm/rmap.c > @@ -2147,13 +2147,18 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma, > !anon_exclusive, subpage); > > /* See page_try_share_anon_rmap(): clear PTE first. */ > - if (anon_exclusive && > - page_try_share_anon_rmap(subpage)) { > - if (folio_test_hugetlb(folio)) > + if (folio_test_hugetlb(folio)) { > + if (anon_exclusive && > + hugetlb_try_share_anon_rmap(folio)) { > set_huge_pte_at(mm, address, pvmw.pte, > pteval, hsz); > - else > - set_pte_at(mm, address, pvmw.pte, pteval); > + ret = false; > + page_vma_mapped_walk_done(&pvmw); > + break; > + } > + } else if (anon_exclusive && > + page_try_share_anon_rmap(subpage)) { > + set_pte_at(mm, address, pvmw.pte, pteval); > ret = false; > page_vma_mapped_walk_done(&pvmw); > break;