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 11/15] mm/z3fold: use zpdesc in z3fold_alloc
Date: Fri, 21 Jun 2024 13:46:51 +0800 [thread overview]
Message-ID: <20240621054658.1220796-12-alexs@kernel.org> (raw)
In-Reply-To: <20240621054658.1220796-1-alexs@kernel.org>
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
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 ` [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 ` alexs [this message]
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-12-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