lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240621054658.1220796-12-alexs@kernel.org>
Date: Fri, 21 Jun 2024 13:46:51 +0800
From: alexs@...nel.org
To: Vitaly Wool <vitaly.wool@...sulko.com>,
	Miaohe Lin <linmiaohe@...wei.com>,
	Andrew Morton <akpm@...ux-foundation.org>,
	linux-kernel@...r.kernel.org,
	linux-mm@...ck.org,
	minchan@...nel.org,
	willy@...radead.org,
	senozhatsky@...omium.org,
	david@...hat.com,
	42.hyeyoo@...il.com
Cc: Alex Shi <alexs@...nel.org>
Subject: [PATCH 11/15] mm/z3fold: use zpdesc in z3fold_alloc

From: Alex Shi <alexs@...nel.org>

Convert page to zpdesc in z3fold_alloc func. Since both func use zpdesc
now, we can pass zpdesc to init_z3fold_page().
And introduce zpdesc_trylock helper. This patch could save about 12KB
object file size.

Originally-by: Hyeonggon Yoo <42.hyeyoo@...il.com>
Signed-off-by: Alex Shi <alexs@...nel.org>
---
 mm/z3fold.c | 29 ++++++++++++++---------------
 mm/zpdesc.h |  5 +++++
 2 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/mm/z3fold.c b/mm/z3fold.c
index f164eb4e1139..e780143982c6 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -317,10 +317,9 @@ static inline void free_handle(unsigned long handle, struct z3fold_header *zhdr)
 }
 
 /* Initializes the z3fold header of a newly allocated z3fold page */
-static struct z3fold_header *init_z3fold_page(struct page *page, bool headless,
+static struct z3fold_header *init_z3fold_page(struct zpdesc *zpdesc, bool headless,
 					struct z3fold_pool *pool, gfp_t gfp)
 {
-	struct zpdesc *zpdesc = page_zpdesc(page);
 	struct z3fold_header *zhdr = zpdesc_address(zpdesc);
 	struct z3fold_buddy_slots *slots;
 
@@ -1006,7 +1005,7 @@ static int z3fold_alloc(struct z3fold_pool *pool, size_t size, gfp_t gfp,
 {
 	int chunks = size_to_chunks(size);
 	struct z3fold_header *zhdr = NULL;
-	struct page *page = NULL;
+	struct zpdesc *zpdesc = NULL;
 	enum buddy bud;
 	bool can_sleep = gfpflags_allow_blocking(gfp);
 
@@ -1030,35 +1029,35 @@ static int z3fold_alloc(struct z3fold_pool *pool, size_t size, gfp_t gfp,
 				WARN_ON(1);
 				goto retry;
 			}
-			page = virt_to_page(zhdr);
+			zpdesc = page_zpdesc(virt_to_page(zhdr));
 			goto found;
 		}
 		bud = FIRST;
 	}
 
-	page = alloc_page(gfp);
-	if (!page)
+	zpdesc = page_zpdesc(alloc_page(gfp));
+	if (!zpdesc)
 		return -ENOMEM;
 
-	zhdr = init_z3fold_page(page, bud == HEADLESS, pool, gfp);
+	zhdr = init_z3fold_page(zpdesc, bud == HEADLESS, pool, gfp);
 	if (!zhdr) {
-		__free_page(page);
+		__free_page(zpdesc_page(zpdesc));
 		return -ENOMEM;
 	}
 	atomic64_inc(&pool->pages_nr);
 
 	if (bud == HEADLESS) {
-		set_bit(PAGE_HEADLESS, &page->private);
+		set_bit(PAGE_HEADLESS, &zpdesc->zppage_flag);
 		goto headless;
 	}
 	if (can_sleep) {
-		lock_page(page);
-		__SetPageMovable(page, &z3fold_mops);
-		unlock_page(page);
+		zpdesc_lock(zpdesc);
+		__SetPageMovable(zpdesc_page(zpdesc), &z3fold_mops);
+		zpdesc_unlock(zpdesc);
 	} else {
-		WARN_ON(!trylock_page(page));
-		__SetPageMovable(page, &z3fold_mops);
-		unlock_page(page);
+		WARN_ON(!zpdesc_trylock(zpdesc));
+		__SetPageMovable(zpdesc_page(zpdesc), &z3fold_mops);
+		zpdesc_unlock(zpdesc);
 	}
 	z3fold_page_lock(zhdr);
 
diff --git a/mm/zpdesc.h b/mm/zpdesc.h
index 06cfd33de330..9ead7a452f2a 100644
--- a/mm/zpdesc.h
+++ b/mm/zpdesc.h
@@ -63,6 +63,11 @@ static inline void zpdesc_lock(struct zpdesc *zpdesc)
 	folio_lock(zpdesc_folio(zpdesc));
 }
 
+static inline bool zpdesc_trylock(struct zpdesc *zpdesc)
+{
+	return folio_trylock(zpdesc_folio(zpdesc));
+}
+
 static inline void zpdesc_unlock(struct zpdesc *zpdesc)
 {
 	folio_unlock(zpdesc_folio(zpdesc));
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ