From patchwork Mon Dec 18 11:50:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13496760 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 1EF95C35274 for ; Mon, 18 Dec 2023 11:50:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5FEEB8D000E; Mon, 18 Dec 2023 06:50:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 538618D0001; Mon, 18 Dec 2023 06:50:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 38A5B8D000E; Mon, 18 Dec 2023 06:50:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 16D9C8D0001 for ; Mon, 18 Dec 2023 06:50:50 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id BDDC5161101 for ; Mon, 18 Dec 2023 11:50:49 +0000 (UTC) X-FDA: 81579772218.14.9AC069D Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.182]) by imf08.hostedemail.com (Postfix) with ESMTP id C5F29160017 for ; Mon, 18 Dec 2023 11:50:47 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.182 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702900248; a=rsa-sha256; cv=none; b=jolkInwJ2RoFGIJiJ7m0QakTGwhEYTMJ8RS0bBZ6Dl3wFaIxDnW6xQt0WnrBYTMIiTkz8w hLBNH47my6x1y7u13frtKWmVvxpBn1LnQdQ2s1YNUslHK5b0M1yfc22VSIHSFW7bTaJrWQ /T4GVixCMwjHKMjdmlDUIIT8hv2apow= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.182 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702900248; 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:in-reply-to:references:references; bh=5XHGau3pXpBIRdgWSOxIy56lBlKtyLT1nxaNBp7TWqM=; b=1FnStE3jcHp9mulBAoFr0iM5DqDf8qM45r/bdEytsVkS+vYqu/+bXmHTZvTxpwSzlUrcNo SjVZZWLdNURs9KK3J1OUz1TQZY4Yk9UYBIUaxQG5QolMsetilCTAnuA+xsE0lt1TgbvCwS 873N0RrlE5v29+v32y2jznUPueD3fnQ= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou Date: Mon, 18 Dec 2023 11:50:33 +0000 Subject: [PATCH v3 3/6] mm/zswap: refactor out __zswap_load() MIME-Version: 1.0 Message-Id: <20231213-zswap-dstmem-v3-3-4eac09b94ece@bytedance.com> References: <20231213-zswap-dstmem-v3-0-4eac09b94ece@bytedance.com> In-Reply-To: <20231213-zswap-dstmem-v3-0-4eac09b94ece@bytedance.com> To: Seth Jennings , Yosry Ahmed , Vitaly Wool , Dan Streetman , Johannes Weiner , Chris Li , Andrew Morton , Nhat Pham Cc: Chris Li , Yosry Ahmed , linux-kernel@vger.kernel.org, Chengming Zhou , linux-mm@kvack.org, Nhat Pham X-Developer-Signature: v=1; a=ed25519-sha256; t=1702900234; l=4703; i=zhouchengming@bytedance.com; s=20231204; h=from:subject:message-id; bh=B99wC6AH9+R5m6Djw0+W/AJA7ag/bUbsLCKvYrrlo8Q=; b=ild77L3TDGLGQu8Eca6JaXi/fIaO5CaZVqyj/qCaIHMIACqX9eH+pkWshvQ4Y9TZWp3ytCZsC rYJYgewIBt6BWiDIhPEOZvJMVJypVdwjYuUQ0PbiowCtIZh16LIxHdH X-Developer-Key: i=zhouchengming@bytedance.com; a=ed25519; pk=xFTmRtMG3vELGJBUiml7OYNdM393WOMv0iWWeQEVVdA= X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: C5F29160017 X-Stat-Signature: j7eht3b66gmc4ntu6nmsbbs9hsqt8b5c X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspam: Yes X-HE-Tag: 1702900247-593297 X-HE-Meta: U2FsdGVkX1/ysTU2jnLWitHbG2/+C1qaMy8ANE4JXL60Twveg6xuqo5ZyV1m7ZShesKQEMC8TyRUwakSu9dRNYDvjo2YAepvZMm6QXO9lHXt9XZr85JikZgwSCLD+EIbiF/L7/avgSc2HNe7KTeKms5FcXroYu47Jn3kSVa9n0aQ66IEv59tXAWvzVEjgO1v/MZcR3lwCUhvw5dpv5eXGRHjfX28a6IjwVxqsSRAaoxAPVHiL/1ipgwNeIziAiV48KSTJFaEJEHsgvFDC9do1viWQizJrIrtPFji4ZFu36G8kltQLX9FyGTSG4N4xgWmDjJQmxGbfF6k3K5KbNh12JQBOp/er+b67N1WdU2owGRSA28wVMqw95YBETrg72M2DpF4mJ7K7dqDWGvADbNKKh/erA00Mv5WxKq6C1cfT6twPB1J1Zw12Y+aUzWqecYtBhPOHfyVUxyjl4JOkxjuS+Pn145zb8W3YA2hiVDDBVJTO0mVmZqQhSCfdZORtf50e8XJ7NT30RHNfwlDRDQX5PvzjSO5C4igQsHPIP78IV6wTT4B4LewaKKmSU0axq7keS+qUb67Wt8UG6WEeyEs9h0EL3wSilJCius/RhvXi0rK/fKxwpyaw6IxpmE++Dg8DWtOk8uJzwG7H9gvTiG26AFeX0zAI9xytgrsQjJbDH8vruAtD7e9pfAsYMZaKDPmAoHCkh1RBn8ZbtP79IZFCxo6Ei4tXlkPAUliMT3BDpmXUhvCKBc/6IAuGf3ejWh/xJaXLQUAPaDMN68OYoZaconGExEeyBUzA0Eer9hbEAIfR/j5b4r01D5h3lqV97qIgnhv6m0IcuvRbLSGOMVWuhIwXi6VzDuE8YS5yQWrJogBEdRlxEIOXyMK3Mzf6FKo1epEzRYd0qWLrDF8HZ35lUUA8fOTwoHL3ugW3BF7MgASZSlHQiRfvmkHk6pbDCtQ0ujk2sQRQy9FK9XgQV7 lmNPc36h 4VBNE5B3Z1+Mprg2T4i1FY7upK0X798hHHN/pF6Rd1nVsDSXoeasxBv/eY4YCaMP6eWR3lGTC+cWlbGyJFM1jfAlsHz+rV56n0SXC1dnKnbYYRXs9ekCGLjg5aao+PCxQGMiXc6Yjv9oV/RxUVwWfDB22Xw78pL6uoFdUa6Su2PagUSyOiLeYl0ToSS8Dt67+6WiEvvKOEAdKNg8Izh822idpkJKLoTvakLqVoPMaR8HVJ9aXSLeU+eHgvIWZnOqzw+jn3/j+ZJDoZd07O1oOzrVMpno+7ZUG4AZbVp7HHaIk2SJ+UVHTpP3c1KeeTaazKoABu4BIWDDAuogzeLaOeEFTGkwymaCfjlpZS+levTP6UXVAFktJLtijAXMnC6i8s6N7BiWPWaictdHyWuuDDvT1BIrAjYKdTLf4pkQhX3ceZLU= 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: List-Subscribe: List-Unsubscribe: The zswap_load() and zswap_writeback_entry() have the same part that decompress the data from zswap_entry to page, so refactor out the common part as __zswap_load(entry, page). Reviewed-by: Nhat Pham Reviewed-by: Yosry Ahmed Signed-off-by: Chengming Zhou Acked-by: Chris Li (Google) --- mm/zswap.c | 92 ++++++++++++++++++++++---------------------------------------- 1 file changed, 32 insertions(+), 60 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 6b872744e962..3433bd6b3cef 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1392,6 +1392,35 @@ static int zswap_enabled_param_set(const char *val, return ret; } +static void __zswap_load(struct zswap_entry *entry, struct page *page) +{ + struct zpool *zpool = zswap_find_zpool(entry); + struct scatterlist input, output; + struct crypto_acomp_ctx *acomp_ctx; + u8 *src; + + acomp_ctx = raw_cpu_ptr(entry->pool->acomp_ctx); + mutex_lock(acomp_ctx->mutex); + + src = zpool_map_handle(zpool, entry->handle, ZPOOL_MM_RO); + if (!zpool_can_sleep_mapped(zpool)) { + memcpy(acomp_ctx->dstmem, src, entry->length); + src = acomp_ctx->dstmem; + zpool_unmap_handle(zpool, entry->handle); + } + + sg_init_one(&input, src, entry->length); + sg_init_table(&output, 1); + sg_set_page(&output, page, PAGE_SIZE, 0); + acomp_request_set_params(acomp_ctx->req, &input, &output, entry->length, PAGE_SIZE); + BUG_ON(crypto_wait_req(crypto_acomp_decompress(acomp_ctx->req), &acomp_ctx->wait)); + BUG_ON(acomp_ctx->req->dlen != PAGE_SIZE); + mutex_unlock(acomp_ctx->mutex); + + if (zpool_can_sleep_mapped(zpool)) + zpool_unmap_handle(zpool, entry->handle); +} + /********************************* * writeback code **********************************/ @@ -1413,12 +1442,7 @@ static int zswap_writeback_entry(struct zswap_entry *entry, swp_entry_t swpentry = entry->swpentry; struct page *page; struct mempolicy *mpol; - struct scatterlist input, output; - struct crypto_acomp_ctx *acomp_ctx; - struct zpool *pool = zswap_find_zpool(entry); bool page_was_allocated; - u8 *src; - unsigned int dlen; int ret; struct writeback_control wbc = { .sync_mode = WB_SYNC_NONE, @@ -1456,31 +1480,7 @@ static int zswap_writeback_entry(struct zswap_entry *entry, } spin_unlock(&tree->lock); - /* decompress */ - acomp_ctx = raw_cpu_ptr(entry->pool->acomp_ctx); - dlen = PAGE_SIZE; - mutex_lock(acomp_ctx->mutex); - - src = zpool_map_handle(pool, entry->handle, ZPOOL_MM_RO); - if (!zpool_can_sleep_mapped(pool)) { - memcpy(acomp_ctx->dstmem, src, entry->length); - src = acomp_ctx->dstmem; - zpool_unmap_handle(pool, entry->handle); - } - - sg_init_one(&input, src, entry->length); - sg_init_table(&output, 1); - sg_set_page(&output, page, PAGE_SIZE, 0); - acomp_request_set_params(acomp_ctx->req, &input, &output, entry->length, dlen); - ret = crypto_wait_req(crypto_acomp_decompress(acomp_ctx->req), &acomp_ctx->wait); - dlen = acomp_ctx->req->dlen; - mutex_unlock(acomp_ctx->mutex); - - if (zpool_can_sleep_mapped(pool)) - zpool_unmap_handle(pool, entry->handle); - - BUG_ON(ret); - BUG_ON(dlen != PAGE_SIZE); + __zswap_load(entry, page); /* page is up to date */ SetPageUptodate(page); @@ -1758,11 +1758,7 @@ bool zswap_load(struct folio *folio) struct page *page = &folio->page; struct zswap_tree *tree = zswap_trees[type]; struct zswap_entry *entry; - struct scatterlist input, output; - struct crypto_acomp_ctx *acomp_ctx; - u8 *src, *dst; - struct zpool *zpool; - unsigned int dlen; + u8 *dst; bool ret; VM_WARN_ON_ONCE(!folio_test_locked(folio)); @@ -1784,31 +1780,7 @@ bool zswap_load(struct folio *folio) goto stats; } - zpool = zswap_find_zpool(entry); - - /* decompress */ - dlen = PAGE_SIZE; - acomp_ctx = raw_cpu_ptr(entry->pool->acomp_ctx); - mutex_lock(acomp_ctx->mutex); - - src = zpool_map_handle(zpool, entry->handle, ZPOOL_MM_RO); - if (!zpool_can_sleep_mapped(zpool)) { - memcpy(acomp_ctx->dstmem, src, entry->length); - src = acomp_ctx->dstmem; - zpool_unmap_handle(zpool, entry->handle); - } - - sg_init_one(&input, src, entry->length); - sg_init_table(&output, 1); - sg_set_page(&output, page, PAGE_SIZE, 0); - acomp_request_set_params(acomp_ctx->req, &input, &output, entry->length, dlen); - if (crypto_wait_req(crypto_acomp_decompress(acomp_ctx->req), &acomp_ctx->wait)) - WARN_ON(1); - mutex_unlock(acomp_ctx->mutex); - - if (zpool_can_sleep_mapped(zpool)) - zpool_unmap_handle(zpool, entry->handle); - + __zswap_load(entry, page); ret = true; stats: count_vm_event(ZSWPIN);