From patchwork Mon Dec 18 08:22:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13496352 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 68A21C35274 for ; Mon, 18 Dec 2023 08:22:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ADDB78D0008; Mon, 18 Dec 2023 03:22:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A65E38D0001; Mon, 18 Dec 2023 03:22:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 906158D0008; Mon, 18 Dec 2023 03:22:40 -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 781E98D0001 for ; Mon, 18 Dec 2023 03:22:40 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 46B31802DB for ; Mon, 18 Dec 2023 08:22:40 +0000 (UTC) X-FDA: 81579247680.18.664E6AA Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) by imf07.hostedemail.com (Postfix) with ESMTP id 402FE40028 for ; Mon, 18 Dec 2023 08:22:38 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf07.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.174 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702887758; 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=PXnKmp9hIrs7vWNbgiF/NNHDBUyiGKw3qC+OgCp3sfVDD6boOScaJwYjD4ckGIFcwH/Hoy KSa36j19cWfzQFRAFFNE/EYgJUa9Z1tcBWUX3Qz9sDfs+anPQEUuZY5vEp/qI7aqG0HLtW C+JPJhYfOvaNbyjTI+oeiJBUJiAHqpg= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf07.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.174 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702887758; a=rsa-sha256; cv=none; b=PG0aaLFwbMqGc3+2Wx6khmZ/e5MEXkBXZGTljXpOCN9+2ZxRqq45g9n25JZQlh+YZ0cUUp cQ9CsANsfXql4sNVIV/ujNYbN1kGL0gVmddVUwq207R+4bPjvxfbpGSPXUNxsGnSyTIliO +vylH4yA4Py6A+Lg1Ty4+Ttf7pF4+BU= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou Date: Mon, 18 Dec 2023 08:22:02 +0000 Subject: [PATCH v2 3/6] mm/zswap: refactor out __zswap_load() MIME-Version: 1.0 Message-Id: <20231213-zswap-dstmem-v2-3-daa5d9ae41a7@bytedance.com> References: <20231213-zswap-dstmem-v2-0-daa5d9ae41a7@bytedance.com> In-Reply-To: <20231213-zswap-dstmem-v2-0-daa5d9ae41a7@bytedance.com> To: Seth Jennings , Dan Streetman , Chris Li , Nhat Pham , Vitaly Wool , Yosry Ahmed , Andrew Morton , Johannes Weiner Cc: linux-kernel@vger.kernel.org, Nhat Pham , linux-mm@kvack.org, Yosry Ahmed , Chengming Zhou , Chris Li X-Developer-Signature: v=1; a=ed25519-sha256; t=1702887745; l=4703; i=zhouchengming@bytedance.com; s=20231204; h=from:subject:message-id; bh=B99wC6AH9+R5m6Djw0+W/AJA7ag/bUbsLCKvYrrlo8Q=; b=i4FV3NiKGGQh3MrHNtbjPVINB+qPumTYyPJyDJWpxDhI64MoLtB2CBM8elGupDabajgL3lEDR 6iddEsOkX1UA09nUGr1s1pdovfIltzGUWgVzu3xtbR6x9alb5Q0sCF3 X-Developer-Key: i=zhouchengming@bytedance.com; a=ed25519; pk=xFTmRtMG3vELGJBUiml7OYNdM393WOMv0iWWeQEVVdA= X-Migadu-Flow: FLOW_OUT X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspam-User: X-Rspamd-Queue-Id: 402FE40028 X-Rspamd-Server: rspam05 X-Stat-Signature: 91pnkep67zbd8th5tzqajt1xb43fmfdy X-Rspam: Yes X-HE-Tag: 1702887758-927002 X-HE-Meta: U2FsdGVkX18y2A/MCBtgOu7AgXtQfBBCFOks4YXh/QKnApR83bWjqvzMtCbmUPM4cHDtN4J+iG01aGViBeEw3P4/sVm9CTPUxwt6rVkAhpbfVi5EPd1zTC2dTsFOlBT4INq4vPA668B75D9GCNEBqYeQEnz1df/4ob5XsS0tc8+hsNHRBxCq3kSu4ArohctCnLys+gE4XFlWu8hd1AvrY6sO34dzc2IuBe/YTG2wyDmlhbRnnSV/8Wp1BbIMplWi5pk8c9yECR7fnFpTGRGZxl9wZ4NQs2YEk7AtzxBt/wNIDDqI1vOMEOlGsq0yoGgXHMKg/9FQuAUQDZb2an4nd/mAPe8LxIBYFjajTFa47oT254kNTkfSJ3Se2hAiZrRbxJV3qiO9mYFu/cks1x7OqfWxiliBX7DLeonK3GmWbdj+CILGchhIApKg8fzFqXs4URbMs8yywAVgG/sCO3ZxXHNmQNRHdeq1XdP4fVJVur2tFQ6n/NfeL3f8hT6+ZBlPks5dr4y6d8fIODcoL7iFOAfzKse1w1sCr4TPw/6uegMg98giBe5UrLvj+/A0uy2Hd0Yn3NtvZ/m/HTxdB+jU4LkerkBUTBBPUjOZEndbhFJDY34DAuObZXrAHR2Ak5aHZeZrXrMcWo42lgVX5B2s4KxVPYbuTOGg0ZJM16lFmvnkRutdMHyAxQraN/6H+3iQF/1wX5YXQlXMBMp9QhYteWqYWEcNSD7XCix8yBcNMYEkJVShKK50bQ1Rh963go8IY1pmRYZyjVaN5TZiZErwhXj15vYYS+8zAfN2UXv/MhbUE5CHJMkRaBlDTe0fvybai1YgIgebH3G6kOu1/F96pm4GokYCWyKSY3wrxN/FiPjQAtUSuU45CK9ZzSSgTRcntM61Irf7PTb1VJMmL2kzqDdeSD1f2C7arVY976KLwGvpvJc5sDnLaoShdIxBsYiFt5hIuHIc2HDUmT5gsfx MbtIioWX J8bQqiGEg3OUg7vtblB1CzNo/cbCH3ujjS1bbqyz7IfH7JZy5Bmhv2GTGoEBuk7gRTTp8rrhtXEhK+ZAihOTofRfwkxcF59mTEaDOTUW4PqYZkrPMMUNNNMczoz+zR+ehGXuL54VtiNu2YiertsIdb5WZOHPulqaDBmZ0Dj0OtsdVvjbDldFw0gJx4Dm5kvAptPDsh1yeL3r2KdPoRrBMROIrab6E5RsU6AtSEOxMP+tJSAiznqh0Ri9owcpH1vXeKdysBsEDEWtGo//yDz3bR77ICnER05/BBSTyx9wUfFzKF4bz/xukVoESHKBrjwyaRt3RSXotjAKcqB/DxthnR5D9DGbgLOT0MgmjSPqzTWiwlS6MFeGCrBV8pDyzLg+Sc+ieky077Q08x2nub+gN/8p/mOEeAgjAr3HP82Rs4qkeqMOIOv72xEmoauLwrBg9s2hsZ5X2DphS0/E= 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 --- 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);