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 B429DC001DE for ; Thu, 10 Aug 2023 21:48:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 398166B0071; Thu, 10 Aug 2023 17:48:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 346F96B0072; Thu, 10 Aug 2023 17:48:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20EBE6B0074; Thu, 10 Aug 2023 17:48:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 0E8586B0071 for ; Thu, 10 Aug 2023 17:48:31 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id CD5B01A1002 for ; Thu, 10 Aug 2023 21:48:30 +0000 (UTC) X-FDA: 81109534380.16.8AE0794 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf28.hostedemail.com (Postfix) with ESMTP id BF464C0006 for ; Thu, 10 Aug 2023 21:48:27 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=U+w4MPre; spf=pass (imf28.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@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=1691704107; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=T1ExLvwy+wUPzZuAeU99YLpuaOF9jFHCSTBDaGG9zOU=; b=evVm/HDAu9VFzovLRoanAd8i9GplyWNflrsybs3D2nOWnuHv4ZKCcJUCgp1RGaDr6IjltO pkjGQdjczeSlTlrSwpDScjUYO97ixuYH1S/WNK+UzawrrcZVDvf9hOhXhgHYcyviq8pY6E ihDQjf35suRSuKYrIg1QGvcXqnCTnyQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691704107; a=rsa-sha256; cv=none; b=zqwQ/BEZ51apW0trt/3Xhkyf8i9wtj/tvX61qx4VJVyPca7R4gH+D2ftjrWqfxct53t5Pl VJFLHQIsdvLUrvyGDpAuJreGSxIW0eY0x++Tl+bTngCTlN7FoC0JL3u5ABZbmmUIjtW7bt MxEtlEkB1HIw2wAg6LWf4wJDwz3CFd0= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=U+w4MPre; spf=pass (imf28.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691704107; 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: in-reply-to:in-reply-to:references:references; bh=T1ExLvwy+wUPzZuAeU99YLpuaOF9jFHCSTBDaGG9zOU=; b=U+w4MPreEI4Q4krQLTIwKJ3soPl2HfgFmX7MsahZvAf0kyFi7A88AQdXp7Jih5rQPQcsR1 KZHeP3f7SVBMQwvn5gDUGh3PLOXoh063QbCOTtxKiQt3TG29T4usTr5uL8rqxe2oqVSO88 104LgQ9gbDY8ozLF/02EpQ3rBmHp4XA= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-678-ZVMaIGaDPnWBeXNYMcNVrg-1; Thu, 10 Aug 2023 17:48:22 -0400 X-MC-Unique: ZVMaIGaDPnWBeXNYMcNVrg-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-63f96fcb4ccso3811696d6.1 for ; Thu, 10 Aug 2023 14:48:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691704102; x=1692308902; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=T1ExLvwy+wUPzZuAeU99YLpuaOF9jFHCSTBDaGG9zOU=; b=Z4MiTmmyi/tQgOBfjozhnTttgaFmwt26NKBVHduFWOkUyCl7MAvkGhvu1krxCN9g1F JYkoVFvjPKgHOkIHGukZM4Vju4D2yTIl+yOxbOBOFpL09eO1yT4SJfhApyE4ooIDQBm1 mSNYGdpx0oUIL3Z3vBshXYaDCW4UJrDCLSYcmlr6+JYdZT/SkTM1qESvN4gJPt43+J8S iimhher4GfMHo+peJaa86Koxh8W6/V3HKalCgjNnaotiXFQJOA4nKSwkhhIP2ia55OTn L/xi3ynw5jBFKeg2SrMTtX7Bq5aUh/9th3mQ6y7Jlt/A4bsbzh2OHLh0bi/05NRt0cNB yAaQ== X-Gm-Message-State: AOJu0YwgRa/0s+OE6SGT+gvnjShYPP2qRB1IMCEeQ5CZ0/wUllCbtH6E zm6DnAO4RTpj8PS4GAcpeUmVLcN25bIIIRhiTl8R7B/NbToBa1coeud/OgIzu9x49PeSWSB7zZ8 rA31o6pRiZSI= X-Received: by 2002:ad4:5f87:0:b0:63c:f852:aa3a with SMTP id jp7-20020ad45f87000000b0063cf852aa3amr3922490qvb.4.1691704101698; Thu, 10 Aug 2023 14:48:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFKQjfkLEtHK4TgBS5tvBCJy85maQwvYfEU+5Pht7gJJOOJ/2gXOWy0MnGa+bfiZMEcuCLmRw== X-Received: by 2002:ad4:5f87:0:b0:63c:f852:aa3a with SMTP id jp7-20020ad45f87000000b0063cf852aa3amr3922466qvb.4.1691704101441; Thu, 10 Aug 2023 14:48:21 -0700 (PDT) Received: from x1n (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id b20-20020a0cf054000000b0062ffec0a18esm758095qvl.84.2023.08.10.14.48.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 14:48:20 -0700 (PDT) Date: Thu, 10 Aug 2023 17:48:19 -0400 From: Peter Xu To: David Hildenbrand Cc: Matthew Wilcox , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, Andrew Morton , Jonathan Corbet , Mike Kravetz , Hugh Dickins , Ryan Roberts , Yin Fengwei , Yang Shi , Zi Yan Subject: Re: [PATCH mm-unstable v1] mm: add a total mapcount for large folios Message-ID: References: <20230809083256.699513-1-david@redhat.com> <7e31254d-8889-7e79-50e1-2630bd493d59@redhat.com> MIME-Version: 1.0 In-Reply-To: <7e31254d-8889-7e79-50e1-2630bd493d59@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Rspamd-Queue-Id: BF464C0006 X-Rspam-User: X-Stat-Signature: 73c4bdg9rtngrxdmgkca911oh7dws9j5 X-Rspamd-Server: rspam03 X-HE-Tag: 1691704107-876240 X-HE-Meta: U2FsdGVkX19OlAE56fF50ZWVA6j0+0h4jkgCpWZneulo6m6n1xkWvsF+S0ol2oLDrnJkIZLKoLplyzAt1X2X9TL4IuWNULGocwu6jgWijmBN6mmvhdIqb8xBv+Te2uN7Eu8oV56cW72EVksU0PbYSQd87JduX8v+gIWOAjCKDJ70ajQ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nfdIM+vBrN4UoiuRYne3RjP0s5BbLmgyuy8yVG58jFasyRJwMWjRp33YCaf5Xd21LDCdxrB7T81xJEc5kCBw= 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, Aug 10, 2023 at 10:37:04AM +0200, David Hildenbrand wrote: > On 10.08.23 05:25, Matthew Wilcox wrote: > > On Wed, Aug 09, 2023 at 05:23:46PM -0400, Peter Xu wrote: > > > Hi, David, > > > > > > Some pure questions below.. > > > > > > On Wed, Aug 09, 2023 at 10:32:56AM +0200, David Hildenbrand wrote: > > > > Let's track the total mapcount for all large folios in the first subpage. > > > > > > > > The total mapcount is what we actually want to know in folio_mapcount() > > > > and it is also sufficient for implementing folio_mapped(). This also > > > > gets rid of any "raceiness" concerns as expressed in > > > > folio_total_mapcount(). > > > > > > Any more information for that "raciness" described here? > > > > UTSL. > > > > /* > > * Add all the PTE mappings of those pages mapped by PTE. > > * Limit the loop to folio_nr_pages_mapped()? > > * Perhaps: given all the raciness, that may be a good or a bad idea. > > */ > > > > Yes, that comment from Hugh primarily discusses how we could possibly > optimize the loop, and if relying on folio_nr_pages_mapped() to reduce the > iterations would be racy. As far as I can see, there are cases where "it > would be certainly a bad idea" :) Is the race described about mapcount being changed right after it's read? Are you aware of anything specific that will be broken, and will be fixed with this patch? I assume mapcount==1 will be very special in this case when e.g. holding a pgtable lock, other than that I won't be surprised if mapcount changes in parallel. But I must confess I don't really have any thorough digests on this whole matter. > > > In the other comment in that function, it's also made clear what the > traditional behavior with PMD-mappable THP was "In the common case, avoid > the loop when no pages mapped by PTE", which will no longer hold with > sub-PMD THP. Having a total mapcount does sound helpful if partial folio is common indeed. I'm curious whether that'll be so common after the large anon folio work - isn't it be sad if partial folio will be a norm? It sounds to me that's the case when small page sizes should be used.. and it's prone to waste? -- Peter Xu