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 9E86FEB64DD for ; Fri, 11 Aug 2023 15:58:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2074D6B0072; Fri, 11 Aug 2023 11:58:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1B5E16B0074; Fri, 11 Aug 2023 11:58:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0567D6B0078; Fri, 11 Aug 2023 11:58:45 -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 E451E6B0072 for ; Fri, 11 Aug 2023 11:58:44 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id AD9B7A11A7 for ; Fri, 11 Aug 2023 15:58:44 +0000 (UTC) X-FDA: 81112281768.06.7D0D1D6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 7B3E880011 for ; Fri, 11 Aug 2023 15:58:42 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="GOuXqk1/"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691769522; 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=Y47dcoSrlBDE5lrGiXLN0L0KffGDDtLt9u6t3k003Zc=; b=iyY3aXTLWAbnodEyqnsI7NXL3S5RKCToETBWSx+bP6Cjqftogr2bN9jiip16Fdmp2oi3UO AxtDYbkwWyMBthzBdVA5rVAQiYppSqd/5DWlHUxiK+olDnDwQtyuNwJndKjEP2bkwS7mNz AGsZEocSOHdzv2C8n2Zo1KoNnA3kZps= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="GOuXqk1/"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691769522; a=rsa-sha256; cv=none; b=rPDwvc5pQw6b5lL0c3Py5UPM346ZJXp2THitknepJmwiwLGvcsaH6jZXVqD+f3kf4lDx4O 2KZozgprQtOly//Gj2vBYJYsp0ZWgrSLsxe/zOzgl/wiT4yoY8rQQKetdL4zoa5zjJ9ukL 4YXWgTIuKYghmy+Bkp5hH8aHtBwBP5Q= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691769521; 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=Y47dcoSrlBDE5lrGiXLN0L0KffGDDtLt9u6t3k003Zc=; b=GOuXqk1/izYawDZKm5Yp0Rwo8wDqBeHJ6emKL6XZtRWYmk6/+k3k5LoD6WeOMtU3xNSOif mC/YuRKRehD5FnTBPV4kEYWk4MJp9qA+jKaIC3xXMGewXZs7JWJTgaLceFJ6Ny7f/3GCPG GycuC0FR7rHcf9RTBwNWA9g+BcLr1ZQ= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-524-iv8aidmIM4e7tJO-q8ezeg-1; Fri, 11 Aug 2023 11:58:40 -0400 X-MC-Unique: iv8aidmIM4e7tJO-q8ezeg-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-637948b24bdso5714776d6.1 for ; Fri, 11 Aug 2023 08:58:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691769520; x=1692374320; 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=Y47dcoSrlBDE5lrGiXLN0L0KffGDDtLt9u6t3k003Zc=; b=AC4NapgWVNpQhA+KEJip2Sr6htcdE53/4+1Ca34xoHmLB0AnCevhY+WS6jhwOM1V7p RFoyeMdq4EDqIsBJtBxoDfJEtGndRN77aHwax4HqnoMyYagAZENglsMdkIVdiNO7obKH Bj3m50qNanz46ySgGxeJtEI9eUeWMabnO0ZWVCtx9ASVtOC7zIilIpGM4pvNhWxApwJK g4mzw13GgIGBwbICSS7i/mKYqbd6WbeVQ31G6cqIIIJFp7taoQG15qeoFCBFiKBlPEq7 y0cBC4pBJK6xksTC3HRBptbmBR5tkyafO0NuG1fTPWJuahqcCxbwz/cR52u5+pMshwOm Si9Q== X-Gm-Message-State: AOJu0Yz1sEwYq3JErIa9AJaGyxUZNw1eQg2btV1sa1UwvRJysC2ih8JK Gl1S2Fe73UaCrn7+6KDlZCT9jxwA0tvPRr4WkF6bJG26xgRXZbi9lhCDblyNmaLiK6k+vHZmb2b lu2Rwrzli94E= X-Received: by 2002:a05:6214:2421:b0:63c:fd2d:6ff1 with SMTP id gy1-20020a056214242100b0063cfd2d6ff1mr2705577qvb.1.1691769520116; Fri, 11 Aug 2023 08:58:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGmh+Ln/bhOsUI6nAHdOTMNIxEQWZcV99ppmP+3cdaKawAb9QLhtd6tpcaUaVEMHc/etnBvSA== X-Received: by 2002:a05:6214:2421:b0:63c:fd2d:6ff1 with SMTP id gy1-20020a056214242100b0063cfd2d6ff1mr2705559qvb.1.1691769519883; Fri, 11 Aug 2023 08:58:39 -0700 (PDT) Received: from x1n (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id z17-20020a0cf011000000b0063d561ea04csm1289065qvk.102.2023.08.11.08.58.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 08:58:39 -0700 (PDT) Date: Fri, 11 Aug 2023 11:58:38 -0400 From: Peter Xu To: David Hildenbrand Cc: Matthew Wilcox , Ryan Roberts , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, Andrew Morton , Jonathan Corbet , Mike Kravetz , Hugh Dickins , Yin Fengwei , Yang Shi , Zi Yan Subject: Re: [PATCH mm-unstable v1] mm: add a total mapcount for large folios Message-ID: References: <155bd03e-b75c-4d2d-a89d-a12271ada71b@arm.com> <8222bf8f-6b99-58f4-92cc-44113b151d14@redhat.com> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Rspamd-Queue-Id: 7B3E880011 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: ffqmc81wb9yhuzkig6udmps6qrafgz4f X-HE-Tag: 1691769522-253653 X-HE-Meta: U2FsdGVkX1+PKbU48MDpZMp5pZxltlA5vEfTK/+L7paU0krNyAgLizq2qPdqRfIoi7ZDLqdJI/1gn2sVAJCn6r6dq2GpNNMdTiTOSUUtE54xAjSmgNWYKdurWkuizAs/qvLygE8e45S6y81kkHnUdb0R16iv3Qlhx3C4yRPtRc1TzVu5NdJJlYu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QgfoFoCnS2QSQPUroHE17ad3wt3YqkGPEeufJ9TDLIYSuyFQA/YGm7AB1epxj2dgnSEqa5NICQA3KKdXNEGU8Wl645vi2ramPJeU8UR8GndES9o+1w= 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 Fri, Aug 11, 2023 at 05:32:37PM +0200, David Hildenbrand wrote: > On 11.08.23 17:18, Peter Xu wrote: > > On Fri, Aug 11, 2023 at 12:27:13AM +0200, David Hildenbrand wrote: > > > On 10.08.23 23:48, Matthew Wilcox wrote: > > > > On Thu, Aug 10, 2023 at 04:57:11PM -0400, Peter Xu wrote: > > > > > AFAICS if that patch was all correct (while I'm not yet sure..), you can > > > > > actually fit your new total mapcount field into page 1 so even avoid the > > > > > extra cacheline access. You can have a look: the trick is refcount for > > > > > tail page 1 is still seems to be free on 32 bits (if that was your worry > > > > > before). Then it'll be very nice if to keep Hugh's counter all in tail 1. > > > > > > > > No, refcount must be 0 on all tail pages. We rely on this in many places > > > > in the MM. > > > > > > Very right. > > > > Obviously I could have missed this in the past.. can I ask for an example > > explaining why refcount will be referenced before knowing it's a head? > > I think the issue is, when coming from a PFN walker (or GUP-fast), you might > see "oh, this is a folio, let's lookup the head page". And you do that. > > Then, you try taking a reference on that head page. (see try_get_folio()). > > But as you didn't hold a reference on the folio yet, it can happily get > freed + repurposed in the meantime, so maybe it's not a head page anymore. > > So if the field would get reused for something else, grabbing a reference > would corrupt whatever is now stored in there. Not an issue before large folios, am I right? Because having a head page reused as tail cannot happen iiuc with current thps if only pmd-sized, because the head page is guaranteed to be pmd aligned physically. I don't really know, where a hugetlb 2M head can be reused by a 1G huge later right during the window of fast-gup walking. But obviously that's not common either if that could ever happen. Maybe Matthew was referring to something else (per "in many places")? Thanks, -- Peter Xu