Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp2311625rwo; Thu, 3 Aug 2023 07:44:13 -0700 (PDT) X-Google-Smtp-Source: APBJJlEkeonyBNlqEjCwFCdnLMynhv22yeB/DcdU9xYFvbhg2AJ3/fRHpVCKAPnwL3r+OkGMTU8v X-Received: by 2002:a05:6808:2197:b0:3a4:357a:ebf4 with SMTP id be23-20020a056808219700b003a4357aebf4mr26480757oib.0.1691073852964; Thu, 03 Aug 2023 07:44:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691073852; cv=none; d=google.com; s=arc-20160816; b=pKXLsNLK1ONOWwVbIthjbRi6PXx/38JF90ugHcTOQgaWwxp1qR6a9A7X2SAiFnvWBc tW0jKiOxmH2bj1ESHNu6SUagSecOvvv41sawjQXcGt1sLUbz2K/FwoTF3UX6eZ2FkXDp Gx+1NYY+n8AQ+JA2Np0Z4dfqyvE6yNkkHO7Ur9BwPEVtLZ8J4dqNDAxlMOK4/7g0vcy9 xnNB4IdrMeut5wba3uJZruOqkzUfD0qaDPTtOswzStDv9A3FL4TSh4rEURTzFLCb+0Qh yeS/6jjEheR1Byy7Iayai/pMIDMVyD4+8o4H3G/hUPPDbBRIUZjYl+aHV0HUZ0EgcwHf fmiA== 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:subject:user-agent:mime-version:date:message-id; bh=X3XEghXP8MQ9cdGrgQBqXmD7TBi5eTmRvW2RrCnEhl0=; fh=v8vQgwzarRiO5i1bjakdcj5Lw5vl4PE4MgZyGeDNKsU=; b=VeS1IRAwWispJpotfAQLQPGq8KJwjBEVHRT7F/QpeLPGZs7ggs41RHF0Y/7dJMFD0K OwLnKeVLK0nWwjh+NIw9BDljDm8/5NxZ5pD0tLrQLjY1QQ/tB0cYr4nsS/eWdYhrR8RH MKDrOCzCJJPRaVToJWNtJPR5DE5ZTwYjxDSw45YfwBAx8YYUSqobUPgkQv/CFHlEwFiT DFAjhoVBDIIthARo+yutmymhbLhuZj/TWgT9zDLMEohBgeyd7URi9JCWL/Q6qJL9Yh8A coRYkr3Qpm9uerqH+IGyt6SJM5NhG0Ia5gzQuz8YcVrnf4LwsDi2QkLHwEcS3dWBBkW8 Tf9A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l20-20020a63ea54000000b0055bc22d13d7si9813286pgk.692.2023.08.03.07.44.01; Thu, 03 Aug 2023 07:44:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233758AbjHCOPj (ORCPT + 99 others); Thu, 3 Aug 2023 10:15:39 -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 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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. >