From patchwork Fri Nov 8 16:20:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13868434 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 80574D5C0FF for ; Fri, 8 Nov 2024 16:20:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F081E6B0083; Fri, 8 Nov 2024 11:20:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EB83F6B0088; Fri, 8 Nov 2024 11:20:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D7F5F6B008A; Fri, 8 Nov 2024 11:20:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B912F6B0083 for ; Fri, 8 Nov 2024 11:20:46 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 6A842A0DC3 for ; Fri, 8 Nov 2024 16:20:46 +0000 (UTC) X-FDA: 82763439738.27.01ED09D Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf19.hostedemail.com (Postfix) with ESMTP id 5F3811A0003 for ; Fri, 8 Nov 2024 16:19:58 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=D1zFejxe; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf19.hostedemail.com: domain of 3WjouZwUKCMc6noont11tyr.p1zyv07A-zzx8npx.14t@flex--tabba.bounces.google.com designates 209.85.128.74 as permitted sender) smtp.mailfrom=3WjouZwUKCMc6noont11tyr.p1zyv07A-zzx8npx.14t@flex--tabba.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731082759; 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:in-reply-to: references:dkim-signature; bh=qSNggYYB42ksK77mqLJizRXwTBzrM89QBEMwFFNrJdw=; b=2AojvCGK7bzGTosCIkqIuSnEFOi8jtIu4iFljuwGlqE3x0DGuZF0pfkYQ0rR43/Oy0GQa6 BMOyxHdOOoLNpZNO3lgIJUUbGWnvpzVMrcX0MrFTbMtBA+l3D8zTxYWQVi+1F13tUakYmV Q3+czwi1o0J36mNW336Oj6hSuPOzKZ0= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=D1zFejxe; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf19.hostedemail.com: domain of 3WjouZwUKCMc6noont11tyr.p1zyv07A-zzx8npx.14t@flex--tabba.bounces.google.com designates 209.85.128.74 as permitted sender) smtp.mailfrom=3WjouZwUKCMc6noont11tyr.p1zyv07A-zzx8npx.14t@flex--tabba.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731082759; a=rsa-sha256; cv=none; b=dYQKtkDQ11gmFxPhZfDN/EcmUVDBLsYBpqTnx8wiZhrliL8MvNxkK5gUfHOdwL7pZ0RCEt KOkBEjMzXR199allfTdyOeI5NqKHAsUiF4UW5AVPVVExV1WfECG624gyFXZ4ekRqomwGlH ySGFtS8UN2AN8nQzloJMMdQRo1610E8= Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-4327bd6bd60so15971275e9.1 for ; Fri, 08 Nov 2024 08:20:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731082843; x=1731687643; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=qSNggYYB42ksK77mqLJizRXwTBzrM89QBEMwFFNrJdw=; b=D1zFejxeZjXL2jyosvvXBCaHO2HUtGbl5RgAuocIGBwFMhypZlqQgNhq7Hgh8ROgIC yAgmX6JEn7IY+BXhkcOXcJZlJXk9oej++muMRjmJ+2AwQ6pLy2M8pRw3LvJK3imoYnj+ WWo/hp8P7T7A8XkZ8m3HMdV+SyvsDQXcfS/zX6xIF3djpaB/9kEwAiVA8BFy4woz5zCo fv3qAGk1FPWwtp+Z+/tRW6t8qaTX98MvCqO8MNI2PrYvv9c3LORmoSoDb+6UkhvTK1lo AP0VJr/mrFJXfHQqMGyz2sOtjRitfS/MlmVo5LHt1nPdHjeFHz95Coz0KQC09us51T/h gFgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731082843; x=1731687643; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=qSNggYYB42ksK77mqLJizRXwTBzrM89QBEMwFFNrJdw=; b=xQpZ+y6zAiDija0L7gPgehlANpVheC9zLj/3IkmFwAHJijx3vRy6wQ/uXJZDlFiU/l FWMRhU7EuRVNbNCYHs8BYk7eptaZoWp3hxZmhzwlr15RgYVoY9ogPk9YMg9e1DalcpZ5 1dKsnlT4GYhX3sRuj4PRJGoLmyH+/dY1yyCgbkeiPUHlAaTwws8Z+SSO7IVRVZtBkWqY j35KUx7miDhPPwX563Cc/uX3GDTiFmQvVbeIttXBraesNcYb6u8ZXP9SQjcxdqmouvDb qhBtFAhCWBB+OI2v5ENlfHbzmkTS4tNQ1JpOoNdfHdeYIJcxHW4DKNw+ZgwFm0VI+J+X FfPg== X-Gm-Message-State: AOJu0Yxll8LqlKD7RcWcmvPgkOG8u/7tUCf+M2SaCHlE0KdbnUbzEqDy Wi1qPB7KyzEumytKyPDXiuZ55PaHyZwPJ7A/WNAd20iJyF5bGbac1sBBJftPbjngYs6WdfFKc9/ 9PYAi4lMtSkzJcYLyt+dR8EXIFHzEQ7uiNEUZ+BerlupM1QPLtBTuVKW9gQWRyEgsY397vB9djs nri639s/9j+t9Z1OFsAM6maw== X-Google-Smtp-Source: AGHT+IGNt2ARzTp6h05fXXQEL275e7en0LhPQqztYO3DssrZ2Bpa4ilDg6kO0xlH0JaVTwhHigLo2F9OCQ== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:adf:e611:0:b0:37d:45dd:dfbf with SMTP id ffacd0b85a97d-381f18641abmr2475f8f.4.1731082842629; Fri, 08 Nov 2024 08:20:42 -0800 (PST) Date: Fri, 8 Nov 2024 16:20:30 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Message-ID: <20241108162040.159038-1-tabba@google.com> Subject: [RFC PATCH v1 00/10] mm: Introduce and use folio_owner_ops From: Fuad Tabba To: linux-mm@kvack.org Cc: kvm@vger.kernel.org, nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, david@redhat.com, rppt@kernel.org, jglisse@redhat.com, akpm@linux-foundation.org, muchun.song@linux.dev, simona@ffwll.ch, airlied@gmail.com, pbonzini@redhat.com, seanjc@google.com, willy@infradead.org, jgg@nvidia.com, jhubbard@nvidia.com, ackerleytng@google.com, vannapurve@google.com, mail@maciej.szmigiero.name, kirill.shutemov@linux.intel.com, quic_eberman@quicinc.com, maz@kernel.org, will@kernel.org, qperret@google.com, keirf@google.com, roypat@amazon.co.uk, tabba@google.com X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 5F3811A0003 X-Stat-Signature: ui4jzf3smbxtendw4nhh6nuscrbp1z9c X-HE-Tag: 1731082798-898678 X-HE-Meta: U2FsdGVkX18KHN1nv64L13DMllrh38N0dUX6QdtWsozXuDpbcxY4eQVedhSFmpPYnhXMD6SXX1XyZkN4E8kRjkGAC+f0AWejDoLm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GIYFw9nSDGIDHViSVWYWFShjh4IiJ7F3hWHXBBrHHHv/fGzE7pxrSuYj0MpfIXWXe61N7sNry3ySUEmPVuL7voR7w2tyudoAY9Brp9B/nevWrecbGtC9VKJQMmLvF0B/nKo5LgKvf3JHfCSoAYmG2OcmBeda6UUBszc/jJ/c8gGWhx57CmqYA3RxixOZn6xIqfCM1OwYkibqknAj+0BUZTgS2WVZb9TD0N5hMIaSR0dgpUgYGqJ+Lg5CmmaY6EA/lZ24o+hUMQ07JYd2/yBWgx9UtXPYyPjQN56qi1vtiapSy1HBIatESfEYPDMpjJF3ASKqksdV+2kLgrOg/WUkZ8zODpLZUyK9zE/aOzFv/aozMTubGSLJ7N7w+wSkdqjLOH9K6dh1cERKo2XSUlA02PTozux7IjYyCDH3BsHqE9CxhhQ+ejL3mtjTo7Wor06bjYM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000005, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Some folios, such as hugetlb folios and zone device folios, require special handling when the folio's reference count reaches 0, before being freed. Moreover, guest_memfd folios will likely require special handling to notify it once a folio's reference count reaches 0, to facilitate shared to private folio conversion [*]. Currently, each usecase has a dedicated callback when the folio refcount reaches 0 to that effect. Adding yet more callbacks is not ideal. This patch series introduces struct folio_owner_ops and uses it as a generic way to handle callbacks on freeing a folio. It also applies the callbacks to hugetlb and zone device folios. A pointer to struct folio_owner_ops is overlaid on struct page compound_page, struct page/folio lru. To indicate that the folio uses the callback, this patch series sets bit 1 of the new field, similar to how bit 0 indicates a compound page. Patches 1 to 6 rework the hugetlb code to allow us to reuse folio->lru for the owner ops as long as they are not isolated. Patches 7 to 10 introduce struct folio_owner_ops, and apply the callbacks to zone device and hugetlb folios. Cheers, /fuad [*] https://lore.kernel.org/all/CAGtprH_JP2w-4rq02h_Ugvq5KuHX7TUvegOS7xUs_iy5hriE7g@mail.gmail.com/ David Hildenbrand (6): mm/hugetlb: rename isolate_hugetlb() to folio_isolate_hugetlb() mm/migrate: don't call folio_putback_active_hugetlb() on dst hugetlb folio mm/hugetlb: rename "folio_putback_active_hugetlb()" to "folio_putback_hugetlb()" mm/hugetlb-cgroup: convert hugetlb_cgroup_css_offline() to work on folios mm/hugetlb: use folio->lru int demote_free_hugetlb_folios() mm/hugetlb: use separate folio->_hugetlb_list for hugetlb-internals Fuad Tabba (4): mm: Introduce struct folio_owner_ops mm: Use getters and setters to access page pgmap mm: Use owner_ops on folio_put for zone device pages mm: hugetlb: Use owner_ops on folio_put for hugetlb drivers/gpu/drm/nouveau/nouveau_dmem.c | 4 +- drivers/pci/p2pdma.c | 8 +- include/linux/hugetlb.h | 10 +- include/linux/memremap.h | 14 +- include/linux/mm_types.h | 107 ++++++++++++++- lib/test_hmm.c | 2 +- mm/gup.c | 2 +- mm/hmm.c | 2 +- mm/hugetlb.c | 179 ++++++++++++++++++------- mm/hugetlb_cgroup.c | 19 ++- mm/hugetlb_vmemmap.c | 8 +- mm/internal.h | 1 - mm/memory.c | 2 +- mm/mempolicy.c | 2 +- mm/memremap.c | 49 +------ mm/migrate.c | 20 +-- mm/migrate_device.c | 4 +- mm/mm_init.c | 48 ++++++- mm/swap.c | 25 ++-- 19 files changed, 342 insertions(+), 164 deletions(-) base-commit: beb2622b970047000fa3cae64c23585669b01fca Signed-off-by: David Hildenbrand