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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3B214C3DA63 for ; Tue, 23 Jul 2024 08:19:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=e7cAW2e9eTq2PNCKhGWDYhlkj3Xk8nGIpFjirqjv88A=; b=mo35QF6gEGKoWhfeP0fkS6goY6 HUVnNzAkI8OQamPpGlS2/jOQJL/Pi4v7qKQIesjXg1xkdlP2g/gR9pKCsdLoqgUn26LYKSgN3L2rc zk5uFPbWuI5nyo7RA44W4MmiboIx1tpF730ZAlZSrmDW2K4eS+ZjAZB61GRXvUK0zYRH0XfO4A+DK ub1lZljVEw4fHmjn1W6styCMjb6+cp8M9z68G3s3QkNMfGw7lxL7qDlvDp+qmuK4VoUOv3H3VP2/B 7p+iNoarzKvKHMV0oVdZ9W1oktacko2/FkztdhfhBEqqUK6kYa3JgopEOBe0Eek8ppygb+mmN+jRz SY3fc/EA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sWAjk-0000000BpF1-1tJP; Tue, 23 Jul 2024 08:19:08 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sWAjM-0000000Bp8O-3P06 for linux-arm-kernel@lists.infradead.org; Tue, 23 Jul 2024 08:18:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721722723; 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:autocrypt:autocrypt; bh=e7cAW2e9eTq2PNCKhGWDYhlkj3Xk8nGIpFjirqjv88A=; b=SY+vCyBih68++XuOfZuju/LUfNt2eutuAzy/Zlp4wihmtXW+0uz5mX2czAgIiaoc4tV1Vn 9d0bJj6luD3qRjcinecFYR9AvM6GPNMigmkky/ApOqqQQlYfEWT64TKUlDxXA0I+dCL9My exBp0QOwP+dbUeVtdZnxI2ov90UbZa0= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-246-gzL-gE76OiGzu08Tilu4Ww-1; Tue, 23 Jul 2024 04:18:41 -0400 X-MC-Unique: gzL-gE76OiGzu08Tilu4Ww-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-42725ef39e2so37503795e9.0 for ; Tue, 23 Jul 2024 01:18:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721722720; x=1722327520; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=e7cAW2e9eTq2PNCKhGWDYhlkj3Xk8nGIpFjirqjv88A=; b=IA/OrcPbJf+NyFavszb7W9imFWLA83yEfiAsgFhNLi1rLphqXHT3u5OwXjvJLUYpnd T9QysFh6kJzPfcA9DeP2pamvXdUw5mS4gUfJphree4xMnfivYwbZ9PnoxGrDn7gF1vVh B869ZtDi1XxI3RoV9hZZgWwZYzxvWryTgD44OazJ8lrBnECCQ1l9dcugyfOFU/v760Y3 P74vLtSTfItkANo5CIjWG9YY/xOWhTPansqQOTuYfHjbL73vqiM7qEVefLOdzyFz8AvZ +ER+YpbxJkErL5PjvHhgnagU3ZSrsieMkBpOgOkbWpARm7bvOL1xbtofXh9oXAua+mUj yhFw== X-Forwarded-Encrypted: i=1; AJvYcCWYN01H61hUErMSMCWR0S3xnvtECy01Y03P8l5RwpqCDOF2FZZkbHDbSTIIj3iOhimS+/S2EWMdF1G2nP/3faVVqHUCqRyu85deLQ8DHfSpXQEGucc= X-Gm-Message-State: AOJu0YzT7szvVKm0ZJd7Rm3qYVRXxaB6UJcwArCVUOpfEi1Eu/72J+w8 WgSFkB0fgBtkR7WAfR8Lk5PwGImaBOcr62NuXNT1VxnjbXwEb7c6QE8vB+7JfGmg49p6Pox5vPh lwULTzrvisTry6pkm6cB7vBrLnk9J4ldMWJkUiGX+uYkJh2jeFp6IMs7IgBqkYLM3jDja8ymLqZ 8Hwph1 X-Received: by 2002:a05:600c:500f:b0:426:6326:4cec with SMTP id 5b1f17b1804b1-427df7a7828mr59109975e9.29.1721722720305; Tue, 23 Jul 2024 01:18:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFUWHnl+IF1Uo0ddKTvKJTZa1BJHPgCl9dGzav/h00NQB9OiTQfs5h5kD6cvqR3xzQXjLrG9w== X-Received: by 2002:a05:600c:500f:b0:426:6326:4cec with SMTP id 5b1f17b1804b1-427df7a7828mr59109795e9.29.1721722719834; Tue, 23 Jul 2024 01:18:39 -0700 (PDT) Received: from ?IPV6:2003:cb:c72f:ed00:9dc2:1adb:d133:4434? (p200300cbc72fed009dc21adbd1334434.dip0.t-ipconnect.de. [2003:cb:c72f:ed00:9dc2:1adb:d133:4434]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d6929827sm160330615e9.34.2024.07.23.01.18.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Jul 2024 01:18:39 -0700 (PDT) Message-ID: Date: Tue, 23 Jul 2024 10:18:37 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RFC 0/6] mm: THP-agnostic refactor on huge mappings To: Peter Xu Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Vlastimil Babka , Oscar Salvador , linux-s390@vger.kernel.org, Andrew Morton , Matthew Wilcox , Dan Williams , Michal Hocko , linux-riscv@lists.infradead.org, sparclinux@vger.kernel.org, Alex Williamson , Jason Gunthorpe , x86@kernel.org, Alistair Popple , linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, Ryan Roberts , Hugh Dickins , Axel Rasmussen References: <20240717220219.3743374-1-peterx@redhat.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmr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pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240723_011844_967961_94B60BB6 X-CRM114-Status: GOOD ( 38.09 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 22.07.24 17:31, Peter Xu wrote: > On Mon, Jul 22, 2024 at 03:29:43PM +0200, David Hildenbrand wrote: >> On 18.07.24 00:02, Peter Xu wrote: >>> This is an RFC series, so not yet for merging. Please don't be scared by >>> the code changes: most of them are code movements only. >>> >>> This series is based on the dax mprotect fix series here (while that one is >>> based on mm-unstable): >>> >>> [PATCH v3 0/8] mm/mprotect: Fix dax puds >>> https://lore.kernel.org/r/20240715192142.3241557-1-peterx@redhat.com >>> >>> Overview >>> ======== >>> >>> This series doesn't provide any feature change. The only goal of this >>> series is to start decoupling two ideas: "THP" and "huge mapping". We >>> already started with having PGTABLE_HAS_HUGE_LEAVES config option, and this >>> one extends that idea into the code. >>> >>> The issue is that we have so many functions that only compile with >>> CONFIG_THP=on, even though they're about huge mappings, and huge mapping is >>> a pretty common concept, which can apply to many things besides THPs >>> nowadays. The major THP file is mm/huge_memory.c as of now. >>> >>> The first example of such huge mapping users will be hugetlb. We lived >>> until now with no problem simply because Linux almost duplicated all the >>> logics there in the "THP" files into hugetlb APIs. If we want to get rid >>> of hugetlb specific APIs and paths, this _might_ be the first thing we want >>> to do, because we want to be able to e.g., zapping a hugetlb pmd entry even >>> if !CONFIG_THP. >>> >>> Then consider other things like dax / pfnmaps. Dax can depend on THP, then >>> it'll naturally be able to use pmd/pud helpers, that's okay. However is it >>> a must? Do we also want to have every new pmd/pud mappings in the future >>> to depend on THP (like PFNMAP)? My answer is no, but I'm open to opinions. >>> >>> If anyone agrees with me that "huge mapping" (aka, PMD/PUD mappings that >>> are larger than PAGE_SIZE) is a more generic concept than THP, then I think >>> at some point we need to move the generic code out of THP code into a >>> common code base. >>> >>> This is what this series does as a start. >> >> Hi Peter! >> >> From a quick glimpse, patch #1-#4 do make sense independent of patch #5. >> >> I am not so sure about all of the code movement in patch #5. If large folios >> are the future, then likely huge_memory.c should simply be the home for all >> that logic. >> >> Maybe the goal should better be to compile huge_memory.c not only for THP, >> but also for other use cases that require that logic, and fence off all THP >> specific stuff using #ifdef? >> >> Not sure, though. But a lot of this code movements/churn might be avoidable. > > I'm fine using ifdefs in the current fine, but IMHO it's a matter of > whether we want to keep huge_memory.c growing into even larger file, and > keep all large folio logics only in that file. Currently it's ~4000 LOCs. Depends on "how much" for sure. huge_memory.c is currently on place 12 of the biggest files in mm/. So there might not be immediate cause for action ... just yet :) [guess which file is on #2 :) ] > > Nornally I don't see this as much of a "code churn" category, because it > doesn't changes the code itself but only move things. I personally also > prefer without code churns, but only in the case where there'll be tiny > little functional changes here and there without real benefit. > > It's pretty unavoidable to me when one file grows too large and we'll need > to split, and in this case git doesn't have a good way to track such > movement.. Yes, that's what I mean. I've been recently thinking if we should pursue a different direction: Just as we recently relocated most follow_huge_* stuff into gup.c, likely we should rather look into moving copy_huge_pmd, change_huge_pmd, copy_huge_pmd ... into the files where they logically belong to. In madvise.c, we've been doing that in some places already: For madvise_cold_or_pageout_pte_range() we inline the code, but not for madvise_free_huge_pmd(). pmd_trans_huge() would already compile to a NOP without CONFIG_TRANSPARENT_HUGEPAGE, but to make that code avoid most CONFIG_TRANSPARENT_HUGEPAGE, we'd need a couple more function stubs to make the compiler happy while still being able to compile that code out when not required. The idea would be that e.g., pmd_leaf() would return "false" at compile time if no active configuration (THP, HUGETLB, ...) would be active. So we could just use pmd_leaf() similar to pmd_trans_huge() in relevant code and have the compiler optimize it all out without putting it into separate files. That means, large folios and PMD/PUD mappings will become "more common" and better integrated, without the need to jump between files. Just some thought about an alternative that would make sense to me. > > Irrelevant of this, just to mention I think there's still one option that I > at least can make the huge pfnmap depends on THP again which shouldn't be a > huge deal (I don't have any use case that needs huge pfnmap but disable > THP, anyway..), so this series isn't an immediate concern to me for that > route. But for a hugetlb rework this might be something we need to do, > because we simplly can't make CONFIG_HUGETLB rely on CONFIG_THP.. Yes, likely. FSDAX went a similar direction and called that FSDAX thing a "THP" whereby it really doesn't have anything in common with a THP, besides being partially mappable -- IMHO. -- Cheers, David / dhildenb