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 3F2A8C04A6A for ; Thu, 10 Aug 2023 17:47:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B279B6B0071; Thu, 10 Aug 2023 13:47:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AD8AF6B0072; Thu, 10 Aug 2023 13:47:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9A0B96B0075; Thu, 10 Aug 2023 13:47:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8C5296B0071 for ; Thu, 10 Aug 2023 13:47:43 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3826916011B for ; Thu, 10 Aug 2023 17:47:39 +0000 (UTC) X-FDA: 81108927606.29.A4F0851 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 2DE3C1A000D for ; Thu, 10 Aug 2023 17:47:39 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SFYyteIL; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691689660; 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=oU7y2MwySKI8Jyjp8rHjmRFDUK7yH9mFWODVue0LC6k=; b=SDZZ8ub3pn64BUW/XBcr0Hyr4gb5/0vSNDypzzO63vYBMPz1eeb6aztw+YanDu/Qdu9qQt sr0igu4YnSqxFezJ+bcZCVtkNAWQYbi0wukuwr8HbP5m5EHH66OZQ8uJgqGDzv3YtK1wJs 7Oxv//i/T070AQVDXVUsJJbTU5in1s8= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SFYyteIL; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691689660; a=rsa-sha256; cv=none; b=TM25uadD6pc6bMXfytVvnNAuvlStk9IOg4fMlNyP+K4sUsmPKRD5CjoXK9vxxfeK5/Y9mI JAIRjSuoagomHegLAnrHf4w3ojTAUEE9rbHYBcSgDgma4eB2+X9wXDO8nU4CqmYnEPhyFL 5v6KE5j7HlBm4HeoHnWT6Sp+15Spidc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691689659; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oU7y2MwySKI8Jyjp8rHjmRFDUK7yH9mFWODVue0LC6k=; b=SFYyteIL+5EohknTjuWGow0ZfbvnThKM7H8KZXixnYvJqH32A6B9hSkM66LCq/XLKCLPLR MYhR+wKkg4ljRUhkgDo1o2NdzWAPUdY4KuZBTysjNV8/L5r3hKAR/kzxi9ESNVfAWEgS7J X+Z4HdMSNKpqwboWmEQfqBfJ8nSai+U= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-217-DdMzLFy-MRKLzh3l9YFMhg-1; Thu, 10 Aug 2023 13:47:38 -0400 X-MC-Unique: DdMzLFy-MRKLzh3l9YFMhg-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-317df1add39so721804f8f.3 for ; Thu, 10 Aug 2023 10:47:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691689657; x=1692294457; h=content-transfer-encoding:in-reply-to:subject:organization:from :references:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=oU7y2MwySKI8Jyjp8rHjmRFDUK7yH9mFWODVue0LC6k=; b=YZfK9SC1xdCA2qyqsRhXzNMoFEpINB13kgcwo0Hhcf7GGfyfQxsi4zPSqUJe8WnMKC FFMruvT5kctobIZNF178A/jT3lLW4Kks4NrSQ125jJR8s6S+I7leaQFCyWEDA8pDDaa/ R0qKZqXiueKHqjTeFhZsAeL/G9LvFcZFe85q455q2yLfx+ns/sH3Hrx2OP/VflCO2L8K IaaNiyzWRT4H7Zbgdyz07nv1Ag2j0kG83jM6adNX/LhBnPbgwK35/2lvxz/IloX9IiN2 3MVHuwt4KkmEWxUupP5lo7HoKUhYVNZmoD82iTryuzZ+vUlYI+NsC5BIoT/CA1TfsBin 2X/w== X-Gm-Message-State: AOJu0YyvWZxDb6dhKzxMaewqFXTg+y3/8d1SgkgzpqxVMF5HgJLXdZDZ MB8+U5O7WUVCqHVVPNT3vcmlfcWfUDrni0vDkP/QLSk4S0cF3/9MyK0ekTGoWcbCtONj3jRkULK KtzR39PtGxS8= X-Received: by 2002:a05:6000:1010:b0:317:5ed6:887 with SMTP id a16-20020a056000101000b003175ed60887mr2589672wrx.66.1691689656983; Thu, 10 Aug 2023 10:47:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGd5a43eooBSZBw90DEpfdZTNsoD/ddgvcTiFpWbNXO7eJpBo5l/9LyJ4ZEFkBQfsQWoHPcFg== X-Received: by 2002:a05:6000:1010:b0:317:5ed6:887 with SMTP id a16-20020a056000101000b003175ed60887mr2589655wrx.66.1691689656528; Thu, 10 Aug 2023 10:47:36 -0700 (PDT) Received: from ?IPV6:2003:cb:c71a:8a00:8200:f041:4b87:a8be? (p200300cbc71a8a008200f0414b87a8be.dip0.t-ipconnect.de. [2003:cb:c71a:8a00:8200:f041:4b87:a8be]) by smtp.gmail.com with ESMTPSA id m9-20020a7bce09000000b003fe2120ad0bsm5663845wmc.41.2023.08.10.10.47.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 10 Aug 2023 10:47:36 -0700 (PDT) Message-ID: Date: Thu, 10 Aug 2023 19:47:35 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 To: Peter Xu , Ryan Roberts Cc: 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 References: <20230809083256.699513-1-david@redhat.com> <155bd03e-b75c-4d2d-a89d-a12271ada71b@arm.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH mm-unstable v1] mm: add a total mapcount for large folios In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 2DE3C1A000D X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: n47urfpidmqw46sacmytfoxwm6mx7ebd X-HE-Tag: 1691689659-990646 X-HE-Meta: U2FsdGVkX18et2WA+lgKNUwn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qZ7O8CdkKmsHfAGDttXdxjedTuOIH3rNal/lgprS8a7LwnBSXpd9jA/19sE1ZQOxg/hhiDQcBNCLJ6Wo9dU0AY539/UOyaKKiULRTd9JYdT1h8jxjGVqwhePh/Ioav4bXYPe1YPIcwKH6RsKI+YOOKmf0T7Zvf8LWEu2YoCr7GwRpBQcxroG91cEkvuRhbtmTO3c3g5IE7lwF+iTV59lUMJdiMu2A0yIYRooaXt+uLWz5zfE1BuxRg4ZZDyeXR6i//sRRFf379UNHXn05M0F6EwtmL8mZ/wY9oTGvgniAU/71tiR+YJmo7g8yzcNIBLQKxMxk2BbdjgS1TM/Yfm2jAl/6Qynq0moSJ978KEp5FFstveWjV5ToU9xoeWdulPuYWY/gpR 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 10.08.23 19:15, Peter Xu wrote: > 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? Not in my opinion. Batching rmap makes sense even without this change, and this change makes sense even without batching. > > 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, Okay, so your speculation right now is: 1) The change in cacheline might be problematic. 2) The additional atomic operation might be problematic. > then measure the split (by e.g. mprotect() at offset 1M on a 4K?) time it > takes before/after this patch. I can certainly try getting some numbers on that. If you're aware of other micro-benchmarks that would likely notice slower pte-mapping of THPs, please let me know. > > 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. > I think your math is correct. prep_compound_head() is called after prep_compound_tail(), so prep_compound_head() wins. In __split_huge_page_tail() there is a VM_BUG_ON_PAGE() that explains the situation: /* ->mapping in first and second tail page is replaced by other uses */ VM_BUG_ON_PAGE(tail > 2 && page_tail->mapping != TAIL_MAPPING, page_tail); Thanks for raising that, I had to look into that myself. -- Cheers, David / dhildenb