From patchwork Sun Oct 9 09:07:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13001947 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 40469C433FE for ; Sun, 9 Oct 2022 09:07:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CFC7B6B0075; Sun, 9 Oct 2022 05:07:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C870E6B007B; Sun, 9 Oct 2022 05:07:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B0CD76B0075; Sun, 9 Oct 2022 05:07:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9E0C16B0075 for ; Sun, 9 Oct 2022 05:07:35 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6FEE91407E3 for ; Sun, 9 Oct 2022 09:07:35 +0000 (UTC) X-FDA: 80000832870.24.91521C5 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by imf17.hostedemail.com (Postfix) with ESMTP id 0E73640026 for ; Sun, 9 Oct 2022 09:07:34 +0000 (UTC) Received: by mail-pg1-f182.google.com with SMTP id s206so8113011pgs.3 for ; Sun, 09 Oct 2022 02:07:34 -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=NpDlcwWZSRK+GLE9jeOjGHO/GXqOD7ElWxbYUhdOrA4=; b=m/pPO/9xut56toEBoPrxZZRoR2qK004hf4UOkxTjnrozUXN7IvLCcvwk7FCrdEbtmv UcUpkQjZZdv77JkrcOn3KRTs/KPJaMi8J2NEQtT0vQZnwdZa00RA9gESYlF10wu7FW3W CsuaSVfjOrbsPVaazJib/NqDbLehCZx6rr5/A= 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=NpDlcwWZSRK+GLE9jeOjGHO/GXqOD7ElWxbYUhdOrA4=; b=oqf9TUAYMkXBF/vCkOT8RIkISfG8g3BTPpNQfy1/sFIOTkxe3RAzpVvGrEJBu4Hlvc TEuvyWDzruBGZuXef5pSHRG7O3irpiBtaE9wnvqE8/b4bswCeYL3KE/P1UR1UcVvVVbJ cBGEyRYkckK6wNf7rnb12bz/jJdOIeTkFu927p7fkGwg+kg0XXEAN43K+RpUEH28+mz4 W5EUWnet+UgwTfDECFTh845ljbk9B+lxgYhCUI7117WRvt59I3iqj1PM/DdinN9YwW2d tXP0m/eO1mWiLTeosl6YcTtVEt+m/O/JOCsB6vhtdQTAIlm9k4xlQqF7qsIL4GxGWcPt GXAw== X-Gm-Message-State: ACrzQf2r7Zw3LJLJ9Yd6efm4qIF73u5BCjWImydWKkTvq/iVBFOdRCi/ fGpCXQa41Nty23A3ygFiwyqBjQ== X-Google-Smtp-Source: AMsMyM5O6XJLSh+H0wcf7xO6063i9Fd43x32Eg2ntgvjKRu11pYf1BZfHPExCSvDcr2/A0Gi6aZQfg== X-Received: by 2002:a63:1944:0:b0:455:bea0:97ee with SMTP id 4-20020a631944000000b00455bea097eemr12190033pgz.258.1665306454057; Sun, 09 Oct 2022 02:07:34 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:8517:d51e:5fe9:9be7]) by smtp.gmail.com with ESMTPSA id q194-20020a632acb000000b00439d071c110sm4335148pgq.43.2022.10.09.02.07.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Oct 2022 02:07:33 -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: [PATCHv3 3/8] zram: Factor out WB and non-WB zram read functions Date: Sun, 9 Oct 2022 18:07:15 +0900 Message-Id: <20221009090720.1040633-4-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20221009090720.1040633-1-senozhatsky@chromium.org> References: <20221009090720.1040633-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665306455; a=rsa-sha256; cv=none; b=fMXNtLDqKPc3hJZllPOjox3pKU+h0pdPkVdO76i1vbTbQiBlafCpTUYKkGmwR5GEkjZqiK T3HfqO//CmomGkflzjflE7j26b+jucswwkFmlfxCDQcJfjVQxmoINdveqlaSIX4C2O8FYE 13JUF/zCSWhB2GX30T0dTP5aYEn4Iyg= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="m/pPO/9x"; spf=pass (imf17.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.215.182 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=1665306455; 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=NpDlcwWZSRK+GLE9jeOjGHO/GXqOD7ElWxbYUhdOrA4=; b=eIRFd/tih5TWs03uwtXfm8uTHmijHcsA/nru2a8aCRA4jupbAMCjSSmgYPN6pz/xEvfe4t DRaTTG5Gx6RNvgHvaOBH2AcLDEuQ9HUMkqTXgkD+awXfAFpC1SQEm0HsSBEUzf/kOVAS98 t2OStaFEjc/7egTOeB9npD2AJD2/hHs= Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="m/pPO/9x"; spf=pass (imf17.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.215.182 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Stat-Signature: 75nhe6srj7gftxgwkri9c4woa4678su4 X-Rspamd-Queue-Id: 0E73640026 X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1665306454-366744 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;