From: alexs@kernel.org
To: Vitaly Wool <vitaly.wool@konsulko.com>,
Miaohe Lin <linmiaohe@huawei.com>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
minchan@kernel.org, willy@infradead.org,
senozhatsky@chromium.org, david@redhat.com, 42.hyeyoo@gmail.com
Cc: Alex Shi <alexs@kernel.org>
Subject: [PATCH 01/15] mm/z3fold: add zpdesc struct and helper and use them in z3fold_page_isolate
Date: Fri, 21 Jun 2024 13:46:41 +0800 [thread overview]
Message-ID: <20240621054658.1220796-2-alexs@kernel.org> (raw)
In-Reply-To: <20240621054658.1220796-1-alexs@kernel.org>
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
next prev parent reply other threads:[~2024-06-21 5:42 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-21 5:46 [PATCH 00/15] add zpdesc memory descriptor for zswap.zpool alexs
2024-06-21 5:46 ` alexs [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240621054658.1220796-2-alexs@kernel.org \
--to=alexs@kernel.org \
--cc=42.hyeyoo@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=linmiaohe@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=minchan@kernel.org \
--cc=senozhatsky@chromium.org \
--cc=vitaly.wool@konsulko.com \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox