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 BBE63C6FD1F for ; Thu, 21 Mar 2024 22:08:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3846B6B0082; Thu, 21 Mar 2024 18:08:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 334BA6B0093; Thu, 21 Mar 2024 18:08:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1D5306B0095; Thu, 21 Mar 2024 18:08:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 10B9D6B0082 for ; Thu, 21 Mar 2024 18:08:11 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id CD684A1C94 for ; Thu, 21 Mar 2024 22:08:10 +0000 (UTC) X-FDA: 81922435140.22.4F821F6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf15.hostedemail.com (Postfix) with ESMTP id B9791A000D for ; Thu, 21 Mar 2024 22:08:08 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NsyMRPY3; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.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=1711058888; 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: references:dkim-signature; bh=qBwIOGN4e8d3gKHF9DSbgwYKpkkiYBwtwtMI0MG6X/U=; b=LS2jxbJ7g/xlachLZBu+cT0fntEydwvwbHbkdifPqpH3xhgeoNwVUy9QivOne8nUg1sLgd HhlZFIlh08NJANuZ1Hfv6mR5TKns4M/dZa15ol3AtSn66SWfSZcO4wXK6qw/fdB+zWwtrB cMKof4wHz4LLIXoWSW4RNSC9GOb6sb0= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NsyMRPY3; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711058888; a=rsa-sha256; cv=none; b=fqaKDDIqCbzDSS+F/a9aZtnU0P/0uHo0SSVrg4I4fgKO0fkZkk2tH0/gVb8rVeonFsYMrv QWLXnFCJAPHNAxqeJMPef1qV8JG2kWiYpEcDqtI2hyTL6L/T11RsOjsPxopqZv/xqP8qB7 9I/8OLAbHES1lKo/KjELHKQDl+wkxg0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711058888; 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; bh=qBwIOGN4e8d3gKHF9DSbgwYKpkkiYBwtwtMI0MG6X/U=; b=NsyMRPY35MmFMs6OaKZzO/0NrYb4sN8QgAFToQV8Djz3/ikvMIC522ls8aCqHwaQgmtQgj z/ua5XIymiOlQsIe/B+BkxKKMvnI7mOo24+WirxqlDtf32WfQd4ZlbqOXuW0wtBJO7t/Mc BooJZY8pV1JE2yQVIAs9XorjvINcIKw= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-609-m2EUbC08N5-PWvxX2cY-3Q-1; Thu, 21 Mar 2024 18:08:06 -0400 X-MC-Unique: m2EUbC08N5-PWvxX2cY-3Q-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-69152af7760so3924536d6.1 for ; Thu, 21 Mar 2024 15:08:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711058886; x=1711663686; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qBwIOGN4e8d3gKHF9DSbgwYKpkkiYBwtwtMI0MG6X/U=; b=oBZGDJO7ThouuxNvDR0gQhcFYc4ubKUJdl98vQIS0CAscYgsaehZf32pZL2O22uMuK FTpTte320dShXidzuY4JYWCImgXDcjysoROwEvtOtHCEYpBms1wG5skhpUPLSg7VQWCN OPe4V1zzAZeOtGI0WuIJxA3uS2QD+XJBSaFhOvK5KZr4G3PWZuK03rVzwdVUG1jkeyxx XdIiH2R1dopPlT151W6gl+xuXK60rbw4UrhOP1HEXRgYvdCppJapDN4OnEv90cHKIXCU kT2mbXAKtZUuDM9IAE2aaZQvv3ssLHIm0/+kGSLkqXKFJBpQ1sNHQcQ/KyDRvbR7yxPH R9FQ== X-Gm-Message-State: AOJu0YwQtYVOvw2iBNsgv0pu6e1wdGDUQ5S2mue5DE3oF21sml6+PwpL ZE9XWiwuOajOOIokRpV0+0sBjIYJkhkPC/nc2Ad+FkgILCseGJVBFPxIIdTRLrvszSjP6lytBIO fttdOtwCVS35B2VlMbr39KwrBUwpp35jV++A6pPp+uRAeZC/C46+XDarRhZDvbaZV1be7B2D0IQ ED3SxA0ZcH4nPs5PInR7kF1RQ7QWm/Nw== X-Received: by 2002:a05:6214:4198:b0:695:c55d:fdf8 with SMTP id ld24-20020a056214419800b00695c55dfdf8mr219318qvb.1.1711058885723; Thu, 21 Mar 2024 15:08:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEjJcDDJC7HZiortxxZHWVHGJUJGwG79NEWr9Sr06E8nvFXSb1um5gXNtJQjx6vxfyzbm5MLg== X-Received: by 2002:a05:6214:4198:b0:695:c55d:fdf8 with SMTP id ld24-20020a056214419800b00695c55dfdf8mr219273qvb.1.1711058885190; Thu, 21 Mar 2024 15:08:05 -0700 (PDT) Received: from x1n.redhat.com ([99.254.121.117]) by smtp.gmail.com with ESMTPSA id o6-20020a0562140e4600b00690baf5cde9sm351663qvc.118.2024.03.21.15.08.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 15:08:04 -0700 (PDT) From: peterx@redhat.com To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Christophe Leroy , Matthew Wilcox , Rik van Riel , Lorenzo Stoakes , Axel Rasmussen , peterx@redhat.com, Yang Shi , John Hubbard , linux-arm-kernel@lists.infradead.org, "Kirill A . Shutemov" , Andrew Jones , Vlastimil Babka , Mike Rapoport , Andrew Morton , Muchun Song , Christoph Hellwig , linux-riscv@lists.infradead.org, James Houghton , David Hildenbrand , Jason Gunthorpe , Andrea Arcangeli , "Aneesh Kumar K . V" , Mike Kravetz Subject: [PATCH v3 00/12] mm/gup: Unify hugetlb, part 2 Date: Thu, 21 Mar 2024 18:07:50 -0400 Message-ID: <20240321220802.679544-1-peterx@redhat.com> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: B9791A000D X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 45deqajct8gxct3su5wphc51jicdbngn X-HE-Tag: 1711058888-331017 X-HE-Meta: U2FsdGVk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rZLuzH+rWKUX1nmBWPePK+/js8f+JzRb/iEyIulIPWkth82uVjmMNSqDvWjhq2/msoefFIV0vHYgNySG99gYrcMapSsSI+Td/wYmaYQR/pvZF3hG4moeBA3xVgC1pEzeJF2QTgd8cPoFwwKH0jzlf412YItG2/kiFjO+Cj+J55C8O5Sg3IHNnnNErB2AS8CSKW+ZsdKpee5qRD3AVVP8z+RwfVNmedBuHYPb0Cm8c7ASvjB+3C0087a3tLcGTx++3I7Q8OI3C6nv9XdfUz9E6l/Dm00+bur91MedVQXrZ5qKRM0Syj65c2vy6gUwNRIgy9GdlaYvHxPxhxdvGMy4I/Ys 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: List-Subscribe: List-Unsubscribe: From: Peter Xu v3: - Rebased to latest mm-unstalbe (a824831a082f, of March 21th) - Dropped patch to introduce pmd_thp_or_huge(), replace such uses (and also pXd_huge() users) with pXd_leaf() [Jason] - Add a comment for CONFIG_PGTABLE_HAS_HUGE_LEAVES [Jason] - Use IS_ENABLED() in follow_huge_pud() [Jason] - Remove redundant none pud check in follow_pud_mask() [Jason] rfc: https://lore.kernel.org/r/20231116012908.392077-1-peterx@redhat.com v1: https://lore.kernel.org/r/20231219075538.414708-1-peterx@redhat.com v2: https://lore.kernel.org/r/20240103091423.400294-1-peterx@redhat.com The series removes the hugetlb slow gup path after a previous refactor work [1], so that slow gup now uses the exact same path to process all kinds of memory including hugetlb. For the long term, we may want to remove most, if not all, call sites of huge_pte_offset(). It'll be ideal if that API can be completely dropped from arch hugetlb API. This series is one small step towards merging hugetlb specific codes into generic mm paths. From that POV, this series removes one reference to huge_pte_offset() out of many others. One goal of such a route is that we can reconsider merging hugetlb features like High Granularity Mapping (HGM). It was not accepted in the past because it may add lots of hugetlb specific codes and make the mm code even harder to maintain. With a merged codeset, features like HGM can hopefully share some code with THP, legacy (PMD+) or modern (continuous PTEs). To make it work, the generic slow gup code will need to at least understand hugepd, which is already done like so in fast-gup. Due to the specialty of hugepd to be software-only solution (no hardware recognizes the hugepd format, so it's purely artificial structures), there's chance we can merge some or all hugepd formats with cont_pte in the future. That question is yet unsettled from Power side to have an acknowledgement. As of now for this series, I kept the hugepd handling because we may still need to do so before getting a clearer picture of the future of hugepd. The other reason is simply that we did it already for fast-gup and most codes are still around to be reused. It'll make more sense to keep slow/fast gup behave the same before a decision is made to remove hugepd. There's one major difference for slow-gup on cont_pte / cont_pmd handling, currently supported on three architectures (aarch64, riscv, ppc). Before the series, slow gup will be able to recognize e.g. cont_pte entries with the help of huge_pte_offset() when hstate is around. Now it's gone but still working, by looking up pgtable entries one by one. It's not ideal, but hopefully this change should not affect yet on major workloads. There's some more information in the commit message of the last patch. If this would be a concern, we can consider teaching slow gup to recognize cont pte/pmd entries, and that should recover the lost performance. But I doubt its necessity for now, so I kept it as simple as it can be. Test Done ========= For x86_64, tested full gup_test matrix over 2MB huge pages. For aarch64, tested the same over 64KB cont_pte huge pages. One note is that this v3 didn't go through any ppc test anymore, as finding such system can always take time. It's based on the fact that it was tested in previous versions, and this version should have zero change regarding to hugepd sections. If anyone (Christophe?) wants to give it a shot on PowerPC, please do and I would appreciate it: "./run_vmtests.sh -a -t gup_test" should do well enough (please consider [2] applied if hugepd is <1MB), as long as we're sure the hugepd pages are touched as expected. Patch layout ============= Patch 1-8: Preparation works, or cleanups in relevant code paths Patch 9-11: Teach slow gup with all kinds of huge entries (pXd, hugepd) Patch 12: Drop hugetlb_follow_page_mask() More information can be found in the commit messages of each patch. Any comment will be welcomed. Thanks. [1] https://lore.kernel.org/all/20230628215310.73782-1-peterx@redhat.com [2] https://lore.kernel.org/r/20240321215047.678172-1-peterx@redhat.com Peter Xu (12): mm/Kconfig: CONFIG_PGTABLE_HAS_HUGE_LEAVES mm/hugetlb: Declare hugetlbfs_pagecache_present() non-static mm: Make HPAGE_PXD_* macros even if !THP mm: Introduce vma_pgtable_walk_{begin|end}() mm/gup: Drop folio_fast_pin_allowed() in hugepd processing mm/gup: Refactor record_subpages() to find 1st small page mm/gup: Handle hugetlb for no_page_table() mm/gup: Cache *pudp in follow_pud_mask() mm/gup: Handle huge pud for follow_pud_mask() mm/gup: Handle huge pmd for follow_pmd_mask() mm/gup: Handle hugepd for follow_page() mm/gup: Handle hugetlb in the generic follow_page_mask code include/linux/huge_mm.h | 25 +-- include/linux/hugetlb.h | 16 +- include/linux/mm.h | 3 + mm/Kconfig | 6 + mm/gup.c | 354 +++++++++++++++++++++++++++++++++------- mm/huge_memory.c | 133 +-------------- mm/hugetlb.c | 75 +-------- mm/internal.h | 7 +- mm/memory.c | 12 ++ 9 files changed, 337 insertions(+), 294 deletions(-) -- 2.44.0