From patchwork Wed Nov 9 11:50:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13037463 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 D7D66C433FE for ; Wed, 9 Nov 2022 11:52:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 724918E0006; Wed, 9 Nov 2022 06:52:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D5298E0005; Wed, 9 Nov 2022 06:52:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 59D2C8E0006; Wed, 9 Nov 2022 06:52:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4E23E8E0005 for ; Wed, 9 Nov 2022 06:52:09 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 01CF8AB36E for ; Wed, 9 Nov 2022 11:52:03 +0000 (UTC) X-FDA: 80113740168.29.9633929 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf06.hostedemail.com (Postfix) with ESMTP id 9CA2C180012 for ; Wed, 9 Nov 2022 11:51:58 +0000 (UTC) Received: by mail-pl1-f172.google.com with SMTP id 4so16908919pli.0 for ; Wed, 09 Nov 2022 03:51:58 -0800 (PST) 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=NwLhHMvq7VueCMpUkTq+C+HTS32+Lk3Kl1y4kkNY1lI=; b=XU5vLFwkohaoQzaV3wsD4syG9ewC5z9qtbUASnBpI7yZfx6A/26UPA/KGss1F89lzr bLhHgQibUdXpBvhVKkTalBkDQSjdosyCaORUHtLQtl3nxDZaeFifxXfpsE09Dx1L42Ag Lh43EhiVNoB8JL3gbSz6XvnAW519pupdtZBZ0= 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=NwLhHMvq7VueCMpUkTq+C+HTS32+Lk3Kl1y4kkNY1lI=; b=RXUk7OFxKpgVzoWB19WJSQHImliQNHe54F0cI7n+4GQz/tRGYDIizYcmp8rKkGsvG9 H2Ba0b/9MCt3+YMlKsxkLsvuOZIP/ntzSMjFFtBRPBw1+mVIQjELq/uj/UiJ1r2xBLQ9 Rfztd1n3VD/PCuJQ1KHCcOJj14m7cQyYjWbH7tcN31WqZv4oDjZTc5RnAWv/gUhdqvKd BxnnOmbr5nq7X4MZ18U5WYVerfEWVHHq1lS2PvyAKKyiEBtDQ3bgxSIm5dsZjLWVp2a+ oIzYWCEB5jJJUCETH9mod0D05m/RV29TiLb719ZCnhnYCL2ThwrRCgEh6cwDfjFTAOfL BRxg== X-Gm-Message-State: ACrzQf2JcFRNmNKYTpa6cl3a3Xvwntt67AHq7lhVsW1RocHfEAgYQFYs FzLvux69THrNRq65/HbjSsEUxw== X-Google-Smtp-Source: AMsMyM6YjoApz2cmt93xkc5aPeuhMLaP2uc6ExE39WsDWmfAadxJs9lufYlSSW28eW1IwTrpZrxuvA== X-Received: by 2002:a17:90b:3b8d:b0:214:1066:67c7 with SMTP id pc13-20020a17090b3b8d00b00214106667c7mr45511923pjb.209.1667994662480; Wed, 09 Nov 2022 03:51:02 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:61f1:44d3:3f47:2cdb]) by smtp.gmail.com with ESMTPSA id f5-20020a655505000000b00434760ee36asm7292311pgr.16.2022.11.09.03.51.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 03:51:02 -0800 (PST) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , Suleiman Souhlal , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCHv5 03/13] zram: Factor out WB and non-WB zram read functions Date: Wed, 9 Nov 2022 20:50:37 +0900 Message-Id: <20221109115047.2921851-4-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <20221109115047.2921851-1-senozhatsky@chromium.org> References: <20221109115047.2921851-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667994718; a=rsa-sha256; cv=none; b=5czQ/3KlrmczbBZ0FDzUuo3Yj8sEbPkidoPgXWD8lX1qm/9CTgPljevlH7xresvmEO7xue hVOHXM71cG1ziF1gLd6LZJBHBZxOR371aJYLznGLfT5vYE/mu7yzxqKEhtN0qszAYlCY7P dFIPeZ8yhXNNvPHlxe5GR10oaW3Ngns= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=XU5vLFwk; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf06.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.172 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667994718; 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=NwLhHMvq7VueCMpUkTq+C+HTS32+Lk3Kl1y4kkNY1lI=; b=HNr0Egr6/vwl3BnFt9EO0M5j3o8m1H09zGcpu8pOhsiKiVPOsmouse7xib0MxnmQ+TbJXb TYdVdm1hCRE+9Z6SJ1g4P/AZ0nYz2jyomr8ayUR6DwBg5NhcV3SCsiYLnZ47R49ezWPGN6 I4uoL9UQD1AMATQFemw0PfNIUyjGEdU= Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=XU5vLFwk; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf06.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.172 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org X-Rspam-User: X-Stat-Signature: s848she7g4qqk6f6z31j3nhijhykq4z7 X-Rspamd-Queue-Id: 9CA2C180012 X-Rspamd-Server: rspam05 X-HE-Tag: 1667994718-241825 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 | 72 ++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 23 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 56026a6deb70..a6a5fd2474d7 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1339,8 +1339,29 @@ 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_bvec_read_from_bdev(struct zram *zram, struct page *page, + u32 index, struct bio *bio, bool partial_io) +{ + struct bio_vec bvec = { + .bv_page = page, + .bv_len = PAGE_SIZE, + .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; @@ -1348,23 +1369,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; @@ -1374,7 +1378,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; } @@ -1396,17 +1399,40 @@ static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP]); } 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_bvec_read_from_bdev(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;