Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4088040rdb; Mon, 11 Dec 2023 08:29:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IHwKqOHA0TQ6xtFzRjq3xxQdaSEx8HhyH0Ho5PfUF206QVnGTSqm4exJ7mroZkDpXxORp2y X-Received: by 2002:a17:90b:b14:b0:287:1bb5:691a with SMTP id bf20-20020a17090b0b1400b002871bb5691amr1958378pjb.25.1702312177380; Mon, 11 Dec 2023 08:29:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702312177; cv=none; d=google.com; s=arc-20160816; b=aqaCTG38zu7BdmLdSn2l+GkRuxPkK+OJQOWkUgRE4Rm0R1WlnRF0eJDTHof95+5Z6R caZw6RX9d16HonGP9or2UZcXRLeT95FkK9BgGmP7xxto27hVs+kSoo8cFUQwPLvKYycG n8hB58UnOQ65CPlWfGP/J9M0fIEkFtvXBDh+vkUCW7dEJsr7juZtDPpi9oI/IiJkdd55 37G4y9Ml9DGSr1Agmd0dfstoFNWsUB2SFrOtQ7IlfC61zGFXeIy4aU+ezbjE2YC310je c0F+8QRnWFsQgjGIKLBEa9ydkGrFBg/5Z4oz/q9p9XbTHk4jDzWMbLy4Gwq3TMbLe6wC XVUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=vo2qZt3ysnVXQVTospJiJAbqLL/zwId670Ca3iZhqfo=; fh=GlLzLBhqF07GE0FJUf82nnkBDPyXS9iIZ0BDzvPX32s=; b=wPdbcP8NFjYwb48DNcdago1ktjePWIBtXpWzeMAaNaWyRXHhXCRQYKlUTa/qJ+DJSs lARGmNoEH4aGganAOYMYiUeahco8rfL+eBYQPgVczp0T1nYyiWP0BxP8krJHmHu44ZCt /Rh7lBIqR+Bpaq2X77PPMHY1B7sHDzhmfWPt4ROkbpUsVoMuuPWNTlLoDIiW/XhThPmy q8GzfHYDPeg9UHGS0Q9lS0cMXZLgaLx80Px61NC7nabB1ANI+7UMoPUx0XPQmwP0/bsA mqrIg5kUYJEFnrpgZTW6b6P4/7qLZcyEVMPmBA4iHtL/hpgT8Dz29OQ8gu1I9iqPofvT gJyw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id mu16-20020a17090b389000b002858ed80acfsi7767792pjb.131.2023.12.11.08.29.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 08:29:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id F3EE8809E8E9; Mon, 11 Dec 2023 08:29:33 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344189AbjLKQ3J (ORCPT + 99 others); Mon, 11 Dec 2023 11:29:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344611AbjLKQ3E (ORCPT ); Mon, 11 Dec 2023 11:29:04 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E6925FE for ; Mon, 11 Dec 2023 08:29:09 -0800 (PST) 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-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 11 Dec 2023 08:29:34 -0800 (PST) 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;