From patchwork Wed Oct 5 02:40:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12998836 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 92283C433F5 for ; Wed, 5 Oct 2022 02:40:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24A9D6B0075; Tue, 4 Oct 2022 22:40:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F92A6B0078; Tue, 4 Oct 2022 22:40:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C19A6B007B; Tue, 4 Oct 2022 22:40:33 -0400 (EDT) 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 F17626B0075 for ; Tue, 4 Oct 2022 22:40:32 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A4449120682 for ; Wed, 5 Oct 2022 02:40:32 +0000 (UTC) X-FDA: 79985342304.07.1AEB3A6 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by imf25.hostedemail.com (Postfix) with ESMTP id 0C701A0009 for ; Wed, 5 Oct 2022 02:40:30 +0000 (UTC) Received: by mail-pj1-f45.google.com with SMTP id o9-20020a17090a0a0900b0020ad4e758b3so539985pjo.4 for ; Tue, 04 Oct 2022 19:40:30 -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; bh=+8HyA4g1G7SzaN6nxygfOgRk8GE0piuM7BVZrp+fZZ0=; b=iJZoZ988DbLfqFyS85LiqYK0iD0Jl5QFkdRZH/o20Tn4yzm1XYNlW1NvR8vRf6IVWb pRjXWrj+frDOYasSYToNs0l/W03Wt0QpzcH/Ya0mtEBpV4j42YFvVLcLyWZpMf9YkFJ7 Zs6v0x3YQ6L/TCAVKMbkXph43Miyvc2knSfbA= 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; bh=+8HyA4g1G7SzaN6nxygfOgRk8GE0piuM7BVZrp+fZZ0=; b=ICWXi+7dua8tlUsCLgEwBd5o5Cep+ktoYJphP3AyzSrWNenmJKTpSiNNZtpDhiVKhe 7EEviq21xyNVAgq5pMgbEC4NOjih0vH03+IQpFtiUY+Uhf4twagivSr3yCY3Jb+tgpCx o8ags6P0oEs7vrmKp9m3tPzGwCYNBJXmZh28S5BuAGH3OGe5gWnZao2RX0AukxZZ5a/3 Z0RlXW1tSi/wrd3ABjLVKGYYovvJMHbj6Y0yz94zxOJUQAsd+JLBG8XZhu6hl2tCrtyQ /4dGIhEpt2HmtPJ8F1e6XQMaXycyDkjw0+1mQSFIOeJBqbZRX0ssuXYILWRzbSr4wIXz ctxQ== X-Gm-Message-State: ACrzQf1btc8t1TtRSS+cy9btz+gOhn/xR05mXX3r8r4HMNzqXEy20Ziu CZK5QEp5H4zRHmEHQen24w2JyA== X-Google-Smtp-Source: AMsMyM5PtNm+kNj458oT3nacLJb/Pc90yrx3l6fXrSCv72h7b3aeffHIBEIPGYclwk6h6GPHs0r6AA== X-Received: by 2002:a17:902:8541:b0:17f:6b27:7a75 with SMTP id d1-20020a170902854100b0017f6b277a75mr8912286plo.65.1664937629863; Tue, 04 Oct 2022 19:40:29 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:a9d9:6396:ee12:8be8]) by smtp.gmail.com with ESMTPSA id a14-20020aa794ae000000b00561e010a309sm1673579pfl.19.2022.10.04.19.40.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 19:40:29 -0700 (PDT) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCHv2 3/8] zram: Factor out WB and non-WB zram read functions Date: Wed, 5 Oct 2022 11:40:09 +0900 Message-Id: <20221005024014.22914-4-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20221005024014.22914-1-senozhatsky@chromium.org> References: <20221005024014.22914-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664937631; 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=+8HyA4g1G7SzaN6nxygfOgRk8GE0piuM7BVZrp+fZZ0=; b=Hn/rKnR0mdFHgJZGyBMt1SxS9DJVrgp0IUOIYHmWQYSDsBc7LyjLdn96DgA5BDkKttUpAx eOBG4TNgBs1EaVxxy5atHpxFGpenQcu257fZbHQE8cbe6evaB7iRPu0p6Vr9fQ4tE++XaK kdkRMJs2f0yaym3oDrBkRnO8CWi8aSw= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=iJZoZ988; spf=pass (imf25.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.45 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=1664937631; a=rsa-sha256; cv=none; b=8kuIVZeP77FYuylgB+i17wfpkuek4Zc6TKanzRgHvdffSRlWKcj94uT+ekwe6KCpP/ECtO G9DWBHF1RrU/jAWWcovZ14M2YBOjURVnjOmFJhVRzH2CnLqmk9ft1P17axBwBOC91RLQMm YlFggtP0v27QuIM1t9D+qKf7sju4kyc= X-Stat-Signature: muy5gikk57nfq5cru6d65mitjjpmjk83 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 0C701A0009 Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=iJZoZ988; spf=pass (imf25.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.45 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspam-User: X-HE-Tag: 1664937630-982244 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 | 70 ++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index a8ef3c0c3dae..9ec60deeb186 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1314,8 +1314,34 @@ 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; + + /* 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); +} + +/* + * 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 +1349,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 +1358,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,7 +1379,25 @@ 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); + ret = zram_read_from_writeback(zram, page, index, bio, + partial_io); + } /* Should NEVER happen. Return bio error if it does. */ if (WARN_ON(ret)) @@ -1381,7 +1407,7 @@ static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, } 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;