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 6A673C001B0 for ; Thu, 10 Aug 2023 17:15:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D09756B0071; Thu, 10 Aug 2023 13:15:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CB9936B0072; Thu, 10 Aug 2023 13:15:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B816B6B0075; Thu, 10 Aug 2023 13:15:42 -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 A7E0C6B0071 for ; Thu, 10 Aug 2023 13:15:42 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 6767A160866 for ; Thu, 10 Aug 2023 17:15:38 +0000 (UTC) X-FDA: 81108846924.02.F509FD9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 127EE1C0009 for ; Thu, 10 Aug 2023 17:15:39 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SfN3muai; spf=pass (imf18.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=1691687740; 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=uwwHD8VGaiWAT/OeGl9cbv1dKygcTMDJVAfWo13hyco=; b=mNLUOxJCyacKPEBerLxm+7uYeIy3+rEK/YmZilK+WJnx3X1Z7pWDKQMj0emNhIbLe04Hzh rn5mdJtMHaoshTJHz0USdJgz2sio0azrFejWiM0+imfiATDqdVkWucOl5FIWDx8H/aZc55 AcY1csCUtgaoGTX6InQqMXaIrWrBcVM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691687740; a=rsa-sha256; cv=none; b=ugTwPE7JejBLEtSR3Lxo6NaG9HK4q8RR8etjweWPUlXUBkTGFBSmJ3/Iyk+W+vKR9ir5+L rFKIbD2U+5ZcIRQrzhGTLRMTJRFuxFH/EScNOeh8QzZQ3vhj/NZfPY3Ri/iL/YtuXAwChz IHWFHVdKPwfkFOTMR3fFZa6v8ZDk50w= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SfN3muai; spf=pass (imf18.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=1691687739; 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=uwwHD8VGaiWAT/OeGl9cbv1dKygcTMDJVAfWo13hyco=; b=SfN3muaiBeekgj7NeN56QDrMiqgo3yxxbec37ztPEgoEmPpWaeK2Ks856RDxKC1B7xq4p+ ntFb/frA1+IWi6Az4GNN0ALwp726ujTGzQAzYtxVq5u5UpG+b513G+y/MC8qKIuFJpKEe1 OVON4JIMP82ZdCHSuj7ebleIv9QiBpo= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-398-9GIoKIDePtaPMA64FvGOgQ-1; Thu, 10 Aug 2023 13:15:36 -0400 X-MC-Unique: 9GIoKIDePtaPMA64FvGOgQ-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-4059b5c3dd0so2853261cf.0 for ; Thu, 10 Aug 2023 10:15:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691687736; x=1692292536; 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=uwwHD8VGaiWAT/OeGl9cbv1dKygcTMDJVAfWo13hyco=; b=QD+BBllKSVQyVuDJG+XTyU3PF1p3Wgb/93AlrveVqKBkEJ65+V1M7eL0nUGo77Kb2P gWNonrMX9JJo2X4IUNIkrA3GdaNcSDB34EpeqJz/k2mk9nYjLRvnhGoQIoHtmeitE3xU 2T7mR3Y6dvj8oUTXxNDpSgbe2o0852DWNwF9QfUTGUaABTSp2rmLhd1T30vNRWxxdPgR Lt+z4bAZiqTPD2mSBhZiK/4hTbYN9DGt8BRemqySFi8YzXzxXa6qjEr886PIvbuK1/di ZLel5ZFxq0L8bq/curHLf1vnlyEF7sxDnQ5eo/KXl8ecHZSl/PUTpzgI+a3hfpanQCte /Q3g== X-Gm-Message-State: AOJu0YyknBCsdQekmW9ugbaQ7dAUan+oX8sXePkqkr+gqyTsWSq6cXWF GSFt0PE2D83+Bn/hJibh2Zb7w4N9pZE7a9hesOObKgvO5I7w/+yC90B795lWVOwewGq81XRdPUj dRKa/WNI0hsA= X-Received: by 2002:a05:622a:1988:b0:40f:da40:88a with SMTP id u8-20020a05622a198800b0040fda40088amr3472008qtc.4.1691687735818; Thu, 10 Aug 2023 10:15:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFOvLflZLhzqs/o1dFdKrDK86gwB1luRyxfHHC4XYJOKYPj1zHGYvpz0bPlj5yUP7dvujle3w== X-Received: by 2002:a05:622a:1988:b0:40f:da40:88a with SMTP id u8-20020a05622a198800b0040fda40088amr3471988qtc.4.1691687735565; Thu, 10 Aug 2023 10:15:35 -0700 (PDT) Received: from x1n ([2605:8d80:6a3:cb2:d8d8:cd75:7bfe:b6d7]) by smtp.gmail.com with ESMTPSA id d18-20020ac81192000000b00403ff38d855sm623720qtj.4.2023.08.10.10.15.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 10:15:35 -0700 (PDT) Date: Thu, 10 Aug 2023 13:15:32 -0400 From: Peter Xu To: Ryan Roberts Cc: David Hildenbrand , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, Andrew Morton , Jonathan Corbet , Mike Kravetz , Hugh Dickins , "Matthew Wilcox (Oracle)" , 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> <155bd03e-b75c-4d2d-a89d-a12271ada71b@arm.com> MIME-Version: 1.0 In-Reply-To: <155bd03e-b75c-4d2d-a89d-a12271ada71b@arm.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Stat-Signature: ap9q5r3qzmjbr31fq1jubeapwia9bhgk X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 127EE1C0009 X-Rspam-User: X-HE-Tag: 1691687739-711693 X-HE-Meta: U2FsdGVkX1+ifTVyxUQBYI0XbvBEmcprJ9CfB2QIK6dh3SIXN3V+W+afMb4FZtAWyJuqQqDTHlP67e2cw0oVbBHStYgoX5NJVPklmjQtqF5fNAjUxCmm+x6mSBnqXMgC6ZfqGyGin9sih6kAm47QhTvwwMaoox/Hnn0Z5TqUJz/6PLFRhJ8epAh80lMNHRIorTla9FEJTzpCdD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B6O9KApwNUuZqyoL8TU0DpZChQvFn8F+dm6JbCH6cbTdBBwvHNYWSKgkTRIEI9wk0HaHdvkcTPQ6GN9/PmspDLO0ibtSLNJQqwaQ/RtG0qjmcSsgFoiFt/rJnEzbp11hWtv+W++BjJ5IL2RylHaj3txC+waRPVfypo+SKI6U3XTx6b9jO5F4B5GVrkc= 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 11:48:27AM +0100, Ryan Roberts wrote: > > For PTE-mapped THP, it might be a bit bigger noise, although I doubt it is > > really significant (judging from my experience on managing PageAnonExclusive > > using set_bit/test_bit/clear_bit when (un)mapping anon pages). > > > > As folio_add_file_rmap_range() indicates, for PTE-mapped THPs we should be > > batching where possible (and Ryan is working on some more rmap batching). > > Yes, I've just posted [1] which batches the rmap removal. That would allow you > to convert the per-page atomic_dec() into a (usually) single per-large-folio > atomic_sub(). > > [1] https://lore.kernel.org/linux-mm/20230810103332.3062143-1-ryan.roberts@arm.com/ Right, that'll definitely make more sense, thanks for the link; I'd be very happy to read more later (finally I got some free time recently..). But then does it mean David's patch can be attached at the end instead of proposed separately and early? I was asking mostly because I read it as a standalone patch first, and honestly I don't know the effect. It's based on not only the added atomic ops itself, but also the field changes. For example, this patch moves Hugh's _nr_pages_mapped into the 2nd tail page, I think it means for any rmap change of any small page of a huge one we'll need to start touching one more 64B cacheline on x86. I really have no idea what does it mean for especially a large SMP: see 292648ac5cf1 on why I had an impression of that. But I've no enough experience or clue to prove it a problem either, maybe would be interesting to measure the time needed for some pte-mapped loops? E.g., something like faulting in a thp, then measure the split (by e.g. mprotect() at offset 1M on a 4K?) time it takes before/after this patch. When looking at this, I actually found one thing that is slightly confusing, not directly relevant to your patch, but regarding the reuse of tail page 1 on offset 24 bytes. Current it's Hugh's _nr_pages_mapped, and you're proposing to replace it with the total mapcount: atomic_t _nr_pages_mapped; /* 88 4 */ Now my question is.. isn't byte 24 of tail page 1 used for keeping a poisoned mapping? See prep_compound_tail() where it has: p->mapping = TAIL_MAPPING; While here mapping is, afaict, also using offset 24 of the tail page 1: struct address_space * mapping; /* 24 8 */ I hope I did a wrong math somewhere, though. -- Peter Xu