Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 12 May 2025 17:46:51 GMT
From:      =?utf-8?Q?Jean-S=C3=A9bastien?= =?utf-8?Q?P=C3=A9dron?= <dumbbell@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: c8089810a940 - main - linuxkpi: Make "free page" code paths closer to Linux
Message-ID:  <202505121746.54CHkpwR035372@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by dumbbell:

URL: https://cgit.FreeBSD.org/src/commit/?id=c8089810a94027b7f937b9e63d2d8d31a02aaac5

commit c8089810a94027b7f937b9e63d2d8d31a02aaac5
Author:     Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
AuthorDate: 2025-04-13 11:13:17 +0000
Commit:     Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
CommitDate: 2025-05-12 17:08:02 +0000

    linuxkpi: Make "free page" code paths closer to Linux
    
    There is basically one code path to free pages on Linux. In particular,
    `free_pages()` is used for other pages than those returned by
    `alloc_pages()`.
    
    Also on Linux, `release_pages()` takes either `struct page` or `struct
    folio`. `struct folio` support will be added in a followup commit.
    Regardless, because pages come from several sources,
    `linux_free_pages()` need to accept managed and unmanaged pages.
    
    Reviewed by:    bz, markj
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D49813
---
 sys/compat/linuxkpi/common/include/linux/mm.h |  3 ++-
 sys/compat/linuxkpi/common/src/linux_page.c   | 22 +++++++++++++++++++---
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/sys/compat/linuxkpi/common/include/linux/mm.h b/sys/compat/linuxkpi/common/include/linux/mm.h
index f523395cc71c..569e2a8b70f1 100644
--- a/sys/compat/linuxkpi/common/include/linux/mm.h
+++ b/sys/compat/linuxkpi/common/include/linux/mm.h
@@ -278,7 +278,8 @@ get_page(struct page *page)
 static inline void
 put_page(struct page *page)
 {
-	vm_page_unwire(page, PQ_ACTIVE);
+	/* `__free_page()` takes care of the refcounting (unwire). */
+	__free_page(page);
 }
 
 void linux_release_pages(struct page **pages, int nr);
diff --git a/sys/compat/linuxkpi/common/src/linux_page.c b/sys/compat/linuxkpi/common/src/linux_page.c
index c299457f042a..7ce52cbf95eb 100644
--- a/sys/compat/linuxkpi/common/src/linux_page.c
+++ b/sys/compat/linuxkpi/common/src/linux_page.c
@@ -165,8 +165,24 @@ linux_free_pages(struct page *page, unsigned int order)
 		for (x = 0; x != npages; x++) {
 			vm_page_t pgo = page + x;
 
-			if (vm_page_unwire_noq(pgo))
-				vm_page_free(pgo);
+			/*
+			 * The "free page" function is used in several
+			 * contexts.
+			 *
+			 * Some pages are allocated by `linux_alloc_pages()`
+			 * above, but not all of them are. For instance in the
+			 * DRM drivers, some pages come from
+			 * `shmem_read_mapping_page_gfp()`.
+			 *
+			 * That's why we need to check if the page is managed
+			 * or not here.
+			 */
+			if ((pgo->oflags & VPO_UNMANAGED) == 0) {
+				vm_page_unwire(pgo, PQ_ACTIVE);
+			} else {
+				if (vm_page_unwire_noq(pgo))
+					vm_page_free(pgo);
+			}
 		}
 	} else {
 		vm_offset_t vaddr;
@@ -183,7 +199,7 @@ linux_release_pages(struct page **pages, int nr)
 	int i;
 
 	for (i = 0; i < nr; i++)
-		put_page(pages[i]);
+		__free_page(pages[i]);
 }
 
 vm_offset_t



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202505121746.54CHkpwR035372>