From patchwork Wed Jan 29 06:43:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13953469 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 89885C02192 for ; Wed, 29 Jan 2025 06:49:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1490D280027; Wed, 29 Jan 2025 01:49:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0F87A28001A; Wed, 29 Jan 2025 01:49:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F03BB280027; Wed, 29 Jan 2025 01:49:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D059728001A for ; Wed, 29 Jan 2025 01:49:34 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 87E5146256 for ; Wed, 29 Jan 2025 06:49:34 +0000 (UTC) X-FDA: 83059563468.12.8725EC3 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf05.hostedemail.com (Postfix) with ESMTP id A1468100007 for ; Wed, 29 Jan 2025 06:49:32 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="c5/NepHR"; spf=pass (imf05.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.174 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=1738133372; 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=jm+b3R/xkgu1u5aIyHjEy9+3hXzV4kVBwpygpgrob3Q=; b=hSJ9+Sadrx20wIS2Jdzl3gJ+4ToGmHZemMTdvsyZvzd2HiZQwNntBmkL9XieoCu+Q8RTL9 yHLQLP230zZdX89xQJghchcWF7jojt7jLP4Uf7bQypFfJt6RhgfxH1APIVcsx/LbZyTsUd +ai6hHZ4T+WakxKJCx6lnVp8/Sggge0= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="c5/NepHR"; spf=pass (imf05.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.174 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=1738133372; a=rsa-sha256; cv=none; b=Le+efu76y5IQZULeA+BV/85f/xv2ntKfWgaiCENW7mBP+7ftTy6SfOoLlZJB5ICC38NwYP /p6A+Bbps8TIOFxQbtC7hYrNJmoO9OfGnzGs/2yWmE85e3krCyMat+OUo65EIEWv5HyuZe BUebflASwxWZOrWa2wIfn+e9ySa/c+M= Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-21bc1512a63so122284975ad.1 for ; Tue, 28 Jan 2025 22:49:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1738133371; x=1738738171; 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=jm+b3R/xkgu1u5aIyHjEy9+3hXzV4kVBwpygpgrob3Q=; b=c5/NepHRuYgbFzNLgUz15x283DSbgU0MOtxkQCMhxbaOhpgKwhNEOH+rNUQYkAQ9OH T7fB6uNXxdN0QVcL7ZURe5zw3Xw0w9S/j3A+iiKGJSOQmtMCdYT9JhZQuYff3+Ep2kh3 OftAGSPyA0j1lOKzkJVezVCPkSUpY2j3ipO14= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738133371; x=1738738171; 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=jm+b3R/xkgu1u5aIyHjEy9+3hXzV4kVBwpygpgrob3Q=; b=a4OElFuunRZFA9P72RzgimbPzfE5EBQMrK+pcN1Bd8ZND7CxfXNilcdHZmL9ZQKaRH pZIPKjudg3KGRb1a7GvS1CKDQQUXmzhHw6BjBygEC1yzNPUmeZIA3T9v1+tHv9gKysVF 8YVJGq11EuGnDtyQGYxawBY92phVI5aqnmqFlMhyL98MoMetTr9LGG4jjCYjun+yUm6k Bhc1dEIYmsmxrmYc8RQbMpvnhZaVkhnh1vaxS/wO588ayaMxUOJEdqKcYDwo7AzdUif5 OOlaWrvy0eP4hptz8kezFaKTxNQ484rbuFPWyaMbBgqKywph1C7jkBYMoY3mBI4CG/yn gcFw== X-Gm-Message-State: AOJu0YzVDOeVoRNVx5VnmL2s1p2+Q5vJncLZAWqPichHEcLPZfd6nTAv 9wEwJBVMd4Zrj43pokoU8c4miWFj2f9Knxaa9ppuUn0PSMV3FiaFtQwaLwquwA== X-Gm-Gg: ASbGncuz+SpDem7SYMyt5RXHBUbZ1MXHt70Os1IpvqdkmEyqFMdT6UvPOSpiV7fxeFz KXZzaU657dNFTmgaitfMK6lsw+jaEP5gVlzW9BHFTqhJPGj/PFKPRFfXaQkDkRvnuItltZGi5QF Ac3FmDzPu8NK8uDeehWlH8aga99hkRyiaSXAbZWASuCqUaPaoeityTQyNqElZKjGWGNffIgMf6u 3lgme2JCDwdy3dJwnvql7QVatXr+rFKEXEHLfiIE+Amk+RAk1WQ5QeT5Z8hVUAHj7IkcCOq8mTr 80DQb8FOIg8xqGC/xQ== X-Google-Smtp-Source: AGHT+IEK5agvR4qJHKICT0NvwP5kGDqjZ0/0rvwL4OJXcfuzB8y1QaZ9wi33U86Y9zDYeiv8HE16ww== X-Received: by 2002:a05:6a00:2406:b0:72d:9cbc:730d with SMTP id d2e1a72fcca58-72fd0c2246cmr2931620b3a.11.1738133371409; Tue, 28 Jan 2025 22:49:31 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:b323:d70b:a1b8:1683]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-72f8a7608b1sm10312341b3a.116.2025.01.28.22.49.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 28 Jan 2025 22:49:31 -0800 (PST) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim , Johannes Weiner , Yosry Ahmed , Nhat Pham Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv1 5/6] zram: switch to new zsmalloc object mapping API Date: Wed, 29 Jan 2025 15:43:51 +0900 Message-ID: <20250129064853.2210753-6-senozhatsky@chromium.org> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog In-Reply-To: <20250129064853.2210753-1-senozhatsky@chromium.org> References: <20250129064853.2210753-1-senozhatsky@chromium.org> MIME-Version: 1.0 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: A1468100007 X-Stat-Signature: igkrfccmxfubcsc8qnwmtx4jkbmkc3xr X-Rspam-User: X-HE-Tag: 1738133372-308337 X-HE-Meta: U2FsdGVkX19YmN95u/8d6aeMsywk+EtNiVq6MmHrzgj2LZvvmzajOhNLR9WTPNMN89w81vkYB7GtDhJ/nRy1Z0TuU92z1W1PylQzN49mRL0+anbEjNvYUjlrqU/RcQIgQJ2g6uHleYkg9/pIM16UAnHIw+kxur2Olvjx22AHYBa2HbbyrAyzu8S00GwnWsE/UEs2GYhIpVf4Gr1fYTMAUYJVvhStA63SCd3bnilY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TJn5o1VCA== 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: Use new read/write zsmalloc object API. For cases when RO mapped object spans two physical pages (requires temp buffer) compression streams now carry around one extra physical page. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zcomp.c | 4 +++- drivers/block/zram/zcomp.h | 2 ++ drivers/block/zram/zram_drv.c | 28 ++++++++++------------------ 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c index efd5919808d9..675f2a51ad5f 100644 --- a/drivers/block/zram/zcomp.c +++ b/drivers/block/zram/zcomp.c @@ -45,6 +45,7 @@ static const struct zcomp_ops *backends[] = { static void zcomp_strm_free(struct zcomp *comp, struct zcomp_strm *strm) { comp->ops->destroy_ctx(&strm->ctx); + vfree(strm->local_copy); vfree(strm->buffer); kfree(strm); } @@ -66,12 +67,13 @@ static struct zcomp_strm *zcomp_strm_alloc(struct zcomp *comp) return NULL; } + strm->local_copy = vzalloc(PAGE_SIZE); /* * allocate 2 pages. 1 for compressed data, plus 1 extra in case if * compressed data is larger than the original one. */ strm->buffer = vzalloc(2 * PAGE_SIZE); - if (!strm->buffer) { + if (!strm->buffer || !strm->local_copy) { zcomp_strm_free(comp, strm); return NULL; } diff --git a/drivers/block/zram/zcomp.h b/drivers/block/zram/zcomp.h index 62330829db3f..9683d4aa822d 100644 --- a/drivers/block/zram/zcomp.h +++ b/drivers/block/zram/zcomp.h @@ -34,6 +34,8 @@ struct zcomp_strm { struct list_head entry; /* compression buffer */ void *buffer; + /* local copy of handle memory */ + void *local_copy; struct zcomp_ctx ctx; }; diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index ad3e8885b0d2..d73e8374e9cc 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1562,11 +1562,11 @@ static int read_incompressible_page(struct zram *zram, struct page *page, void *src, *dst; handle = zram_get_handle(zram, index); - src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO); + src = zs_obj_read_begin(zram->mem_pool, handle, NULL); dst = kmap_local_page(page); copy_page(dst, src); kunmap_local(dst); - zs_unmap_object(zram->mem_pool, handle); + zs_obj_read_end(zram->mem_pool, handle, src); return 0; } @@ -1584,11 +1584,11 @@ static int read_compressed_page(struct zram *zram, struct page *page, u32 index) prio = zram_get_priority(zram, index); zstrm = zcomp_stream_get(zram->comps[prio]); - src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO); + src = zs_obj_read_begin(zram->mem_pool, handle, zstrm->local_copy); dst = kmap_local_page(page); ret = zcomp_decompress(zram->comps[prio], zstrm, src, size, dst); kunmap_local(dst); - zs_unmap_object(zram->mem_pool, handle); + zs_obj_read_end(zram->mem_pool, handle, src); zcomp_stream_put(zram->comps[prio], zstrm); return ret; @@ -1684,7 +1684,7 @@ static int write_incompressible_page(struct zram *zram, struct page *page, u32 index) { unsigned long handle; - void *src, *dst; + void *src; /* * This function is called from preemptible context so we don't need @@ -1701,11 +1701,9 @@ static int write_incompressible_page(struct zram *zram, struct page *page, return -ENOMEM; } - dst = zs_map_object(zram->mem_pool, handle, ZS_MM_WO); src = kmap_local_page(page); - memcpy(dst, src, PAGE_SIZE); + zs_obj_write(zram->mem_pool, handle, src, PAGE_SIZE); kunmap_local(src); - zs_unmap_object(zram->mem_pool, handle); zram_slot_write_lock(zram, index); zram_set_flag(zram, index, ZRAM_HUGE); @@ -1726,7 +1724,7 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 index) int ret = 0; unsigned long handle; unsigned int comp_len; - void *dst, *mem; + void *mem; struct zcomp_strm *zstrm; unsigned long element; bool same_filled; @@ -1769,11 +1767,8 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 index) return -ENOMEM; } - dst = zs_map_object(zram->mem_pool, handle, ZS_MM_WO); - - memcpy(dst, zstrm->buffer, comp_len); + zs_obj_write(zram->mem_pool, handle, zstrm->buffer, comp_len); zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP], zstrm); - zs_unmap_object(zram->mem_pool, handle); zram_slot_write_lock(zram, index); zram_set_handle(zram, index, handle); @@ -1882,7 +1877,7 @@ static int recompress_slot(struct zram *zram, u32 index, struct page *page, unsigned int class_index_old; unsigned int class_index_new; u32 num_recomps = 0; - void *src, *dst; + void *src; int ret; handle_old = zram_get_handle(zram, index); @@ -2020,12 +2015,9 @@ static int recompress_slot(struct zram *zram, u32 index, struct page *page, return 0; } - dst = zs_map_object(zram->mem_pool, handle_new, ZS_MM_WO); - memcpy(dst, zstrm->buffer, comp_len_new); + zs_obj_write(zram->mem_pool, handle_new, zstrm->buffer, comp_len_new); zcomp_stream_put(zram->comps[prio], zstrm); - zs_unmap_object(zram->mem_pool, handle_new); - zram_free_page(zram, index); zram_set_handle(zram, index, handle_new); zram_set_obj_size(zram, index, comp_len_new);