From patchwork Thu Aug 3 07:08:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjie Ruan X-Patchwork-Id: 13339336 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF61BC001DF for ; Thu, 3 Aug 2023 07:09:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4BE0B280211; Thu, 3 Aug 2023 03:09:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 46EC02801EB; Thu, 3 Aug 2023 03:09:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 30FAB280211; Thu, 3 Aug 2023 03:09:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 1DCDC2801EB for ; Thu, 3 Aug 2023 03:09:00 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id DC024161027 for ; Thu, 3 Aug 2023 07:08:59 +0000 (UTC) X-FDA: 81081916398.10.495331E Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf13.hostedemail.com (Postfix) with ESMTP id C890B2001B for ; Thu, 3 Aug 2023 07:08:57 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf13.hostedemail.com: domain of ruanjinjie@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=ruanjinjie@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691046538; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=dGWVxE0wGas+3QKjFuSsim0YfwZvetxS6G83jQwDdXg=; b=eb53LN1AWP7j/ShsIRMubRT/n7fj3ck87tK9sKHlIJMisXChUumokgWatfRVG+JzSSRuzC L/enJznZaqeE2d7KaCOTfhbTegFkU8PWDujGo+1EdwpTi1puJzLzcg+Dyhv9gKFIAuc7LO IucLc/yUkUeVqwHdNLrB936vn//c7+4= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf13.hostedemail.com: domain of ruanjinjie@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=ruanjinjie@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691046538; a=rsa-sha256; cv=none; b=OWhsfFBWxtFh/36y/ilgCYJyPbFHfbqGUzw0aV6CpxANaxQ7uBh2Ha2+SFA/gqNs245014 kajmf5tNnvDyijy+ED/xyMz4FPh2zpbZoiOKFRGcfiEPfxgBEcWidBQAjEk7MI3gqNrv/b m2XcAihuM5Jshwdf+ipWP4fMvlOOvNQ= Received: from kwepemi500008.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RGfxh4v4JzNmfR; Thu, 3 Aug 2023 15:05:28 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemi500008.china.huawei.com (7.221.188.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 3 Aug 2023 15:08:54 +0800 From: Ruan Jinjie To: , Vitaly Wool , Miaohe Lin , Andrew Morton CC: Subject: [PATCH -next] mm: zswap: use helper function put_z3fold_locked() Date: Thu, 3 Aug 2023 15:08:20 +0800 Message-ID: <20230803070820.3775663-1-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemi500008.china.huawei.com (7.221.188.139) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: C890B2001B X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: hxhcmyj5g956z9ktey468kxd1m8956so X-HE-Tag: 1691046537-752437 X-HE-Meta: U2FsdGVkX1+zTu/zyOX2tbDxjyge3yyZMykE9h02IzxCyCMyTqoiOPst0m90UytEh3L0mcI2DXXHPjcdxSOzPGbJMKAqALzcahYO2RXnC+9FyhCoNWbYUZtjo35dnUKKGWKYAwnx1CI10WjyH4wuzpI5ZrqvsHkhMgtG+aXHjn741a+gnObD9n7jF/MYWiRy4A+zw4J5Z9CoRASyw9ZCs/PaqY9UuQA3rLfO/fUQeMNBhEBE+6/w7A1Ql/p5TubReEN81TYGt5v6PmZE8al3/cIfh8d8zQI6lgum2GVuormtEQ+ADDmt8cDnx7A3UTYlzwskj3fOnsVoRBblfHRyWn98iwVTP10UxsgIyUvoHgpOWiqDCO4lWZgWyQELo3+bt1l754cOWeiKrTVaHIO+s+jAgYozqJMjmxo6UgZ7b4tWrOW65WI35x4oIph22FgIwUqDKX0mHMwbJ6MDnqnA2v4P5SJyt1YeIIB1xlTBVzKK8Ivjd7v+Ic6uklJ6uKa+GCTJtAsp0zyWeFiuNb73BEjZdG9RKszxlZ/8uinq5GNpTtvWzax/wJlembnEKFSsLokmbODnN9zYHGRa0k4K72qppv9hnc2ZNYXxSYJ1vnq3u3p3p/r3DMtCrBjFLqrA3fE1sm166kI/lhNfwOp7NQywXon2uryA9absWzlzfe2X8YMpM3Rdc/jbsNN3hxbOML4byf+Vmn0H+X5azZ3uJonxoIVIS+GbXmrHFmfpwPibeZfnmPwFSbU6z6ULptUUHLg+NoaCjAW6xbXvsFjwakfNFINAqfpskCwgdX5rF5gRGRuVhz2p03lrSO/PJxZQ1aaJludFQ/PPrPNnFIE0hM/bpuYgKqv8LNbTKGabwuoaorh9EQrx5cVUyibjtq2ynQ2BfpzDpnYd4ahj23JhgmbRUuZp5LbcSKtlfnnNcVfl7YkQ6xH7/ZV/3zxp6xWgB4TZvHYndqPS+BQ9p5j FuhN4BpA ZjbWw69Bb9uhbUi7sja6r0/SZfEE8U7NEE6qZmPd/RMM0GHn9LMi8DEtxk6/PB6PMWQAvae9sLqAJPbxqkXUtDqTOCyEtH0TmSK7Zw33WLCUNQN9Xd02DucmWhUOGO61JtSLohokIWoNQ1i0j8NhGEzhjz6KwIimoR4DYyyWUrwQNC2xBKbnjj/4Wiv50vaM5p5d5 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This code is already duplicated six times, use helper function put_z3fold_locked() to release z3fold page instead of open code it to help improve code readability a bit. No functional change involved. Signed-off-by: Ruan Jinjie --- mm/z3fold.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/mm/z3fold.c b/mm/z3fold.c index e84de91ecccb..0b483de83d95 100644 --- a/mm/z3fold.c +++ b/mm/z3fold.c @@ -480,6 +480,11 @@ static void release_z3fold_page_locked_list(struct kref *ref) __release_z3fold_page(zhdr, true); } +static inline int put_z3fold_locked(struct z3fold_header *zhdr) +{ + return kref_put(&zhdr->refcount, release_z3fold_page_locked); +} + static void free_pages_work(struct work_struct *w) { struct z3fold_pool *pool = container_of(w, struct z3fold_pool, work); @@ -666,7 +671,7 @@ static struct z3fold_header *compact_single_buddy(struct z3fold_header *zhdr) return new_zhdr; out_fail: - if (new_zhdr && !kref_put(&new_zhdr->refcount, release_z3fold_page_locked)) { + if (new_zhdr && !put_z3fold_locked(new_zhdr)) { add_to_unbuddied(pool, new_zhdr); z3fold_page_unlock(new_zhdr); } @@ -741,7 +746,7 @@ 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)) + if (put_z3fold_locked(zhdr)) return; if (test_bit(PAGE_STALE, &page->private) || @@ -752,7 +757,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)) { + if (!put_z3fold_locked(zhdr)) { clear_bit(PAGE_CLAIMED, &page->private); z3fold_page_unlock(zhdr); } @@ -878,7 +883,7 @@ static inline struct z3fold_header *__z3fold_alloc(struct z3fold_pool *pool, return zhdr; out_fail: - if (!kref_put(&zhdr->refcount, release_z3fold_page_locked)) { + if (!put_z3fold_locked(zhdr)) { add_to_unbuddied(pool, zhdr); z3fold_page_unlock(zhdr); } @@ -1012,8 +1017,7 @@ 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, - release_z3fold_page_locked)) + if (!put_z3fold_locked(zhdr)) z3fold_page_unlock(zhdr); pr_err("No free chunks in unbuddied\n"); WARN_ON(1); @@ -1346,7 +1350,7 @@ 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)) + if (put_z3fold_locked(zhdr)) return; if (list_empty(&zhdr->buddy)) add_to_unbuddied(pool, zhdr);