From patchwork Fri Sep 15 22:43:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13387795 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 ACC8FCD37AE for ; Fri, 15 Sep 2023 22:43:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5F0B68D0040; Fri, 15 Sep 2023 18:43:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 561698D0037; Fri, 15 Sep 2023 18:43:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F5158D0005; Fri, 15 Sep 2023 18:43:55 -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 07B038D0037 for ; Fri, 15 Sep 2023 18:43:55 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D47C61A068C for ; Fri, 15 Sep 2023 22:43:54 +0000 (UTC) X-FDA: 81240310788.30.0398E37 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf17.hostedemail.com (Postfix) with ESMTP id BE15440008 for ; Fri, 15 Sep 2023 22:43:52 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=xX7TFA9k; spf=none (imf17.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694817833; h=from:from:sender: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=OTSjAv0PEMH+tCuP3ffDEqRz+yWbCz97RfaFT2lMORg=; b=o7NfuNVXRG3HucFbZHsF1Y2fIX19GEWi5tuoWlqm5FVlOVylQySsTiu83LSU0A0GkfRICW tFYPsCrIjIB3BFf3iCPY4q64IDPp3VUqvHkLOCaomVKkPYWUgzOTfyJ9SmPo0EtdcLFaKn n6YxkB9KW5H7EVDfsP0Iy6r23RaxQ7k= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694817833; a=rsa-sha256; cv=none; b=fcwsDMUzjz0lCcTLJoys7gI8JJszqeFk4LDkv4v+vsy5IG3O9Zcm6NlX4HiHLCwnoQRWlP Ky12Za9Eme0AwdowMV4LJz3B5cOWKIqrB593tHZugaJNaUlkhaRS/Ot9DPXnJCxmO6b+W3 W67GBmEBcA2BoeUjIvHnOUgm5r56c+k= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=xX7TFA9k; spf=none (imf17.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=OTSjAv0PEMH+tCuP3ffDEqRz+yWbCz97RfaFT2lMORg=; b=xX7TFA9kztVjOz7d+p1P/TM7Ay nomWAhSivQ5lCdYaAeQK3cLiJwl2lWQjj7B6LNKYf1vfNWGbzkrCZMyNLm6Xz2TU9IbPPJp2V9vDp sQRh+Sstun+Z0VSd9LRO9XmHZ18g7f+6Gk3qAyBGtCb7Db23OD+grSKpMAjzWlAHpruUvoReSSHoL FVA7AVwZFM51kSRVjdptDf4W4Ul1PNFHmTYueINUMel+3WCyzzfPJyYQBgAqmZUxP6GWv6YGQdUCU nybG1VZrotzL0I0hsJgT58ibcJ778KXSwP4LuGA3/rm7WCzSQLcDIh/QqPl2oLQ441Z3Dm7mjfkmU FcOwZwkA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qhHXM-00BUtT-38; Fri, 15 Sep 2023 22:43:44 +0000 From: Luis Chamberlain To: axboe@kernel.dk, agk@redhat.com, snitzer@kernel.org, philipp.reisner@linbit.com, lars.ellenberg@linbit.com, christoph.boehmwalder@linbit.com, hch@infradead.org, djwong@kernel.org, minchan@kernel.org, senozhatsky@chromium.org Cc: patches@lists.linux.dev, linux-block@vger.kernel.org, linux-mm@kvack.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, dm-devel@redhat.com, drbd-dev@lists.linbit.com, linux-kernel@vger.kernel.org, willy@infradead.org, hare@suse.de, p.raghav@samsung.com, da.gomez@samsung.com, rohan.puri@samsung.com, rpuri.linux@gmail.com, kbusch@kernel.org, mcgrof@kernel.org Subject: [PATCH v3 4/4] zram: use generic PAGE_SECTORS and PAGE_SECTORS_SHIFT Date: Fri, 15 Sep 2023 15:43:43 -0700 Message-Id: <20230915224343.2740317-5-mcgrof@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230915224343.2740317-1-mcgrof@kernel.org> References: <20230915224343.2740317-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: BE15440008 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: y9azbq55yj55tt3wdbtjonxfb7a6pi7k X-HE-Tag: 1694817832-946759 X-HE-Meta: U2FsdGV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Kr+e/BHkoyghIngJ8y48sQVk96Fo/5bicwkzxaqdzYFkV7flhUrFwYXYIYFv8+spv79yEhayNT6+QeOw9DKG+6+phTIhRGpRhIUFXcKcB4xR5FrdfX5cbieygOksrwh1eLrVMZKY8O6q7sGvJeoRn+J6MDsuLAsSw/QMlPcEmul/w/ulF6m2In0BGob8BSK8+2K/2ZoVNR0GR5J3rPXHZhKZ1PxTebSxgYcmPjwUxIwkCCsngqH7fPh3//DXXqdVvEP+GkUda08ixCnscjS0ZlE2Q2vRBSEYsWMwr/Y/2Xt3dsFYrsSlNDGE7U/S5RaEVYz0raKENaqwnpAApUzojPGQYAvDq2uYaLUVbbJi4dFHbB+oMSgmYtC1qdRbkQ06C+hBunyk+bjYPIHJOwo1o2nYMAstcs0BmpEHVaDIFyZOOYSyte31mklwSq2D9pt1fOLBo0nFYoy0PdSm34DYDh2D0 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: Instead of re-defining the already existing constants use the provided ones: So replace: o SECTORS_PER_PAGE_SHIFT with PAGE_SECTORS_SHIFT o SECTORS_PER_PAGE with PAGE_SECTORS o SECTORS_PER_PAGE - 1 with SECTOR_MASK This produces no functional changes. Reviewed-by: Sergey Senozhatsky Signed-off-by: Luis Chamberlain Reviewed-by: Johannes Thumshirn --- drivers/block/zram/zram_drv.c | 15 ++++++--------- drivers/block/zram/zram_drv.h | 2 -- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 06673c6ca255..58d36c8574d4 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1834,9 +1834,8 @@ static ssize_t recompress_store(struct device *dev, static void zram_bio_discard(struct zram *zram, struct bio *bio) { size_t n = bio->bi_iter.bi_size; - u32 index = bio->bi_iter.bi_sector >> SECTORS_PER_PAGE_SHIFT; - u32 offset = (bio->bi_iter.bi_sector & (SECTORS_PER_PAGE - 1)) << - SECTOR_SHIFT; + u32 index = bio->bi_iter.bi_sector >> PAGE_SECTORS_SHIFT; + u32 offset = (bio->bi_iter.bi_sector & SECTOR_MASK) << SECTOR_SHIFT; /* * zram manages data in physical block size units. Because logical block @@ -1874,9 +1873,8 @@ static void zram_bio_read(struct zram *zram, struct bio *bio) struct bvec_iter iter = bio->bi_iter; do { - u32 index = iter.bi_sector >> SECTORS_PER_PAGE_SHIFT; - u32 offset = (iter.bi_sector & (SECTORS_PER_PAGE - 1)) << - SECTOR_SHIFT; + u32 index = iter.bi_sector >> PAGE_SECTORS_SHIFT; + u32 offset = (iter.bi_sector & SECTOR_MASK) << SECTOR_SHIFT; struct bio_vec bv = bio_iter_iovec(bio, iter); bv.bv_len = min_t(u32, bv.bv_len, PAGE_SIZE - offset); @@ -1905,9 +1903,8 @@ static void zram_bio_write(struct zram *zram, struct bio *bio) struct bvec_iter iter = bio->bi_iter; do { - u32 index = iter.bi_sector >> SECTORS_PER_PAGE_SHIFT; - u32 offset = (iter.bi_sector & (SECTORS_PER_PAGE - 1)) << - SECTOR_SHIFT; + u32 index = iter.bi_sector >> PAGE_SECTORS_SHIFT; + u32 offset = (iter.bi_sector & SECTOR_MASK) << SECTOR_SHIFT; struct bio_vec bv = bio_iter_iovec(bio, iter); bv.bv_len = min_t(u32, bv.bv_len, PAGE_SIZE - offset); diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index ca7a15bd4845..9f2543af5c76 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -21,8 +21,6 @@ #include "zcomp.h" -#define SECTORS_PER_PAGE_SHIFT (PAGE_SHIFT - SECTOR_SHIFT) -#define SECTORS_PER_PAGE (1 << SECTORS_PER_PAGE_SHIFT) #define ZRAM_LOGICAL_BLOCK_SHIFT 12 #define ZRAM_LOGICAL_BLOCK_SIZE (1 << ZRAM_LOGICAL_BLOCK_SHIFT) #define ZRAM_SECTOR_PER_LOGICAL_BLOCK \