From: Minchan Kim <minchan@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>,
linux-mm <linux-mm@kvack.org>, Minchan Kim <minchan@kernel.org>
Subject: [PATCH 5/8] zsmalloc: move huge compressed obj from page to zspage
Date: Wed, 10 Nov 2021 10:54:30 -0800 [thread overview]
Message-ID: <20211110185433.1981097-6-minchan@kernel.org> (raw)
In-Reply-To: <20211110185433.1981097-1-minchan@kernel.org>
the flag aims for zspage, not per page. Let's move it to zspage.
Signed-off-by: Minchan Kim <minchan@kernel.org>
---
mm/zsmalloc.c | 50 ++++++++++++++++++++++++++------------------------
1 file changed, 26 insertions(+), 24 deletions(-)
diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index 8f9cd07033de..da15d98a6e29 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -121,6 +121,7 @@
#define OBJ_INDEX_BITS (BITS_PER_LONG - _PFN_BITS - OBJ_TAG_BITS)
#define OBJ_INDEX_MASK ((_AC(1, UL) << OBJ_INDEX_BITS) - 1)
+#define HUGE_BITS 1
#define FULLNESS_BITS 2
#define CLASS_BITS 8
#define ISOLATED_BITS 3
@@ -213,22 +214,6 @@ struct size_class {
struct zs_size_stat stats;
};
-/* huge object: pages_per_zspage == 1 && maxobj_per_zspage == 1 */
-static void SetPageHugeObject(struct page *page)
-{
- SetPageOwnerPriv1(page);
-}
-
-static void ClearPageHugeObject(struct page *page)
-{
- ClearPageOwnerPriv1(page);
-}
-
-static int PageHugeObject(struct page *page)
-{
- return PageOwnerPriv1(page);
-}
-
/*
* Placed within free objects to form a singly linked list.
* For every zspage, zspage->freeobj gives head of this list.
@@ -278,6 +263,7 @@ struct zs_pool {
struct zspage {
struct {
+ unsigned int huge:HUGE_BITS;
unsigned int fullness:FULLNESS_BITS;
unsigned int class:CLASS_BITS + 1;
unsigned int isolated:ISOLATED_BITS;
@@ -298,6 +284,17 @@ struct mapping_area {
enum zs_mapmode vm_mm; /* mapping mode */
};
+/* huge object: pages_per_zspage == 1 && maxobj_per_zspage == 1 */
+static void SetZsHugePage(struct zspage *zspage)
+{
+ zspage->huge = 1;
+}
+
+static bool ZsHugePage(struct zspage *zspage)
+{
+ return zspage->huge;
+}
+
#ifdef CONFIG_COMPACTION
static int zs_register_migration(struct zs_pool *pool);
static void zs_unregister_migration(struct zs_pool *pool);
@@ -830,7 +827,9 @@ static struct zspage *get_zspage(struct page *page)
static struct page *get_next_page(struct page *page)
{
- if (unlikely(PageHugeObject(page)))
+ struct zspage *zspage = get_zspage(page);
+
+ if (unlikely(ZsHugePage(zspage)))
return NULL;
return page->freelist;
@@ -880,8 +879,9 @@ static unsigned long handle_to_obj(unsigned long handle)
static bool obj_allocated(struct page *page, void *obj, unsigned long *phandle)
{
unsigned long handle;
+ struct zspage *zspage = get_zspage(page);
- if (unlikely(PageHugeObject(page))) {
+ if (unlikely(ZsHugePage(zspage))) {
VM_BUG_ON_PAGE(!is_first_page(page), page);
handle = page->index;
} else
@@ -920,7 +920,6 @@ static void reset_page(struct page *page)
ClearPagePrivate(page);
set_page_private(page, 0);
page_mapcount_reset(page);
- ClearPageHugeObject(page);
page->freelist = NULL;
}
@@ -1062,7 +1061,7 @@ static void create_page_chain(struct size_class *class, struct zspage *zspage,
SetPagePrivate(page);
if (unlikely(class->objs_per_zspage == 1 &&
class->pages_per_zspage == 1))
- SetPageHugeObject(page);
+ SetZsHugePage(zspage);
} else {
prev_page->freelist = page;
}
@@ -1307,7 +1306,7 @@ void *zs_map_object(struct zs_pool *pool, unsigned long handle,
ret = __zs_map_object(area, pages, off, class->size);
out:
- if (likely(!PageHugeObject(page)))
+ if (likely(!ZsHugePage(zspage)))
ret += ZS_HANDLE_SIZE;
return ret;
@@ -1395,7 +1394,7 @@ static unsigned long obj_malloc(struct zs_pool *pool,
vaddr = kmap_atomic(m_page);
link = (struct link_free *)vaddr + m_offset / sizeof(*link);
set_freeobj(zspage, link->next >> OBJ_TAG_BITS);
- if (likely(!PageHugeObject(m_page)))
+ if (likely(!ZsHugePage(zspage)))
/* record handle in the header of allocated chunk */
link->handle = handle;
else
@@ -1496,7 +1495,10 @@ static void obj_free(int class_size, unsigned long obj)
/* Insert this object in containing zspage's freelist */
link = (struct link_free *)(vaddr + f_offset);
- link->next = get_freeobj(zspage) << OBJ_TAG_BITS;
+ if (likely(!ZsHugePage(zspage)))
+ link->next = get_freeobj(zspage) << OBJ_TAG_BITS;
+ else
+ f_page->index = 0;
kunmap_atomic(vaddr);
set_freeobj(zspage, f_objidx);
mod_zspage_inuse(zspage, -1);
@@ -1866,7 +1868,7 @@ static void replace_sub_page(struct size_class *class, struct zspage *zspage,
create_page_chain(class, zspage, pages);
set_first_obj_offset(newpage, get_first_obj_offset(oldpage));
- if (unlikely(PageHugeObject(oldpage)))
+ if (unlikely(ZsHugePage(zspage)))
newpage->index = oldpage->index;
__SetPageMovable(newpage, page_mapping(oldpage));
}
--
2.34.0.rc1.387.gb447b232ab-goog
next prev parent reply other threads:[~2021-11-10 18:54 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-10 18:54 [PATCH 0/8] zsmalloc: remove bit_spin_lock Minchan Kim
2021-11-10 18:54 ` [PATCH 1/8] zsmalloc: introduce some helper functions Minchan Kim
2021-11-10 18:54 ` [PATCH 2/8] zsmalloc: rename zs_stat_type to class_stat_type Minchan Kim
2021-11-10 18:54 ` [PATCH 3/8] zsmalloc: decouple class actions from zspage works Minchan Kim
2021-11-10 18:54 ` [PATCH 4/8] zsmalloc: introduce obj_allocated Minchan Kim
2021-11-10 18:54 ` Minchan Kim [this message]
2021-11-10 18:54 ` [PATCH 6/8] zsmalloc: remove zspage isolation for migration Minchan Kim
2021-11-10 18:54 ` [PATCH 7/8] zsmalloc: replace per zpage lock with pool->migrate_lock Minchan Kim
2021-11-11 9:07 ` Sebastian Andrzej Siewior
2021-11-11 23:11 ` Minchan Kim
2021-11-12 7:28 ` Sebastian Andrzej Siewior
2021-11-12 7:31 ` Sebastian Andrzej Siewior
2021-11-12 22:10 ` Minchan Kim
2021-11-11 10:13 ` kernel test robot
2021-11-11 10:13 ` kernel test robot
2021-11-10 18:54 ` [PATCH 8/8] zsmalloc: replace get_cpu_var with local_lock Minchan Kim
2021-11-11 8:56 ` Sebastian Andrzej Siewior
2021-11-11 23:08 ` Minchan Kim
2021-11-15 3:56 ` Davidlohr Bueso
2021-11-15 7:27 ` Sebastian Andrzej Siewior
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=20211110185433.1981097-6-minchan@kernel.org \
--to=minchan@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=linux-mm@kvack.org \
--cc=senozhatsky@chromium.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.