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>,
LKML <linux-kernel@vger.kernel.org>,
Minchan Kim <minchan@kernel.org>
Subject: [PATCH v2 4/9] zsmalloc: introduce obj_allocated
Date: Mon, 15 Nov 2021 10:59:04 -0800 [thread overview]
Message-ID: <20211115185909.3949505-5-minchan@kernel.org> (raw)
In-Reply-To: <20211115185909.3949505-1-minchan@kernel.org>
The usage pattern for obj_to_head is to check whether the zpage
is allocated or not. Thus, introduce obj_allocated.
Signed-off-by: Minchan Kim <minchan@kernel.org>
---
mm/zsmalloc.c | 33 ++++++++++++++++-----------------
1 file changed, 16 insertions(+), 17 deletions(-)
diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index 7a14090e4a53..6ca130c0f7dc 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -877,13 +877,21 @@ static unsigned long handle_to_obj(unsigned long handle)
return *(unsigned long *)handle;
}
-static unsigned long obj_to_head(struct page *page, void *obj)
+static bool obj_allocated(struct page *page, void *obj, unsigned long *phandle)
{
+ unsigned long handle;
+
if (unlikely(PageHugeObject(page))) {
VM_BUG_ON_PAGE(!is_first_page(page), page);
- return page->index;
+ handle = page->index;
} else
- return *(unsigned long *)obj;
+ handle = *(unsigned long *)obj;
+
+ if (!(handle & OBJ_ALLOCATED_TAG))
+ return false;
+
+ *phandle = handle & ~OBJ_ALLOCATED_TAG;
+ return true;
}
static inline int testpin_tag(unsigned long handle)
@@ -1606,7 +1614,6 @@ static void zs_object_copy(struct size_class *class, unsigned long dst,
static unsigned long find_alloced_obj(struct size_class *class,
struct page *page, int *obj_idx)
{
- unsigned long head;
int offset = 0;
int index = *obj_idx;
unsigned long handle = 0;
@@ -1616,9 +1623,7 @@ static unsigned long find_alloced_obj(struct size_class *class,
offset += class->size * index;
while (offset < PAGE_SIZE) {
- head = obj_to_head(page, addr + offset);
- if (head & OBJ_ALLOCATED_TAG) {
- handle = head & ~OBJ_ALLOCATED_TAG;
+ if (obj_allocated(page, addr + offset, &handle)) {
if (trypin_tag(handle))
break;
handle = 0;
@@ -1928,7 +1933,7 @@ static int zs_page_migrate(struct address_space *mapping, struct page *newpage,
struct page *dummy;
void *s_addr, *d_addr, *addr;
int offset, pos;
- unsigned long handle, head;
+ unsigned long handle;
unsigned long old_obj, new_obj;
unsigned int obj_idx;
int ret = -EAGAIN;
@@ -1964,9 +1969,7 @@ static int zs_page_migrate(struct address_space *mapping, struct page *newpage,
pos = offset;
s_addr = kmap_atomic(page);
while (pos < PAGE_SIZE) {
- head = obj_to_head(page, s_addr + pos);
- if (head & OBJ_ALLOCATED_TAG) {
- handle = head & ~OBJ_ALLOCATED_TAG;
+ if (obj_allocated(page, s_addr + pos, &handle)) {
if (!trypin_tag(handle))
goto unpin_objects;
}
@@ -1982,9 +1985,7 @@ static int zs_page_migrate(struct address_space *mapping, struct page *newpage,
for (addr = s_addr + offset; addr < s_addr + pos;
addr += class->size) {
- head = obj_to_head(page, addr);
- if (head & OBJ_ALLOCATED_TAG) {
- handle = head & ~OBJ_ALLOCATED_TAG;
+ if (obj_allocated(page, addr, &handle)) {
BUG_ON(!testpin_tag(handle));
old_obj = handle_to_obj(handle);
@@ -2029,9 +2030,7 @@ static int zs_page_migrate(struct address_space *mapping, struct page *newpage,
unpin_objects:
for (addr = s_addr + offset; addr < s_addr + pos;
addr += class->size) {
- head = obj_to_head(page, addr);
- if (head & OBJ_ALLOCATED_TAG) {
- handle = head & ~OBJ_ALLOCATED_TAG;
+ if (obj_allocated(page, addr, &handle)) {
BUG_ON(!testpin_tag(handle));
unpin_tag(handle);
}
--
2.34.0.rc1.387.gb447b232ab-goog
next prev parent reply other threads:[~2021-11-15 18:59 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-15 18:59 [PATCH v2 0/9] zsmalloc: remove bit_spin_lock Minchan Kim
2021-11-15 18:59 ` [PATCH v2 1/9] zsmalloc: introduce some helper functions Minchan Kim
2021-11-15 18:59 ` [PATCH v2 2/9] zsmalloc: rename zs_stat_type to class_stat_type Minchan Kim
2021-11-15 18:59 ` [PATCH v2 3/9] zsmalloc: decouple class actions from zspage works Minchan Kim
2021-11-15 18:59 ` Minchan Kim [this message]
2021-11-15 18:59 ` [PATCH v2 5/9] zsmalloc: move huge compressed obj from page to zspage Minchan Kim
2021-11-15 18:59 ` [PATCH v2 6/9] zsmalloc: remove zspage isolation for migration Minchan Kim
2021-11-15 18:59 ` [PATCH v2 7/9] locking/rwlocks: introduce write_lock_nested Minchan Kim
2021-11-16 10:27 ` Peter Zijlstra
2021-11-19 10:35 ` Sebastian Andrzej Siewior
2021-11-19 18:21 ` Minchan Kim
2021-11-20 15:38 ` Sebastian Andrzej Siewior
2021-11-20 3:50 ` kernel test robot
2021-11-15 18:59 ` [PATCH v2 8/9] zsmalloc: replace per zpage lock with pool->migrate_lock Minchan Kim
2021-11-15 18:59 ` [PATCH v2 9/9] zsmalloc: replace get_cpu_var with local_lock Minchan Kim
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=20211115185909.3949505-5-minchan@kernel.org \
--to=minchan@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).