From patchwork Mon Jun 12 09:38:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Domenico Cerasuolo X-Patchwork-Id: 13275958 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 7A805C7EE25 for ; Mon, 12 Jun 2023 09:38:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 855B98E0007; Mon, 12 Jun 2023 05:38:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7DC6F900002; Mon, 12 Jun 2023 05:38:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5E0F48E0009; Mon, 12 Jun 2023 05:38:33 -0400 (EDT) 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 4162E8E0007 for ; Mon, 12 Jun 2023 05:38:33 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 13D8F1A0181 for ; Mon, 12 Jun 2023 09:38:33 +0000 (UTC) X-FDA: 80893595706.02.1F40D0E Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) by imf02.hostedemail.com (Postfix) with ESMTP id 0D5EC8000C for ; Mon, 12 Jun 2023 09:38:30 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=rPyAJhbx; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of cerasuolodomenico@gmail.com designates 209.85.218.51 as permitted sender) smtp.mailfrom=cerasuolodomenico@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686562711; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fU56VIBLxnADHQ9EwUvFSMVUPT9Hc1VDImYlSwrw2UY=; b=qsH2pG0VNyVVKNKSeN+utxiz7zdUv/HdyJIbFcnn8b2oPWbgEfCMF3jdAfm7row0vr4Llz GAz4eGxbNNV5z79HKmYzDTUNx7FSJcaNUg4J80OeltoDjxsXfFO9DB+7fcOS4Aa/ozpHz5 sB8PnZbRNIPPngMC6iAfqkPPQT3K12g= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=rPyAJhbx; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of cerasuolodomenico@gmail.com designates 209.85.218.51 as permitted sender) smtp.mailfrom=cerasuolodomenico@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686562711; a=rsa-sha256; cv=none; b=lIIBpENHcYBDDffxAG1d4HWH854jFW7D6yqrRyMDrT06/obMTiJdbpoEJ69M06XzJaJ6DJ rzQokLb5UzYoxF4DnoniIQON+oQ4cZlv3bMahzR+7HtXCvd4qe3nuOJu/FMKbADDHf/33J yUo8BOVhOkyNz7zupkesfm4qYK8sBso= Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-977d0288fd2so696846566b.1 for ; Mon, 12 Jun 2023 02:38:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686562709; x=1689154709; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fU56VIBLxnADHQ9EwUvFSMVUPT9Hc1VDImYlSwrw2UY=; b=rPyAJhbxdlqwUwyy7dTVMaBUHWn0yYtfrSsTXXjp3XScuykpDtMKUSRhLnII7AOPxy LygimtnshwNmGzZp4SRktLKkKrw8YeGsLVvcXVWqwRg152gnuniKlICI/PUGjYrtNuDq 9X0D0FfNc5DWhWUDwEYpeM09XkhOgj2vDLd+Tjx3qAT/jjzC93d32u43pbaRamHma0RQ FsMxBQqZ7lT0u3yAK7jrmhH1wHXB8K2cfVWkD5Z4zFPU6KuSLfQv4wL/ExHNW6YHyJKr HkrM1linZUifX/ITa62cR+cLUd4YP51PHa/Sj/Xd9+Nw8tflILQf6C5Alyzxrb95S5JA pP4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686562709; x=1689154709; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fU56VIBLxnADHQ9EwUvFSMVUPT9Hc1VDImYlSwrw2UY=; b=FRgEDKQREeuRTwi95CxsgaeY+BIM4dWCXt67OZaSpHT9Df0Mho3OYvzRsDN2yUMsLm 6JzF30PMCK7hfW638bO7SGx1tTgOKfLkd2axfrpGjOUXRQbawIy0RNNwAKOOvLhwOZED nMuyce7C3PdwYVkxnUyhe+pKKlqCupIK5lRNxzTsGsMtTjEd6FEkjfeWMY8mIuyeOxBp OBJUFGasMoXhEt2geSYjGGR7t8JH+imteRitxzwAg/0HBP7GQQSNKZk7Uq3QKgwLyQa5 RL19GrLYPJZbXKRkDfVyIzUTzJ4EUOZuSac8pH6aw0O4At0cjKY8mKP+eUVrRSC4Cc3Y Orcw== X-Gm-Message-State: AC+VfDygD0lU8KRawZrnHiUzDc3GnWN8wW0rWf3Wywc1UVNzrtJRh1AV D7KoWQg3mHVcpKOzZQuRoco= X-Google-Smtp-Source: ACHHUZ4Ka4ubZrdavFDrfWTwpLTvFWbauCZbwoMXabv7dPstChJIOunVXKEghyabVP0TxIpzU3irVQ== X-Received: by 2002:a17:907:7f09:b0:973:a30d:b264 with SMTP id qf9-20020a1709077f0900b00973a30db264mr9422554ejc.46.1686562709657; Mon, 12 Jun 2023 02:38:29 -0700 (PDT) Received: from lelloman-5950.homenet.telecomitalia.it (host-212-171-43-8.retail.telecomitalia.it. [212.171.43.8]) by smtp.gmail.com with ESMTPSA id ce23-20020a170906b25700b0097887b68c17sm4951358ejb.98.2023.06.12.02.38.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 02:38:29 -0700 (PDT) From: Domenico Cerasuolo To: vitaly.wool@konsulko.com, minchan@kernel.org, senozhatsky@chromium.org, yosryahmed@google.com, linux-mm@kvack.org Cc: ddstreet@ieee.org, sjenning@redhat.com, nphamcs@gmail.com, hannes@cmpxchg.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, Domenico Cerasuolo Subject: [PATCH v3 7/7] mm: zswap: remove zswap_header Date: Mon, 12 Jun 2023 11:38:15 +0200 Message-Id: <20230612093815.133504-8-cerasuolodomenico@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230612093815.133504-1-cerasuolodomenico@gmail.com> References: <20230612093815.133504-1-cerasuolodomenico@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 0D5EC8000C X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: yghjpnfux9gtswn9d8tcopqy7doi8ct5 X-HE-Tag: 1686562710-98027 X-HE-Meta: U2FsdGVkX18YKqa0PMSG8xgj2vD7Weu3fEZgkPUAUjWSaAKP9OKl3OCUuZ2H6//NY3KTXHlV5gN/t5TPm/3urGXr1KR2q3cdl+FbyVNehmG5rnXSPO9dGd/dJlDCnUQdV5D7Vb9VlZ1GX2A0NFsTd1Vnms5vHuoKRfAG+H3hqlAcahyELC9fVsBY9Sgbbu+HBvo5UKrcJyvXFlPQZAHUSrN3qtIxY5m6EiuDJnZMJL7o6VrocZkSk8VpFjSUP9qWWOO9ZXyBiziAMhmVYoVvgKAXngscnAZty3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kPjCwwjouk3GbUB2m6v9qyOjHyRmdX6vGUkSAEm+w5w9Cr3tbgBcWd0pk2kv2rVMPLWM1CLOrzfxkDGB7oicKhRxkV8aYrS7qsBCrQUYE7tbTvmyIi2eU/L+x5V/eD 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: Previously, zswap_header served the purpose of storing the swpentry within zpool pages. This allowed zpool implementations to pass relevant information to the writeback function. However, with the current implementation, writeback is directly handled within zswap. Consequently, there is no longer a necessity for zswap_header, as the swp_entry_t can be stored directly in zswap_entry. Tested-by: Yosry Ahmed Suggested-by: Yosry Ahmed Signed-off-by: Domenico Cerasuolo Acked-by: Johannes Weiner --- mm/zswap.c | 52 ++++++++++++++++++++++------------------------------ 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 3a6b07a19262..02d0a6f46f4a 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -197,7 +197,7 @@ struct zswap_pool { */ struct zswap_entry { struct rb_node rbnode; - pgoff_t offset; + swp_entry_t swpentry; int refcount; unsigned int length; struct zswap_pool *pool; @@ -209,10 +209,6 @@ struct zswap_entry { struct list_head lru; }; -struct zswap_header { - swp_entry_t swpentry; -}; - /* * The tree lock in the zswap_tree struct protects a few things: * - the rbtree @@ -254,7 +250,7 @@ static bool zswap_has_pool; pr_debug("%s pool %s/%s\n", msg, (p)->tfm_name, \ zpool_get_type((p)->zpool)) -static int zswap_writeback_entry(struct zswap_entry *entry, struct zswap_header *zhdr, +static int zswap_writeback_entry(struct zswap_entry *entry, struct zswap_tree *tree); static int zswap_pool_get(struct zswap_pool *pool); static void zswap_pool_put(struct zswap_pool *pool); @@ -315,12 +311,14 @@ static struct zswap_entry *zswap_rb_search(struct rb_root *root, pgoff_t offset) { struct rb_node *node = root->rb_node; struct zswap_entry *entry; + pgoff_t entry_offset; while (node) { entry = rb_entry(node, struct zswap_entry, rbnode); - if (entry->offset > offset) + entry_offset = swp_offset(entry->swpentry); + if (entry_offset > offset) node = node->rb_left; - else if (entry->offset < offset) + else if (entry_offset < offset) node = node->rb_right; else return entry; @@ -337,13 +335,15 @@ static int zswap_rb_insert(struct rb_root *root, struct zswap_entry *entry, { struct rb_node **link = &root->rb_node, *parent = NULL; struct zswap_entry *myentry; + pgoff_t myentry_offset, entry_offset = swp_offset(entry->swpentry); while (*link) { parent = *link; myentry = rb_entry(parent, struct zswap_entry, rbnode); - if (myentry->offset > entry->offset) + myentry_offset = swp_offset(myentry->swpentry); + if (myentry_offset > entry_offset) link = &(*link)->rb_left; - else if (myentry->offset < entry->offset) + else if (myentry_offset < entry_offset) link = &(*link)->rb_right; else { *dupentry = myentry; @@ -601,7 +601,6 @@ static struct zswap_pool *zswap_pool_find_get(char *type, char *compressor) static int zswap_reclaim_entry(struct zswap_pool *pool) { - struct zswap_header *zhdr; struct zswap_entry *entry; struct zswap_tree *tree; pgoff_t swpoffset; @@ -615,15 +614,13 @@ static int zswap_reclaim_entry(struct zswap_pool *pool) } entry = list_last_entry(&pool->lru, struct zswap_entry, lru); list_del_init(&entry->lru); - zhdr = zpool_map_handle(pool->zpool, entry->handle, ZPOOL_MM_RO); - tree = zswap_trees[swp_type(zhdr->swpentry)]; - zpool_unmap_handle(pool->zpool, entry->handle); /* * Once the lru lock is dropped, the entry might get freed. The * swpoffset is copied to the stack, and entry isn't deref'd again * until the entry is verified to still be alive in the tree. */ - swpoffset = swp_offset(zhdr->swpentry); + swpoffset = swp_offset(entry->swpentry); + tree = zswap_trees[swp_type(entry->swpentry)]; spin_unlock(&pool->lru_lock); /* Check for invalidate() race */ @@ -636,7 +633,7 @@ static int zswap_reclaim_entry(struct zswap_pool *pool) zswap_entry_get(entry); spin_unlock(&tree->lock); - ret = zswap_writeback_entry(entry, zhdr, tree); + ret = zswap_writeback_entry(entry, tree); spin_lock(&tree->lock); if (ret) { @@ -1055,10 +1052,10 @@ static int zswap_get_swap_cache_page(swp_entry_t entry, * the swap cache, the compressed version stored by zswap can be * freed. */ -static int zswap_writeback_entry(struct zswap_entry *entry, struct zswap_header *zhdr, +static int zswap_writeback_entry(struct zswap_entry *entry, struct zswap_tree *tree) { - swp_entry_t swpentry = zhdr->swpentry; + swp_entry_t swpentry = entry->swpentry; struct page *page; struct scatterlist input, output; struct crypto_acomp_ctx *acomp_ctx; @@ -1098,7 +1095,7 @@ static int zswap_writeback_entry(struct zswap_entry *entry, struct zswap_header * writing. */ spin_lock(&tree->lock); - if (zswap_rb_search(&tree->rbroot, entry->offset) != entry) { + if (zswap_rb_search(&tree->rbroot, swp_offset(entry->swpentry)) != entry) { spin_unlock(&tree->lock); delete_from_swap_cache(page_folio(page)); ret = -ENOMEM; @@ -1110,8 +1107,7 @@ static int zswap_writeback_entry(struct zswap_entry *entry, struct zswap_header acomp_ctx = raw_cpu_ptr(entry->pool->acomp_ctx); dlen = PAGE_SIZE; - zhdr = zpool_map_handle(pool, entry->handle, ZPOOL_MM_RO); - src = (u8 *)zhdr + sizeof(struct zswap_header); + src = zpool_map_handle(pool, entry->handle, ZPOOL_MM_RO); if (!zpool_can_sleep_mapped(pool)) { memcpy(tmp, src, entry->length); src = tmp; @@ -1205,11 +1201,10 @@ static int zswap_frontswap_store(unsigned type, pgoff_t offset, struct obj_cgroup *objcg = NULL; struct zswap_pool *pool; int ret; - unsigned int hlen, dlen = PAGE_SIZE; + unsigned int dlen = PAGE_SIZE; unsigned long handle, value; char *buf; u8 *src, *dst; - struct zswap_header zhdr = { .swpentry = swp_entry(type, offset) }; gfp_t gfp; /* THP isn't supported */ @@ -1254,7 +1249,7 @@ static int zswap_frontswap_store(unsigned type, pgoff_t offset, src = kmap_atomic(page); if (zswap_is_page_same_filled(src, &value)) { kunmap_atomic(src); - entry->offset = offset; + entry->swpentry = swp_entry(type, offset); entry->length = 0; entry->value = value; atomic_inc(&zswap_same_filled_pages); @@ -1308,11 +1303,10 @@ static int zswap_frontswap_store(unsigned type, pgoff_t offset, } /* store */ - hlen = sizeof(zhdr); gfp = __GFP_NORETRY | __GFP_NOWARN | __GFP_KSWAPD_RECLAIM; if (zpool_malloc_support_movable(entry->pool->zpool)) gfp |= __GFP_HIGHMEM | __GFP_MOVABLE; - ret = zpool_malloc(entry->pool->zpool, hlen + dlen, gfp, &handle); + ret = zpool_malloc(entry->pool->zpool, dlen, gfp, &handle); if (ret == -ENOSPC) { zswap_reject_compress_poor++; goto put_dstmem; @@ -1322,13 +1316,12 @@ static int zswap_frontswap_store(unsigned type, pgoff_t offset, goto put_dstmem; } buf = zpool_map_handle(entry->pool->zpool, handle, ZPOOL_MM_WO); - memcpy(buf, &zhdr, hlen); - memcpy(buf + hlen, dst, dlen); + memcpy(buf, dst, dlen); zpool_unmap_handle(entry->pool->zpool, handle); mutex_unlock(acomp_ctx->mutex); /* populate entry */ - entry->offset = offset; + entry->swpentry = swp_entry(type, offset); entry->handle = handle; entry->length = dlen; @@ -1437,7 +1430,6 @@ static int zswap_frontswap_load(unsigned type, pgoff_t offset, /* decompress */ dlen = PAGE_SIZE; src = zpool_map_handle(entry->pool->zpool, entry->handle, ZPOOL_MM_RO); - src += sizeof(struct zswap_header); if (!zpool_can_sleep_mapped(entry->pool->zpool)) { memcpy(tmp, src, entry->length);