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 DBD19C4332F for ; Thu, 10 Nov 2022 16:58:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2806A6B0071; Thu, 10 Nov 2022 11:58:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 208AB6B0072; Thu, 10 Nov 2022 11:58:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0AA406B0074; Thu, 10 Nov 2022 11:58:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E81526B0071 for ; Thu, 10 Nov 2022 11:58:22 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B78CA1402A2 for ; Thu, 10 Nov 2022 16:58:22 +0000 (UTC) X-FDA: 80118140844.10.69129E1 Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) by imf18.hostedemail.com (Postfix) with ESMTP id 4D7C91C0005 for ; Thu, 10 Nov 2022 16:58:21 +0000 (UTC) Received: by mail-qk1-f170.google.com with SMTP id z17so1438861qki.11 for ; Thu, 10 Nov 2022 08:58:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=0PcjM7Qx8NCGxX+37pMucCBResM/T5j/rL0qDgsxmxo=; b=GU5BzO5E1+Cms1HYFBdUrm1Y5OvAAUG4KFQcbS5w0UjAygwbAQajcCUP8Pq2JUKYdh /g5abIY/j/2ZzkZ16EAAI3XcK6IBhJL1xAeUkNvtdNLcs/kpHjqkXcS8ze7RhW9veGvP a9RDzAb+CeBzGB1tg24Ku+X8S9jQ0TV1Ft4os= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=0PcjM7Qx8NCGxX+37pMucCBResM/T5j/rL0qDgsxmxo=; b=x+Av84i5Sy0/5vsTwPWSb/x3uDktDrkEhxR9+fF3asD/c6NUBsuOxT2Z9Xzbmel2e5 FxgFWXaHJoONc6s+/B3McZsB+q/3HrrmNJitlTygyeggtv2c2gK+kTPeCwOapV65JmdK JGJktw5eCEEV0L9rZjh6iGVoW6CLuqP9h8avhpxXn25U8rNhRCrsZpHkkwxXDgpT3fde ye49xc9Ml45jHlVeZnbwqkJ+1k11DO7oFb+noudQ8TKkes2JWvPiXn9IvQjdwf2n1HfD KrmkeGOV6+oQvqsYaZB+RCbtxyk8yy4G/9Iy4jDCv0noHz8FyFOhstQwHuwUbB94yMWc VgOg== X-Gm-Message-State: ACrzQf0466xXG+OqokGaaTGUVWx612nhcJcgVBB00opXiBif/x2tVjNC GWQ0z1HPIG22V+w8+QK/JHq7a0ScxA/wfA== X-Google-Smtp-Source: AMsMyM5aHGeuOgegocBmxsgXhqqSCb6FJELbPGk4hzVeJF20elqFsU4ntZPU4CJiwLmjs7VJ5siNSQ== X-Received: by 2002:a37:5586:0:b0:6fa:d64:c018 with SMTP id j128-20020a375586000000b006fa0d64c018mr1420106qkb.145.1668099500155; Thu, 10 Nov 2022 08:58:20 -0800 (PST) Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com. [209.85.219.169]) by smtp.gmail.com with ESMTPSA id bk32-20020a05620a1a2000b006cec8001bf4sm13316551qkb.26.2022.11.10.08.58.17 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 10 Nov 2022 08:58:18 -0800 (PST) Received: by mail-yb1-f169.google.com with SMTP id o70so3000222yba.7 for ; Thu, 10 Nov 2022 08:58:17 -0800 (PST) X-Received: by 2002:a05:6902:124f:b0:66e:e3da:487e with SMTP id t15-20020a056902124f00b0066ee3da487emr66657978ybu.310.1668099497288; Thu, 10 Nov 2022 08:58:17 -0800 (PST) MIME-Version: 1.0 References: <5f52de70-975-e94f-f141-543765736181@google.com> In-Reply-To: From: Linus Torvalds Date: Thu, 10 Nov 2022 08:58:01 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 4/3] mm,thp,rmap: handle the normal !PageCompound case first To: Matthew Wilcox Cc: Hugh Dickins , Andrew Morton , Johannes Weiner , "Kirill A. Shutemov" , David Hildenbrand , Vlastimil Babka , Peter Xu , Yang Shi , John Hubbard , Mike Kravetz , Sidhartha Kumar , Muchun Song , Miaohe Lin , Naoya Horiguchi , Mina Almasry , James Houghton , "Zach O'Keefe" , linux-kernel@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=google header.b=GU5BzO5E; spf=pass (imf18.hostedemail.com: domain of torvalds@linuxfoundation.org designates 209.85.222.170 as permitted sender) smtp.mailfrom=torvalds@linuxfoundation.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668099501; a=rsa-sha256; cv=none; b=tU0XfMo4fSB4TDVJvm3dkXty/Yp8Oal8UC3x7NXCfnJIhrTT9I5csp1RIZzwJshqaEXGVq 4qx9ByYbdI1LlbKA1aI9dtgRlICfOE4xsga/VhAk53N6ioyrkHCRpWV67zpdfV3yMJzhyx UxyUhpByy+Yu+n19vzVcqJO0D0M2O64= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668099501; 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=0PcjM7Qx8NCGxX+37pMucCBResM/T5j/rL0qDgsxmxo=; b=Zg99+NhIRp6DWa2YL3+sfwn5YzSi5hu+M5IKgzvAjgO9UavGsgd/GXiimlWN7g/EQUqotu K3iNtxhUV96udCmU9popE44oSadZSd4BxMG1Cjs9ceLm7Fq8ifqLY9un2pbK+WhS+c20CM OjR+ZjZvkfWhOl7/W8y/nlzhgw8OGJY= X-Stat-Signature: n3p7sd5h6amy8e7c65hk8xc9cj67m3ih X-Rspamd-Queue-Id: 4D7C91C0005 Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=google header.b=GU5BzO5E; spf=pass (imf18.hostedemail.com: domain of torvalds@linuxfoundation.org designates 209.85.222.170 as permitted sender) smtp.mailfrom=torvalds@linuxfoundation.org; dmarc=none X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1668099501-491089 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, Nov 10, 2022 at 8:31 AM Matthew Wilcox wrote: > > Ah. I've been trying to understand what that 'compound' really means, > and what the difference is to 'PageCompound()' and why we need both. Yeah, so the 'why' is: (a) to distinguish the case of "I'm mapping the first sub-page of a compound page as a _single_ page page entry in the pte" from "I'm mapping the whole compound/THP/HUGETLB page as a pmd" The actual 'page' pointer can be the same in both cases, so you can't tell from that: PageCompound() will be true in both cases. Of course, sometimes you *can* tell from the page pointer too (eg the HUGETLB case can never be mapped as a small page), but not always. (b) because we do completely different things from a page locking and statistics standpoint for the two cases. That (b) is obviously related to (a), but it's effectively the main reason why rmap needs to be able to tell the difference in the first place. > HugeTLB pages _are_ marked as Compound. Oh, ok. It's not clear why they would be, and historically I don't think they were, but I guess it's for random implementation details (probably to look up the head page logic). > There's some fairly horrific > code to manually make them compound when they have to be allocated > piecemeal (because they're 1GB and too large for the page allocator). Yeah, the HUGETLB case is a mess these days, but it made sense historically, because it was a much simpler thing than the THP pages that have all the fragmentation cases. Now that we handle pmd-sized pages anyway, the HUGETLB case is mostly just a nasty oddity, but we obviously also do the pud case with HUGETLB. And who knows what ia64 did with its completely random page-size thing. I don't even want to think about it, and thankfully these days I don't feel like I need to care any more ;) > > To make things more confusing, some places use PageHeadHuge() > > instead (but the folio version of said test is called > > "folio_test_hugetlb()", just so that nobody could possibly ever accuse > > the HUGETLB code to have consistency). > > That one's my fault, but it's a reaction to all the times that I and > others have got confused between PageHuge and PageTransHuge. I suppose > we could do a big sed s/PageHuge/PageHugeTLB/, but I'm hopeful the > entire hugetlb codebase is either converted to folios or unified with > THP handling. Yeah, it would be lovely to make HUGETLB some THP special case some day. Linus