From patchwork Tue Dec 19 07:55:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13497956 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 2C89BC46CD2 for ; Tue, 19 Dec 2023 07:56: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: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=biJ9DoQ5wpkJiX8R2z0J3y6uDyrlZayttUUnmd7qCDA=; b=A/LcQzSqxQSBHO FGSjSV5AizZVWcQs0V4qxUbaEBi9Yi1MkxU6DBudseUJigtJvNXaDv8tUB6tiSq0tnfrCtYOhWs6k tXvZVuwxej0GipGQGMVdSd0+A3oFA54CSE9EHapSNrthydMRyCoQX5RDxu+kJg8UPiWBGT5/ZOVhc IG4fX9GslteXwi+pfDOCQ8WEgN/Vx6Xh2CjNQoFCSmxmzJbJUS3FjNA1NOIVsZp0qJC2eUwao7VC3 CFEnh7gWtlYSRBtL2vHfzRIadmuD/SibPRouaTTlT9Pm7IpqySyqiZwZK1lolTYiE9GWX3BtHz91Y Gv2ePn9kwUKsyPMamDSg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rFUxO-00DAcZ-2e; Tue, 19 Dec 2023 07:56:02 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rFUxK-00DAZN-1d for linux-arm-kernel@lists.infradead.org; Tue, 19 Dec 2023 07:56:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702972556; 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=+h83lLyn/5apLRr4X1Iml0TGvxqR5/pwpG6+wMVRoO8=; b=XR8GUsaluDchgruKmarqBEqjW3Wqmhwn4GplqLYMVIMv0CFAKTWmyjaZJ4QLKt6Y03shFw 5SPz1ofzy3xk0tM53bvNAgaXdpVWJxzfVMba7MLpXt7SgdL9i/0dCMaKKz9fVEpw8TaBHi XD0l0+6cK3iff/FxWtQuYwIL0K3Oa2w= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-460-78fty2BGN2uAAfrfPZNG0g-1; Tue, 19 Dec 2023 02:55:53 -0500 X-MC-Unique: 78fty2BGN2uAAfrfPZNG0g-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 065E63C025C1; Tue, 19 Dec 2023 07:55:52 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 83B262026D66; Tue, 19 Dec 2023 07:55:40 +0000 (UTC) From: peterx@redhat.com To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Matthew Wilcox , Christophe Leroy , Lorenzo Stoakes , David Hildenbrand , Vlastimil Babka , Mike Kravetz , Mike Rapoport , Christoph Hellwig , John Hubbard , Andrew Jones , linux-arm-kernel@lists.infradead.org, Michael Ellerman , "Kirill A . Shutemov" , linuxppc-dev@lists.ozlabs.org, Rik van Riel , linux-riscv@lists.infradead.org, Yang Shi , James Houghton , "Aneesh Kumar K . V" , Andrew Morton , Jason Gunthorpe , Andrea Arcangeli , peterx@redhat.com, Axel Rasmussen Subject: [PATCH 00/13] mm/gup: Unify hugetlb, part 2 Date: Tue, 19 Dec 2023 15:55:25 +0800 Message-ID: <20231219075538.414708-1-peterx@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231218_235558_620207_E4C5D901 X-CRM114-Status: GOOD ( 19.82 ) 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 From: Peter Xu This is v1 of the series. 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 handle all kinds of memory including hugetlb. It's based on latest mm-unstalbe (c13bdc82ada9). RFC->v1 (use old verion's patch index): - Fix build for !THP and/or !HUGETLB - Fix a bug in the hugepd path that can cause a loop - patch 3: - Rename to "Make HPAGE_PXD_* macros visible even if !THP" [Christoph, MikeR] - patch 5: - Posted separately as a devmap bugfix - patch 6: - Add a comment above gup_huge_pd() explaining the file folio writeback issue, with references when anyone would extend hugepd to other types of file memories [Christoph] - patch 7: - Keep parameter name as "page" in record_subpages(), modify the commit message by removing any assumption on head page. [Matthew] - patch 12: - Rename to: "mm/gup: handle hugetlb in the generic follow_page_mask code" [Christoph] - Added patch: - "mm/Kconfig: CONFIG_PGTABLE_HAS_HUGE_LEAVES", this helps to fix build for !THP and/or !HUGETLB - Added patch - "mm/gup: Cache *pudp in follow_pud_mask()", as suggested by Christoph For the long term, this 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. To make it work, the generic code will need to at least understand hugepd, which is already done like so in fast-gup. Fortunately it seems that's the only major thing I need to teach slow GUP to share the common path for now besides normal huge PxD entries. Non-gup can be more challenging, but that's a question for later. 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 cont entries with the help of huge_pte_offset(). 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 ========= This v1 went through the normal GUP smoke tests over different memory types on archs (using VM instances): x86_64, aarch64, ppc64le. For aarch64, tested over 64KB cont_pte huge pages. For ppc64le, tested over 16MB hugepd entries (Power8 hash MMU on 4K base page size). Patch layout ============= Patch 1-7: Preparation works, or cleanups in relevant code paths Patch 8-12: Teach slow gup with all kinds of huge entries (pXd, hugepd) Patch 13: 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 Peter Xu (13): mm/Kconfig: CONFIG_PGTABLE_HAS_HUGE_LEAVES mm/hugetlb: Declare hugetlbfs_pagecache_present() non-static mm: Provide generic pmd_thp_or_huge() 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 + include/linux/pgtable.h | 4 + mm/Kconfig | 3 + mm/gup.c | 362 ++++++++++++++++++++++++++++++++-------- mm/huge_memory.c | 133 +-------------- mm/hugetlb.c | 75 +-------- mm/internal.h | 7 +- mm/memory.c | 12 ++ 10 files changed, 342 insertions(+), 298 deletions(-)