Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp958647rwb; Fri, 28 Jul 2023 02:29:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlEt21tSLbS54zLlv8Als6dsyAR/Dknk4QTkrVwmzpaaBfwwyLyZDA7zSuY0bN8eYjlfgXtR X-Received: by 2002:a17:906:7785:b0:99b:ed53:5c12 with SMTP id s5-20020a170906778500b0099bed535c12mr1069622ejm.17.1690536554930; Fri, 28 Jul 2023 02:29:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690536554; cv=none; d=google.com; s=arc-20160816; b=d3NFMeW5T1Sfx9dbb/Lqx+cnfZBKS8SwKm4VieW69VRdgew/wBMifmoUQzKlN2+nkP F++i2NK6BPQYpbzxhlCzevAfQ+5i2mYxmh6lR/pnsd2LaJjy8pp43pGm1bfoRY8NV26g 0S1PQqqDSuBF1SjAZExB8PkAyYxGbm9SJn3fabjnbJ7vaU0ATNda7HB9ho31jik8TUZ7 JTduEOlEGmp3I0Ou9DvnmXkU/Qe3f5c6yHXj78roenvmluin0D9OKpipm0YAJZZ7VLzr mRzO8ybLkHJoVALBGFVQHF8amahPZ1DcnhVqzHqyU7KqCzc4s5rdsi+szaNLF/sQxK6v TP/A== 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=spvSSPujjhykQfRCGOgwTP3LB4gvdPkdL4dh2Z/YdbU=; fh=boyD5tmcdaW0C84OS6LZxl+jnPZdzYaatHV4i4D5bj4=; b=gRlCU+vEDKG6FwDrYYcY90VP2v9i5jpWcvobSa9RpCCirKc/NEy2O3+nDW8zMGWydy FfUfyZ0jP4j/H0TPxpn5n3asy46O7WHO3BkLGlqyW5uw5TYJNoRRlCn40DAY+kS4EYo2 aF/lTMspEdSMmUwFPYA3E+4ISdwf8wnZhhzwrVEP/oMJjEeBNDv5SPR7hSJ7kcFN0M1H JCNp0Nmfgf+ttp4qFa2ve05MQQmiFSK2JaUJHu6lme2DhXQTTOZxEcVGPy577pTe2G5B d02lSgUKVgvktyAjMTsHoKhfZw1D6O19WImNEKGZNlFC3Zs1Hgg/H8afg3OvafUrdD1F R4fw== 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 h15-20020a1709063c0f00b0098e0739532fsi2340495ejg.732.2023.07.28.02.28.49; Fri, 28 Jul 2023 02:29:14 -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 S231986AbjG1JXn (ORCPT + 99 others); Fri, 28 Jul 2023 05:23:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235320AbjG1JWr (ORCPT ); Fri, 28 Jul 2023 05:22:47 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A1B6B8A7F for ; Fri, 28 Jul 2023 02:17:30 -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 B8B42D75; Fri, 28 Jul 2023 02:17:21 -0700 (PDT) Received: from [10.57.77.173] (unknown [10.57.77.173]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8985D3F67D; Fri, 28 Jul 2023 02:16:36 -0700 (PDT) Message-ID: <9b54e5af-af1a-6741-424b-6c667d0b405b@arm.com> Date: Fri, 28 Jul 2023 10:16:34 +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: Yu Zhao , Matthew Wilcox , David Hildenbrand Cc: Andrew Morton , Yin Fengwei , Yang Shi , "Huang, Ying" , Zi Yan , Nathan Chancellor , Alexander Gordeev , Gerald Schaefer , linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20230727141837.3386072-1-ryan.roberts@arm.com> <20230727141837.3386072-4-ryan.roberts@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 27/07/2023 18:22, Yu Zhao wrote: > On Thu, Jul 27, 2023 at 8:18 AM Ryan Roberts wrote: >> >> This allows batching the rmap removal with folio_remove_rmap_range(), >> which means we avoid spuriously adding a partially unmapped folio to the >> deferred split queue in the common case, which reduces split queue lock >> contention. >> >> Previously each page was removed from the rmap individually with >> page_remove_rmap(). If the first page belonged to a large folio, this >> would cause page_remove_rmap() to conclude that the folio was now >> partially mapped and add the folio to the deferred split queue. But >> subsequent calls would cause the folio to become fully unmapped, meaning >> there is no value to adding it to the split queue. >> >> A complicating factor is that for platforms where MMU_GATHER_NO_GATHER >> is enabled (e.g. s390), __tlb_remove_page() drops a reference to the >> page. This means that the folio reference count could drop to zero while >> still in use (i.e. before folio_remove_rmap_range() is called). This >> does not happen on other platforms because the actual page freeing is >> deferred. >> >> Solve this by appropriately getting/putting the folio to guarrantee it >> does not get freed early. Given the need to get/put the folio in the >> batch path, we stick to the non-batched path if the folio is not large. >> While the batched path is functionally correct for a folio with 1 page, >> it is unlikely to be as efficient as the existing non-batched path in >> this case. >> >> Signed-off-by: Ryan Roberts > > This ad hoc patch looks unacceptable to me: we can't afford to keep > adding special cases. > > I vote for completely converting zap_pte_range() to use > folio_remove_rmap_range(), and that includes tlb_flush_rmap_batch() > and other types of large folios, not just anon. The intent of the change is to avoid the deferred split queue lock contention, and this is only a problem for anon folios; page cache folios are never split in this way. My intention was to do the smallest change to solve the problem. I don't see the value in reworking a much bigger piece of the code, making it more complex, when its not going to give any clear perf benefits. Otherwise I'll leave > it to Matthew and David. If there is concensus that this is _required_ in order to merge this series, then I guess I'll bite the bullet and do it. But my preference is to leave it for if/when a reason is found that it is actually bringing benefit.