linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool
@ 2024-06-21  5:46 alexs
  2024-06-21  5:46 ` [PATCH 01/15] mm/z3fold: add zpdesc struct and helper and use them in z3fold_page_isolate alexs
                   ` (16 more replies)
  0 siblings, 17 replies; 25+ messages in thread
From: alexs @ 2024-06-21  5:46 UTC (permalink / raw)
  To: Vitaly Wool, Miaohe Lin, Andrew Morton, linux-kernel, linux-mm,
	minchan, willy, senozhatsky, david, 42.hyeyoo
  Cc: Alex Shi

From: Alex Shi <alexs@kernel.org>

According to Metthew's plan, the page descriptor will be replace by a 8
bytes mem_desc on destination purpose.
https://lore.kernel.org/lkml/YvV1KTyzZ+Jrtj9x@casper.infradead.org/

Here is a implement on z3fold to replace page descriptor by zpdesc,
which is still overlay on struct page now. but it's a step move forward
above destination.

To name the struct zpdesc instead of z3fold_desc, since there are 3 zpool
usages under zswap, zbud, z3fold, zsmalloc. It looks like we may extend the
zpdesc to zbud and zsmalloc, combined their usage into one.

For zpdesc(page), z3fold just uses the 5th member zppage_flag, which
match with page.private. Potentially uses the first member flags for
headless PG_locked, list_head lru and page.mapping|PAGE_MAPPING_MOVABLE
for page migration.

This patachset could save 26Kbyetes z3fold.o size, basely saving come
from the page to folio conversion.

Thanks a lot!
Alex

Alex Shi (15):
  mm/z3fold: add zpdesc struct and helper and use them in
    z3fold_page_isolate
  mm/z3fold: use zpdesc in z3fold_page_migrate
  mm/z3fold: use zpdesc in z3fold_page_putback
  mm/z3fold: use zpdesc in get/put_z3fold_header funcs
  mm/z3fold: use zpdesc in init_z3fold_page
  mm/z3fold: use zpdesc in free_z3fold_page
  mm/z3fold: convert page to zpdesc in __release_z3fold_page
  mm/z3fold: use zpdesc free_pages_work
  mm/z3fold: use zpdesc in z3fold_compact_page and do_compact_page
  mm/z3fold: use zpdesc in __z3fold_alloc
  mm/z3fold: use zpdesc in z3fold_alloc
  mm/z3fold: use zpdesc in free_z3fold_page and z3fold_free
  mm/z3fold: use zpdesc in z3fold_map/z3fold_unmap
  mm/z3fold: introduce __zpdesc_set_movable
  mm/z3fold: introduce __zpdesc_clear_movable

 mm/z3fold.c | 190 +++++++++++++++++++++++++++-------------------------
 mm/zpdesc.h |  87 ++++++++++++++++++++++++
 2 files changed, 184 insertions(+), 93 deletions(-)
 create mode 100644 mm/zpdesc.h

-- 
2.43.0



^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 01/15] mm/z3fold: add zpdesc struct and helper and use them in z3fold_page_isolate
  2024-06-21  5:46 [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool alexs
@ 2024-06-21  5:46 ` alexs
  2024-06-21  5:46 ` [PATCH 02/15] mm/z3fold: use zpdesc in z3fold_page_migrate alexs
                   ` (15 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: alexs @ 2024-06-21  5:46 UTC (permalink / raw)
  To: Vitaly Wool, Miaohe Lin, Andrew Morton, linux-kernel, linux-mm,
	minchan, willy, senozhatsky, david, 42.hyeyoo
  Cc: Alex Shi

From: Alex Shi <alexs@kernel.org>

The 1st patch here, we introduce some helper functions along with struct
zpdesc, like zpdesc_page/zpdesc_folio/page_zpdesc and zpdesc_address
similar with folio_address, and convert page to zpdesc in func
z3fold_page_isolate. z3fold_page_isolate() hooked to page_isolate that
the reason we could not fully remove page from its parameter for now.

Originally-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>
Suggested-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Alex Shi <alexs@kernel.org>
---
 mm/z3fold.c | 14 ++++++++------
 mm/zpdesc.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+), 6 deletions(-)
 create mode 100644 mm/zpdesc.h

diff --git a/mm/z3fold.c b/mm/z3fold.c
index 2ebfed32871b..b1229c0520f1 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -40,6 +40,7 @@
 #include <linux/spinlock.h>
 #include <linux/zpool.h>
 #include <linux/kmemleak.h>
+#include "zpdesc.h"
 
 /*
  * NCHUNKS_ORDER determines the internal allocation granularity, effectively
@@ -1251,22 +1252,23 @@ static bool z3fold_page_isolate(struct page *page, isolate_mode_t mode)
 {
 	struct z3fold_header *zhdr;
 	struct z3fold_pool *pool;
+	struct zpdesc *zpdesc = page_zpdesc(page);
 
-	VM_BUG_ON_PAGE(PageIsolated(page), page);
+	VM_BUG_ON_PAGE(PageIsolated(zpdesc_page(zpdesc)), zpdesc_page(zpdesc));
 
-	if (test_bit(PAGE_HEADLESS, &page->private))
+	if (test_bit(PAGE_HEADLESS, &zpdesc->zppage_flag))
 		return false;
 
-	zhdr = page_address(page);
+	zhdr = zpdesc_address(zpdesc);
 	z3fold_page_lock(zhdr);
-	if (test_bit(NEEDS_COMPACTING, &page->private) ||
-	    test_bit(PAGE_STALE, &page->private))
+	if (test_bit(NEEDS_COMPACTING, &zpdesc->zppage_flag) ||
+	    test_bit(PAGE_STALE, &zpdesc->zppage_flag))
 		goto out;
 
 	if (zhdr->mapped_count != 0 || zhdr->foreign_handles != 0)
 		goto out;
 
-	if (test_and_set_bit(PAGE_CLAIMED, &page->private))
+	if (test_and_set_bit(PAGE_CLAIMED, &zpdesc->zppage_flag))
 		goto out;
 	pool = zhdr_to_pool(zhdr);
 	spin_lock(&pool->lock);
diff --git a/mm/zpdesc.h b/mm/zpdesc.h
new file mode 100644
index 000000000000..d51785863596
--- /dev/null
+++ b/mm/zpdesc.h
@@ -0,0 +1,51 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* zpdesc.h: zswap.zpool memory descriptor
+ *
+ * Written by Alex Shi (Tencent) <alexs@kernel.org>
+ */
+#ifndef __MM_ZPDESC_H__
+#define __MM_ZPDESC_H__
+
+/*
+ * struct zpdesc -	Memory descriptor for z3fold memory
+ * @flags:		Page flags, PG_locked for headless z3fold memory
+ * @lru:		Indirected used by page migration
+ * @zppage_flag:	z3fold memory flags
+ *
+ * This struct overlays struct page for now. Do not modify without a good
+ * understanding of the issues.
+ */
+struct zpdesc {
+	unsigned long flags;
+	struct list_head lru;
+	unsigned long _zp_pad_1;
+	unsigned long _zp_pad_2;
+	unsigned long zppage_flag;
+};
+#define ZPDESC_MATCH(pg, zp) \
+	static_assert(offsetof(struct page, pg) == offsetof(struct zpdesc, zp))
+
+ZPDESC_MATCH(flags, flags);
+ZPDESC_MATCH(lru, lru);
+ZPDESC_MATCH(private, zppage_flag);
+#undef ZPDESC_MATCH
+static_assert(sizeof(struct zpdesc) <= sizeof(struct page));
+
+#define zpdesc_page(zp)			(_Generic((zp),			\
+	const struct zpdesc *:		(const struct page *)(zp),	\
+	struct zpdesc *:		(struct page *)(zp)))
+
+#define zpdesc_folio(zp)		(_Generic((zp),			\
+	const struct zpdesc *:		(const struct folio *)(zp),	\
+	struct zpdesc *:		(struct folio *)(zp)))
+
+#define page_zpdesc(p)			(_Generic((p),			\
+	const struct page *:		(const struct zpdesc *)(p),	\
+	struct page *:			(struct zpdesc *)(p)))
+
+static inline void *zpdesc_address(const struct zpdesc *zpdesc)
+{
+	return folio_address(zpdesc_folio(zpdesc));
+}
+
+#endif
-- 
2.43.0



^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 02/15] mm/z3fold: use zpdesc in z3fold_page_migrate
  2024-06-21  5:46 [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool alexs
  2024-06-21  5:46 ` [PATCH 01/15] mm/z3fold: add zpdesc struct and helper and use them in z3fold_page_isolate alexs
@ 2024-06-21  5:46 ` alexs
  2024-06-21  5:46 ` [PATCH 03/15] mm/z3fold: use zpdesc in z3fold_page_putback alexs
                   ` (14 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: alexs @ 2024-06-21  5:46 UTC (permalink / raw)
  To: Vitaly Wool, Miaohe Lin, Andrew Morton, linux-kernel, linux-mm,
	minchan, willy, senozhatsky, david, 42.hyeyoo
  Cc: Alex Shi

From: Alex Shi <alexs@kernel.org>

Convert page to zpdesc in z3fold_page_migrate. And introduce
zpdesc_get/put base on folio_get/put helpers, since z3fold only
deal with single pages.

This patch could save about 12Kbytes.

Signed-off-by: Alex Shi <alexs@kernel.org>
---
 mm/z3fold.c | 30 ++++++++++++++++--------------
 mm/zpdesc.h | 10 ++++++++++
 2 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/mm/z3fold.c b/mm/z3fold.c
index b1229c0520f1..b7f86c1b57a3 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -1290,18 +1290,20 @@ static int z3fold_page_migrate(struct page *newpage, struct page *page,
 {
 	struct z3fold_header *zhdr, *new_zhdr;
 	struct z3fold_pool *pool;
+	struct zpdesc *zpdesc = page_zpdesc(page);
+	struct zpdesc *newzpdesc = page_zpdesc(newpage);
 
-	VM_BUG_ON_PAGE(!PageIsolated(page), page);
-	VM_BUG_ON_PAGE(!test_bit(PAGE_CLAIMED, &page->private), page);
-	VM_BUG_ON_PAGE(!PageLocked(newpage), newpage);
+	VM_BUG_ON_PAGE(!PageIsolated(zpdesc_page(zpdesc)), zpdesc_page(zpdesc));
+	VM_BUG_ON_PAGE(!test_bit(PAGE_CLAIMED, &zpdesc->zppage_flag), zpdesc_page(zpdesc));
+	VM_BUG_ON_PAGE(!PageLocked(zpdesc_page(newzpdesc)), zpdesc_page(newzpdesc));
 
-	zhdr = page_address(page);
+	zhdr = zpdesc_address(zpdesc);
 	pool = zhdr_to_pool(zhdr);
 
 	if (!z3fold_page_trylock(zhdr))
 		return -EAGAIN;
 	if (zhdr->mapped_count != 0 || zhdr->foreign_handles != 0) {
-		clear_bit(PAGE_CLAIMED, &page->private);
+		clear_bit(PAGE_CLAIMED, &zpdesc->zppage_flag);
 		z3fold_page_unlock(zhdr);
 		return -EBUSY;
 	}
@@ -1309,10 +1311,10 @@ static int z3fold_page_migrate(struct page *newpage, struct page *page,
 		z3fold_page_unlock(zhdr);
 		return -EAGAIN;
 	}
-	new_zhdr = page_address(newpage);
+	new_zhdr = zpdesc_address(newzpdesc);
 	memcpy(new_zhdr, zhdr, PAGE_SIZE);
-	newpage->private = page->private;
-	set_bit(PAGE_MIGRATED, &page->private);
+	newzpdesc->zppage_flag = zpdesc->zppage_flag;
+	set_bit(PAGE_MIGRATED, &zpdesc->zppage_flag);
 	z3fold_page_unlock(zhdr);
 	spin_lock_init(&new_zhdr->page_lock);
 	INIT_WORK(&new_zhdr->work, compact_page_work);
@@ -1321,9 +1323,9 @@ static int z3fold_page_migrate(struct page *newpage, struct page *page,
 	 * so we only have to reinitialize it.
 	 */
 	INIT_LIST_HEAD(&new_zhdr->buddy);
-	__ClearPageMovable(page);
+	__ClearPageMovable(zpdesc_page(zpdesc));
 
-	get_page(newpage);
+	zpdesc_get(newzpdesc);
 	z3fold_page_lock(new_zhdr);
 	if (new_zhdr->first_chunks)
 		encode_handle(new_zhdr, FIRST);
@@ -1331,16 +1333,16 @@ static int z3fold_page_migrate(struct page *newpage, struct page *page,
 		encode_handle(new_zhdr, LAST);
 	if (new_zhdr->middle_chunks)
 		encode_handle(new_zhdr, MIDDLE);
-	set_bit(NEEDS_COMPACTING, &newpage->private);
+	set_bit(NEEDS_COMPACTING, &newzpdesc->zppage_flag);
 	new_zhdr->cpu = smp_processor_id();
-	__SetPageMovable(newpage, &z3fold_mops);
+	__SetPageMovable(zpdesc_page(newzpdesc), &z3fold_mops);
 	z3fold_page_unlock(new_zhdr);
 
 	queue_work_on(new_zhdr->cpu, pool->compact_wq, &new_zhdr->work);
 
 	/* PAGE_CLAIMED and PAGE_MIGRATED are cleared now. */
-	page->private = 0;
-	put_page(page);
+	zpdesc->zppage_flag = 0;
+	zpdesc_put(zpdesc);
 	return 0;
 }
 
diff --git a/mm/zpdesc.h b/mm/zpdesc.h
index d51785863596..7fde29645331 100644
--- a/mm/zpdesc.h
+++ b/mm/zpdesc.h
@@ -48,4 +48,14 @@ static inline void *zpdesc_address(const struct zpdesc *zpdesc)
 	return folio_address(zpdesc_folio(zpdesc));
 }
 
+static inline void zpdesc_get(struct zpdesc *zpdesc)
+{
+	folio_get(zpdesc_folio(zpdesc));
+}
+
+static inline void zpdesc_put(struct zpdesc *zpdesc)
+{
+	folio_put(zpdesc_folio(zpdesc));
+}
+
 #endif
-- 
2.43.0



^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 03/15] mm/z3fold: use zpdesc in z3fold_page_putback
  2024-06-21  5:46 [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool alexs
  2024-06-21  5:46 ` [PATCH 01/15] mm/z3fold: add zpdesc struct and helper and use them in z3fold_page_isolate alexs
  2024-06-21  5:46 ` [PATCH 02/15] mm/z3fold: use zpdesc in z3fold_page_migrate alexs
@ 2024-06-21  5:46 ` alexs
  2024-06-21  5:46 ` [PATCH 04/15] mm/z3fold: use zpdesc in get/put_z3fold_header funcs alexs
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: alexs @ 2024-06-21  5:46 UTC (permalink / raw)
  To: Vitaly Wool, Miaohe Lin, Andrew Morton, linux-kernel, linux-mm,
	minchan, willy, senozhatsky, david, 42.hyeyoo
  Cc: Alex Shi

From: Alex Shi <alexs@kernel.org>

Convert page to zpdesc in z3fold_page_putback function, and keep the
'page' parameter since the function hooks to page_putback, which is used
by other users.

Signed-off-by: Alex Shi <alexs@kernel.org>
---
 mm/z3fold.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/mm/z3fold.c b/mm/z3fold.c
index b7f86c1b57a3..5cb156fc03be 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -1350,8 +1350,9 @@ static void z3fold_page_putback(struct page *page)
 {
 	struct z3fold_header *zhdr;
 	struct z3fold_pool *pool;
+	struct zpdesc *zpdesc = page_zpdesc(page);
 
-	zhdr = page_address(page);
+	zhdr = zpdesc_address(zpdesc);
 	pool = zhdr_to_pool(zhdr);
 
 	z3fold_page_lock(zhdr);
@@ -1362,7 +1363,7 @@ static void z3fold_page_putback(struct page *page)
 		return;
 	if (list_empty(&zhdr->buddy))
 		add_to_unbuddied(pool, zhdr);
-	clear_bit(PAGE_CLAIMED, &page->private);
+	clear_bit(PAGE_CLAIMED, &zpdesc->zppage_flag);
 	z3fold_page_unlock(zhdr);
 }
 
-- 
2.43.0



^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 04/15] mm/z3fold: use zpdesc in get/put_z3fold_header funcs
  2024-06-21  5:46 [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool alexs
                   ` (2 preceding siblings ...)
  2024-06-21  5:46 ` [PATCH 03/15] mm/z3fold: use zpdesc in z3fold_page_putback alexs
@ 2024-06-21  5:46 ` alexs
  2024-06-21  5:46 ` [PATCH 05/15] mm/z3fold: use zpdesc in init_z3fold_page alexs
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: alexs @ 2024-06-21  5:46 UTC (permalink / raw)
  To: Vitaly Wool, Miaohe Lin, Andrew Morton, linux-kernel, linux-mm,
	minchan, willy, senozhatsky, david, 42.hyeyoo
  Cc: Alex Shi

From: Alex Shi <alexs@kernel.org>

Convert the get/put_z3fold_header funcs pair to use zpdesc.

Signed-off-by: Alex Shi <alexs@kernel.org>
---
 mm/z3fold.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/mm/z3fold.c b/mm/z3fold.c
index 5cb156fc03be..bfbc9f9fdfd4 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -254,9 +254,9 @@ static inline struct z3fold_header *get_z3fold_header(unsigned long handle)
 			locked = z3fold_page_trylock(zhdr);
 			read_unlock(&slots->lock);
 			if (locked) {
-				struct page *page = virt_to_page(zhdr);
+				struct zpdesc *zpdesc = page_zpdesc(virt_to_page(zhdr));
 
-				if (!test_bit(PAGE_MIGRATED, &page->private))
+				if (!test_bit(PAGE_MIGRATED, &zpdesc->zppage_flag))
 					break;
 				z3fold_page_unlock(zhdr);
 			}
@@ -271,9 +271,9 @@ static inline struct z3fold_header *get_z3fold_header(unsigned long handle)
 
 static inline void put_z3fold_header(struct z3fold_header *zhdr)
 {
-	struct page *page = virt_to_page(zhdr);
+	struct zpdesc *zpdesc = page_zpdesc(virt_to_page(zhdr));
 
-	if (!test_bit(PAGE_HEADLESS, &page->private))
+	if (!test_bit(PAGE_HEADLESS, &zpdesc->zppage_flag))
 		z3fold_page_unlock(zhdr);
 }
 
-- 
2.43.0



^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 05/15] mm/z3fold: use zpdesc in init_z3fold_page
  2024-06-21  5:46 [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool alexs
                   ` (3 preceding siblings ...)
  2024-06-21  5:46 ` [PATCH 04/15] mm/z3fold: use zpdesc in get/put_z3fold_header funcs alexs
@ 2024-06-21  5:46 ` alexs
  2024-06-21  5:46 ` [PATCH 06/15] mm/z3fold: use zpdesc in free_z3fold_page alexs
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: alexs @ 2024-06-21  5:46 UTC (permalink / raw)
  To: Vitaly Wool, Miaohe Lin, Andrew Morton, linux-kernel, linux-mm,
	minchan, willy, senozhatsky, david, 42.hyeyoo
  Cc: Alex Shi

From: Alex Shi <alexs@kernel.org>

The func only uses page.private member, now use zpdesc.zppage_flag to
replace it.

Signed-off-by: Alex Shi <alexs@kernel.org>
---
 mm/z3fold.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/mm/z3fold.c b/mm/z3fold.c
index bfbc9f9fdfd4..cd1332243c62 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -320,15 +320,16 @@ static inline void free_handle(unsigned long handle, struct z3fold_header *zhdr)
 static struct z3fold_header *init_z3fold_page(struct page *page, bool headless,
 					struct z3fold_pool *pool, gfp_t gfp)
 {
-	struct z3fold_header *zhdr = page_address(page);
+	struct zpdesc *zpdesc = page_zpdesc(page);
+	struct z3fold_header *zhdr = zpdesc_address(zpdesc);
 	struct z3fold_buddy_slots *slots;
 
-	clear_bit(PAGE_HEADLESS, &page->private);
-	clear_bit(MIDDLE_CHUNK_MAPPED, &page->private);
-	clear_bit(NEEDS_COMPACTING, &page->private);
-	clear_bit(PAGE_STALE, &page->private);
-	clear_bit(PAGE_CLAIMED, &page->private);
-	clear_bit(PAGE_MIGRATED, &page->private);
+	clear_bit(PAGE_HEADLESS, &zpdesc->zppage_flag);
+	clear_bit(MIDDLE_CHUNK_MAPPED, &zpdesc->zppage_flag);
+	clear_bit(NEEDS_COMPACTING, &zpdesc->zppage_flag);
+	clear_bit(PAGE_STALE, &zpdesc->zppage_flag);
+	clear_bit(PAGE_CLAIMED, &zpdesc->zppage_flag);
+	clear_bit(PAGE_MIGRATED, &zpdesc->zppage_flag);
 	if (headless)
 		return zhdr;
 
-- 
2.43.0



^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 06/15] mm/z3fold: use zpdesc in free_z3fold_page
  2024-06-21  5:46 [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool alexs
                   ` (4 preceding siblings ...)
  2024-06-21  5:46 ` [PATCH 05/15] mm/z3fold: use zpdesc in init_z3fold_page alexs
@ 2024-06-21  5:46 ` alexs
  2024-06-21  5:46 ` [PATCH 07/15] mm/z3fold: convert page to zpdesc in __release_z3fold_page alexs
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: alexs @ 2024-06-21  5:46 UTC (permalink / raw)
  To: Vitaly Wool, Miaohe Lin, Andrew Morton, linux-kernel, linux-mm,
	minchan, willy, senozhatsky, david, 42.hyeyoo
  Cc: Alex Shi

From: Alex Shi <alexs@kernel.org>

Convert page to zpdesc in free_z3fold_page and introduce new helper
zpdesc_lock/unlock. this patch could saves about 10kbytes on object
file size.

Signed-off-by: Alex Shi <alexs@kernel.org>
---
 mm/z3fold.c | 10 ++++++----
 mm/zpdesc.h | 10 ++++++++++
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/mm/z3fold.c b/mm/z3fold.c
index cd1332243c62..c3c740b42052 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -351,12 +351,14 @@ static struct z3fold_header *init_z3fold_page(struct page *page, bool headless,
 /* Resets the struct page fields and frees the page */
 static void free_z3fold_page(struct page *page, bool headless)
 {
+	struct zpdesc *zpdesc = page_zpdesc(page);
+
 	if (!headless) {
-		lock_page(page);
-		__ClearPageMovable(page);
-		unlock_page(page);
+		zpdesc_lock(zpdesc);
+		__ClearPageMovable(zpdesc_page(zpdesc));
+		zpdesc_unlock(zpdesc);
 	}
-	__free_page(page);
+	__free_page(zpdesc_page(zpdesc));
 }
 
 /* Helper function to build the index */
diff --git a/mm/zpdesc.h b/mm/zpdesc.h
index 7fde29645331..06cfd33de330 100644
--- a/mm/zpdesc.h
+++ b/mm/zpdesc.h
@@ -58,4 +58,14 @@ static inline void zpdesc_put(struct zpdesc *zpdesc)
 	folio_put(zpdesc_folio(zpdesc));
 }
 
+static inline void zpdesc_lock(struct zpdesc *zpdesc)
+{
+	folio_lock(zpdesc_folio(zpdesc));
+}
+
+static inline void zpdesc_unlock(struct zpdesc *zpdesc)
+{
+	folio_unlock(zpdesc_folio(zpdesc));
+}
+
 #endif
-- 
2.43.0



^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 07/15] mm/z3fold: convert page to zpdesc in __release_z3fold_page
  2024-06-21  5:46 [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool alexs
                   ` (5 preceding siblings ...)
  2024-06-21  5:46 ` [PATCH 06/15] mm/z3fold: use zpdesc in free_z3fold_page alexs
@ 2024-06-21  5:46 ` alexs
  2024-06-21  5:46 ` [PATCH 08/15] mm/z3fold: use zpdesc free_pages_work alexs
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: alexs @ 2024-06-21  5:46 UTC (permalink / raw)
  To: Vitaly Wool, Miaohe Lin, Andrew Morton, linux-kernel, linux-mm,
	minchan, willy, senozhatsky, david, 42.hyeyoo
  Cc: Alex Shi

From: Alex Shi <alexs@kernel.org>

The main purpose is converting page->private to zpdesc->zppage_flag.

Signed-off-by: Alex Shi <alexs@kernel.org>
---
 mm/z3fold.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/z3fold.c b/mm/z3fold.c
index c3c740b42052..afdf21024f83 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -441,12 +441,12 @@ static inline struct z3fold_pool *zhdr_to_pool(struct z3fold_header *zhdr)
 
 static void __release_z3fold_page(struct z3fold_header *zhdr, bool locked)
 {
-	struct page *page = virt_to_page(zhdr);
+	struct zpdesc *zpdesc = page_zpdesc(virt_to_page(zhdr));
 	struct z3fold_pool *pool = zhdr_to_pool(zhdr);
 
 	WARN_ON(!list_empty(&zhdr->buddy));
-	set_bit(PAGE_STALE, &page->private);
-	clear_bit(NEEDS_COMPACTING, &page->private);
+	set_bit(PAGE_STALE, &zpdesc->zppage_flag);
+	clear_bit(NEEDS_COMPACTING, &zpdesc->zppage_flag);
 	spin_lock(&pool->lock);
 	spin_unlock(&pool->lock);
 
-- 
2.43.0



^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 08/15] mm/z3fold: use zpdesc free_pages_work
  2024-06-21  5:46 [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool alexs
                   ` (6 preceding siblings ...)
  2024-06-21  5:46 ` [PATCH 07/15] mm/z3fold: convert page to zpdesc in __release_z3fold_page alexs
@ 2024-06-21  5:46 ` alexs
  2024-06-21  5:46 ` [PATCH 09/15] mm/z3fold: use zpdesc in z3fold_compact_page and do_compact_page alexs
                   ` (8 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: alexs @ 2024-06-21  5:46 UTC (permalink / raw)
  To: Vitaly Wool, Miaohe Lin, Andrew Morton, linux-kernel, linux-mm,
	minchan, willy, senozhatsky, david, 42.hyeyoo
  Cc: Alex Shi

From: Alex Shi <alexs@kernel.org>

The main purpose is converting page->private to zpdesc->zppage_flag.

Signed-off-by: Alex Shi <alexs@kernel.org>
---
 mm/z3fold.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/z3fold.c b/mm/z3fold.c
index afdf21024f83..97580e2224c2 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -501,14 +501,14 @@ static void free_pages_work(struct work_struct *w)
 	while (!list_empty(&pool->stale)) {
 		struct z3fold_header *zhdr = list_first_entry(&pool->stale,
 						struct z3fold_header, buddy);
-		struct page *page = virt_to_page(zhdr);
+		struct zpdesc *zpdesc = page_zpdesc(virt_to_page(zhdr));
 
 		list_del(&zhdr->buddy);
-		if (WARN_ON(!test_bit(PAGE_STALE, &page->private)))
+		if (WARN_ON(!test_bit(PAGE_STALE, &zpdesc->zppage_flag)))
 			continue;
 		spin_unlock(&pool->stale_lock);
 		cancel_work_sync(&zhdr->work);
-		free_z3fold_page(page, false);
+		free_z3fold_page(zpdesc_page(zpdesc), false);
 		cond_resched();
 		spin_lock(&pool->stale_lock);
 	}
-- 
2.43.0



^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 09/15] mm/z3fold: use zpdesc in z3fold_compact_page and do_compact_page
  2024-06-21  5:46 [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool alexs
                   ` (7 preceding siblings ...)
  2024-06-21  5:46 ` [PATCH 08/15] mm/z3fold: use zpdesc free_pages_work alexs
@ 2024-06-21  5:46 ` alexs
  2024-06-21  5:46 ` [PATCH 10/15] mm/z3fold: use zpdesc in __z3fold_alloc alexs
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: alexs @ 2024-06-21  5:46 UTC (permalink / raw)
  To: Vitaly Wool, Miaohe Lin, Andrew Morton, linux-kernel, linux-mm,
	minchan, willy, senozhatsky, david, 42.hyeyoo
  Cc: Alex Shi

From: Alex Shi <alexs@kernel.org>

The main purpose is converting page->private to zpdesc->zppage_flag too.

Signed-off-by: Alex Shi <alexs@kernel.org>
---
 mm/z3fold.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/mm/z3fold.c b/mm/z3fold.c
index 97580e2224c2..3d36448885c9 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -691,12 +691,12 @@ static struct z3fold_header *compact_single_buddy(struct z3fold_header *zhdr)
 /* Has to be called with lock held */
 static int z3fold_compact_page(struct z3fold_header *zhdr)
 {
-	struct page *page = virt_to_page(zhdr);
+	struct zpdesc *zpdesc = page_zpdesc(virt_to_page(zhdr));
 
-	if (test_bit(MIDDLE_CHUNK_MAPPED, &page->private))
+	if (test_bit(MIDDLE_CHUNK_MAPPED, &zpdesc->zppage_flag))
 		return 0; /* can't move middle chunk, it's used */
 
-	if (unlikely(PageIsolated(page)))
+	if (unlikely(PageIsolated(zpdesc_page(zpdesc))))
 		return 0;
 
 	if (zhdr->middle_chunks == 0)
@@ -739,14 +739,13 @@ static int z3fold_compact_page(struct z3fold_header *zhdr)
 static void do_compact_page(struct z3fold_header *zhdr, bool locked)
 {
 	struct z3fold_pool *pool = zhdr_to_pool(zhdr);
-	struct page *page;
+	struct zpdesc *zpdesc = page_zpdesc(virt_to_page(zhdr));
 
-	page = virt_to_page(zhdr);
 	if (locked)
 		WARN_ON(z3fold_page_trylock(zhdr));
 	else
 		z3fold_page_lock(zhdr);
-	if (WARN_ON(!test_and_clear_bit(NEEDS_COMPACTING, &page->private))) {
+	if (WARN_ON(!test_and_clear_bit(NEEDS_COMPACTING, &zpdesc->zppage_flag))) {
 		z3fold_page_unlock(zhdr);
 		return;
 	}
@@ -757,8 +756,8 @@ static void do_compact_page(struct z3fold_header *zhdr, bool locked)
 	if (put_z3fold_locked(zhdr))
 		return;
 
-	if (test_bit(PAGE_STALE, &page->private) ||
-	    test_and_set_bit(PAGE_CLAIMED, &page->private)) {
+	if (test_bit(PAGE_STALE, &zpdesc->zppage_flag) ||
+	    test_and_set_bit(PAGE_CLAIMED, &zpdesc->zppage_flag)) {
 		z3fold_page_unlock(zhdr);
 		return;
 	}
@@ -766,7 +765,7 @@ static void do_compact_page(struct z3fold_header *zhdr, bool locked)
 	if (!zhdr->foreign_handles && buddy_single(zhdr) &&
 	    zhdr->mapped_count == 0 && compact_single_buddy(zhdr)) {
 		if (!put_z3fold_locked(zhdr)) {
-			clear_bit(PAGE_CLAIMED, &page->private);
+			clear_bit(PAGE_CLAIMED, &zpdesc->zppage_flag);
 			z3fold_page_unlock(zhdr);
 		}
 		return;
@@ -774,7 +773,7 @@ static void do_compact_page(struct z3fold_header *zhdr, bool locked)
 
 	z3fold_compact_page(zhdr);
 	add_to_unbuddied(pool, zhdr);
-	clear_bit(PAGE_CLAIMED, &page->private);
+	clear_bit(PAGE_CLAIMED, &zpdesc->zppage_flag);
 	z3fold_page_unlock(zhdr);
 }
 
-- 
2.43.0



^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 10/15] mm/z3fold: use zpdesc in __z3fold_alloc
  2024-06-21  5:46 [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool alexs
                   ` (8 preceding siblings ...)
  2024-06-21  5:46 ` [PATCH 09/15] mm/z3fold: use zpdesc in z3fold_compact_page and do_compact_page alexs
@ 2024-06-21  5:46 ` alexs
  2024-06-21  5:46 ` [PATCH 11/15] mm/z3fold: use zpdesc in z3fold_alloc alexs
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: alexs @ 2024-06-21  5:46 UTC (permalink / raw)
  To: Vitaly Wool, Miaohe Lin, Andrew Morton, linux-kernel, linux-mm,
	minchan, willy, senozhatsky, david, 42.hyeyoo
  Cc: Alex Shi

From: Alex Shi <alexs@kernel.org>

The main purpose is converting page->private to zpdesc->zppage_flag.

Signed-off-by: Alex Shi <alexs@kernel.org>
---
 mm/z3fold.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/mm/z3fold.c b/mm/z3fold.c
index 3d36448885c9..f164eb4e1139 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -790,7 +790,7 @@ static inline struct z3fold_header *__z3fold_alloc(struct z3fold_pool *pool,
 						size_t size, bool can_sleep)
 {
 	struct z3fold_header *zhdr = NULL;
-	struct page *page;
+	struct zpdesc *zpdesc;
 	struct list_head *unbuddied;
 	int chunks = size_to_chunks(size), i;
 
@@ -823,9 +823,9 @@ static inline struct z3fold_header *__z3fold_alloc(struct z3fold_pool *pool,
 		zhdr->cpu = -1;
 		spin_unlock(&pool->lock);
 
-		page = virt_to_page(zhdr);
-		if (test_bit(NEEDS_COMPACTING, &page->private) ||
-		    test_bit(PAGE_CLAIMED, &page->private)) {
+		zpdesc = page_zpdesc(virt_to_page(zhdr));
+		if (test_bit(NEEDS_COMPACTING, &zpdesc->zppage_flag) ||
+		    test_bit(PAGE_CLAIMED, &zpdesc->zppage_flag)) {
 			z3fold_page_unlock(zhdr);
 			zhdr = NULL;
 			migrate_enable();
@@ -868,9 +868,9 @@ static inline struct z3fold_header *__z3fold_alloc(struct z3fold_pool *pool,
 			zhdr->cpu = -1;
 			spin_unlock(&pool->lock);
 
-			page = virt_to_page(zhdr);
-			if (test_bit(NEEDS_COMPACTING, &page->private) ||
-			    test_bit(PAGE_CLAIMED, &page->private)) {
+			zpdesc = page_zpdesc(virt_to_page(zhdr));
+			if (test_bit(NEEDS_COMPACTING, &zpdesc->zppage_flag) ||
+			    test_bit(PAGE_CLAIMED, &zpdesc->zppage_flag)) {
 				z3fold_page_unlock(zhdr);
 				zhdr = NULL;
 				if (can_sleep)
-- 
2.43.0



^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 11/15] mm/z3fold: use zpdesc in z3fold_alloc
  2024-06-21  5:46 [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool alexs
                   ` (9 preceding siblings ...)
  2024-06-21  5:46 ` [PATCH 10/15] mm/z3fold: use zpdesc in __z3fold_alloc alexs
@ 2024-06-21  5:46 ` alexs
  2024-06-21  5:46 ` [PATCH 12/15] mm/z3fold: use zpdesc in free_z3fold_page and z3fold_free alexs
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: alexs @ 2024-06-21  5:46 UTC (permalink / raw)
  To: Vitaly Wool, Miaohe Lin, Andrew Morton, linux-kernel, linux-mm,
	minchan, willy, senozhatsky, david, 42.hyeyoo
  Cc: Alex Shi

From: Alex Shi <alexs@kernel.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@gmail.com>
Signed-off-by: Alex Shi <alexs@kernel.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



^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 12/15] mm/z3fold: use zpdesc in free_z3fold_page and z3fold_free
  2024-06-21  5:46 [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool alexs
                   ` (10 preceding siblings ...)
  2024-06-21  5:46 ` [PATCH 11/15] mm/z3fold: use zpdesc in z3fold_alloc alexs
@ 2024-06-21  5:46 ` alexs
  2024-06-21  5:46 ` [PATCH 13/15] mm/z3fold: use zpdesc in z3fold_map/z3fold_unmap alexs
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: alexs @ 2024-06-21  5:46 UTC (permalink / raw)
  To: Vitaly Wool, Miaohe Lin, Andrew Morton, linux-kernel, linux-mm,
	minchan, willy, senozhatsky, david, 42.hyeyoo
  Cc: Alex Shi

From: Alex Shi <alexs@kernel.org>

Convert page to zpdesc in free_z3fold_page and its caller z3fold_free,
it could save 430bytes.

Signed-off-by: Alex Shi <alexs@kernel.org>
---
 mm/z3fold.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/mm/z3fold.c b/mm/z3fold.c
index e780143982c6..6283f90d1c22 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -347,11 +347,9 @@ static struct z3fold_header *init_z3fold_page(struct zpdesc *zpdesc, bool headle
 	return zhdr;
 }
 
-/* Resets the struct page fields and frees the page */
-static void free_z3fold_page(struct page *page, bool headless)
+/* Resets the struct zpdesc fields and frees the page */
+static void free_z3fold_page(struct zpdesc *zpdesc, bool headless)
 {
-	struct zpdesc *zpdesc = page_zpdesc(page);
-
 	if (!headless) {
 		zpdesc_lock(zpdesc);
 		__ClearPageMovable(zpdesc_page(zpdesc));
@@ -507,7 +505,7 @@ static void free_pages_work(struct work_struct *w)
 			continue;
 		spin_unlock(&pool->stale_lock);
 		cancel_work_sync(&zhdr->work);
-		free_z3fold_page(zpdesc_page(zpdesc), false);
+		free_z3fold_page(zpdesc, false);
 		cond_resched();
 		spin_lock(&pool->stale_lock);
 	}
@@ -1095,15 +1093,15 @@ static int z3fold_alloc(struct z3fold_pool *pool, size_t size, gfp_t gfp,
 static void z3fold_free(struct z3fold_pool *pool, unsigned long handle)
 {
 	struct z3fold_header *zhdr;
-	struct page *page;
+	struct zpdesc *zpdesc;
 	enum buddy bud;
 	bool page_claimed;
 
 	zhdr = get_z3fold_header(handle);
-	page = virt_to_page(zhdr);
-	page_claimed = test_and_set_bit(PAGE_CLAIMED, &page->private);
+	zpdesc = page_zpdesc(virt_to_page(zhdr));
+	page_claimed = test_and_set_bit(PAGE_CLAIMED, &zpdesc->zppage_flag);
 
-	if (test_bit(PAGE_HEADLESS, &page->private)) {
+	if (test_bit(PAGE_HEADLESS, &zpdesc->zppage_flag)) {
 		/* if a headless page is under reclaim, just leave.
 		 * NB: we use test_and_set_bit for a reason: if the bit
 		 * has not been set before, we release this page
@@ -1111,7 +1109,7 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle)
 		 */
 		if (!page_claimed) {
 			put_z3fold_header(zhdr);
-			free_z3fold_page(page, true);
+			free_z3fold_page(zpdesc, true);
 			atomic64_dec(&pool->pages_nr);
 		}
 		return;
@@ -1146,20 +1144,20 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle)
 		put_z3fold_header(zhdr);
 		return;
 	}
-	if (test_and_set_bit(NEEDS_COMPACTING, &page->private)) {
-		clear_bit(PAGE_CLAIMED, &page->private);
+	if (test_and_set_bit(NEEDS_COMPACTING, &zpdesc->zppage_flag)) {
+		clear_bit(PAGE_CLAIMED, &zpdesc->zppage_flag);
 		put_z3fold_header(zhdr);
 		return;
 	}
 	if (zhdr->cpu < 0 || !cpu_online(zhdr->cpu)) {
 		zhdr->cpu = -1;
 		kref_get(&zhdr->refcount);
-		clear_bit(PAGE_CLAIMED, &page->private);
+		clear_bit(PAGE_CLAIMED, &zpdesc->zppage_flag);
 		do_compact_page(zhdr, true);
 		return;
 	}
 	kref_get(&zhdr->refcount);
-	clear_bit(PAGE_CLAIMED, &page->private);
+	clear_bit(PAGE_CLAIMED, &zpdesc->zppage_flag);
 	queue_work_on(zhdr->cpu, pool->compact_wq, &zhdr->work);
 	put_z3fold_header(zhdr);
 }
-- 
2.43.0



^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 13/15] mm/z3fold: use zpdesc in z3fold_map/z3fold_unmap
  2024-06-21  5:46 [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool alexs
                   ` (11 preceding siblings ...)
  2024-06-21  5:46 ` [PATCH 12/15] mm/z3fold: use zpdesc in free_z3fold_page and z3fold_free alexs
@ 2024-06-21  5:46 ` alexs
  2024-06-21  5:46 ` [PATCH 14/15] mm/z3fold: introduce __zpdesc_set_movable alexs
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: alexs @ 2024-06-21  5:46 UTC (permalink / raw)
  To: Vitaly Wool, Miaohe Lin, Andrew Morton, linux-kernel, linux-mm,
	minchan, willy, senozhatsky, david, 42.hyeyoo
  Cc: Alex Shi

From: Alex Shi <alexs@kernel.org>

Convert page to zpdesc in z3fold_map/z3fold_unmap pair, the main purpose
is doing page->private to zpdesc->zppage_flag conversion.

Signed-off-by: Alex Shi <alexs@kernel.org>
---
 mm/z3fold.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/mm/z3fold.c b/mm/z3fold.c
index 6283f90d1c22..7d95c0293664 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -1175,15 +1175,15 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle)
 static void *z3fold_map(struct z3fold_pool *pool, unsigned long handle)
 {
 	struct z3fold_header *zhdr;
-	struct page *page;
+	struct zpdesc *zpdesc;
 	void *addr;
 	enum buddy buddy;
 
 	zhdr = get_z3fold_header(handle);
 	addr = zhdr;
-	page = virt_to_page(zhdr);
+	zpdesc = page_zpdesc(virt_to_page(zhdr));
 
-	if (test_bit(PAGE_HEADLESS, &page->private))
+	if (test_bit(PAGE_HEADLESS, &zpdesc->zppage_flag))
 		goto out;
 
 	buddy = handle_to_buddy(handle);
@@ -1193,7 +1193,7 @@ static void *z3fold_map(struct z3fold_pool *pool, unsigned long handle)
 		break;
 	case MIDDLE:
 		addr += zhdr->start_middle << CHUNK_SHIFT;
-		set_bit(MIDDLE_CHUNK_MAPPED, &page->private);
+		set_bit(MIDDLE_CHUNK_MAPPED, &zpdesc->zppage_flag);
 		break;
 	case LAST:
 		addr += PAGE_SIZE - (handle_to_chunks(handle) << CHUNK_SHIFT);
@@ -1220,18 +1220,18 @@ static void *z3fold_map(struct z3fold_pool *pool, unsigned long handle)
 static void z3fold_unmap(struct z3fold_pool *pool, unsigned long handle)
 {
 	struct z3fold_header *zhdr;
-	struct page *page;
+	struct zpdesc *zpdesc;
 	enum buddy buddy;
 
 	zhdr = get_z3fold_header(handle);
-	page = virt_to_page(zhdr);
+	zpdesc = page_zpdesc(virt_to_page(zhdr));
 
-	if (test_bit(PAGE_HEADLESS, &page->private))
+	if (test_bit(PAGE_HEADLESS, &zpdesc->zppage_flag))
 		return;
 
 	buddy = handle_to_buddy(handle);
 	if (buddy == MIDDLE)
-		clear_bit(MIDDLE_CHUNK_MAPPED, &page->private);
+		clear_bit(MIDDLE_CHUNK_MAPPED, &zpdesc->zppage_flag);
 	zhdr->mapped_count--;
 	put_z3fold_header(zhdr);
 }
-- 
2.43.0



^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 14/15] mm/z3fold: introduce __zpdesc_set_movable
  2024-06-21  5:46 [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool alexs
                   ` (12 preceding siblings ...)
  2024-06-21  5:46 ` [PATCH 13/15] mm/z3fold: use zpdesc in z3fold_map/z3fold_unmap alexs
@ 2024-06-21  5:46 ` alexs
  2024-06-21  5:46 ` [PATCH 15/15] mm/z3fold: introduce __zpdesc_clear_movable alexs
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: alexs @ 2024-06-21  5:46 UTC (permalink / raw)
  To: Vitaly Wool, Miaohe Lin, Andrew Morton, linux-kernel, linux-mm,
	minchan, willy, senozhatsky, david, 42.hyeyoo
  Cc: Alex Shi

From: Alex Shi <alexs@kernel.org>

Add a helper __zpdesc_set_movable() for __SetPageMovable(), and use it
in callers.
Since we actually use the page.mapping for 'struct movable_operations'
pointer, we could add it into zpdesc struct now.

Originally-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>
Signed-off-by: Alex Shi <alexs@kernel.org>
---
 mm/z3fold.c | 6 +++---
 mm/zpdesc.h | 6 ++++++
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/mm/z3fold.c b/mm/z3fold.c
index 7d95c0293664..35e48440c517 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -1050,11 +1050,11 @@ static int z3fold_alloc(struct z3fold_pool *pool, size_t size, gfp_t gfp,
 	}
 	if (can_sleep) {
 		zpdesc_lock(zpdesc);
-		__SetPageMovable(zpdesc_page(zpdesc), &z3fold_mops);
+		__zpdesc_set_movable(zpdesc, &z3fold_mops);
 		zpdesc_unlock(zpdesc);
 	} else {
 		WARN_ON(!zpdesc_trylock(zpdesc));
-		__SetPageMovable(zpdesc_page(zpdesc), &z3fold_mops);
+		__zpdesc_set_movable(zpdesc, &z3fold_mops);
 		zpdesc_unlock(zpdesc);
 	}
 	z3fold_page_lock(zhdr);
@@ -1334,7 +1334,7 @@ static int z3fold_page_migrate(struct page *newpage, struct page *page,
 		encode_handle(new_zhdr, MIDDLE);
 	set_bit(NEEDS_COMPACTING, &newzpdesc->zppage_flag);
 	new_zhdr->cpu = smp_processor_id();
-	__SetPageMovable(zpdesc_page(newzpdesc), &z3fold_mops);
+	__zpdesc_set_movable(newzpdesc, &z3fold_mops);
 	z3fold_page_unlock(new_zhdr);
 
 	queue_work_on(new_zhdr->cpu, pool->compact_wq, &new_zhdr->work);
diff --git a/mm/zpdesc.h b/mm/zpdesc.h
index 9ead7a452f2a..44473382f2cc 100644
--- a/mm/zpdesc.h
+++ b/mm/zpdesc.h
@@ -73,4 +73,10 @@ static inline void zpdesc_unlock(struct zpdesc *zpdesc)
 	folio_unlock(zpdesc_folio(zpdesc));
 }
 
+static inline void __zpdesc_set_movable(struct zpdesc *zpdesc,
+					const struct movable_operations *mops)
+{
+	__SetPageMovable(zpdesc_page(zpdesc), mops);
+}
+
 #endif
-- 
2.43.0



^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 15/15] mm/z3fold: introduce __zpdesc_clear_movable
  2024-06-21  5:46 [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool alexs
                   ` (13 preceding siblings ...)
  2024-06-21  5:46 ` [PATCH 14/15] mm/z3fold: introduce __zpdesc_set_movable alexs
@ 2024-06-21  5:46 ` alexs
  2024-06-21  6:43 ` [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool Alex Shi
  2024-06-24 21:46 ` Yosry Ahmed
  16 siblings, 0 replies; 25+ messages in thread
From: alexs @ 2024-06-21  5:46 UTC (permalink / raw)
  To: Vitaly Wool, Miaohe Lin, Andrew Morton, linux-kernel, linux-mm,
	minchan, willy, senozhatsky, david, 42.hyeyoo
  Cc: Alex Shi

From: Alex Shi <alexs@kernel.org>

Add a helper __zpdesc_clear_movable() for __ClearPageMovable(), and use it
in callers, that make code clear.

Signed-off-by: Alex Shi <alexs@kernel.org>
---
 mm/z3fold.c | 4 ++--
 mm/zpdesc.h | 5 +++++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/mm/z3fold.c b/mm/z3fold.c
index 35e48440c517..e23d56f46760 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -352,7 +352,7 @@ static void free_z3fold_page(struct zpdesc *zpdesc, bool headless)
 {
 	if (!headless) {
 		zpdesc_lock(zpdesc);
-		__ClearPageMovable(zpdesc_page(zpdesc));
+		__zpdesc_clear_movable(zpdesc);
 		zpdesc_unlock(zpdesc);
 	}
 	__free_page(zpdesc_page(zpdesc));
@@ -1322,7 +1322,7 @@ static int z3fold_page_migrate(struct page *newpage, struct page *page,
 	 * so we only have to reinitialize it.
 	 */
 	INIT_LIST_HEAD(&new_zhdr->buddy);
-	__ClearPageMovable(zpdesc_page(zpdesc));
+	__zpdesc_clear_movable(zpdesc);
 
 	zpdesc_get(newzpdesc);
 	z3fold_page_lock(new_zhdr);
diff --git a/mm/zpdesc.h b/mm/zpdesc.h
index 44473382f2cc..1319575dc31a 100644
--- a/mm/zpdesc.h
+++ b/mm/zpdesc.h
@@ -79,4 +79,9 @@ static inline void __zpdesc_set_movable(struct zpdesc *zpdesc,
 	__SetPageMovable(zpdesc_page(zpdesc), mops);
 }
 
+static inline void __zpdesc_clear_movable(struct zpdesc *zpdesc)
+{
+	__ClearPageMovable(zpdesc_page(zpdesc));
+}
+
 #endif
-- 
2.43.0



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool
  2024-06-21  5:46 [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool alexs
                   ` (14 preceding siblings ...)
  2024-06-21  5:46 ` [PATCH 15/15] mm/z3fold: introduce __zpdesc_clear_movable alexs
@ 2024-06-21  6:43 ` Alex Shi
  2024-06-24 21:46 ` Yosry Ahmed
  16 siblings, 0 replies; 25+ messages in thread
From: Alex Shi @ 2024-06-21  6:43 UTC (permalink / raw)
  To: alexs, Vitaly Wool, Miaohe Lin, Andrew Morton, linux-kernel,
	linux-mm, minchan, willy, senozhatsky, david, 42.hyeyoo



On 6/21/24 1:46 PM, alexs@kernel.org wrote:
> From: Alex Shi <alexs@kernel.org>
> 
> According to Metthew's plan, the page descriptor will be replace by a 8
> bytes mem_desc on destination purpose.
> https://lore.kernel.org/lkml/YvV1KTyzZ+Jrtj9x@casper.infradead.org/
> 
> Here is a implement on z3fold to replace page descriptor by zpdesc,
> which is still overlay on struct page now. but it's a step move forward
> above destination.
> 
> To name the struct zpdesc instead of z3fold_desc, since there are 3 zpool
> usages under zswap, zbud, z3fold, zsmalloc. It looks like we may extend the
> zpdesc to zbud and zsmalloc, combined their usage into one.
BTW, 
Thanks for David and Willy's suggestion!
Since all zpool candidates are single page users, then we could use zpdesc to
descript them all in future.

Thanks

> 
> For zpdesc(page), z3fold just uses the 5th member zppage_flag, which
> match with page.private. Potentially uses the first member flags for
> headless PG_locked, list_head lru and page.mapping|PAGE_MAPPING_MOVABLE
> for page migration.> 
> This patachset could save 26Kbyetes z3fold.o size, basely saving come
> from the page to folio conversion.
> 
> Thanks a lot!
> Alex
> 
> Alex Shi (15):
>   mm/z3fold: add zpdesc struct and helper and use them in
>     z3fold_page_isolate
>   mm/z3fold: use zpdesc in z3fold_page_migrate
>   mm/z3fold: use zpdesc in z3fold_page_putback
>   mm/z3fold: use zpdesc in get/put_z3fold_header funcs
>   mm/z3fold: use zpdesc in init_z3fold_page
>   mm/z3fold: use zpdesc in free_z3fold_page
>   mm/z3fold: convert page to zpdesc in __release_z3fold_page
>   mm/z3fold: use zpdesc free_pages_work
>   mm/z3fold: use zpdesc in z3fold_compact_page and do_compact_page
>   mm/z3fold: use zpdesc in __z3fold_alloc
>   mm/z3fold: use zpdesc in z3fold_alloc
>   mm/z3fold: use zpdesc in free_z3fold_page and z3fold_free
>   mm/z3fold: use zpdesc in z3fold_map/z3fold_unmap
>   mm/z3fold: introduce __zpdesc_set_movable
>   mm/z3fold: introduce __zpdesc_clear_movable
> 
>  mm/z3fold.c | 190 +++++++++++++++++++++++++++-------------------------
>  mm/zpdesc.h |  87 ++++++++++++++++++++++++
>  2 files changed, 184 insertions(+), 93 deletions(-)
>  create mode 100644 mm/zpdesc.h
> 


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool
  2024-06-21  5:46 [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool alexs
                   ` (15 preceding siblings ...)
  2024-06-21  6:43 ` [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool Alex Shi
@ 2024-06-24 21:46 ` Yosry Ahmed
  2024-06-25  8:11   ` Alex Shi
  16 siblings, 1 reply; 25+ messages in thread
From: Yosry Ahmed @ 2024-06-24 21:46 UTC (permalink / raw)
  To: alexs
  Cc: Vitaly Wool, Miaohe Lin, Andrew Morton, linux-kernel, linux-mm,
	minchan, willy, senozhatsky, david, 42.hyeyoo

On Thu, Jun 20, 2024 at 10:42 PM <alexs@kernel.org> wrote:
>
> From: Alex Shi <alexs@kernel.org>
>
> According to Metthew's plan, the page descriptor will be replace by a 8
> bytes mem_desc on destination purpose.
> https://lore.kernel.org/lkml/YvV1KTyzZ+Jrtj9x@casper.infradead.org/
>
> Here is a implement on z3fold to replace page descriptor by zpdesc,
> which is still overlay on struct page now. but it's a step move forward
> above destination.
>
> To name the struct zpdesc instead of z3fold_desc, since there are 3 zpool
> usages under zswap, zbud, z3fold, zsmalloc. It looks like we may extend the
> zpdesc to zbud and zsmalloc, combined their usage into one.

Please do not focus your development efforts on z3fold. We really want
to deprecate/remove it, as well as zbud eventually. See [1].

For zsmalloc, there is already an ongoing effort to split zsdesc from
struct page [2].

[1]https://lore.kernel.org/lkml/CAJD7tkbRF6od-2x_L8-A1QL3=2Ww13sCj4S3i4bNndqF+3+_Vg@mail.gmail.com/

[2]https://lore.kernel.org/lkml/20230713042037.980211-1-42.hyeyoo@gmail.com/

>
> For zpdesc(page), z3fold just uses the 5th member zppage_flag, which
> match with page.private. Potentially uses the first member flags for
> headless PG_locked, list_head lru and page.mapping|PAGE_MAPPING_MOVABLE
> for page migration.
>
> This patachset could save 26Kbyetes z3fold.o size, basely saving come
> from the page to folio conversion.
>
> Thanks a lot!
> Alex
>
> Alex Shi (15):
>   mm/z3fold: add zpdesc struct and helper and use them in
>     z3fold_page_isolate
>   mm/z3fold: use zpdesc in z3fold_page_migrate
>   mm/z3fold: use zpdesc in z3fold_page_putback
>   mm/z3fold: use zpdesc in get/put_z3fold_header funcs
>   mm/z3fold: use zpdesc in init_z3fold_page
>   mm/z3fold: use zpdesc in free_z3fold_page
>   mm/z3fold: convert page to zpdesc in __release_z3fold_page
>   mm/z3fold: use zpdesc free_pages_work
>   mm/z3fold: use zpdesc in z3fold_compact_page and do_compact_page
>   mm/z3fold: use zpdesc in __z3fold_alloc
>   mm/z3fold: use zpdesc in z3fold_alloc
>   mm/z3fold: use zpdesc in free_z3fold_page and z3fold_free
>   mm/z3fold: use zpdesc in z3fold_map/z3fold_unmap
>   mm/z3fold: introduce __zpdesc_set_movable
>   mm/z3fold: introduce __zpdesc_clear_movable
>
>  mm/z3fold.c | 190 +++++++++++++++++++++++++++-------------------------
>  mm/zpdesc.h |  87 ++++++++++++++++++++++++
>  2 files changed, 184 insertions(+), 93 deletions(-)
>  create mode 100644 mm/zpdesc.h
>
> --
> 2.43.0
>
>


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool
  2024-06-24 21:46 ` Yosry Ahmed
@ 2024-06-25  8:11   ` Alex Shi
  2024-06-25  9:28     ` Hyeonggon Yoo
  2024-06-25 10:30     ` Yosry Ahmed
  0 siblings, 2 replies; 25+ messages in thread
From: Alex Shi @ 2024-06-25  8:11 UTC (permalink / raw)
  To: Yosry Ahmed, alexs
  Cc: Vitaly Wool, Miaohe Lin, Andrew Morton, linux-kernel, linux-mm,
	minchan, willy, senozhatsky, david, 42.hyeyoo



On 6/25/24 5:46 AM, Yosry Ahmed wrote:
> On Thu, Jun 20, 2024 at 10:42 PM <alexs@kernel.org> wrote:
>>
>> From: Alex Shi <alexs@kernel.org>
>>
>> According to Metthew's plan, the page descriptor will be replace by a 8
>> bytes mem_desc on destination purpose.
>> https://lore.kernel.org/lkml/YvV1KTyzZ+Jrtj9x@casper.infradead.org/
>>
>> Here is a implement on z3fold to replace page descriptor by zpdesc,
>> which is still overlay on struct page now. but it's a step move forward
>> above destination.
>>
>> To name the struct zpdesc instead of z3fold_desc, since there are 3 zpool
>> usages under zswap, zbud, z3fold, zsmalloc. It looks like we may extend the
>> zpdesc to zbud and zsmalloc, combined their usage into one.
> 
> Please do not focus your development efforts on z3fold. We really want
> to deprecate/remove it, as well as zbud eventually. See [1].
> 
> For zsmalloc, there is already an ongoing effort to split zsdesc from
> struct page [2].
> 
> [1]https://lore.kernel.org/lkml/CAJD7tkbRF6od-2x_L8-A1QL3=2Ww13sCj4S3i4bNndqF+3+_Vg@mail.gmail.com/

Hi Yosry,

Thanks a lot for the info and comments! It's my stupid w/o checking the email list before work on it.
Anyway don't know if z3fold would be removed, jut left this tested patchset here if someone need it.

> 
> [2]https://lore.kernel.org/lkml/20230713042037.980211-1-42.hyeyoo@gmail.com/

David had pointed out this to me few weeks ago too. This patchset hasn't updated nearly a year. If Yoo don't object I'd like to pick up from his left and update it to latest zsmalloc.c.

Thanks
Alex
> 
>>
>> For zpdesc(page), z3fold just uses the 5th member zppage_flag, which
>> match with page.private. Potentially uses the first member flags for
>> headless PG_locked, list_head lru and page.mapping|PAGE_MAPPING_MOVABLE
>> for page migration.
>>
>> This patachset could save 26Kbyetes z3fold.o size, basely saving come
>> from the page to folio conversion.
>>
>> Thanks a lot!
>> Alex
>>
>> Alex Shi (15):
>>   mm/z3fold: add zpdesc struct and helper and use them in
>>     z3fold_page_isolate
>>   mm/z3fold: use zpdesc in z3fold_page_migrate
>>   mm/z3fold: use zpdesc in z3fold_page_putback
>>   mm/z3fold: use zpdesc in get/put_z3fold_header funcs
>>   mm/z3fold: use zpdesc in init_z3fold_page
>>   mm/z3fold: use zpdesc in free_z3fold_page
>>   mm/z3fold: convert page to zpdesc in __release_z3fold_page
>>   mm/z3fold: use zpdesc free_pages_work
>>   mm/z3fold: use zpdesc in z3fold_compact_page and do_compact_page
>>   mm/z3fold: use zpdesc in __z3fold_alloc
>>   mm/z3fold: use zpdesc in z3fold_alloc
>>   mm/z3fold: use zpdesc in free_z3fold_page and z3fold_free
>>   mm/z3fold: use zpdesc in z3fold_map/z3fold_unmap
>>   mm/z3fold: introduce __zpdesc_set_movable
>>   mm/z3fold: introduce __zpdesc_clear_movable
>>
>>  mm/z3fold.c | 190 +++++++++++++++++++++++++++-------------------------
>>  mm/zpdesc.h |  87 ++++++++++++++++++++++++
>>  2 files changed, 184 insertions(+), 93 deletions(-)
>>  create mode 100644 mm/zpdesc.h
>>
>> --
>> 2.43.0
>>
>>


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool
  2024-06-25  8:11   ` Alex Shi
@ 2024-06-25  9:28     ` Hyeonggon Yoo
  2024-06-25 13:39       ` Alex Shi
  2024-06-25 10:30     ` Yosry Ahmed
  1 sibling, 1 reply; 25+ messages in thread
From: Hyeonggon Yoo @ 2024-06-25  9:28 UTC (permalink / raw)
  To: Alex Shi
  Cc: Yosry Ahmed, alexs, Vitaly Wool, Miaohe Lin, Andrew Morton,
	linux-kernel, linux-mm, minchan, willy, senozhatsky, david

[-- Attachment #1: Type: text/plain, Size: 1596 bytes --]

On Tue, Jun 25, 2024 at 5:11 PM Alex Shi <seakeel@gmail.com> wrote:

>
>
> On 6/25/24 5:46 AM, Yosry Ahmed wrote:
> > On Thu, Jun 20, 2024 at 10:42 PM <alexs@kernel.org> wrote:
> >>
> >> From: Alex Shi <alexs@kernel.org>
> >>
> >> According to Metthew's plan, the page descriptor will be replace by a 8
> >> bytes mem_desc on destination purpose.
> >> https://lore.kernel.org/lkml/YvV1KTyzZ+Jrtj9x@casper.infradead.org/
> >>
> >> Here is a implement on z3fold to replace page descriptor by zpdesc,
> >> which is still overlay on struct page now. but it's a step move forward
> >> above destination.
> >>
> >> To name the struct zpdesc instead of z3fold_desc, since there are 3
> zpool
> >> usages under zswap, zbud, z3fold, zsmalloc. It looks like we may extend
> the
> >> zpdesc to zbud and zsmalloc, combined their usage into one.
> >
> > For zsmalloc, there is already an ongoing effort to split zsdesc from
> > struct page [2].
> >
> > [2]
> https://lore.kernel.org/lkml/20230713042037.980211-1-42.hyeyoo@gmail.com/
>
> David had pointed out this to me few weeks ago too. This patchset hasn't
> updated nearly a year. If Yoo don't object I'd like to pick up from his
> left and update it to latest zsmalloc.c.
>

Hi Alex and Yosry,

Thank you for mentioning this! I still believe the work is worth pursuing,
but recently I haven't had the capacity to push it further.

I'm on board with you taking it over and updating it with the latest source
code. If you have any questions while bringing it up to date, don't
hesitate please reach out to me.

[-- Attachment #2: Type: text/html, Size: 2481 bytes --]

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool
  2024-06-25  8:11   ` Alex Shi
  2024-06-25  9:28     ` Hyeonggon Yoo
@ 2024-06-25 10:30     ` Yosry Ahmed
  2024-06-25 13:44       ` Alex Shi
  2024-06-25 17:22       ` Nhat Pham
  1 sibling, 2 replies; 25+ messages in thread
From: Yosry Ahmed @ 2024-06-25 10:30 UTC (permalink / raw)
  To: Alex Shi
  Cc: alexs, Vitaly Wool, Miaohe Lin, Andrew Morton, linux-kernel,
	linux-mm, minchan, willy, senozhatsky, david, 42.hyeyoo

On Tue, Jun 25, 2024 at 1:11 AM Alex Shi <seakeel@gmail.com> wrote:
>
>
>
> On 6/25/24 5:46 AM, Yosry Ahmed wrote:
> > On Thu, Jun 20, 2024 at 10:42 PM <alexs@kernel.org> wrote:
> >>
> >> From: Alex Shi <alexs@kernel.org>
> >>
> >> According to Metthew's plan, the page descriptor will be replace by a 8
> >> bytes mem_desc on destination purpose.
> >> https://lore.kernel.org/lkml/YvV1KTyzZ+Jrtj9x@casper.infradead.org/
> >>
> >> Here is a implement on z3fold to replace page descriptor by zpdesc,
> >> which is still overlay on struct page now. but it's a step move forward
> >> above destination.
> >>
> >> To name the struct zpdesc instead of z3fold_desc, since there are 3 zpool
> >> usages under zswap, zbud, z3fold, zsmalloc. It looks like we may extend the
> >> zpdesc to zbud and zsmalloc, combined their usage into one.
> >
> > Please do not focus your development efforts on z3fold. We really want
> > to deprecate/remove it, as well as zbud eventually. See [1].
> >
> > For zsmalloc, there is already an ongoing effort to split zsdesc from
> > struct page [2].
> >
> > [1]https://lore.kernel.org/lkml/CAJD7tkbRF6od-2x_L8-A1QL3=2Ww13sCj4S3i4bNndqF+3+_Vg@mail.gmail.com/
>
> Hi Yosry,
>
> Thanks a lot for the info and comments! It's my stupid w/o checking the email list before work on it.
> Anyway don't know if z3fold would be removed, jut left this tested patchset here if someone need it.

It's partially our fault for leaving z3fold knowing that it is headed
toward deprecation/removal. FWIW, I tried to remove it or mark it as
deprecated, but there was some resistance :/


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool
  2024-06-25  9:28     ` Hyeonggon Yoo
@ 2024-06-25 13:39       ` Alex Shi
  0 siblings, 0 replies; 25+ messages in thread
From: Alex Shi @ 2024-06-25 13:39 UTC (permalink / raw)
  To: Hyeonggon Yoo
  Cc: Yosry Ahmed, alexs, Vitaly Wool, Miaohe Lin, Andrew Morton,
	linux-kernel, linux-mm, minchan, willy, senozhatsky, david



On 6/25/24 5:28 PM, Hyeonggon Yoo wrote:
> 
> 
> On Tue, Jun 25, 2024 at 5:11 PM Alex Shi <seakeel@gmail.com <mailto:seakeel@gmail.com>> wrote:
> 
> 
> 
>     On 6/25/24 5:46 AM, Yosry Ahmed wrote:
>     > On Thu, Jun 20, 2024 at 10:42 PM <alexs@kernel.org <mailto:alexs@kernel.org>> wrote:
>     >>
>     >> From: Alex Shi <alexs@kernel.org <mailto:alexs@kernel.org>>
>     >>
>     >> According to Metthew's plan, the page descriptor will be replace by a 8
>     >> bytes mem_desc on destination purpose.
>     >> https://lore.kernel.org/lkml/YvV1KTyzZ+Jrtj9x@casper.infradead.org/ <https://lore.kernel.org/lkml/YvV1KTyzZ+Jrtj9x@casper.infradead.org/>
>     >>
>     >> Here is a implement on z3fold to replace page descriptor by zpdesc,
>     >> which is still overlay on struct page now. but it's a step move forward
>     >> above destination.
>     >>
>     >> To name the struct zpdesc instead of z3fold_desc, since there are 3 zpool
>     >> usages under zswap, zbud, z3fold, zsmalloc. It looks like we may extend the
>     >> zpdesc to zbud and zsmalloc, combined their usage into one.
>     >
>     > For zsmalloc, there is already an ongoing effort to split zsdesc from
>     > struct page [2].
>     >
>     > [2]https://lore.kernel.org/lkml/20230713042037.980211-1-42.hyeyoo@gmail.com/ <https://lore.kernel.org/lkml/20230713042037.980211-1-42.hyeyoo@gmail.com/>
> 
>     David had pointed out this to me few weeks ago too. This patchset hasn't updated nearly a year. If Yoo don't object I'd like to pick up from his left and update it to latest zsmalloc.c.
> 
> 
> Hi Alex and Yosry,
> 
> Thank you for mentioning this! I still believe the work is worth pursuing, but recently I haven't had the capacity to push it further.
> 
> I'm on board with you taking it over and updating it with the latest source code. If you have any questions while bringing it up to date, don't hesitate please reach out to me.


Hi Yoo,

Thanks a lot for generous offer! I will update the patchset and send you for review ASAP. :)

Cheers!
Alex 


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool
  2024-06-25 10:30     ` Yosry Ahmed
@ 2024-06-25 13:44       ` Alex Shi
  2024-06-25 17:22       ` Nhat Pham
  1 sibling, 0 replies; 25+ messages in thread
From: Alex Shi @ 2024-06-25 13:44 UTC (permalink / raw)
  To: Yosry Ahmed
  Cc: alexs, Vitaly Wool, Miaohe Lin, Andrew Morton, linux-kernel,
	linux-mm, minchan, willy, senozhatsky, david, 42.hyeyoo



On 6/25/24 6:30 PM, Yosry Ahmed wrote:
> On Tue, Jun 25, 2024 at 1:11 AM Alex Shi <seakeel@gmail.com> wrote:
>>
>>
>>
>> On 6/25/24 5:46 AM, Yosry Ahmed wrote:
>>> On Thu, Jun 20, 2024 at 10:42 PM <alexs@kernel.org> wrote:
>>>>
>>>> From: Alex Shi <alexs@kernel.org>
>>>>
>>>> According to Metthew's plan, the page descriptor will be replace by a 8
>>>> bytes mem_desc on destination purpose.
>>>> https://lore.kernel.org/lkml/YvV1KTyzZ+Jrtj9x@casper.infradead.org/
>>>>
>>>> Here is a implement on z3fold to replace page descriptor by zpdesc,
>>>> which is still overlay on struct page now. but it's a step move forward
>>>> above destination.
>>>>
>>>> To name the struct zpdesc instead of z3fold_desc, since there are 3 zpool
>>>> usages under zswap, zbud, z3fold, zsmalloc. It looks like we may extend the
>>>> zpdesc to zbud and zsmalloc, combined their usage into one.
>>>
>>> Please do not focus your development efforts on z3fold. We really want
>>> to deprecate/remove it, as well as zbud eventually. See [1].
>>>
>>> For zsmalloc, there is already an ongoing effort to split zsdesc from
>>> struct page [2].
>>>
>>> [1]https://lore.kernel.org/lkml/CAJD7tkbRF6od-2x_L8-A1QL3=2Ww13sCj4S3i4bNndqF+3+_Vg@mail.gmail.com/
>>
>> Hi Yosry,
>>
>> Thanks a lot for the info and comments! It's my stupid w/o checking the email list before work on it.
>> Anyway don't know if z3fold would be removed, jut left this tested patchset here if someone need it.
> 
> It's partially our fault for leaving z3fold knowing that it is headed
> toward deprecation/removal. FWIW, I tried to remove it or mark it as
> deprecated, but there was some resistance :/

Yes, It happens. Community is too huge. Always someone want sth.


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool
  2024-06-25 10:30     ` Yosry Ahmed
  2024-06-25 13:44       ` Alex Shi
@ 2024-06-25 17:22       ` Nhat Pham
  2024-06-25 21:02         ` Yosry Ahmed
  1 sibling, 1 reply; 25+ messages in thread
From: Nhat Pham @ 2024-06-25 17:22 UTC (permalink / raw)
  To: Yosry Ahmed
  Cc: Alex Shi, alexs, Vitaly Wool, Miaohe Lin, Andrew Morton,
	linux-kernel, linux-mm, minchan, willy, senozhatsky, david,
	42.hyeyoo, Shakeel Butt, Johannes Weiner

On Tue, Jun 25, 2024 at 3:32 AM Yosry Ahmed <yosryahmed@google.com> wrote:
>
> On Tue, Jun 25, 2024 at 1:11 AM Alex Shi <seakeel@gmail.com> wrote:
> >
> > Thanks a lot for the info and comments! It's my stupid w/o checking the email list before work on it.
> > Anyway don't know if z3fold would be removed, jut left this tested patchset here if someone need it.
>
> It's partially our fault for leaving z3fold knowing that it is headed
> toward deprecation/removal. FWIW, I tried to remove it or mark it as
> deprecated, but there was some resistance :/
>
Our apologies, Alex. Thank you for your contribution regardless!

Regarding zbud and z3fold, this is the second time this conversation
has come up within a week or so. Chengming was trying to revert the
multiple zpool changes. zsmalloc (after we re-introduce the class
locks) does not seem to regress (at least based on benchmarking), but
z3fold and zbud suffer. I think we are starting to pay the price of
maintaining z3fold and zbud:

1. Future improvement to related subsystems now hurts z3fold.
Developers/maintainers have to spend extra mental capacity to consider
this, and users could potentially see worse performance if they select
z3fold/zbud unknowingly.

2. Contributors are confused on where they should spend their effort
on improving.

Can we at least have a roadmap for deprecating these 2? Something
along the line of:

1. Deprecate either zbud or z3fold. We do not really need both of them.

2. Make zsmalloc independent of MMU, somehow (IIRC, compaction was one
reason right? maybe making zsmalloc compaction dependent on MMU
availability?).

3. Deprecate the remaining one - zsmalloc can be used in all deployments now.

4. (Optional) Maybe adding another allocator for the edge cases that
zsmalloc does not handle well? I'd need to see numbers to be convinced
that this is the case. I think I saw somewhere that Vitaly was working
on zblock - look forward to seeing this :)


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool
  2024-06-25 17:22       ` Nhat Pham
@ 2024-06-25 21:02         ` Yosry Ahmed
  0 siblings, 0 replies; 25+ messages in thread
From: Yosry Ahmed @ 2024-06-25 21:02 UTC (permalink / raw)
  To: Nhat Pham
  Cc: Alex Shi, alexs, Vitaly Wool, Miaohe Lin, Andrew Morton,
	linux-kernel, linux-mm, minchan, willy, senozhatsky, david,
	42.hyeyoo, Shakeel Butt, Johannes Weiner

On Tue, Jun 25, 2024 at 10:22 AM Nhat Pham <nphamcs@gmail.com> wrote:
>
> On Tue, Jun 25, 2024 at 3:32 AM Yosry Ahmed <yosryahmed@google.com> wrote:
> >
> > On Tue, Jun 25, 2024 at 1:11 AM Alex Shi <seakeel@gmail.com> wrote:
> > >
> > > Thanks a lot for the info and comments! It's my stupid w/o checking the email list before work on it.
> > > Anyway don't know if z3fold would be removed, jut left this tested patchset here if someone need it.
> >
> > It's partially our fault for leaving z3fold knowing that it is headed
> > toward deprecation/removal. FWIW, I tried to remove it or mark it as
> > deprecated, but there was some resistance :/
> >
> Our apologies, Alex. Thank you for your contribution regardless!
>
> Regarding zbud and z3fold, this is the second time this conversation
> has come up within a week or so. Chengming was trying to revert the
> multiple zpool changes. zsmalloc (after we re-introduce the class
> locks) does not seem to regress (at least based on benchmarking), but
> z3fold and zbud suffer. I think we are starting to pay the price of
> maintaining z3fold and zbud:
>
> 1. Future improvement to related subsystems now hurts z3fold.
> Developers/maintainers have to spend extra mental capacity to consider
> this, and users could potentially see worse performance if they select
> z3fold/zbud unknowingly.
>
> 2. Contributors are confused on where they should spend their effort
> on improving.
>
> Can we at least have a roadmap for deprecating these 2? Something
> along the line of:

100% agreed. I think we can start with z3fold given that it doesn't
offer significant advantages over zbud in my testing, and zbud is
probably more popular since it was the default zpool for a while.

Then we should be able to remove zbud as well after we take care of
the MMU dependency in zsmalloc. After that, if no new allocators show
up in a while, we can drop the zpool abstraction entirely.

Just my 2c.


^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2024-06-25 21:03 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-21  5:46 [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool alexs
2024-06-21  5:46 ` [PATCH 01/15] mm/z3fold: add zpdesc struct and helper and use them in z3fold_page_isolate alexs
2024-06-21  5:46 ` [PATCH 02/15] mm/z3fold: use zpdesc in z3fold_page_migrate alexs
2024-06-21  5:46 ` [PATCH 03/15] mm/z3fold: use zpdesc in z3fold_page_putback alexs
2024-06-21  5:46 ` [PATCH 04/15] mm/z3fold: use zpdesc in get/put_z3fold_header funcs alexs
2024-06-21  5:46 ` [PATCH 05/15] mm/z3fold: use zpdesc in init_z3fold_page alexs
2024-06-21  5:46 ` [PATCH 06/15] mm/z3fold: use zpdesc in free_z3fold_page alexs
2024-06-21  5:46 ` [PATCH 07/15] mm/z3fold: convert page to zpdesc in __release_z3fold_page alexs
2024-06-21  5:46 ` [PATCH 08/15] mm/z3fold: use zpdesc free_pages_work alexs
2024-06-21  5:46 ` [PATCH 09/15] mm/z3fold: use zpdesc in z3fold_compact_page and do_compact_page alexs
2024-06-21  5:46 ` [PATCH 10/15] mm/z3fold: use zpdesc in __z3fold_alloc alexs
2024-06-21  5:46 ` [PATCH 11/15] mm/z3fold: use zpdesc in z3fold_alloc alexs
2024-06-21  5:46 ` [PATCH 12/15] mm/z3fold: use zpdesc in free_z3fold_page and z3fold_free alexs
2024-06-21  5:46 ` [PATCH 13/15] mm/z3fold: use zpdesc in z3fold_map/z3fold_unmap alexs
2024-06-21  5:46 ` [PATCH 14/15] mm/z3fold: introduce __zpdesc_set_movable alexs
2024-06-21  5:46 ` [PATCH 15/15] mm/z3fold: introduce __zpdesc_clear_movable alexs
2024-06-21  6:43 ` [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool Alex Shi
2024-06-24 21:46 ` Yosry Ahmed
2024-06-25  8:11   ` Alex Shi
2024-06-25  9:28     ` Hyeonggon Yoo
2024-06-25 13:39       ` Alex Shi
2024-06-25 10:30     ` Yosry Ahmed
2024-06-25 13:44       ` Alex Shi
2024-06-25 17:22       ` Nhat Pham
2024-06-25 21:02         ` Yosry Ahmed

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox