Commit 5e36c25b authored by Miaohe Lin's avatar Miaohe Lin Committed by akpm

mm/z3fold: move decrement of pool->pages_nr into __release_z3fold_page()

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

Link: https://lkml.kernel.org/r/20220308134311.59086-7-linmiaohe@huawei.comSigned-off-by: default avatarMiaohe Lin <linmiaohe@huawei.com>
Cc: Vitaly Wool <vitaly.wool@konsulko.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent a3148b5f
...@@ -520,6 +520,8 @@ static void __release_z3fold_page(struct z3fold_header *zhdr, bool locked) ...@@ -520,6 +520,8 @@ static void __release_z3fold_page(struct z3fold_header *zhdr, bool locked)
list_add(&zhdr->buddy, &pool->stale); list_add(&zhdr->buddy, &pool->stale);
queue_work(pool->release_wq, &pool->work); queue_work(pool->release_wq, &pool->work);
spin_unlock(&pool->stale_lock); spin_unlock(&pool->stale_lock);
atomic64_dec(&pool->pages_nr);
} }
static void release_z3fold_page(struct kref *ref) static void release_z3fold_page(struct kref *ref)
...@@ -737,13 +739,9 @@ static struct z3fold_header *compact_single_buddy(struct z3fold_header *zhdr) ...@@ -737,13 +739,9 @@ static struct z3fold_header *compact_single_buddy(struct z3fold_header *zhdr)
return new_zhdr; return new_zhdr;
out_fail: out_fail:
if (new_zhdr) { if (new_zhdr && !kref_put(&new_zhdr->refcount, release_z3fold_page_locked)) {
if (kref_put(&new_zhdr->refcount, release_z3fold_page_locked)) add_to_unbuddied(pool, new_zhdr);
atomic64_dec(&pool->pages_nr); z3fold_page_unlock(new_zhdr);
else {
add_to_unbuddied(pool, new_zhdr);
z3fold_page_unlock(new_zhdr);
}
} }
return NULL; return NULL;
...@@ -816,10 +814,8 @@ static void do_compact_page(struct z3fold_header *zhdr, bool locked) ...@@ -816,10 +814,8 @@ static void do_compact_page(struct z3fold_header *zhdr, bool locked)
list_del_init(&zhdr->buddy); list_del_init(&zhdr->buddy);
spin_unlock(&pool->lock); spin_unlock(&pool->lock);
if (kref_put(&zhdr->refcount, release_z3fold_page_locked)) { if (kref_put(&zhdr->refcount, release_z3fold_page_locked))
atomic64_dec(&pool->pages_nr);
return; return;
}
if (test_bit(PAGE_STALE, &page->private) || if (test_bit(PAGE_STALE, &page->private) ||
test_and_set_bit(PAGE_CLAIMED, &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) ...@@ -829,9 +825,7 @@ static void do_compact_page(struct z3fold_header *zhdr, bool locked)
if (!zhdr->foreign_handles && buddy_single(zhdr) && if (!zhdr->foreign_handles && buddy_single(zhdr) &&
zhdr->mapped_count == 0 && compact_single_buddy(zhdr)) { zhdr->mapped_count == 0 && compact_single_buddy(zhdr)) {
if (kref_put(&zhdr->refcount, release_z3fold_page_locked)) if (!kref_put(&zhdr->refcount, release_z3fold_page_locked)) {
atomic64_dec(&pool->pages_nr);
else {
clear_bit(PAGE_CLAIMED, &page->private); clear_bit(PAGE_CLAIMED, &page->private);
z3fold_page_unlock(zhdr); z3fold_page_unlock(zhdr);
} }
...@@ -1089,10 +1083,8 @@ static int z3fold_alloc(struct z3fold_pool *pool, size_t size, gfp_t gfp, ...@@ -1089,10 +1083,8 @@ static int z3fold_alloc(struct z3fold_pool *pool, size_t size, gfp_t gfp,
if (zhdr) { if (zhdr) {
bud = get_free_buddy(zhdr, chunks); bud = get_free_buddy(zhdr, chunks);
if (bud == HEADLESS) { if (bud == HEADLESS) {
if (kref_put(&zhdr->refcount, if (!kref_put(&zhdr->refcount,
release_z3fold_page_locked)) release_z3fold_page_locked))
atomic64_dec(&pool->pages_nr);
else
z3fold_page_unlock(zhdr); z3fold_page_unlock(zhdr);
pr_err("No free chunks in unbuddied\n"); pr_err("No free chunks in unbuddied\n");
WARN_ON(1); WARN_ON(1);
...@@ -1239,10 +1231,8 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle) ...@@ -1239,10 +1231,8 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle)
if (!page_claimed) if (!page_claimed)
free_handle(handle, zhdr); free_handle(handle, zhdr);
if (kref_put(&zhdr->refcount, release_z3fold_page_locked_list)) { if (kref_put(&zhdr->refcount, release_z3fold_page_locked_list))
atomic64_dec(&pool->pages_nr);
return; return;
}
if (page_claimed) { if (page_claimed) {
/* the page has not been claimed by us */ /* the page has not been claimed by us */
put_z3fold_header(zhdr); put_z3fold_header(zhdr);
...@@ -1353,9 +1343,7 @@ static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries) ...@@ -1353,9 +1343,7 @@ static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries)
break; break;
} }
if (!z3fold_page_trylock(zhdr)) { if (!z3fold_page_trylock(zhdr)) {
if (kref_put(&zhdr->refcount, kref_put(&zhdr->refcount, release_z3fold_page);
release_z3fold_page))
atomic64_dec(&pool->pages_nr);
zhdr = NULL; zhdr = NULL;
continue; /* can't evict at this point */ continue; /* can't evict at this point */
} }
...@@ -1366,10 +1354,8 @@ static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries) ...@@ -1366,10 +1354,8 @@ static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries)
*/ */
if (zhdr->foreign_handles || if (zhdr->foreign_handles ||
test_and_set_bit(PAGE_CLAIMED, &page->private)) { test_and_set_bit(PAGE_CLAIMED, &page->private)) {
if (kref_put(&zhdr->refcount, if (!kref_put(&zhdr->refcount,
release_z3fold_page_locked)) release_z3fold_page_locked))
atomic64_dec(&pool->pages_nr);
else
z3fold_page_unlock(zhdr); z3fold_page_unlock(zhdr);
zhdr = NULL; zhdr = NULL;
continue; /* can't evict such page */ continue; /* can't evict such page */
...@@ -1447,7 +1433,6 @@ static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries) ...@@ -1447,7 +1433,6 @@ static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries)
if (kref_put(&zhdr->refcount, if (kref_put(&zhdr->refcount,
release_z3fold_page_locked)) { release_z3fold_page_locked)) {
kmem_cache_free(pool->c_handle, slots); kmem_cache_free(pool->c_handle, slots);
atomic64_dec(&pool->pages_nr);
return 0; return 0;
} }
/* /*
...@@ -1669,10 +1654,8 @@ static void z3fold_page_putback(struct page *page) ...@@ -1669,10 +1654,8 @@ static void z3fold_page_putback(struct page *page)
if (!list_empty(&zhdr->buddy)) if (!list_empty(&zhdr->buddy))
list_del_init(&zhdr->buddy); list_del_init(&zhdr->buddy);
INIT_LIST_HEAD(&page->lru); INIT_LIST_HEAD(&page->lru);
if (kref_put(&zhdr->refcount, release_z3fold_page_locked)) { if (kref_put(&zhdr->refcount, release_z3fold_page_locked))
atomic64_dec(&pool->pages_nr);
return; return;
}
spin_lock(&pool->lock); spin_lock(&pool->lock);
list_add(&page->lru, &pool->lru); list_add(&page->lru, &pool->lru);
spin_unlock(&pool->lock); spin_unlock(&pool->lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment