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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BBDA1EB64DD for ; Thu, 3 Aug 2023 14:15:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234044AbjHCOPm (ORCPT ); Thu, 3 Aug 2023 10:15:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231143AbjHCOPc (ORCPT ); Thu, 3 Aug 2023 10:15:32 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3431F1BF6 for ; Thu, 3 Aug 2023 07:15:31 -0700 (PDT) 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 E263A113E; Thu, 3 Aug 2023 07:16:13 -0700 (PDT) Received: from [10.1.35.53] (C02Z41KALVDN.cambridge.arm.com [10.1.35.53]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2801C3F5A1; Thu, 3 Aug 2023 07:15:29 -0700 (PDT) Message-ID: Date: Thu, 3 Aug 2023 15:15:27 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH v4 3/3] mm: Batch-zap large anonymous folio PTE mappings To: David Hildenbrand , Andrew Morton , Matthew Wilcox , Yin Fengwei , Yu Zhao , Yang Shi , "Huang, Ying" , Zi Yan , Nathan Chancellor , Alexander Gordeev , Gerald Schaefer Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20230727141837.3386072-1-ryan.roberts@arm.com> <20230727141837.3386072-4-ryan.roberts@arm.com> <6cda91b3-bb7a-4c4c-a618-2572b9c8bbf9@redhat.com> <4255e71a-63c9-b2f9-5e97-e46834f7837c@arm.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/08/2023 15:10, David Hildenbrand wrote: >>> >>> With this patch, you'll might suddenly have mapcount > refcount for a folio, or >>> am I wrong? >> >> Yes you would. Does that break things? >> > > It is problematic whenever you want to check for additional page references that > are not from mappings (i.e., GUP refs/pins or anything else) > > One example lives in KSM code (!compound only): > > page_mapcount(page) + 1 + swapped != page_count(page) > > Another one in compaction code: > > if (!mapping && (folio_ref_count(folio) - 1) > folio_mapcount(folio)) > > And another one in khugepaged (is_refcount_suitable) > > ... and in THP split can_split_folio() (although that can deal with false > positives and false negatives). > > > We want to avoid detecting "no other references" if there *are* other > references. Detecting "there are other references" although there are not is > usually better. > > > Assume you have mapcount > refcount for some time due to concurrent unmapping, > AND some unrelated reference. You would suddenly pass these checks (mapcount == > refcount) and might not detect other references. OK. I'll rework with the 2 loop approach, assuming I can calculate the number of free slots in the mmu_gather ahead of time. > >>> >>>> + >>>> +    for (i = 0; i < nr_pages;) { >>>> +        ptent = ptep_get_and_clear_full(mm, addr, pte, tlb->fullmm); >>>> +        tlb_remove_tlb_entry(tlb, pte, addr); >>>> +        zap_install_uffd_wp_if_needed(vma, addr, pte, details, ptent); >>>> +        full = __tlb_remove_page(tlb, page, 0); >>>> + >>>> +        if (unlikely(page_mapcount(page) < 1)) >>>> +            print_bad_pte(vma, addr, ptent, page); >>> >>> Can we avoid new users of page_mapcount() outside rmap code, please? :) >> >> Sure. This is just trying to replicate the same diagnstics that's done on the >> non-batched path. I'm happy to remove it. > > Spotted it afterwards in the existing code already, so you're effetively not > adding new ones. >