From patchwork Mon Sep 5 08:15:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12965752 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 79C0CECAAD5 for ; Mon, 5 Sep 2022 08:16:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F1F69801BF; Mon, 5 Sep 2022 04:16:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EA893801B3; Mon, 5 Sep 2022 04:16:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D4B05801BF; Mon, 5 Sep 2022 04:16:21 -0400 (EDT) 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 C04D9801B3 for ; Mon, 5 Sep 2022 04:16:21 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 932B71418AA for ; Mon, 5 Sep 2022 08:16:21 +0000 (UTC) X-FDA: 79877324562.03.4067069 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by imf04.hostedemail.com (Postfix) with ESMTP id 3FF2240069 for ; Mon, 5 Sep 2022 08:16:21 +0000 (UTC) Received: by mail-pf1-f173.google.com with SMTP id 72so7940865pfx.9 for ; Mon, 05 Sep 2022 01:16:20 -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=MkTg5zDd6KOHOk4vuhlZ6bZv6q468yLoqf3LP8Ucpys=; b=Yh6VENY7q3YjaerT3c1AQXDjiIILaH8AUngGutf7HnKvu8GAnr9IlHVsTgfRuTLGOO OKBaaaGmULjMztF0WOR43xP/EjqpicbbeSx+EEE6wGwDXLoLTYATlGao7+E9mhA0InQW EdYiOFN772ahgE+GNg4JzbKFc/cocrdCjFz8U= 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=MkTg5zDd6KOHOk4vuhlZ6bZv6q468yLoqf3LP8Ucpys=; b=gVEr7P7NxpJhUiq+KMiJ2tznGzkRF4tzDJrjDc4pZuCVWpBdxUimmtoJMaxKye7yjI afympVHHCJ8vzuCU7F5by6UQ4PmA2r6bW7qXbLc/a5kbdYxlpbgGdKOrP2pg4ZdkGQbi eS9TGiJjGga+RIq2ng+xb3UBgAye2aOKNQWkIC0MyFzVCSEtu9UoCcDvi7HIKwO8rhk7 XargDFFsuRyOn48T/Y6t75F0zAMVc9QhtLI/PNeNrDRWqhYCx/18RlloR1MrZrYh3CHV 4BmhjUF2a5DULT1hGhaZuM/o5+Dd7+5swz1i/4A23SqF4OJM2sofQx4h4JzB5U9DnKmo FlKQ== X-Gm-Message-State: ACgBeo3y2oAYTZJ5q99kC+qL185FjLcxYqG3loc83DKMd0EqU+RI3ufz 5uwMykHWJrZ8pjYI/FW7DzXxlk8W8NvB/A== X-Google-Smtp-Source: AA6agR5MfYBqXmqx8e3N43HvnHj+epezxnhAQ669hTNgt9FrJdUmOYNGNHPziNFBCcO5mcmBn1/e8g== X-Received: by 2002:a63:26c7:0:b0:434:5712:8432 with SMTP id m190-20020a6326c7000000b0043457128432mr3647624pgm.404.1662365780348; Mon, 05 Sep 2022 01:16:20 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:71e2:8444:42d9:4bb0]) by smtp.gmail.com with ESMTPSA id w12-20020aa79a0c000000b005363bc65bafsm7075864pfj.57.2022.09.05.01.16.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 01:16:19 -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: [PATCH RFC 3/7] zram: Factor out WB and non-WB zram read functions Date: Mon, 5 Sep 2022 17:15:48 +0900 Message-Id: <20220905081552.2740917-7-senozhatsky@chromium.org> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220905081552.2740917-1-senozhatsky@chromium.org> References: <20220905081552.2740917-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Yh6VENY7; spf=pass (imf04.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.210.173 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=1662365781; a=rsa-sha256; cv=none; b=mWkuMzzOU64X5SEFtiJcUqzdwVLVJ7sxESj71yqsjSQFei38o23xBhHcuD6l93q6MNXH7O accGOIwVRhf6294mYpEOxYxELkRAKkHejgGbfQZ6+3MSzHZh8Vgn8IZ4dJ7idrEhHILbfF tD09oY8qqFjDF551s5p6QRakFhhSBYM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662365781; 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=MkTg5zDd6KOHOk4vuhlZ6bZv6q468yLoqf3LP8Ucpys=; b=TElDV9lmuJQcFPV7TH6Z+XdF4Q7+sA7vvKrnUz8yAchbpOdFGbcEUwAPwtY72bzzgsmmOO UrXqaxq6cCmuhRpo0pZL+sWtwgKBUF4xVDei/ojrtwaOZ2hbGr2l5qy7t1wSLd5x5q6xWP bgoIA7sTauXBsGWruAl7ARzA9KlIpYI= Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Yh6VENY7; spf=pass (imf04.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.210.173 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspam-User: X-Stat-Signature: uwuk8qpm9tyiamik4rbzjpbgx8yay4xt X-Rspamd-Queue-Id: 3FF2240069 X-Rspamd-Server: rspam05 X-HE-Tag: 1662365781-176283 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 | 66 +++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 19 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 694c8c426cb2..de2970865b7b 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1325,8 +1325,33 @@ 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; @@ -1334,20 +1359,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); - - 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; @@ -1357,7 +1368,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; } @@ -1379,7 +1389,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)) @@ -1389,7 +1417,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;