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 A3D92EB64DD for ; Thu, 3 Aug 2023 13:57:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 31E2628025D; Thu, 3 Aug 2023 09:57:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2CE5128022C; Thu, 3 Aug 2023 09:57:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 16F2828025D; Thu, 3 Aug 2023 09:57:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id F2A5028022C for ; Thu, 3 Aug 2023 09:57:21 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A9A904127A for ; Thu, 3 Aug 2023 13:57:21 +0000 (UTC) X-FDA: 81082945482.24.C56F658 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 5B63EC001B for ; Thu, 3 Aug 2023 13:57:19 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=au+4M4jJ; spf=pass (imf28.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691071039; 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:dkim-signature; bh=h8q6Z7pqkoedTXIWap9LkOruYe/sbO2nQstX3LZJ7yU=; b=VUuGLNsCMb+dg5lEZtbm/4un5UxMgYskZxUNlsZyzmQtPXcVFtnCHaV2qpyJER2loV7ImO rrnm29rY5JhA+6dD004eMR7oBJzZf62YrfnyxwynaAmwG5VNDyO/HaohlTq9Y6A1tH72dy x8YvGcA2uC9YLTAx30mIgULsgsvDW54= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=au+4M4jJ; spf=pass (imf28.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691071039; a=rsa-sha256; cv=none; b=mJTwVhMPvR+HrF4AQEXxHNTOJCjmhXRway0uJ5Diw+wCvHIQy62i2Q1cagsXd3s13FeZZm WCT6dh/FP34pXO6p5M2QfsLLHbyoUPU8Siz2VTE9jKxMMJtEPXo+JaZTANsYzHFMqtN/C2 vOAX3isU93EyPM/5wMRl6FGYQxEStl8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691071038; h=from:from: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=h8q6Z7pqkoedTXIWap9LkOruYe/sbO2nQstX3LZJ7yU=; b=au+4M4jJD2bqfXEcuAjuJw0AwuwO39kVM5nWhZxMUBG7aVrEsjDbDpIRLZBi5gMNbmmHR/ iZDU6xVBR7RPXRespNzFHDtle9MBja+WnhwA9iCTEkDz6IVCuVYJAdcZ7fbfc1smGpUlaN 4tRCnOnk3AOX47GxKztipoCw7p0RhzA= Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-175-oBlbX3jWN2-brd-BOF9B9w-1; Thu, 03 Aug 2023 09:57:17 -0400 X-MC-Unique: oBlbX3jWN2-brd-BOF9B9w-1 Received: by mail-lf1-f72.google.com with SMTP id 2adb3069b0e04-4fe3c8465e0so999659e87.1 for ; Thu, 03 Aug 2023 06:57:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691071036; x=1691675836; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=h8q6Z7pqkoedTXIWap9LkOruYe/sbO2nQstX3LZJ7yU=; b=ZZoeFoT/dSYQRYVkd8PiQN5DlgV/fg1smqcfaakz1yFYnTIb0kxHGZZAXCxkYHRMKT NFrq/K70WhjsSg4WXq3QL6U/ZIoF54N1NR35KccH9pQv5BBw6cOnf/TekS0Fp3OerC0+ r4BPdJyfMVR9T2p6rEssyndc8UObRQbv/mmFZ8v7eZ1DnIRboMKJ/Xzp7tLlDRSLEo4o 132fnvcVf5yh2rmsK7/h3BsRmTQP93nsQ7Dpe3nl36X7SJ4IKOEAzGKafYH4Ui7Mcr14 86OIeMhgCp7asePedyxsT+mH5i+jvIAsPhJKuyjDNFzqoPieVfcxukzZFzh7c2b2dxkv Budg== X-Gm-Message-State: ABy/qLaRSLHAD6sn/mSCEe9LVMBGnLfehzu+q6p06qiKrD+f5pdC3k5t U3JDDJ2YPfhD43XT/u1i3M4+keWi+NrPsLslhCpNyQNu8L8dN5YmLxS3bkZH8wWVFVo22Ib7FAb Cj/g+2rNF0Lo= X-Received: by 2002:a05:6512:538:b0:4fb:73d1:58e5 with SMTP id o24-20020a056512053800b004fb73d158e5mr6026042lfc.53.1691071035960; Thu, 03 Aug 2023 06:57:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlH/adeNKqLJO3yJHoENqb6qn8CC14RihTNj12oBa59rhbZwveOAERtZXKtmV659jUXZGZWRyQ== X-Received: by 2002:a05:6512:538:b0:4fb:73d1:58e5 with SMTP id o24-20020a056512053800b004fb73d158e5mr6026026lfc.53.1691071035531; Thu, 03 Aug 2023 06:57:15 -0700 (PDT) Received: from ?IPV6:2003:cb:c718:9a00:a5f5:5315:b9fa:64df? (p200300cbc7189a00a5f55315b9fa64df.dip0.t-ipconnect.de. [2003:cb:c718:9a00:a5f5:5315:b9fa:64df]) by smtp.gmail.com with ESMTPSA id t13-20020a19ad0d000000b004fe333128c0sm1913291lfc.242.2023.08.03.06.57.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Aug 2023 06:57:14 -0700 (PDT) Message-ID: <3d0ebaf0-894c-8238-c18b-92d624dc39a6@redhat.com> Date: Thu, 3 Aug 2023 15:57:11 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; 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 , Ryan Roberts , Matthew Wilcox 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: David Hildenbrand Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 5B63EC001B X-Rspam-User: X-Stat-Signature: wqnzob74hdpuh8cjdstjme5k85z77k7n X-Rspamd-Server: rspam01 X-HE-Tag: 1691071039-64647 X-HE-Meta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RXsdLHzyzw13ceriyiWzWHBkyXAG9Dh0n0BLEvy2VwMiVrEI2ndXhS63Pa0AzttMzzjAsntl2edZRczefEEjbWCqCq+yyccSBmeinU5eq3FfoK6k+9TaPIM113BSrq1OHnWWne6XdhVcVJav/V+0PDCpb3CS2xKdr3nGxQDiYn+3WAAuHV/zr6AHBJqw5b70ioWy2S9Y3k3DBXkSEqd55F2KcLdCVUxmwk3SfmClFlpCfhTml8P3dQCONx4ttwzEMTbVR4rPyLVzdCMuVfgiuhnCOB5L7i9cwWwdzVnnTvD7I4Z5N1syWfz660Gn34VxlqmueZVAzuJYeEMWpE0Oud/la5iIfGgFg3r5F 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: On 27.07.23 19: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. Otherwise I'll leave > it to Matthew and David. The !anon case with tlb_delay_rmap() really hurts my brain (again). We're already special-casing on !anon ... so splitting anon and !anon also doesn't sound completely off to me. But yes, we should find ways to just avoid any special casing here, or at least minimize them. (The bigger problem I have with this patch, as raised in my replies, is that it messes up the order in which we adjust mapcount+refcount, and I am *really* not a friend of that :) ) -- Cheers, David / dhildenb