[PATCH 11/15] mm/z3fold: use zpdesc in z3fold_alloc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Alex Shi <alexs@xxxxxxxxxx>

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@xxxxxxxxx>
Signed-off-by: Alex Shi <alexs@xxxxxxxxxx>
---
 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





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux