From patchwork Thu Jan 30 04:42:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13954304 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 0F18AC0218F for ; Thu, 30 Jan 2025 04:45:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9AA9C2800C1; Wed, 29 Jan 2025 23:45:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 95C0E2800B9; Wed, 29 Jan 2025 23:45:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 822BF2800C1; Wed, 29 Jan 2025 23:45:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 62D462800B9 for ; Wed, 29 Jan 2025 23:45:40 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 24E4B140820 for ; Thu, 30 Jan 2025 04:45:40 +0000 (UTC) X-FDA: 83062880040.01.2B7D767 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf10.hostedemail.com (Postfix) with ESMTP id 24E7AC0003 for ; Thu, 30 Jan 2025 04:45:37 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=CoBjNYNn; spf=pass (imf10.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.179 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=1738212338; 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=6xqKPithuDvcfchXX2HV+lT8GXNY6TmErXPBW8V3+VeaZlq2DroYZQINELagAN+LGvRL9r cIPe+iRXoLM9koj93FWhLEncj9VzQpLhAm5ukhYUriDkNGbnWvR78atuKrBYo+n33AF9In 2eEFdWYJ+GKD2zRrm+EhUG0FzN3YDzg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738212338; a=rsa-sha256; cv=none; b=sLUEfO3nPJD+7ufzHNgeruPkkaph3ssZPFVPKCf1UHLDY76HmHkbVquUJGJVu1ZUAj3yty LrDWXfJH1L3vqVoz4VktphAnk9f065HnOkoIXgLhi9Pg3h+fv0hK5h3J1mO8Oaewxm3VFG sYp7H76/8cQmUBpyu6nMUqkVj12NIJE= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=CoBjNYNn; spf=pass (imf10.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.179 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-21669fd5c7cso5198815ad.3 for ; Wed, 29 Jan 2025 20:45:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1738212337; x=1738817137; 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=CoBjNYNnZNS3A3R9dgl+EaGKsKUK1t4WIEpQ2gb3mkRBegqMOJZSNrJHVrniBrF20i ZOEi5C3lWURYTBYA6rjmQo689PYKffW0BXgCteAvw8r748C4pe/W/nXhT0s0dFef9k5H IGykZOwcNWBxqp/Dq+dvZfwtvV+tVo2FB6ggE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738212337; x=1738817137; 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=Vs/POhEslieYiWigJUpJKKBbp9E6gqkt/UMOV+r8EPptKczbk2L18QpOijyRkCsGY3 8GZbWNo81rikfb9Y44bxLlU8B2/sAznyJCK0p1Ca8w0IWcV8za3P6CEbOk26/KCGkiS0 ZQYUyecij/vjc0l4Wz1AXySdGz0ain9e4WqmSo7+nlQp8gfppaUEnsFsd/fI/68Fj4b8 rlFrQlCkdJ8UNl5pYvcMcqDpkXTc0KI67IO3XNnCsK5YDRy1F3PNhNMLslQeQhfLyne5 MyRoxp/kOxYNABATm+B8bMAlxOKIVbttGt0j0VFhSmDx5FV1FJaw5YgPXqckekG5Ojd4 tNCg== X-Forwarded-Encrypted: i=1; AJvYcCWcXV8RNWt2/RYLbjzMxMWkrc7dwm+wJrT/n/2VfbqImrhPEjOjXFnYx57/3c6sf/0EHX4wZA9tNA==@kvack.org X-Gm-Message-State: AOJu0Yxvo8y9O191uKpuvdjRpoGLtvvT3nXWs3wwL51SPERXk6BDQEHY fNP90+G6jJbujOsYovhgjV7rUeAmXIBcKZHbqJW+RUqNGEzPUuR2CgE2AVUmnw== X-Gm-Gg: ASbGnctO/qSdVCfHCiPPkB3kOG9fXyS9yvX6Rk5Gg36yF3WcddEmWp8lsfJQNWfEZvQ A/8rotOMm4WyG7nYuXItWd55MMJy15/hRLJMB1heOxSpfgyb4j63lPYtKIqIzvVp7Df4kt+ZbpM 6rVUrBYMAQ/FhjMVnH0VqR4W5cHhb1K3aZV2b/FC+atbTj01g4sJflre6ET/BtaGjmy+xJnCvds KOYf2M194cTBHdTAS5ujaUlpaI4a3EO6kd7rKOFmpuEhacsv+U6GqVNVq0MXe+UbTp+8LVBIeuY T2ZnavHpT/83pPWmhw== X-Google-Smtp-Source: AGHT+IHUyr8/2Fq8AovilKRJ28NBYk+8bvRw/3TGJlSrvnfXxKWiWthlwKdxoZwtf3TrFQyikvGQUQ== X-Received: by 2002:a17:903:594:b0:216:36ff:ba33 with SMTP id d9443c01a7336-21dd7c67e06mr67817495ad.26.1738212336948; Wed, 29 Jan 2025 20:45:36 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:d794:9e7a:5186:857e]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-21de33000e0sm4566895ad.167.2025.01.29.20.45.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Jan 2025 20:45:36 -0800 (PST) From: Sergey Senozhatsky To: Andrew Morton , Yosry Ahmed Cc: Minchan Kim , Johannes Weiner , Nhat Pham , Uros Bizjak , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv2 6/7] zram: switch to new zsmalloc object mapping API Date: Thu, 30 Jan 2025 13:42:49 +0900 Message-ID: <20250130044455.2642465-7-senozhatsky@chromium.org> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog In-Reply-To: <20250130044455.2642465-1-senozhatsky@chromium.org> References: <20250130044455.2642465-1-senozhatsky@chromium.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 24E7AC0003 X-Stat-Signature: 87m415dogro5ifenca9o87excmjibr6s X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1738212337-400693 X-HE-Meta: U2FsdGVkX18nFme/2I2kzLU0kB9DYIEhLYv5vpyxa0fKsxoU2uXi9m/ESJWKHyJ2+D2nMLkWyFsTGWNo4V8nZf49DLViPilbligodx6xTeO+7pfXQXV4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ocCQk4htkVv6ve4jYmbRIXPKAWwbRycmh4N6rOt7Pza1ZhDKPEzuMzEHUgFXbbRy8bSyeMffyy0DY8vVkh/g3MwknQ74KI8EUpjNplmbQQUOS6sUcyhcU50AuwyiZj0w== 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);