From patchwork Wed Dec 18 06:34:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13913088 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 B7892E77187 for ; Wed, 18 Dec 2024 06:35:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A96F6B0096; Wed, 18 Dec 2024 01:35:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 457EA6B0098; Wed, 18 Dec 2024 01:35:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F83F6B0099; Wed, 18 Dec 2024 01:35:43 -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 076F06B0096 for ; Wed, 18 Dec 2024 01:35:43 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B274A80BE5 for ; Wed, 18 Dec 2024 06:35:42 +0000 (UTC) X-FDA: 82907118630.14.484708D Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf23.hostedemail.com (Postfix) with ESMTP id DDE4D140010 for ; Wed, 18 Dec 2024 06:35:19 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Gvh0PhwP; spf=pass (imf23.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.210.169 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=1734503719; 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=8UlIfnWhj8akIUQw35UgTdzrn/T1WzL/Vbski8Obleg=; b=wwiF8pLnnWP2m2RD3CuhZixLO5wR6WSZR8ldrgEpd4pKT7R+p1HICVgxtAn7fBqWqrq2kV Vgd1Cp3cOaLNVvGbeW3HBh+ThgmdDlB8aTNMXANhhSqV/sDdnrS4dckpEeWiv6f7p8Di7g JBhxvAOrTrOh/HX5pxKNDUkT8/Toil4= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Gvh0PhwP; spf=pass (imf23.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.210.169 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=1734503719; a=rsa-sha256; cv=none; b=vOANWh6QOstFEZdKL6ECjIgqvf4xl8O/Hn//vmAOd1wrbw5NbA58JADmTCVlPuSyVUMIVQ oh5JPgHe3WKZXUvNQa5z8EqcEk723c7gkbPENIDkofVxz4IFhTXBzYlj4wHBuwRgZixllp OAVaoz4/cHI188U2fHgMmLx737ACbSY= Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-728ea1573c0so5345057b3a.0 for ; Tue, 17 Dec 2024 22:35:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1734503739; x=1735108539; 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=8UlIfnWhj8akIUQw35UgTdzrn/T1WzL/Vbski8Obleg=; b=Gvh0PhwPEPSIb3+40GIE8KIxdiYKaRhlqoxtHxooXgHD2ZhRpV1FMzqbbNjFSuBOwN VkYXiVvIUtsk8N7wZJp4t64INzPm0rHU1BACdkgxP+RfRZK73SBxbDQekGAiEjfsgOvi +VNGVcz6UpAfeJtSVgww/IPP0IMFMyTKYka2c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734503739; x=1735108539; 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=8UlIfnWhj8akIUQw35UgTdzrn/T1WzL/Vbski8Obleg=; b=T1Q7oY6HlCziuMbjuCYbYAjOzlVSh0dwSExjcZPCdR/4XiJ6Zb4lP/QgyLqmXwaFxn L8T8BJ0mZSqF9qBJMwqemZqnGHYVG1KPZLZTsnycVtuf4rJYpmHqch0dzuLr18PcN1nN ok6fozz1bQVfStsqPxXvEvvZOAWQKnpgx/41/QYcka0lyl1ZKant5TdNsV/NgdlOq4dg /D30hKkTz5JsQFvWPLLYI79Bm51ArvQL31iMLm3T2fp15+s5rCfvx779NUzrpEDnjMHR RVYZLr3ukc3vM/yQf23rhFxztt/SuZmP3D+jpXReMDlTOzzcox4+SbfDfKlrIhKzylEf FSwA== X-Forwarded-Encrypted: i=1; AJvYcCXGeD5LLo6kcfE412lYEAjO8lrswCGGGEUkdSRvsYVbfCtAq2Nsmuda1lIC19tlGjJBRJXkx0W2ag==@kvack.org X-Gm-Message-State: AOJu0YzEQn9+tCeGJPnVRDkG0U4fh7vTW6mZKL29229Ooi19Ra2p6riB mRBXWdbdXS1+QZfFTY8JEq6tFsHK7ITl/C+KK+k6bQv/kUqn6qGQvFe44+EJOQ== X-Gm-Gg: ASbGncsg+vON74v0Dbatf2APkTpwIgd+n41GfdB6a6OB8Nn+yMJ2RW/QKKU9Ddy3y0y O0rpvuri+DvMlsqfdjynlwNOViFRHjxI3e89+/ySG9dQzPOzTRHKB/TkNvJcD7z5zq+6K6N9Yuh OGYa0/Jbe36VC/uPbHIUcus4dV1W9LX5xrzEPkYskG30imd/oRe62vPTQm9ZegbKmfzaJyA1Ve5 1zRRV6NZaG3/QwIfJROKY/9P5FFaosHJY9dIaIkF6+OvBwDS+ClSPMV6nQ= X-Google-Smtp-Source: AGHT+IGwQ0wQAXBUGI22Q3J+XJvZdIgvdCXo+/PUjQeIZFjzJ+5utt6loeABpMh/C7JssxnEtaeHvw== X-Received: by 2002:a05:6a20:3948:b0:1e1:aef4:9ce8 with SMTP id adf61e73a8af0-1e5b48a15a5mr2391517637.28.1734503739653; Tue, 17 Dec 2024 22:35:39 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:3bcc:36cc:b9fe:9379]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-72918bad760sm7760879b3a.152.2024.12.17.22.35.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Dec 2024 22:35:39 -0800 (PST) From: Sergey Senozhatsky To: Andrew Morton Cc: Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv2 5/7] zram: factor out different page types read Date: Wed, 18 Dec 2024 15:34:22 +0900 Message-ID: <20241218063513.297475-6-senozhatsky@chromium.org> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog In-Reply-To: <20241218063513.297475-1-senozhatsky@chromium.org> References: <20241218063513.297475-1-senozhatsky@chromium.org> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Stat-Signature: 9o9ycmrttre8sj77yd9wykm8txtsqqis X-Rspamd-Queue-Id: DDE4D140010 X-Rspam-User: X-HE-Tag: 1734503719-16203 X-HE-Meta: U2FsdGVkX18MRchNNdWytUfAZSCzz6ecH9GxdWbBfRtmYDiKG66ScDoStT16er6m2hPCqD0tCgPg0jIQXNyX20HLGT4YPd7gf7iVrTxbLdFi3YADFjwchkCFCzzrP5YnQ90nLxha1KQX+K7HHX/NdcsDLh+stDBB6vXx1Pbvg148Wxk6U6X/FqAxb+2tn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bogofilter, spamicity=0.222401, 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 write, split the page read code into ZRAM_HUGE read, ZRAM_SAME read and compressed page read to simplify the code. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 85 +++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 33 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 1339776bc6c5..465297d31bdf 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1530,54 +1530,73 @@ static void zram_free_page(struct zram *zram, size_t index) zram_set_obj_size(zram, index, 0); } -/* - * Reads (decompresses if needed) a page from zspool (zsmalloc). - * Corresponding ZRAM slot should be locked. - */ -static int zram_read_from_zspool(struct zram *zram, struct page *page, +static int read_same_filled_page(struct zram *zram, struct page *page, u32 index) { - struct zcomp_strm *zstrm; + void *mem; + + mem = kmap_local_page(page); + zram_fill_page(mem, PAGE_SIZE, zram_get_handle(zram, index)); + kunmap_local(mem); + return 0; +} + +static int read_incompressible_page(struct zram *zram, struct page *page, + u32 index) +{ unsigned long handle; - unsigned int size; void *src, *dst; - u32 prio; - int ret; handle = zram_get_handle(zram, index); - if (!handle || zram_test_flag(zram, index, ZRAM_SAME)) { - void *mem; + src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO); + dst = kmap_local_page(page); + copy_page(dst, src); + kunmap_local(dst); + zs_unmap_object(zram->mem_pool, handle); - mem = kmap_local_page(page); - zram_fill_page(mem, PAGE_SIZE, handle); - kunmap_local(mem); - return 0; - } + return 0; +} - size = zram_get_obj_size(zram, index); +static int read_compressed_page(struct zram *zram, struct page *page, u32 index) +{ + struct zcomp_strm *zstrm; + unsigned long handle; + unsigned int size; + void *src, *dst; + int ret, prio; - if (size != PAGE_SIZE) { - prio = zram_get_priority(zram, index); - zstrm = zcomp_stream_get(zram->comps[prio]); - } + handle = zram_get_handle(zram, index); + size = zram_get_obj_size(zram, 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); - if (size == PAGE_SIZE) { - dst = kmap_local_page(page); - copy_page(dst, src); - kunmap_local(dst); - ret = 0; - } else { - dst = kmap_local_page(page); - ret = zcomp_decompress(zram->comps[prio], zstrm, - src, size, dst); - kunmap_local(dst); - zcomp_stream_put(zram->comps[prio]); - } + 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); + zcomp_stream_put(zram->comps[prio]); + return ret; } +/* + * Reads (decompresses if needed) a page from zspool (zsmalloc). + * Corresponding ZRAM slot should be locked. + */ +static int zram_read_from_zspool(struct zram *zram, struct page *page, + u32 index) +{ + if (zram_test_flag(zram, index, ZRAM_SAME) || + !zram_get_handle(zram, index)) + return read_same_filled_page(zram, page, index); + + if (!zram_test_flag(zram, index, ZRAM_HUGE)) + return read_compressed_page(zram, page, index); + else + return read_incompressible_page(zram, page, index); +} + static int zram_read_page(struct zram *zram, struct page *page, u32 index, struct bio *parent) {