From patchwork Thu Mar 6 22:44:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 14005454 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 23F09C28B23 for ; Thu, 6 Mar 2025 22:45:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 72C18280009; Thu, 6 Mar 2025 17:45:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6DE92280002; Thu, 6 Mar 2025 17:45:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4BC13280009; Thu, 6 Mar 2025 17:45:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 27C1D280002 for ; Thu, 6 Mar 2025 17:45:13 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8B61B16062F for ; Thu, 6 Mar 2025 22:45:13 +0000 (UTC) X-FDA: 83192608506.06.6277912 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf14.hostedemail.com (Postfix) with ESMTP id D8441100003 for ; Thu, 6 Mar 2025 22:45:11 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=W4zVS91m; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.hostedemail.com: domain of luizcap@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=luizcap@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1741301111; a=rsa-sha256; cv=none; b=z+xjE+C6ckTiGGV8gjaLnYZ8NRVb9cvi3XP9j3sLfvvDww1VxAfmBmASAEycHkUBaEUnjA rQydtqpAS7dlCTjB/3B71qzLQS1I+S1+5Ql3S42+xW+BktBm/NfYh4tid2PQ+7uvomwaQz OsQCndT+JO5bSyhbxzXnsSFlgKVMrdg= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=W4zVS91m; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.hostedemail.com: domain of luizcap@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=luizcap@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1741301111; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=jizhA/rqhXJwS3A3pxZ/QRAfj5aycaqM9rDetHR50vU=; b=QWmNIFCp2lutykHlnHFIAjrppeWs3deYQdHu5bJxXP50N4LYTWlXzEApQc6+ApJpsqPZ61 teZ+nNLATyCVxFj8UJ2LO5hMJ5/s6cyqLqZNevAZgKyRcmrUSKmBC+3Iv17ubnCpWRuNHd vbLetQlCO/73FieGSCGJeoIaxHFon5M= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741301111; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=jizhA/rqhXJwS3A3pxZ/QRAfj5aycaqM9rDetHR50vU=; b=W4zVS91m57y11x3KrvbKPtpwp8ngImPN+570j+INLWasflTe388OT6V9M8lL3ezGDsQtQS f8VlG4DZ3jKuvK8kBUruPCmjn/zI65BJj09IGio1eQC+nCXxk9iW9xAiVwGdErrC7O5Dr+ 0BERmIBWW/LqnIIxybit/rTu2w6U6zQ= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-141-FqxMgNPlNeesPetHBR-TRg-1; Thu, 06 Mar 2025 17:45:04 -0500 X-MC-Unique: FqxMgNPlNeesPetHBR-TRg-1 X-Mimecast-MFC-AGG-ID: FqxMgNPlNeesPetHBR-TRg_1741301103 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 366F6195609E; Thu, 6 Mar 2025 22:45:02 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.88.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1763E180174C; Thu, 6 Mar 2025 22:44:58 +0000 (UTC) From: Luiz Capitulino To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, david@redhat.com, yuzhao@google.com, pasha.tatashin@soleen.com Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, muchun.song@linux.dev, luizcap@redhat.com Subject: [PATCH v3 0/3] mm: page_ext: Introduce new iteration API Date: Thu, 6 Mar 2025 17:44:49 -0500 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: D8441100003 X-Stat-Signature: d9ksuxzwg5crhpeo5jjxpys1a6jxjstm X-HE-Tag: 1741301111-592394 X-HE-Meta: U2FsdGVkX188s7NTAbYgvPIdCq6cW3IDe0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Ru0c7/Qhfs4biwM74tXmPNuz0fHFJHWUGWKO3BNSkgoeKRWApA/5ct3Hty0BMR+wqpgI4mIPZEiaG2P9IDRh45tBSdrnE+YDL4tggttKWb6XA8BV4QitSLHKKttQwkyZS/KYQapyeP+1u3+7jn+lITA4WDl3Dy/X3+dOB2nHj8RKFVRqZhTBSXja8iJZa7k1vAFjilaKreT/iCOdr2D3mw9H1gIEW69QyFpYzHPBro0WsXwBqWXFOSFMzPER3nEvZUWySA== 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: This series is against v6.14-rc5. The introduction is after the changelog. v2 -> v3 ======== - Change the new API to take a PFN number instead of a struct page, which solves header file issue (David) - Optimize page_ext_get()/page_ext_put() in __folio_copy_owner (David) v1 -> v2 ======== - Drop for_each_page_ext_order() (David) - Make page_ext_iter_begin() and page_ext_iter_next() inline functions (David) - Move loop logic into page_ext_iter_begin() and page_ext_iter_next() (David) RFC -> v1 ========= - Revamped the API by introducing for_each_page_ext macros - Implemented various suggestions from David Hildenbrand, including page_ext lookup optimization - Fixed changelogs Introduction ============ [ Thanks to David Hildenbrand for identifying the root cause of this issue and proving guidance on how to fix it. The new API idea, bugs and misconceptions are all mine though ] Currently, trying to reserve 1G pages with page_owner=on and sparsemem causes a crash. The reproducer is very simple: 1. Build the kernel with CONFIG_SPARSEMEM=y and the table extensions 2. Pass 'default_hugepagesz=1 page_owner=on' in the kernel command-line 3. Reserve one 1G page at run-time, this should crash (see patch 1 for backtrace) [ A crash with page_table_check is also possible, but harder to trigger ] Apparently, starting with commit cf54f310d0d3 ("mm/hugetlb: use __GFP_COMP for gigantic folios") we now pass the full allocation order to page extension clients and the page extension implementation assumes that all PFNs of an allocation range will be stored in the same memory section (which is not true for 1G pages). To fix this, this series introduces a new iteration API for page extension objects. The API checks if the next page extension object can be retrieved from the current section or if it needs to look up for it in another section. Please, find all details in patch 1. I tested this series on arm64 and x86 by reserving 1G pages at run-time and doing kernel builds (always with page_owner=on and page_table_check=on). Luiz Capitulino (3): mm: page_ext: add an iteration API for page extensions mm: page_table_check: use new iteration API mm: page_owner: use new iteration API include/linux/page_ext.h | 93 ++++++++++++++++++++++++++++++++++++++++ mm/page_ext.c | 13 ++++++ mm/page_owner.c | 84 +++++++++++++++++------------------- mm/page_table_check.c | 39 ++++++----------- 4 files changed, 157 insertions(+), 72 deletions(-)