* [PATCH v2 0/8] A few cleanup patches for z3fold
@ 2022-03-08 13:43 Miaohe Lin
2022-03-08 13:43 ` [PATCH v2 1/8] mm/z3fold: declare z3fold_mount with __init Miaohe Lin
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: Miaohe Lin @ 2022-03-08 13:43 UTC (permalink / raw)
To: akpm, vitaly.wool; +Cc: linux-mm, linux-kernel, linmiaohe
Hi,
This series contains a few patches to simplify the code, remove unneeded
code, fix obsolete comment and so on. More details can be found in the
respective changelogs. Thanks!
---
v1->v2:
collect Reviewed-by tag. Thanks Vitaly, Souptick and David for review
drop mm/z3fold: remove unneeded return value of z3fold_compact_page()
split the enhance of reducing atomic_ops overhead into separate patch
---
Miaohe Lin (8):
mm/z3fold: declare z3fold_mount with __init
mm/z3fold: remove obsolete comment in z3fold_alloc
mm/z3fold: minor clean up for z3fold_free
mm/z3fold: remove unneeded page_mapcount_reset and ClearPagePrivate
mm/z3fold: remove confusing local variable l reassignment
mm/z3fold: move decrement of pool->pages_nr into
__release_z3fold_page()
mm/z3fold: remove redundant list_del_init of zhdr->buddy in
z3fold_free
mm/z3fold: remove unneeded PAGE_HEADLESS check in free_handle()
mm/z3fold.c | 64 ++++++++++++++---------------------------------------
1 file changed, 17 insertions(+), 47 deletions(-)
--
2.23.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 1/8] mm/z3fold: declare z3fold_mount with __init
2022-03-08 13:43 [PATCH v2 0/8] A few cleanup patches for z3fold Miaohe Lin
@ 2022-03-08 13:43 ` Miaohe Lin
2022-03-08 13:43 ` [PATCH v2 2/8] mm/z3fold: remove obsolete comment in z3fold_alloc Miaohe Lin
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Miaohe Lin @ 2022-03-08 13:43 UTC (permalink / raw)
To: akpm, vitaly.wool; +Cc: linux-mm, linux-kernel, linmiaohe
z3fold_mount is only called during init. So we should declare it
with __init.
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Reviewed-by: Vitaly Wool <vitaly.wool@konsulko.com>
---
mm/z3fold.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/z3fold.c b/mm/z3fold.c
index b3c0577b8095..e86aafea6599 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -345,7 +345,7 @@ static struct file_system_type z3fold_fs = {
};
static struct vfsmount *z3fold_mnt;
-static int z3fold_mount(void)
+static int __init z3fold_mount(void)
{
int ret = 0;
--
2.23.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 2/8] mm/z3fold: remove obsolete comment in z3fold_alloc
2022-03-08 13:43 [PATCH v2 0/8] A few cleanup patches for z3fold Miaohe Lin
2022-03-08 13:43 ` [PATCH v2 1/8] mm/z3fold: declare z3fold_mount with __init Miaohe Lin
@ 2022-03-08 13:43 ` Miaohe Lin
2022-03-08 13:43 ` [PATCH v2 3/8] mm/z3fold: minor clean up for z3fold_free Miaohe Lin
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Miaohe Lin @ 2022-03-08 13:43 UTC (permalink / raw)
To: akpm, vitaly.wool; +Cc: linux-mm, linux-kernel, linmiaohe
The highmem pages are supported since commit f1549cb5ab2b ("mm/z3fold.c:
allow __GFP_HIGHMEM in z3fold_alloc"). Remove the residual comment.
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Reviewed-by: Vitaly Wool <vitaly.wool@konsulko.com>
---
mm/z3fold.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/mm/z3fold.c b/mm/z3fold.c
index e86aafea6599..87689f50f709 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -1064,9 +1064,6 @@ static void z3fold_destroy_pool(struct z3fold_pool *pool)
* performed first. If no suitable free region is found, then a new page is
* allocated and added to the pool to satisfy the request.
*
- * gfp should not set __GFP_HIGHMEM as highmem pages cannot be used
- * as z3fold pool pages.
- *
* Return: 0 if success and handle is set, otherwise -EINVAL if the size or
* gfp arguments are invalid or -ENOMEM if the pool was unable to allocate
* a new page.
--
2.23.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 3/8] mm/z3fold: minor clean up for z3fold_free
2022-03-08 13:43 [PATCH v2 0/8] A few cleanup patches for z3fold Miaohe Lin
2022-03-08 13:43 ` [PATCH v2 1/8] mm/z3fold: declare z3fold_mount with __init Miaohe Lin
2022-03-08 13:43 ` [PATCH v2 2/8] mm/z3fold: remove obsolete comment in z3fold_alloc Miaohe Lin
@ 2022-03-08 13:43 ` Miaohe Lin
2022-03-08 13:43 ` [PATCH v2 4/8] mm/z3fold: remove unneeded page_mapcount_reset and ClearPagePrivate Miaohe Lin
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Miaohe Lin @ 2022-03-08 13:43 UTC (permalink / raw)
To: akpm, vitaly.wool; +Cc: linux-mm, linux-kernel, linmiaohe
Use put_z3fold_header() to pair with get_z3fold_header. Also fix the wrong
comments. Minor readability improvement.
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Reviewed-by: Vitaly Wool <vitaly.wool@konsulko.com>
---
mm/z3fold.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/mm/z3fold.c b/mm/z3fold.c
index 87689f50f709..eb89271aea83 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -1187,9 +1187,9 @@ static int z3fold_alloc(struct z3fold_pool *pool, size_t size, gfp_t gfp,
* @handle: handle associated with the allocation returned by z3fold_alloc()
*
* In the case that the z3fold page in which the allocation resides is under
- * reclaim, as indicated by the PG_reclaim flag being set, this function
- * only sets the first|last_chunks to 0. The page is actually freed
- * once both buddies are evicted (see z3fold_reclaim_page() below).
+ * reclaim, as indicated by the PAGE_CLAIMED flag being set, this function
+ * only sets the first|middle|last_chunks to 0. The page is actually freed
+ * once all buddies are evicted (see z3fold_reclaim_page() below).
*/
static void z3fold_free(struct z3fold_pool *pool, unsigned long handle)
{
@@ -1247,7 +1247,7 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle)
}
if (page_claimed) {
/* the page has not been claimed by us */
- z3fold_page_unlock(zhdr);
+ put_z3fold_header(zhdr);
return;
}
if (test_and_set_bit(NEEDS_COMPACTING, &page->private)) {
--
2.23.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 4/8] mm/z3fold: remove unneeded page_mapcount_reset and ClearPagePrivate
2022-03-08 13:43 [PATCH v2 0/8] A few cleanup patches for z3fold Miaohe Lin
` (2 preceding siblings ...)
2022-03-08 13:43 ` [PATCH v2 3/8] mm/z3fold: minor clean up for z3fold_free Miaohe Lin
@ 2022-03-08 13:43 ` Miaohe Lin
2022-03-08 13:43 ` [PATCH v2 5/8] mm/z3fold: remove confusing local variable l reassignment Miaohe Lin
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Miaohe Lin @ 2022-03-08 13:43 UTC (permalink / raw)
To: akpm, vitaly.wool; +Cc: linux-mm, linux-kernel, linmiaohe
Page->page_type and PagePrivate are not used in z3fold. We should remove
these confusing unneeded operations. The z3fold do these here is due to
referring to zsmalloc's migration code which does need these operations.
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Reviewed-by: Vitaly Wool <vitaly.wool@konsulko.com>
---
mm/z3fold.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/mm/z3fold.c b/mm/z3fold.c
index eb89271aea83..2f848ea45b4d 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -420,7 +420,6 @@ static void free_z3fold_page(struct page *page, bool headless)
__ClearPageMovable(page);
unlock_page(page);
}
- ClearPagePrivate(page);
__free_page(page);
}
@@ -1635,7 +1634,6 @@ static int z3fold_page_migrate(struct address_space *mapping, struct page *newpa
INIT_LIST_HEAD(&new_zhdr->buddy);
new_mapping = page_mapping(page);
__ClearPageMovable(page);
- ClearPagePrivate(page);
get_page(newpage);
z3fold_page_lock(new_zhdr);
@@ -1655,7 +1653,6 @@ static int z3fold_page_migrate(struct address_space *mapping, struct page *newpa
queue_work_on(new_zhdr->cpu, pool->compact_wq, &new_zhdr->work);
- page_mapcount_reset(page);
clear_bit(PAGE_CLAIMED, &page->private);
put_page(page);
return 0;
--
2.23.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 5/8] mm/z3fold: remove confusing local variable l reassignment
2022-03-08 13:43 [PATCH v2 0/8] A few cleanup patches for z3fold Miaohe Lin
` (3 preceding siblings ...)
2022-03-08 13:43 ` [PATCH v2 4/8] mm/z3fold: remove unneeded page_mapcount_reset and ClearPagePrivate Miaohe Lin
@ 2022-03-08 13:43 ` Miaohe Lin
2022-03-08 13:43 ` [PATCH v2 6/8] mm/z3fold: move decrement of pool->pages_nr into __release_z3fold_page() Miaohe Lin
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Miaohe Lin @ 2022-03-08 13:43 UTC (permalink / raw)
To: akpm, vitaly.wool; +Cc: linux-mm, linux-kernel, linmiaohe
The local variable l holds the address of unbuddied[i] which won't change
after we take the pool lock. Remove it to avoid confusion.
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Reviewed-by: Vitaly Wool <vitaly.wool@konsulko.com>
---
mm/z3fold.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/mm/z3fold.c b/mm/z3fold.c
index 2f848ea45b4d..adc0b3fa4906 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -876,7 +876,6 @@ static inline struct z3fold_header *__z3fold_alloc(struct z3fold_pool *pool,
/* Re-check under lock. */
spin_lock(&pool->lock);
- l = &unbuddied[i];
if (unlikely(zhdr != list_first_entry(READ_ONCE(l),
struct z3fold_header, buddy)) ||
!z3fold_page_trylock(zhdr)) {
--
2.23.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 6/8] mm/z3fold: move decrement of pool->pages_nr into __release_z3fold_page()
2022-03-08 13:43 [PATCH v2 0/8] A few cleanup patches for z3fold Miaohe Lin
` (4 preceding siblings ...)
2022-03-08 13:43 ` [PATCH v2 5/8] mm/z3fold: remove confusing local variable l reassignment Miaohe Lin
@ 2022-03-08 13:43 ` Miaohe Lin
2022-03-08 13:43 ` [PATCH v2 7/8] mm/z3fold: remove redundant list_del_init of zhdr->buddy in z3fold_free Miaohe Lin
2022-03-08 13:43 ` [PATCH v2 8/8] mm/z3fold: remove unneeded PAGE_HEADLESS check in free_handle() Miaohe Lin
7 siblings, 0 replies; 9+ messages in thread
From: Miaohe Lin @ 2022-03-08 13:43 UTC (permalink / raw)
To: akpm, vitaly.wool; +Cc: linux-mm, linux-kernel, linmiaohe
The z3fold will always do atomic64_dec(&pool->pages_nr) when the
__release_z3fold_page() is called. Thus we can move decrement of
pool->pages_nr into __release_z3fold_page() to simplify the code.
Also we can reduce the size of z3fold.o ~1k.
Without this patch:
text data bss dec hex filename
15444 1376 8 16828 41bc mm/z3fold.o
With this patch:
text data bss dec hex filename
15044 1248 8 16300 3fac mm/z3fold.o
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
mm/z3fold.c | 41 ++++++++++++-----------------------------
1 file changed, 12 insertions(+), 29 deletions(-)
diff --git a/mm/z3fold.c b/mm/z3fold.c
index adc0b3fa4906..18a697f6fe32 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -520,6 +520,8 @@ static void __release_z3fold_page(struct z3fold_header *zhdr, bool locked)
list_add(&zhdr->buddy, &pool->stale);
queue_work(pool->release_wq, &pool->work);
spin_unlock(&pool->stale_lock);
+
+ atomic64_dec(&pool->pages_nr);
}
static void release_z3fold_page(struct kref *ref)
@@ -737,13 +739,9 @@ static struct z3fold_header *compact_single_buddy(struct z3fold_header *zhdr)
return new_zhdr;
out_fail:
- if (new_zhdr) {
- if (kref_put(&new_zhdr->refcount, release_z3fold_page_locked))
- atomic64_dec(&pool->pages_nr);
- else {
- add_to_unbuddied(pool, new_zhdr);
- z3fold_page_unlock(new_zhdr);
- }
+ if (new_zhdr && !kref_put(&new_zhdr->refcount, release_z3fold_page_locked)) {
+ add_to_unbuddied(pool, new_zhdr);
+ z3fold_page_unlock(new_zhdr);
}
return NULL;
@@ -816,10 +814,8 @@ static void do_compact_page(struct z3fold_header *zhdr, bool locked)
list_del_init(&zhdr->buddy);
spin_unlock(&pool->lock);
- if (kref_put(&zhdr->refcount, release_z3fold_page_locked)) {
- atomic64_dec(&pool->pages_nr);
+ if (kref_put(&zhdr->refcount, release_z3fold_page_locked))
return;
- }
if (test_bit(PAGE_STALE, &page->private) ||
test_and_set_bit(PAGE_CLAIMED, &page->private)) {
@@ -829,9 +825,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 (kref_put(&zhdr->refcount, release_z3fold_page_locked))
- atomic64_dec(&pool->pages_nr);
- else {
+ if (!kref_put(&zhdr->refcount, release_z3fold_page_locked)) {
clear_bit(PAGE_CLAIMED, &page->private);
z3fold_page_unlock(zhdr);
}
@@ -1089,10 +1083,8 @@ static int z3fold_alloc(struct z3fold_pool *pool, size_t size, gfp_t gfp,
if (zhdr) {
bud = get_free_buddy(zhdr, chunks);
if (bud == HEADLESS) {
- if (kref_put(&zhdr->refcount,
+ if (!kref_put(&zhdr->refcount,
release_z3fold_page_locked))
- atomic64_dec(&pool->pages_nr);
- else
z3fold_page_unlock(zhdr);
pr_err("No free chunks in unbuddied\n");
WARN_ON(1);
@@ -1239,10 +1231,8 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle)
if (!page_claimed)
free_handle(handle, zhdr);
- if (kref_put(&zhdr->refcount, release_z3fold_page_locked_list)) {
- atomic64_dec(&pool->pages_nr);
+ if (kref_put(&zhdr->refcount, release_z3fold_page_locked_list))
return;
- }
if (page_claimed) {
/* the page has not been claimed by us */
put_z3fold_header(zhdr);
@@ -1353,9 +1343,7 @@ static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries)
break;
}
if (!z3fold_page_trylock(zhdr)) {
- if (kref_put(&zhdr->refcount,
- release_z3fold_page))
- atomic64_dec(&pool->pages_nr);
+ kref_put(&zhdr->refcount, release_z3fold_page);
zhdr = NULL;
continue; /* can't evict at this point */
}
@@ -1366,10 +1354,8 @@ static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries)
*/
if (zhdr->foreign_handles ||
test_and_set_bit(PAGE_CLAIMED, &page->private)) {
- if (kref_put(&zhdr->refcount,
+ if (!kref_put(&zhdr->refcount,
release_z3fold_page_locked))
- atomic64_dec(&pool->pages_nr);
- else
z3fold_page_unlock(zhdr);
zhdr = NULL;
continue; /* can't evict such page */
@@ -1447,7 +1433,6 @@ static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries)
if (kref_put(&zhdr->refcount,
release_z3fold_page_locked)) {
kmem_cache_free(pool->c_handle, slots);
- atomic64_dec(&pool->pages_nr);
return 0;
}
/*
@@ -1669,10 +1654,8 @@ static void z3fold_page_putback(struct page *page)
if (!list_empty(&zhdr->buddy))
list_del_init(&zhdr->buddy);
INIT_LIST_HEAD(&page->lru);
- if (kref_put(&zhdr->refcount, release_z3fold_page_locked)) {
- atomic64_dec(&pool->pages_nr);
+ if (kref_put(&zhdr->refcount, release_z3fold_page_locked))
return;
- }
spin_lock(&pool->lock);
list_add(&page->lru, &pool->lru);
spin_unlock(&pool->lock);
--
2.23.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 7/8] mm/z3fold: remove redundant list_del_init of zhdr->buddy in z3fold_free
2022-03-08 13:43 [PATCH v2 0/8] A few cleanup patches for z3fold Miaohe Lin
` (5 preceding siblings ...)
2022-03-08 13:43 ` [PATCH v2 6/8] mm/z3fold: move decrement of pool->pages_nr into __release_z3fold_page() Miaohe Lin
@ 2022-03-08 13:43 ` Miaohe Lin
2022-03-08 13:43 ` [PATCH v2 8/8] mm/z3fold: remove unneeded PAGE_HEADLESS check in free_handle() Miaohe Lin
7 siblings, 0 replies; 9+ messages in thread
From: Miaohe Lin @ 2022-03-08 13:43 UTC (permalink / raw)
To: akpm, vitaly.wool; +Cc: linux-mm, linux-kernel, linmiaohe
The do_compact_page will do list_del_init(&zhdr->buddy) for us. Remove this
extra one to save some possible cpu cycles.
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Reviewed-by: Vitaly Wool <vitaly.wool@konsulko.com>
---
mm/z3fold.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/mm/z3fold.c b/mm/z3fold.c
index 18a697f6fe32..867c590df027 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -1244,9 +1244,6 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle)
return;
}
if (zhdr->cpu < 0 || !cpu_online(zhdr->cpu)) {
- spin_lock(&pool->lock);
- list_del_init(&zhdr->buddy);
- spin_unlock(&pool->lock);
zhdr->cpu = -1;
kref_get(&zhdr->refcount);
clear_bit(PAGE_CLAIMED, &page->private);
--
2.23.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 8/8] mm/z3fold: remove unneeded PAGE_HEADLESS check in free_handle()
2022-03-08 13:43 [PATCH v2 0/8] A few cleanup patches for z3fold Miaohe Lin
` (6 preceding siblings ...)
2022-03-08 13:43 ` [PATCH v2 7/8] mm/z3fold: remove redundant list_del_init of zhdr->buddy in z3fold_free Miaohe Lin
@ 2022-03-08 13:43 ` Miaohe Lin
7 siblings, 0 replies; 9+ messages in thread
From: Miaohe Lin @ 2022-03-08 13:43 UTC (permalink / raw)
To: akpm, vitaly.wool; +Cc: linux-mm, linux-kernel, linmiaohe
The only caller z3fold_free() never calls free_handle() in PAGE_HEADLESS
case. Remove this unneeded check.
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Reviewed-by: Vitaly Wool <vitaly.wool@konsulko.com>
---
mm/z3fold.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/mm/z3fold.c b/mm/z3fold.c
index 867c590df027..83b5a3514427 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -297,9 +297,6 @@ static inline void free_handle(unsigned long handle, struct z3fold_header *zhdr)
int i;
bool is_free;
- if (handle & (1 << PAGE_HEADLESS))
- return;
-
if (WARN_ON(*(unsigned long *)handle == 0))
return;
--
2.23.0
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2022-03-08 13:44 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-08 13:43 [PATCH v2 0/8] A few cleanup patches for z3fold Miaohe Lin
2022-03-08 13:43 ` [PATCH v2 1/8] mm/z3fold: declare z3fold_mount with __init Miaohe Lin
2022-03-08 13:43 ` [PATCH v2 2/8] mm/z3fold: remove obsolete comment in z3fold_alloc Miaohe Lin
2022-03-08 13:43 ` [PATCH v2 3/8] mm/z3fold: minor clean up for z3fold_free Miaohe Lin
2022-03-08 13:43 ` [PATCH v2 4/8] mm/z3fold: remove unneeded page_mapcount_reset and ClearPagePrivate Miaohe Lin
2022-03-08 13:43 ` [PATCH v2 5/8] mm/z3fold: remove confusing local variable l reassignment Miaohe Lin
2022-03-08 13:43 ` [PATCH v2 6/8] mm/z3fold: move decrement of pool->pages_nr into __release_z3fold_page() Miaohe Lin
2022-03-08 13:43 ` [PATCH v2 7/8] mm/z3fold: remove redundant list_del_init of zhdr->buddy in z3fold_free Miaohe Lin
2022-03-08 13:43 ` [PATCH v2 8/8] mm/z3fold: remove unneeded PAGE_HEADLESS check in free_handle() Miaohe Lin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox