From patchwork Tue Oct 18 04:55:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13009904 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 2A46CC4332F for ; Tue, 18 Oct 2022 04:55:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B75F56B007B; Tue, 18 Oct 2022 00:55:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B251B6B007D; Tue, 18 Oct 2022 00:55:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9C6518E0001; Tue, 18 Oct 2022 00:55:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8D3976B007B for ; Tue, 18 Oct 2022 00:55:52 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9037A40F79 for ; Tue, 18 Oct 2022 04:55:51 +0000 (UTC) X-FDA: 80032857702.03.8717D41 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by imf25.hostedemail.com (Postfix) with ESMTP id 34F8CA002F for ; Tue, 18 Oct 2022 04:55:50 +0000 (UTC) Received: by mail-pl1-f177.google.com with SMTP id o21so10336731ple.5 for ; Mon, 17 Oct 2022 21:55:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; 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=lPOwozwW566MrhSDQ5Hik/2oBaG/MJdP0TGgYtIKPis=; b=YnRifkaNMN9xeU3dP05q8Ea3BFeTmAimQBXUIgaGkiE2mSiMswcN01xw+OrW2yPYCF OvIXJvFjayfS/j734H+93oHgzpWOVPR33IaJNC/+srLLlOZGNDfcMf0kZlVFSBcKh4MV dADJd8226DEIE85679/r2I8nGKw2AK68/UaEo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=lPOwozwW566MrhSDQ5Hik/2oBaG/MJdP0TGgYtIKPis=; b=V2o7FDbCCWbWmUyX4qzv3iQOEVDRrNOBD02sti6IrE4iB+zuI7V59xzejHMsrrJ66l EJKug0EhN4WRw8gQ7vTuAAx2OIhQi60D1rEQcZ2DVwSbTtsxsHt0xVarK0zb6Is4gNrV BOgQlwiawd1rJ4EHyqqDSXuywD4Z1N4t5x7AP2IywtV03RkNLO/1PZgfH/4SaMZIxNDB viQo1i7nLiDcPxX1+T4pX7KXn79m60jAT37+kX8Hxaa/5wtDbv76XfALqHQECgxgnBon yYTgJkjJgbyrr/m5Pz/njdnMOLKweOGKrHKk+N+y4ekyubMzjyfYUiuGQ568Aa2/8G7g VGnw== X-Gm-Message-State: ACrzQf04hoGyUgEsQmlZcYxddaHZVv/PdlEf/VxG8+ms70xoSIpgzedG oFZW8lx23zkAImTq/pgq8j67pQkEg1vjnw== X-Google-Smtp-Source: AMsMyM68b3LFlOFKZ5ZmhuvTT7t7kmp/l6V3wTu+yDELsOlS3kOPAXwmAmfP+TaiyKDtir3UTdwQrA== X-Received: by 2002:a17:902:c405:b0:181:83e4:490e with SMTP id k5-20020a170902c40500b0018183e4490emr1173860plk.4.1666068949191; Mon, 17 Oct 2022 21:55:49 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:17a9:73b0:c262:eccd]) by smtp.gmail.com with ESMTPSA id p4-20020a170902e74400b0017b69f99321sm7549220plf.219.2022.10.17.21.55.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 21:55:48 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCHv4 3/9] zram: Factor out WB and non-WB zram read functions Date: Tue, 18 Oct 2022 13:55:27 +0900 Message-Id: <20221018045533.2396670-4-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221018045533.2396670-1-senozhatsky@chromium.org> References: <20221018045533.2396670-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666068950; a=rsa-sha256; cv=none; b=px9XBf1i5pXxq+845JX5U1Rg9e224j4MN9FqjoQ3Bxil9rErewxyiP2DlW7obKMTQOC+66 96UqTaPv1ATCfyh//AV+wQ3UfkAQjaJ9/VybAw4O2gMkb/Jak7rEncDhg6rQoNxo1/PIN8 4lU8tHFcKflbOj2b8+Cymif0oy++pm8= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=YnRifkaN; spf=pass (imf25.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.177 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=1666068950; 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=lPOwozwW566MrhSDQ5Hik/2oBaG/MJdP0TGgYtIKPis=; b=PCzosXnHbHPVpRGWTHjOiFY8mXC4872JcUy/W3J/57kFiQjbHl1Y6mY2cjVKrM/FUVuRj2 KahvBNzIIBqBhSlwlVl+85J3biMDcsLnXua6KNUOgDAA/DZCC/pIwQ+xfYu7j+uCnFcV82 +nxonwbLz1uZwYbugjLt/0rOVpSLSss= X-Stat-Signature: b4oxa6poxrgdj4gmzfbokfricxhn57ym X-Rspamd-Queue-Id: 34F8CA002F X-Rspam-User: X-Rspamd-Server: rspam03 Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=YnRifkaN; spf=pass (imf25.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.177 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-HE-Tag: 1666068950-243487 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: We will use non-WB variant in ZRAM page recompression path. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 73 ++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index a8ef3c0c3dae..94c62d7ea818 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1314,8 +1314,30 @@ static void zram_free_page(struct zram *zram, size_t index) ~(1UL << ZRAM_LOCK | 1UL << ZRAM_UNDER_WB)); } -static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, - struct bio *bio, bool partial_io) +/* + * Reads a page from the writeback devices. Corresponding ZRAM slot + * should be unlocked. + */ +static int zram_read_from_writeback(struct zram *zram, struct page *page, + u32 index, struct bio *bio, + bool partial_io) +{ + struct bio_vec bvec; + + bvec.bv_page = page; + bvec.bv_len = PAGE_SIZE; + bvec.bv_offset = 0; + return read_from_bdev(zram, &bvec, + zram_get_element(zram, index), + bio, partial_io); +} + +/* + * 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) { struct zcomp_strm *zstrm; unsigned long handle; @@ -1323,23 +1345,6 @@ static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, void *src, *dst; int ret; - zram_slot_lock(zram, index); - if (zram_test_flag(zram, index, ZRAM_WB)) { - struct bio_vec bvec; - - zram_slot_unlock(zram, index); - /* A null bio means rw_page was used, we must fallback to bio */ - if (!bio) - return -EOPNOTSUPP; - - bvec.bv_page = page; - bvec.bv_len = PAGE_SIZE; - bvec.bv_offset = 0; - return read_from_bdev(zram, &bvec, - zram_get_element(zram, index), - bio, partial_io); - } - handle = zram_get_handle(zram, index); if (!handle || zram_test_flag(zram, index, ZRAM_SAME)) { unsigned long value; @@ -1349,7 +1354,6 @@ static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, mem = kmap_atomic(page); zram_fill_page(mem, PAGE_SIZE, value); kunmap_atomic(mem); - zram_slot_unlock(zram, index); return 0; } @@ -1371,17 +1375,40 @@ static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, zcomp_stream_put(zram->comps[ZRAM_PRIMARY_ZCOMP]); } zs_unmap_object(zram->mem_pool, handle); - zram_slot_unlock(zram, index); + return ret; +} + +static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, + struct bio *bio, bool partial_io) +{ + int ret; + + zram_slot_lock(zram, index); + if (!zram_test_flag(zram, index, ZRAM_WB)) { + /* Slot should be locked through out the function call */ + ret = zram_read_from_zspool(zram, page, index); + zram_slot_unlock(zram, index); + } else { + /* Slot should be unlocked before the function call */ + zram_slot_unlock(zram, index); + + /* A null bio means rw_page was used, we must fallback to bio */ + if (!bio) + return -EOPNOTSUPP; + + ret = zram_read_from_writeback(zram, page, index, bio, + partial_io); + } /* Should NEVER happen. Return bio error if it does. */ - if (WARN_ON(ret)) + if (WARN_ON(ret < 0)) pr_err("Decompression failed! err=%d, page=%u\n", ret, index); return ret; } static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec, - u32 index, int offset, struct bio *bio) + u32 index, int offset, struct bio *bio) { int ret; struct page *page;