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 1C4F6C0015E for ; Thu, 27 Jul 2023 17:22:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5C4C96B0071; Thu, 27 Jul 2023 13:22:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5754B6B0074; Thu, 27 Jul 2023 13:22:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 43D056B0075; Thu, 27 Jul 2023 13:22:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 373986B0071 for ; Thu, 27 Jul 2023 13:22:49 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E768AB1A39 for ; Thu, 27 Jul 2023 17:22:48 +0000 (UTC) X-FDA: 81058061616.02.3C6A5AB Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) by imf13.hostedemail.com (Postfix) with ESMTP id 0435A20023 for ; Thu, 27 Jul 2023 17:22:46 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=L2j4ig2q; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf13.hostedemail.com: domain of yuzhao@google.com designates 209.85.160.171 as permitted sender) smtp.mailfrom=yuzhao@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690478567; 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=4iBSnQ5X7Bak2sfXDoDjMggzIUJmAFUrUhU8QMi07MQ=; b=yvDMmFSjmcoSPzG3O12g+bnJLsGBTp8+LJMDVkB1gRlEzbmjTMjivph03PhgpVCYbMVuer JVSaujXwMpfdWPccaFFwLbfw0GXzVmmcY1RmNx0XDaSOsTaQGsUEuai/vO4vrcgVahyjvj DMXJH2Vv52HcNsx8kkbYji+l8SH/klQ= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=L2j4ig2q; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf13.hostedemail.com: domain of yuzhao@google.com designates 209.85.160.171 as permitted sender) smtp.mailfrom=yuzhao@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690478567; a=rsa-sha256; cv=none; b=ft22vwxAJQaVuNwstmAl0V7e/iLnY9YQXSZubScvBQl/SZSruM2APjHG46wKKrSFhDPMlJ LO3XjHaWbVgoZ0Sqb5jvGxSXThQnp0MlGwhxjpsn0UAw/jXRcrQfdV4eugywuDJeQfnlTV 2Y/arCkDdJQOfVQ1DUG9t9Z+3TweoT0= Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-40550136e54so19301cf.0 for ; Thu, 27 Jul 2023 10:22:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690478566; x=1691083366; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=4iBSnQ5X7Bak2sfXDoDjMggzIUJmAFUrUhU8QMi07MQ=; b=L2j4ig2q7+TlWH4is4fSMeAnuEDwttbgXN9Ciq1UQsG5WQxpUi5VZ8KMRZOhxaKKF1 UX6Vpbkhimq+/vnFYPLMkI9xCuPgRbBwUcdr3Q17GF1zv7FSLlNURNye1dYwrkJUvBHu YswLU2kI/6W6M7gZnEBKJtyeE5DXwwSQm3EwUraTFmU7W7HUOpKCtwF+5r73I9j0Tri2 GbcyeDmisTMCT49CD6T+7OFJwHcr1FHC1gxKLf67k72x/9aByS74JUSzQebkveBMPLBL jbdWMKLxrLR+oFMJqvrQ/cGlEirp3krzaCsTRjvM/jV1bhOQP9//nj97GW8+S40RLYjJ twIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690478566; x=1691083366; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4iBSnQ5X7Bak2sfXDoDjMggzIUJmAFUrUhU8QMi07MQ=; b=Bjea9tzPMBp1YC5pgGkBP+kD6YKBtNORkueXlNYMEiKkEfLzPdyTAdEehnF7sszuRv jIv7MuRjYT4IMNUCneQ31auNz90qLKTGj6m9naiy+a/vldKuAX0bui/J4NhVWn3QJQRJ bGKi0A3Dvee9fBtT45uN4fwnbKoi0LTXSTCfhgiXkP5HAUqqWMMb3AGRC9/FlJDnx3Np DBkpp9xZyz4liZx+aqGbBEtVyoBF0rW8n2Acp4wy3UU0qO9gclxr1PjlfB7Rh45wXZ/v zux2//I6jSHNp8ZmNmcPwhoAjVJeWKzu49vSwK9TT8j6YGOnb+9xBXsikPW2LbQj4zIW tlqQ== X-Gm-Message-State: ABy/qLZ2bhEBsA/uwIpmwIgJuWnWEHcirWc5hNyLtrrPpcoezyrmrvLP zlvaQsGJeyzUqFcEuPUgXbPNIq52y619g8E9sPPL0w== X-Google-Smtp-Source: APBJJlEHmDtLma/pDt7kAcnkGk4KhU1ciC8WIqe3qlzEIEhkAYIwkfdL5qkyAn8APXdFJB15RqW4Gaxd1ayPgEGqnHA= X-Received: by 2002:a05:622a:247:b0:403:b3ab:393e with SMTP id c7-20020a05622a024700b00403b3ab393emr15394qtx.18.1690478566020; Thu, 27 Jul 2023 10:22:46 -0700 (PDT) MIME-Version: 1.0 References: <20230727141837.3386072-1-ryan.roberts@arm.com> <20230727141837.3386072-4-ryan.roberts@arm.com> In-Reply-To: <20230727141837.3386072-4-ryan.roberts@arm.com> From: Yu Zhao Date: Thu, 27 Jul 2023 11:22:09 -0600 Message-ID: Subject: Re: [PATCH v4 3/3] mm: Batch-zap large anonymous folio PTE mappings To: Ryan Roberts , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 0435A20023 X-Stat-Signature: b3as93qks1ix6yxa9nytfukbnta4eb57 X-Rspam-User: X-HE-Tag: 1690478566-45096 X-HE-Meta: U2FsdGVkX1/OOWy/5faYo86MpaxcobKWIIQTadwOA/S2BVI5ROPGtXwOPAZhU45jnihivVN2lvJGrqdvUCOxH6zlOpjjRneUJ/byt9NvAckNPxnlketE642ptYkTwDDu4LtKW1xQg+ZxjqUQIU4OBrzeGXbZO6Qtfpyvt/DAke5x84N1eKvOaEoOitcSvlMBI3xewtNBenqjNpKHsi63XF4CySs8MqV0JJ98c5yp+leVScn9KQl89wh0HY3M5vKRfncSXYheHSRxKP8jV43qInPXSzJndKASz4B3bob9p3tfl03agTPRtdXV9n0RhFYqzE3uL4+d3dxLyGoGHn2dkNxtMUZy4PqR3FTKQ7VlsF+rIA/gntbHGI4VYRr4f5/qvYTKYqiesQl1L6uMdU6g+DFWKc5Bb8Vpxj6ERDjCpwJDd6NiGiTXJX8o0+WRClxH30JQcWL8pbtp6KKn/8IRo666UjEQ7cm3qKiBhKDlwFIw7ios4kEL2ZOADAM1uMfUZ/00XsaktsqaAZL9kjvLDqw3TgsnAPRdsyu5HZNppV+zBMYLIJUiiVcSAlb/9eoQf/TB/8yn1WTrQKCLt8VvtIUv3Xj238idDSuqZjsA1dqPiBxHGzuuJtVztG85EfZ6eJ2KJnbokCIjPLcxXuPUlKmVnzfY17TxC0RNXjMNoQqV09jEA731P9eyGZXBD/IIihUfnmw/v2h9jOfwCr8eT5cjToTrMNqX3PaORF5WLFScLNuCE5rbK2+MYqvK1XuKybOrFEL5jiCZ0rQGE/VjiXY8/y8zd6u5HH1lj4Zh0/2/Y8oKaIxq82wjUwfNYxqbqxRG28XWyM45pXrVGJbCOe8WBky09KdlIVySGYpLauv/6XUOagbWx592UJ8BBQy0SjWeUqChNFBe/HuTK6wvnwest2NrMXeO/wHKbC9OsYlAKZBtN3qgVnHzohumvZAkLx2Y3Rl3zQFC1rZy8xE rVp488R2 hnD2EgeUUVvQHQML7+k3yB6UOjWoga1wHrWbYkSTlSrVS0TzXLpLYMArhHYtLfrGAP+jiH6p7QxeQGE/tT6gg4xL6/+8i4CXKffl4iav9vDrfedlywsL0nShs/ld9JDsNAVrUG9U41LdCpfcFcEoa3tYpp+RDisHVVpjAdfh5iqMHrAnpjoIkHt08Qcspr+NBFuT3jR8Gcd2gb20wt3j8jN/qn6kiUgPfKj71GHOJxfRTQo9yFmVQG1w75W3ZoW2ICVBMi4Wvf5A0JSOXwO4wwtbRZjHo/e4whbv7 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 Thu, Jul 27, 2023 at 8:18=E2=80=AFAM 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.