From patchwork Wed Jan 22 05:57:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13946859 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 C306AC0218C for ; Wed, 22 Jan 2025 05:59:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 339E56B0089; Wed, 22 Jan 2025 00:59:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2E8676B008A; Wed, 22 Jan 2025 00:59:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 163186B008C; Wed, 22 Jan 2025 00:59:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E35C76B0089 for ; Wed, 22 Jan 2025 00:59:18 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7124B45C3E for ; Wed, 22 Jan 2025 05:59:18 +0000 (UTC) X-FDA: 83034035196.27.33F3782 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by imf21.hostedemail.com (Postfix) with ESMTP id 92F4B1C0003 for ; Wed, 22 Jan 2025 05:59:16 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="OrGY25/D"; spf=pass (imf21.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.48 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737525556; 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=nNJBFEkJ6QI9GsDPc+DtKnpVKRZ1iP1KV3SxEj7y/i4=; b=0c2YD0dm7UR3HUgvW/WXxd3PBzoANab1GHn02OyDryLfo1x8h4842KgAsq7WLkW7fU+Z9q c64oVEZJSp8umgi99oY1qy4ittvGfER/Gkbb8gW5KEPStus9PaD9Gqza/ms0Uxmc2ILWLs I1poD1IIlWMC87z821JopACIwX06Q4Q= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="OrGY25/D"; spf=pass (imf21.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.48 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737525556; a=rsa-sha256; cv=none; b=GAjtmNRqVM08D/WvwM8DzDhLuNAST3GhRlEnPkgY3/i05bXTerPBYBOp+jvFi8ZwXOHgjE NzXJN8UnhCIh5zCA9aUjPZnzJTJ6fC2y4dIgRRvADbe3uizci2SF2PYM9832xcLhpZksoa u5iXhraGbRNzl+Qcn899dYPVaA3uQ5Q= Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-2ef72924e53so11147059a91.3 for ; Tue, 21 Jan 2025 21:59:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1737525555; x=1738130355; darn=kvack.org; 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=nNJBFEkJ6QI9GsDPc+DtKnpVKRZ1iP1KV3SxEj7y/i4=; b=OrGY25/DBfdgF/Ph1KZxxzRFRVK5acNxcuiBfRhRDmnyO4hvsQo8AkqdABlG/l/Av4 CFL2HCwkKooIXbi2z7IwiYTgVbX7mwtUCNfAZyW86SrYG1QTqa5W49HBIG9qCyg6NNrf wfLst3dGnN4/Vc5061RiSvFfHxt+2EH7Wa+jE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737525555; x=1738130355; 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=nNJBFEkJ6QI9GsDPc+DtKnpVKRZ1iP1KV3SxEj7y/i4=; b=n0CO1fxM3wzQ5F/iEiMQTyB3CJbkBY5EFFRt5ZydJ0OgRYsnsenfIHDiWOuT1JnQKi KNZjLGh4hRGmo8VbX95IhGh6WnZts1klJdoxEF15iRS9S1EdLlSyvwRiSaqbDNymYd1N 1zuViAN9XVKpYiZQ+53DgPTUy6z1tpCI0ripCPXSHrGPlkiXBPcCghop+mMPb2VGNaeU dJIA8Mf7wdrdeYyxM2nh0jp7qaJSfdR0hQh37tYNx/ksglB5FilFsTjfQps6rcZsYbKd 3ITKlg5Vxw2Ig18KfaLHyg91tfohe4akgiVb3PwTbRgY1yiy41S898nFtQDseBaGZKrO Wp5A== X-Gm-Message-State: AOJu0YzjGtHQkblWHX2dYbtFoLC4ANQVPOojfsZNQuG/7fYudhpipdP4 J9Hx8JTFUWaYI7iqU4keVDqrMzyZHzNR/LgfozMcSat9CdZ0xlcXBFpnXqD5/Q== X-Gm-Gg: ASbGnct99BTG+YCnVFRj6OaH0wnf/Pbsv/K9ZDnOIgIcuLLd/PNPWZphNa2nL9A34/2 QOHbH/D5Yw6sf5YJcIbzatgUI7ExpEvfvBe3IgB+KxydvVjLrkd7j0VBmPegz3iknOC0qHuHgcH UNNEfjDMwLWLo0Xw8l9PfU8zrxiRPsI7BLr1sDK2+YRDHrOx5Hd2j5RvQppVljmzI5nDEP/0/FR KQt5blmccVHnqVOTC8E+MEH2VAaJRzWonVgyud/IzVI13WBGF3qWbLlRVnVVl1xp0plJNie X-Google-Smtp-Source: AGHT+IFkiDY8ubThsiSVPvY+v+ZW4p7rcixmuj2cYd+76LLUa3zPITbS5RuEp5qCovKlriMjDRnvpw== X-Received: by 2002:a17:90b:540b:b0:2f2:8bdd:cd8b with SMTP id 98e67ed59e1d1-2f782d972a2mr28408515a91.29.1737525555228; Tue, 21 Jan 2025 21:59:15 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:2902:8f0f:12b3:c251]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2f7e6a78ba1sm618280a91.14.2025.01.21.21.59.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 Jan 2025 21:59:14 -0800 (PST) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCH 2/7] zram: do not use per-CPU compression streams Date: Wed, 22 Jan 2025 14:57:40 +0900 Message-ID: <20250122055831.3341175-3-senozhatsky@chromium.org> X-Mailer: git-send-email 2.48.0.rc2.279.g1de40edade-goog In-Reply-To: <20250122055831.3341175-1-senozhatsky@chromium.org> References: <20250122055831.3341175-1-senozhatsky@chromium.org> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 92F4B1C0003 X-Stat-Signature: f6nfkyhyjeabuuo48djnmo7n1ddbfoch X-Rspam-User: X-HE-Tag: 1737525556-260575 X-HE-Meta: U2FsdGVkX1/kxdBgb7Z4n6iMvc+R/DpNarVImZjjkbu+rYpDF7TCXigPavukztqRdsFaA23566jXjVi5PJpD1P6uB6DlzJM5oIoDcFGXU2b84srOQEPj+uQ7mhcDezml8q1HIjJ+r+9yirfbTGD/KqoMSzyMT2mRuvpsjSipbRrW90ql7lsu8QtuIr0Ur1SRpzv9RWFz5eVwooVb6VWovEG+vruqqzzCyTl4c+5HnuHmutahQd3FH+H/bQMU4VVoIrATng8ob2weBN1xD7CGX031yH3GCdD3i88u6zZenypuFBfshwAXR1gPTGVjb8oBhUU3k1BveD5ltRqvX7bbfqmlT+Ffxog6zMBbdsoGRp9Qfsf8khB+hG66EdOXVOPuecCytcFE/vCNK3QMmv3AuV/rWD/okBMgfWuctsX2DcWvg0yrcKFNNqmL1CsmSGnoHWMRQNF4P0yEyfBABogzkzQSAYRqQByUNxuLuaqlMzVsMYqEKz5KpLdIZdiieIgsm+KWMOXPG7Y9UA/gtV/jO4Aw150BEhTjTtjP5KXDwhLe+3CO5wWUrVXAgEe7pEOxzzl7nlSitN+XdrelopndLltUkdBGiMGzZK3FeETnd+MuxOj6z+qgelSkMwS9JybQmfqaIRKabvhJ6xohcs+9h2W4hgSa2eApaKT86ITe5jUHDy8JFTH64XsXaQZhdPHK7u3xgrj4ynq6VJdBYGg0/CfwqGhCVW0lTsql/SJzp7A5nx4Rdas8H282kPQqjaEkOaqXTl2uen3bPyucIXN1Cfk+pBMiChoa+jdolWaAejhvZ4FPfKQBkutusTkhgUCuJ+CMZWmD8Crc+FPHBEXqk3Bu4WkREhIuaEHKwsxEeNg89xT9/iTtI2ZewA4Wg5pZzUUcItZSkEf8qepBb22v7Vkh1i3f0DzkvGOZn+HN/hVtSJ+vCTMefq3EQdn18Ix/T1fV82+UjSxAw/vxsy3 XdqV6DXD cOrVcXNL1A+cMFE1miYvYBi9ItbKzlQ7+Cuq+stP++t0yG5cdRX0cFqvdwf3yFaFfHKRKMHJfiRXGGWCff/rLFWkUaGzpYRJ6p4nE18/qN/5bCN5xDhP5ujo3FHuYYoNcRZvQJCyWypBc0CPo9LfYLIW2McCT3MvtnWsItJNlfHqTIfjQb9PMWDky+wJHK2jBo9DMyEdQwbtWnUW1/3EgIkf/hZBSuzobIBdCNzA92OGxf2tnZwkwCW6fIhLTDzDqc+GKepGTbX7G7TxsaaEprs3rZBMss8Ssr31Mw/yy348IDsnuqmU/A2Pj0g== 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: Similarly to per-entry spin-lock per-CPU compression streams also have a number of shortcoming. First, per-CPU stream access has to be done from a non-preemptible (atomic) section, which imposes the same atomicity requirements on compression backends as entry spin-lock do and makes it impossible to use algorithms that can schedule/wait/sleep during compression and decompression. Second, per-CPU streams noticeably increase memory usage (actually more like wastage) of secondary compression streams. The problem is that secondary compression streams are allocated per-CPU, just like the primary streams are. Yet we never use more that one secondary stream at a time, because recompression is a single threaded action. Which means that remaining num_online_cpu() - 1 streams are allocated for nothing, and this is per-priority list (we can have several secondary compression algorithms). Depending on the algorithm this may lead to a significant memory wastage, in addition each stream also carries a workmem buffer (2 physical pages). Instead of per-CPU streams, maintain a list of idle compression streams and allocate new streams on-demand (something that we used to do many years ago). So that zram read() and write() become non-atomic and ease requirements on the compression algorithm implementation. This also means that we now should have only one secondary stream per-priority list. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zcomp.c | 162 +++++++++++++++++++--------------- drivers/block/zram/zcomp.h | 17 ++-- drivers/block/zram/zram_drv.c | 29 +++--- include/linux/cpuhotplug.h | 1 - 4 files changed, 108 insertions(+), 101 deletions(-) diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c index bb514403e305..5d8298fc2616 100644 --- a/drivers/block/zram/zcomp.c +++ b/drivers/block/zram/zcomp.c @@ -43,31 +43,40 @@ static const struct zcomp_ops *backends[] = { NULL }; -static void zcomp_strm_free(struct zcomp *comp, struct zcomp_strm *zstrm) +static void zcomp_strm_free(struct zcomp *comp, struct zcomp_strm *strm) { - comp->ops->destroy_ctx(&zstrm->ctx); - vfree(zstrm->buffer); - zstrm->buffer = NULL; + comp->ops->destroy_ctx(&strm->ctx); + vfree(strm->buffer); + kfree(strm); } -static int zcomp_strm_init(struct zcomp *comp, struct zcomp_strm *zstrm) +static struct zcomp_strm *zcomp_strm_alloc(struct zcomp *comp) { + struct zcomp_strm *strm; int ret; - ret = comp->ops->create_ctx(comp->params, &zstrm->ctx); - if (ret) - return ret; + strm = kzalloc(sizeof(*strm), GFP_KERNEL); + if (!strm) + return NULL; + + INIT_LIST_HEAD(&strm->entry); + + ret = comp->ops->create_ctx(comp->params, &strm->ctx); + if (ret) { + kfree(strm); + return NULL; + } /* - * allocate 2 pages. 1 for compressed data, plus 1 extra for the - * case when compressed size is larger than the original one + * allocate 2 pages. 1 for compressed data, plus 1 extra in case if + * compressed data is larger than the original one. */ - zstrm->buffer = vzalloc(2 * PAGE_SIZE); - if (!zstrm->buffer) { - zcomp_strm_free(comp, zstrm); - return -ENOMEM; + strm->buffer = vzalloc(2 * PAGE_SIZE); + if (!strm->buffer) { + zcomp_strm_free(comp, strm); + return NULL; } - return 0; + return strm; } static const struct zcomp_ops *lookup_backend_ops(const char *comp) @@ -109,13 +118,59 @@ ssize_t zcomp_available_show(const char *comp, char *buf) struct zcomp_strm *zcomp_stream_get(struct zcomp *comp) { - local_lock(&comp->stream->lock); - return this_cpu_ptr(comp->stream); + struct zcomp_strm *strm; + + might_sleep(); + + while (1) { + spin_lock(&comp->strm_lock); + if (!list_empty(&comp->idle_strm)) { + strm = list_first_entry(&comp->idle_strm, + struct zcomp_strm, + entry); + list_del(&strm->entry); + spin_unlock(&comp->strm_lock); + return strm; + } + + /* cannot allocate new stream, wait for an idle one */ + if (comp->avail_strm >= num_online_cpus()) { + spin_unlock(&comp->strm_lock); + wait_event(comp->strm_wait, + !list_empty(&comp->idle_strm)); + continue; + } + + /* allocate new stream */ + comp->avail_strm++; + spin_unlock(&comp->strm_lock); + + strm = zcomp_strm_alloc(comp); + if (strm) + break; + + spin_lock(&comp->strm_lock); + comp->avail_strm--; + spin_unlock(&comp->strm_lock); + wait_event(comp->strm_wait, !list_empty(&comp->idle_strm)); + } + + return strm; } -void zcomp_stream_put(struct zcomp *comp) +void zcomp_stream_put(struct zcomp *comp, struct zcomp_strm *strm) { - local_unlock(&comp->stream->lock); + spin_lock(&comp->strm_lock); + if (comp->avail_strm <= num_online_cpus()) { + list_add(&strm->entry, &comp->idle_strm); + spin_unlock(&comp->strm_lock); + wake_up(&comp->strm_wait); + return; + } + + comp->avail_strm--; + spin_unlock(&comp->strm_lock); + zcomp_strm_free(comp, strm); } int zcomp_compress(struct zcomp *comp, struct zcomp_strm *zstrm, @@ -148,61 +203,19 @@ int zcomp_decompress(struct zcomp *comp, struct zcomp_strm *zstrm, return comp->ops->decompress(comp->params, &zstrm->ctx, &req); } -int zcomp_cpu_up_prepare(unsigned int cpu, struct hlist_node *node) -{ - struct zcomp *comp = hlist_entry(node, struct zcomp, node); - struct zcomp_strm *zstrm; - int ret; - - zstrm = per_cpu_ptr(comp->stream, cpu); - local_lock_init(&zstrm->lock); - - ret = zcomp_strm_init(comp, zstrm); - if (ret) - pr_err("Can't allocate a compression stream\n"); - return ret; -} - -int zcomp_cpu_dead(unsigned int cpu, struct hlist_node *node) -{ - struct zcomp *comp = hlist_entry(node, struct zcomp, node); - struct zcomp_strm *zstrm; - - zstrm = per_cpu_ptr(comp->stream, cpu); - zcomp_strm_free(comp, zstrm); - return 0; -} - -static int zcomp_init(struct zcomp *comp, struct zcomp_params *params) -{ - int ret; - - comp->stream = alloc_percpu(struct zcomp_strm); - if (!comp->stream) - return -ENOMEM; - - comp->params = params; - ret = comp->ops->setup_params(comp->params); - if (ret) - goto cleanup; - - ret = cpuhp_state_add_instance(CPUHP_ZCOMP_PREPARE, &comp->node); - if (ret < 0) - goto cleanup; - - return 0; - -cleanup: - comp->ops->release_params(comp->params); - free_percpu(comp->stream); - return ret; -} - void zcomp_destroy(struct zcomp *comp) { - cpuhp_state_remove_instance(CPUHP_ZCOMP_PREPARE, &comp->node); + struct zcomp_strm *strm; + + while (!list_empty(&comp->idle_strm)) { + strm = list_first_entry(&comp->idle_strm, + struct zcomp_strm, + entry); + list_del(&strm->entry); + zcomp_strm_free(comp, strm); + } + comp->ops->release_params(comp->params); - free_percpu(comp->stream); kfree(comp); } @@ -229,7 +242,12 @@ struct zcomp *zcomp_create(const char *alg, struct zcomp_params *params) return ERR_PTR(-EINVAL); } - error = zcomp_init(comp, params); + INIT_LIST_HEAD(&comp->idle_strm); + init_waitqueue_head(&comp->strm_wait); + spin_lock_init(&comp->strm_lock); + + comp->params = params; + error = comp->ops->setup_params(comp->params); if (error) { kfree(comp); return ERR_PTR(error); diff --git a/drivers/block/zram/zcomp.h b/drivers/block/zram/zcomp.h index ad5762813842..62330829db3f 100644 --- a/drivers/block/zram/zcomp.h +++ b/drivers/block/zram/zcomp.h @@ -3,10 +3,10 @@ #ifndef _ZCOMP_H_ #define _ZCOMP_H_ -#include - #define ZCOMP_PARAM_NO_LEVEL INT_MIN +#include + /* * Immutable driver (backend) parameters. The driver may attach private * data to it (e.g. driver representation of the dictionary, etc.). @@ -31,7 +31,7 @@ struct zcomp_ctx { }; struct zcomp_strm { - local_lock_t lock; + struct list_head entry; /* compression buffer */ void *buffer; struct zcomp_ctx ctx; @@ -60,16 +60,15 @@ struct zcomp_ops { const char *name; }; -/* dynamic per-device compression frontend */ struct zcomp { - struct zcomp_strm __percpu *stream; + struct list_head idle_strm; + spinlock_t strm_lock; + u32 avail_strm; + wait_queue_head_t strm_wait; const struct zcomp_ops *ops; struct zcomp_params *params; - struct hlist_node node; }; -int zcomp_cpu_up_prepare(unsigned int cpu, struct hlist_node *node); -int zcomp_cpu_dead(unsigned int cpu, struct hlist_node *node); ssize_t zcomp_available_show(const char *comp, char *buf); bool zcomp_available_algorithm(const char *comp); @@ -77,7 +76,7 @@ struct zcomp *zcomp_create(const char *alg, struct zcomp_params *params); void zcomp_destroy(struct zcomp *comp); struct zcomp_strm *zcomp_stream_get(struct zcomp *comp); -void zcomp_stream_put(struct zcomp *comp); +void zcomp_stream_put(struct zcomp *comp, struct zcomp_strm *strm); int zcomp_compress(struct zcomp *comp, struct zcomp_strm *zstrm, const void *src, unsigned int *dst_len); diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 7eb7feba3cac..b217c29448ce 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include @@ -1606,7 +1605,7 @@ static int read_compressed_page(struct zram *zram, struct page *page, u32 index) ret = zcomp_decompress(zram->comps[prio], zstrm, src, size, dst); kunmap_local(dst); zs_unmap_object(zram->mem_pool, handle); - zcomp_stream_put(zram->comps[prio]); + zcomp_stream_put(zram->comps[prio], zstrm); return ret; } @@ -1767,14 +1766,14 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 index) kunmap_local(mem); if (unlikely(ret)) { - zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP]); + zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP], zstrm); pr_err("Compression failed! err=%d\n", ret); zs_free(zram->mem_pool, handle); return ret; } if (comp_len >= huge_class_size) { - zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP]); + zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP], zstrm); return write_incompressible_page(zram, page, index); } @@ -1798,7 +1797,7 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 index) __GFP_HIGHMEM | __GFP_MOVABLE); if (IS_ERR_VALUE(handle)) { - zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP]); + zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP], zstrm); atomic64_inc(&zram->stats.writestall); handle = zs_malloc(zram->mem_pool, comp_len, GFP_NOIO | __GFP_HIGHMEM | @@ -1810,7 +1809,7 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 index) } if (!zram_can_store_page(zram)) { - zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP]); + zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP], zstrm); zs_free(zram->mem_pool, handle); return -ENOMEM; } @@ -1818,7 +1817,7 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 index) dst = zs_map_object(zram->mem_pool, handle, ZS_MM_WO); memcpy(dst, zstrm->buffer, comp_len); - zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP]); + zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP], zstrm); zs_unmap_object(zram->mem_pool, handle); zram_slot_write_lock(zram, index); @@ -1977,7 +1976,7 @@ static int recompress_slot(struct zram *zram, u32 index, struct page *page, kunmap_local(src); if (ret) { - zcomp_stream_put(zram->comps[prio]); + zcomp_stream_put(zram->comps[prio], zstrm); return ret; } @@ -1987,7 +1986,7 @@ static int recompress_slot(struct zram *zram, u32 index, struct page *page, /* Continue until we make progress */ if (class_index_new >= class_index_old || (threshold && comp_len_new >= threshold)) { - zcomp_stream_put(zram->comps[prio]); + zcomp_stream_put(zram->comps[prio], zstrm); continue; } @@ -2045,13 +2044,13 @@ static int recompress_slot(struct zram *zram, u32 index, struct page *page, __GFP_HIGHMEM | __GFP_MOVABLE); if (IS_ERR_VALUE(handle_new)) { - zcomp_stream_put(zram->comps[prio]); + zcomp_stream_put(zram->comps[prio], zstrm); return PTR_ERR((void *)handle_new); } dst = zs_map_object(zram->mem_pool, handle_new, ZS_MM_WO); memcpy(dst, zstrm->buffer, comp_len_new); - zcomp_stream_put(zram->comps[prio]); + zcomp_stream_put(zram->comps[prio], zstrm); zs_unmap_object(zram->mem_pool, handle_new); @@ -2799,7 +2798,6 @@ static void destroy_devices(void) zram_debugfs_destroy(); idr_destroy(&zram_index_idr); unregister_blkdev(zram_major, "zram"); - cpuhp_remove_multi_state(CPUHP_ZCOMP_PREPARE); } static int __init zram_init(void) @@ -2809,15 +2807,9 @@ static int __init zram_init(void) BUILD_BUG_ON(__NR_ZRAM_PAGEFLAGS > sizeof(zram_te.flags) * 8); - ret = cpuhp_setup_state_multi(CPUHP_ZCOMP_PREPARE, "block/zram:prepare", - zcomp_cpu_up_prepare, zcomp_cpu_dead); - if (ret < 0) - return ret; - ret = class_register(&zram_control_class); if (ret) { pr_err("Unable to register zram-control class\n"); - cpuhp_remove_multi_state(CPUHP_ZCOMP_PREPARE); return ret; } @@ -2826,7 +2818,6 @@ static int __init zram_init(void) if (zram_major <= 0) { pr_err("Unable to get major number\n"); class_unregister(&zram_control_class); - cpuhp_remove_multi_state(CPUHP_ZCOMP_PREPARE); return -EBUSY; } diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h index 6cc5e484547c..092ace7db8ee 100644 --- a/include/linux/cpuhotplug.h +++ b/include/linux/cpuhotplug.h @@ -119,7 +119,6 @@ enum cpuhp_state { CPUHP_MM_ZS_PREPARE, CPUHP_MM_ZSWP_POOL_PREPARE, CPUHP_KVM_PPC_BOOK3S_PREPARE, - CPUHP_ZCOMP_PREPARE, CPUHP_TIMERS_PREPARE, CPUHP_TMIGR_PREPARE, CPUHP_MIPS_SOC_PREPARE,