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 3CFE2EB64DD for ; Tue, 1 Aug 2023 07:13:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6658E2800E6; Tue, 1 Aug 2023 03:13:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5EEC52800C8; Tue, 1 Aug 2023 03:13:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 48EEA2800E6; Tue, 1 Aug 2023 03:13:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 333622800C8 for ; Tue, 1 Aug 2023 03:13:14 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E4128804B8 for ; Tue, 1 Aug 2023 07:13:13 +0000 (UTC) X-FDA: 81074669466.30.F33BC89 Received: from mail-qt1-f178.google.com (mail-qt1-f178.google.com [209.85.160.178]) by imf19.hostedemail.com (Postfix) with ESMTP id 161CF1A0016 for ; Tue, 1 Aug 2023 07:13:11 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=N2UDqWSQ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf19.hostedemail.com: domain of yuzhao@google.com designates 209.85.160.178 as permitted sender) smtp.mailfrom=yuzhao@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690873992; a=rsa-sha256; cv=none; b=VpsSQBIcsTl+pRs7L8WtXGoK8KtRCacRxpInkAG4VkruYLVujDRFIHIzbpdxnHU7HYHbbx 6BQiqP1Bon24ZlCQm8CpoY1Uec5lZcasYyg7S0pinvIapS2xX1tBI5UfwRFe95hLM6Kepi uDBbSf/HubF86+rHXFdS2DN8oMHlIuI= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=N2UDqWSQ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf19.hostedemail.com: domain of yuzhao@google.com designates 209.85.160.178 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=1690873992; 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=iOzFHKg5nc9JsX6FYxxovkU86yNMNcWnN0ObAXQMNcE=; b=mLGyQp3S5rpHKl7egKugFOhIsIQoDbTqO/KwHbscg8JXfsedbm/S5IDb2VtVNN4bHuyz1u zjPzxYNYb05JGV/mkmszPWGe+z0EJEzlbkKe0Fn4rleA11mb6qWk5BUIdB2oLIGIm37fTD WYcdQOLNEY2FBn3fm1cYI91nYVbpIRA= Received: by mail-qt1-f178.google.com with SMTP id d75a77b69052e-4036bd4fff1so215181cf.0 for ; Tue, 01 Aug 2023 00:13:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690873991; x=1691478791; 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=iOzFHKg5nc9JsX6FYxxovkU86yNMNcWnN0ObAXQMNcE=; b=N2UDqWSQl8joRYkbeF6pR56CcOv3FsGsiZvI51s2qCJlznNRvwJ32mg11s4J/Y5m2F cNM33bfpO3fBtWqe0dOd4Acc+XqSm1Qz0CyREyC9BO6nF3be7VUdVd9Khg/5HDpoKZ4o AWdBiqY9vKgTBqmp2pqRNwiI1rRh5oQclKk9ssc2gpR0xc5on33vc4P7JyVjWxjjBPiw zBsdsOpt6xpeLB8oAyOuXJmPoYbv4CvZSiseVQcADBzTp+QYciau4o+oIBtdJVGWVgx9 tXXqPBOCUnsHCFcEiuS4aZWEP0r1udq9MSnTKQojDhDacxOqvzBj7/yjITylDfATFrGw RlGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690873991; x=1691478791; 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=iOzFHKg5nc9JsX6FYxxovkU86yNMNcWnN0ObAXQMNcE=; b=M9+8QA9NYrKcOTym5wvpP+JGuQ6YHY/amtM3RLq4NcHP+ZCRpwYxZF3lSgOeDAFRF5 4HvvfF4DNZIOtHikgDQrch7hXj8GK+D7vu0qKRM9d1PDzRoq/PgKZp5R8Hnu24uho0mJ klsWSWk+Hl/XRxds90x4MLQFW9rZ6RkXdC3ypvZRq/W+r0UbVOKjLeAe3MJXeyQPLwY0 jg/wXfxAcQ6CQ4KL+BTXn3WrvkXURHqE6jbU4y4JDfi57YL84mPDj5P23sWFn2xGJXbT o5cEClRuQ94quyoZXnZmqJoALy8Hwr7WVKsYdfVVcaAK9F/RJ2khEUZNEj/T2t/yPOW8 /r6g== X-Gm-Message-State: ABy/qLaz3YIeooaAOsIWGmrPmU819fmqcuiIyzoE+Awzu76SCQZGv0/5 4mZOpWv1eO96bWCs314SWxL+0w2CAz0m+5N5DJ+9fg== X-Google-Smtp-Source: APBJJlGi8avMgQgerOpBeHOmKVY98vF12xGS3li82sLXOz+7OZQGAAotBvs1GsKpqbxm9aX2eGppF1RbecQLLV4oMzA= X-Received: by 2002:ac8:5913:0:b0:3ef:5f97:258f with SMTP id 19-20020ac85913000000b003ef5f97258fmr709528qty.16.1690873990936; Tue, 01 Aug 2023 00:13:10 -0700 (PDT) MIME-Version: 1.0 References: <20230727141837.3386072-1-ryan.roberts@arm.com> <20230727141837.3386072-4-ryan.roberts@arm.com> <9b54e5af-af1a-6741-424b-6c667d0b405b@arm.com> In-Reply-To: <9b54e5af-af1a-6741-424b-6c667d0b405b@arm.com> From: Yu Zhao Date: Tue, 1 Aug 2023 01:12:34 -0600 Message-ID: Subject: Re: [PATCH v4 3/3] mm: Batch-zap large anonymous folio PTE mappings To: Ryan Roberts Cc: Matthew Wilcox , David Hildenbrand , 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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 161CF1A0016 X-Stat-Signature: 1uc17ow8tzhrcrig4teu7eummztzgps7 X-HE-Tag: 1690873991-887784 X-HE-Meta: U2FsdGVkX19fBLXdDWgFhjOS4EKHvoiwV9eUsJoO8bEaJ9vLQbaHW3UDoJX+oKnPoOmLzC4+qNVx9zMJ1wgaw+MniZ5mRTpUCBzmIX8nVP7Gmt1fdfNeTxm4ljWnWKGHBoBygGhB9tou09u6TH/CGFnMdwFCf+CB2LJgLXDkZci9OIvlRJzO4+c9Znr/sQ39veFwvbet3s4qbUqqhs//0R1Gf+u8Fw5J3IQ0Z1fT4T+4KNRQYvQgfG0EJgIzUtYffqpyAy01IHgwo2mXzvAIDKFEf6MIab010uOT8EH1rSRxKch2uCOi0tzTf5M6LP19U7U9xPFPqC1KtObog0vTI6gWtTGo59xfWzDn3W4UhoKVW7DNmWmQYg2MqWyGSD9lonu8jWGBtV7MyPUpk5gMBvryT27XgV6gGYDCDuIUZVYNfawd1u0f7LQuiJ4+w4rV5Vmmd8WFPsMW30qm4OXNxQq2TqV6jTB0g5wbEMr90jsvNSZpALphDAM6RyBtwI4leEBGHZLTNmMRvUSKBYyhvSjCgcbEU5Jsq4Ec3+2WLaWo1tgYK66OZm/Yw4pa6rWT32fRPAm1cb46MhuX9SqkqNHiDOrB7zWVePPqFB9e2J3TfPglrBOtDNGuQIy/BjnPMNFOawaRp8b5NIZDC7LDCvTawcljwjDdCf9qapVPNph+uwgj2yHrRJUC0iFb4jpq5w09jvtQetkMWFNlF7pAzQeCvxLHob4nNz2ykoHymvc9vfatRrNQgjLBkVZ8HqVpLTVig3QIv8AXuvIt5m1w1TPe4cO3tJyrxxitBDTtDqeCieZfVpH+3ZPZzIIP5gPu8EWBEriECuOK1vpK2WioeSjibLqGTNUs8wbKsdSV22ekd+TlSVXqxzE/QCa0xoJBYCgcElodtoOp36Q9oEewSZKXgAluEVh42IasaWx0BTb1PJNmpE4H6ma7ub0cxOTCE8xxZOgA0XG3Jtk23/5 Y8tgfkFr +YMGSboM2q4QNlQlrfWLoAKwvOIX/nb7GjYdd/XjCfLSwO7IIexeLmwgsZLK+tv8G2U3J+9Fcg7DsTg8Q6BH2bp6TlfLaf8rW+k6NxwaMMJkS9pYkqmx2Dvg2CUPrOCW1ESWi8IcxUakN333AD3lXA+d9W1wlE2FoLbRT7NZRqS5yzjOSacAfJFFic0QvHrA7uqjRkIdDXTrjifpzpLppaRJeW7MIkYd313Tg3aBn6HPRvKao/ZoLTo8Q13CFSEBXDn1wIF1s+nv5zSxWZGOdQqAC6hzK7ZGhbycO X-Bogosity: Ham, tests=bogofilter, spamicity=0.000007, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Jul 28, 2023 at 3:16=E2=80=AFAM Ryan Roberts = wrote: > > On 27/07/2023 18:22, Yu Zhao wrote: > > 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 t= he > >> deferred split queue in the common case, which reduces split queue loc= k > >> 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, meani= ng > >> 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 whi= le > >> 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 conten= tion > and this is only a problem for anon folios; This reasoning seems wrong to me: if the goal was to fix the lock contention, the fix should have been in deferred_split_folio(). > page cache folios are never split in > this way. The goal I see here is to enlighten zap_pte_range() with batch operations on folios. > My intention was to do the smallest change to solve the problem. I understand the desire. But we can't do this at the cost of making the codebase harder to maintain. > 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. "Much bigger ... more complex": I'm not sure how you get this impression. Have you tried to do it already or is it just a gut feeling? Supporting other types of large folios, not just anon, actually makes it simpler! > Otherwise I'll leave > > it to Matthew and David. > > If there is concensus that this is _required_ in order to merge this seri= es, > then I guess I'll bite the bullet and do it. But my preference is to leav= e it > for if/when a reason is found that it is actually bringing benefit. There is a clear reason here: this patch is *half-baked* because it doesn't handle tlb_flush_rmap_batch().