From patchwork Wed Jan 3 09:14:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13509763 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 5D000C3DA6E for ; Wed, 3 Jan 2024 09:14:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E6F0A8D004E; Wed, 3 Jan 2024 04:14:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E1F838D0035; Wed, 3 Jan 2024 04:14:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE8CA8D004E; Wed, 3 Jan 2024 04:14:49 -0500 (EST) 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 BE6F38D0035 for ; Wed, 3 Jan 2024 04:14:49 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 854CCA0F41 for ; Wed, 3 Jan 2024 09:14:49 +0000 (UTC) X-FDA: 81637439898.18.BD1B80F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf12.hostedemail.com (Postfix) with ESMTP id C5C154000D for ; Wed, 3 Jan 2024 09:14:46 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=P+yOHYGe; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf12.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.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=1704273287; 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=ECdT86ko6CPDQ7PwUTvJTmsh3hF4cTDBKdjOYZE7Ef8=; b=pQdRBZcEJnTc2DnAqTGgRr1FbYDIRRyfHU0kiatgqTSR1aZE+VUNcNYLKUidmarPfBGuPZ pXyDtOf9TqMs415p2xdXeqVwNasOjsi97JXjUQhUSniGa+thHyXwEUxHkUi+LxG+NgaIbK WcjYiMMC8WBX3Uf/vgBQkYAd3/nKlpQ= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=P+yOHYGe; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf12.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704273287; a=rsa-sha256; cv=none; b=tpHbCxMM00ebhmLjOn1T488lK4YfTgxG6DzRgYas/m4ZG6SuawgP43h5P6zFGAChv9H67r Pv8AoNlE3C4l0zox5Zis/KBC83JGOBuxxZXw2n03E9Kv3dXOncZlyvan1OeixenA0OJRIU uZ2uF+9GtGC52Xr7VIpv2J04sd3Z+cQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704273286; 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=ECdT86ko6CPDQ7PwUTvJTmsh3hF4cTDBKdjOYZE7Ef8=; b=P+yOHYGe62HGUf9HPLjbG5PQ9+bPn+xxLg74lXHLowGJOIyRE6RVfsjUX5vcHlUJYz+otX Sdwv8q6CJwQv19KGXEL3P7pEVIdvglCZgJzcxUm1BaqcQ3oDbN3PT/q1asgJTFVBcMiiMx EBsZutiOmJ+0khpKe/kQU1Ynmpl21AE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-656-YJyX-2z5NWeDsYfFUhlklw-1; Wed, 03 Jan 2024 04:14:40 -0500 X-MC-Unique: YJyX-2z5NWeDsYfFUhlklw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 6FE0C1019DE1; Wed, 3 Jan 2024 09:14:39 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.69]) by smtp.corp.redhat.com (Postfix) with ESMTP id 16526492BF0; Wed, 3 Jan 2024 09:14:26 +0000 (UTC) From: peterx@redhat.com To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: James Houghton , David Hildenbrand , "Kirill A . Shutemov" , Yang Shi , peterx@redhat.com, linux-riscv@lists.infradead.org, Andrew Morton , "Aneesh Kumar K . V" , Rik van Riel , Andrea Arcangeli , Axel Rasmussen , Mike Rapoport , John Hubbard , Vlastimil Babka , Michael Ellerman , Christophe Leroy , Andrew Jones , linuxppc-dev@lists.ozlabs.org, Mike Kravetz , Muchun Song , linux-arm-kernel@lists.infradead.org, Jason Gunthorpe , Christoph Hellwig , Lorenzo Stoakes , Matthew Wilcox Subject: [PATCH v2 00/13] mm/gup: Unify hugetlb, part 2 Date: Wed, 3 Jan 2024 17:14:10 +0800 Message-ID: <20240103091423.400294-1-peterx@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: C5C154000D X-Stat-Signature: pz5cci79cqkpqbm3y955t1wdtxg75moi X-Rspam-User: X-HE-Tag: 1704273286-29344 X-HE-Meta: U2FsdGVkX1/oBpi+OZCn6XXdBA1SjZPb0qabY/WcPalBv5v3QVOoIBlxbfbEI0FgMvQMpxL59bvArvY/7wlefAlChBampzEc7MAuALfLuAzW15u/0mrabLRC3+81za0BwBx1CUohvdDKRSAZ3lVSLax+qF0Cjbd/z1Tzqax7LnWseiNB/cxSU0L6Cg/SbHnY3EMQ9qmPCX61p6+SukreaHrmbMIXd6Wf43u4gjytnqS6OtEuo1nIfacM71qbL0YHTnMVzocgmaptHPvRh3njoug6d1c08tRBClgft5B4rxjAzU9SERgZQhJI4TVy5TegFlGXlZz02tan5mSdn7dzdZfNSOR6caKrgbF+SvKb/AMPZVCuJMZXCypqv1OK4ASOBj7JCqYFDN12NY2ic1FbHXQ+J0q2eVr+/EAn6xJYog9t0UjpPDVub3U4Pt9ZMr1MHjeYStp2pl0c94E3RyQYqjIkzVyMwXor3EupFuxrzvxCi3Rt66ujjg74hV/wcTj0C41dy1WkHaJA0+V4c2l1qpasXbeG0NWlptMX/5oLHIOoZfHTZ6xDWLfFKddDtvDomfKm9aGm2MtDQkaboTZzQ9tyPK2TZRkvWH28KSS7RGiE9Jafo3OVPb97qq0CLxFOT2YbJo+2Z7Ope6xfeaF19Y6Vvo8GRZwjwZ/8BTQ9WJ15FJZ/86m68LmWUOk/FJL16Iv9P1dMuxP89BDFA6TSVzlkEJQ1e7QlVQeObvbY2FKJfPhSN1KIINdkth8U9t/5nPWjy2+4Y49nsZ4Cwd00wX8m9e+auQrfU8VOc1LR+ZlDfR2TyVYA01b5T9UjM56Lk+voDCYh7LkJ3lK8EP719tVvaZI1v5zKU/EwwfnY4Ro= 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 v2: - Collect acks - Patch 9: - Use READ_ONCE() to fetch pud entry [James] rfc: https://lore.kernel.org/r/20231116012908.392077-1-peterx@redhat.com v1: https://lore.kernel.org/r/20231219075538.414708-1-peterx@redhat.com This is v2 of the series, based on latest mm-unstalbe (856325d361df). 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. 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 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 ========= 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(-)