From patchwork Fri Aug 2 15:55:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13751723 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC03D136349 for ; Fri, 2 Aug 2024 15:55:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722614141; cv=none; b=cksblocMB/pBxPDL3ozLv8wxUY2ELKK+q9yAnDe9s6jHxG/uaP0BsDKt8f34b1FE/WydR/zX60l5jRmpcoxnbcrKOdqzQQ++R2lbR9pZZtracI7/ZubFMTWYmx8Ah018yvTjf04t9u+TVgO8qcBcteOp0LrbxdbdfePraqcB3gk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722614141; c=relaxed/simple; bh=aSl3GDoexr7Yt74Cnz0YsaFdausfDIyrzV3WsAcdZ9s=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Zqeis5kfcgfhR3UA1FYTUTUii2qyvKCPvtTxNP/3k4dpwAhcwECOXkhBNQu/mfv0hMEscQXuE6b6KEijibDh+c4PI0cX5jcwn/gUUbOBAnyg1Kev4wY5tkWJ+oPf7rso6n2h5JnHiG/Xo+G5xJZ98CSR6prTewcBnVipy1IAmls= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=hs7X+lNe; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hs7X+lNe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722614138; 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=L1rljUKvL0U4qJqT07GMyS3ShSSr+C5zU092arRl9Dk=; b=hs7X+lNe2cYZm5sr73II51hgrS2ctmjLiH5N27FLzxZfwBYET7yKbFxd47AInxtCefBu+i QE8AvHCwfo/0Bz5aG/qYRwGNkBGdsraJjFdXu2u/pEFndYJqobW6YdpqD6+P+flXcK3rkS B9RrcbWSXQ7nE6b29Gvne4A2SwQhHLg= Received: from mx-prod-mc-04.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-581-nld39d-uMKGpUalxEQkpag-1; Fri, 02 Aug 2024 11:55:35 -0400 X-MC-Unique: nld39d-uMKGpUalxEQkpag-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.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 mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0C34D1944AB0; Fri, 2 Aug 2024 15:55:33 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.113]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 68195300018D; Fri, 2 Aug 2024 15:55:26 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, kvm@vger.kernel.org, linux-s390@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Jonathan Corbet , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Sven Schnelle , Gerald Schaefer Subject: [PATCH v1 00/11] mm: replace follow_page() by folio_walk Date: Fri, 2 Aug 2024 17:55:13 +0200 Message-ID: <20240802155524.517137-1-david@redhat.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Looking into a way of moving the last folio_likely_mapped_shared() call in add_folio_for_migration() under the PTL, I found myself removing follow_page(). This paves the way for cleaning up all the FOLL_, follow_* terminology to just be called "GUP" nowadays. The new page table walker will lookup a mapped folio and return to the caller with the PTL held, such that the folio cannot get unmapped concurrently. Callers can then conditionally decide whether they really want to take a short-term folio reference or whether the can simply unlock the PTL and be done with it. folio_walk is similar to page_vma_mapped_walk(), except that we don't know the folio we want to walk to and that we are only walking to exactly one PTE/PMD/PUD. folio_walk provides access to the pte/pmd/pud (and the referenced folio page because things like KSM need that), however, as part of this series no page table modifications are performed by users. We might be able to convert some other walk_page_range() users that really only walk to one address, such as DAMON with damon_mkold_ops/damon_young_ops. It might make sense to extend folio_walk in the future to optionally fault in a folio (if applicable), such that we can replace some get_user_pages() users that really only want to lookup a single page/folio under PTL without unconditionally grabbing a folio reference. I have plans to extend the approach to a range walker that will try batching various page table entries (not just folio pages) to be a better replace for walk_page_range() -- and users will be able to opt in which type of page table entries they want to process -- but that will require more work and more thoughts. KSM seems to work just fine (ksm_functional_tests selftests) and move_pages seems to work (migration selftest). I tested the leaf implementation excessively using various hugetlb sizes (64K, 2M, 32M, 1G) on arm64 using move_pages and did some more testing on x86-64. Cross compiled on a bunch of architectures. I am not able to test the s390x Secure Execution changes, unfortunately. Cc: Andrew Morton Cc: "Matthew Wilcox (Oracle)" Cc: Jonathan Corbet Cc: Christian Borntraeger Cc: Janosch Frank Cc: Claudio Imbrenda Cc: Heiko Carstens Cc: Vasily Gorbik Cc: Alexander Gordeev Cc: Sven Schnelle Cc: Gerald Schaefer David Hildenbrand (11): mm: provide vm_normal_(page|folio)_pmd() with CONFIG_PGTABLE_HAS_HUGE_LEAVES mm/pagewalk: introduce folio_walk_start() + folio_walk_end() mm/migrate: convert do_pages_stat_array() from follow_page() to folio_walk mm/migrate: convert add_page_for_migration() from follow_page() to folio_walk mm/ksm: convert get_mergeable_page() from follow_page() to folio_walk mm/ksm: convert scan_get_next_rmap_item() from follow_page() to folio_walk mm/huge_memory: convert split_huge_pages_pid() from follow_page() to folio_walk s390/uv: convert gmap_destroy_page() from follow_page() to folio_walk s390/mm/fault: convert do_secure_storage_access() from follow_page() to folio_walk mm: remove follow_page() mm/ksm: convert break_ksm() from walk_page_range_vma() to folio_walk Documentation/mm/transhuge.rst | 6 +- arch/s390/kernel/uv.c | 18 ++- arch/s390/mm/fault.c | 16 ++- include/linux/mm.h | 3 - include/linux/pagewalk.h | 58 ++++++++++ mm/filemap.c | 2 +- mm/gup.c | 24 +--- mm/huge_memory.c | 18 +-- mm/ksm.c | 127 +++++++++------------ mm/memory.c | 2 +- mm/migrate.c | 131 ++++++++++----------- mm/nommu.c | 6 - mm/pagewalk.c | 202 +++++++++++++++++++++++++++++++++ 13 files changed, 413 insertions(+), 200 deletions(-)