From patchwork Wed Dec 18 06:34:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13913086 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 64F09E77187 for ; Wed, 18 Dec 2024 06:35:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB9236B008C; Wed, 18 Dec 2024 01:35:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E69926B0092; Wed, 18 Dec 2024 01:35:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D31746B0093; Wed, 18 Dec 2024 01:35:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B50706B008C for ; Wed, 18 Dec 2024 01:35:34 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 63E24C0B94 for ; Wed, 18 Dec 2024 06:35:34 +0000 (UTC) X-FDA: 82907116740.09.BBAD09D Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by imf03.hostedemail.com (Postfix) with ESMTP id 43B8320008 for ; Wed, 18 Dec 2024 06:35:18 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=fN0mqwms; spf=pass (imf03.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.53 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=1734503697; 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=K01D9WjQ4IDKLASlrrrpT/PTwcowLsveSV75IjoNXbE=; b=F54MOh8WbvT7TQk4sTpKq4CjegOlI/rKnwKTcD5zciP+B0BQAI6bMnX/H1MSL92a6/kez0 VZy4rtd6+Ze90aaFR0iQv8SSBy7BlpI4Gtnm8W1PPzKLA5ZePxeLoiE97d8vScwCkMc+YH RDHZNBFZi3VdD+ldZL/USxaphascT0g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734503697; a=rsa-sha256; cv=none; b=Hf7VU7kiVcASZ0xpdUi/VLth3VSbqS9SFIIRacFTlCl+abUtFkcc4TaOs7KQc400QhrQme 50aJVMelWDIfAyuPMg2kP9BWNBoQD1rigUiiUZBPaVg9jevEGdByffYeGXMpnN35lc1dGS kUfX6o/rUUypqDx8r+pmerSX4e3n0Qw= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=fN0mqwms; spf=pass (imf03.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.53 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-2ee51f8c47dso4243416a91.1 for ; Tue, 17 Dec 2024 22:35:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1734503731; x=1735108531; darn=kvack.org; 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=K01D9WjQ4IDKLASlrrrpT/PTwcowLsveSV75IjoNXbE=; b=fN0mqwms+8GnMJ5W3jDzL4UnBCYh3x33WpQL7Q4uBQooBjy2ObRQA+tIVaxHSLVhvX VqBiXsXNNZ3NeTdOz66tNWMIJQGfDYDBvZWL3P9roTFY3/Tlcl6JNqy985H4nsqCa890 exyopAl7WNUqwQ9NtolS1BV+QlSzoWj7/W14E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734503731; x=1735108531; 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=K01D9WjQ4IDKLASlrrrpT/PTwcowLsveSV75IjoNXbE=; b=R4MuyK7/uV0NFuqtdyFQ1X74nymrG9WAeu4ezR6jUYG76Nn4Y64R3szttOlCE4xiJ1 vL1L0eDRqZn9YYpvsZFEmL/QCLiVDZMAhayWktL1ottai1ijNy5lxYyMuaZ3i6cH9MFV uvvm8G+RybrLg0pxsxLkxI/BXO1aGuXw2NEVhSmActMB4ExuwazP97Uq8hdyEL9m15KO zRmxfqwwrU5DpGGIwe4ySjVCrQ3rpdxhxXyeu3+1CxoEUyp3dLhsOmYmfwcbiaZSJcWL eEqNINbxv0UD7PUJS+4zN66anzpO6UJBUxIm5WDesVfoM/5tDGq7zccQ20vN4P/RTo3R kX4Q== X-Forwarded-Encrypted: i=1; AJvYcCX4XwHuHU1wmDWwM1rIqWPPyP+SKkMZBCbbf43EjzA56LYJb1Dkpc1iMJvek6y3m7QKlbpZYa8zvA==@kvack.org X-Gm-Message-State: AOJu0YzKQ3zIp4oJhgrLmJZPfD0ZQTHMhfXDNQVY1uIG1OH4fQdWMFaJ 0aK9WJuOFcJY4MZpcmUT658EYHpkh1l/96a02q1CXfSlKRDk0g/QQVUv3iiB6w== X-Gm-Gg: ASbGnctE8X6e/9l+iHa85HkXUa4hRWl21XF2Q25Qt30hddE5zdK2SbdJw+NV658FYVb ov+3cPmae210AhD//I4hPGLz3EbPfTrOvTarZvdeaU1mbxepzaVbvy7SviKZ2+L31aesjcSs3Q0 lUFLmphNQvAdfRLP5j8yaz2stPaeC9cgVbOpVpK/T8XmKthrvPUjqyDDo9EPwda5KHLEJEl2n9y L4Y9zrOQIaqQymk3Y94vkVWC2gabZTIU9BrwkQZ6qCP2IDBPr0zsdJqLBQ= X-Google-Smtp-Source: AGHT+IFK5WlahiR5aGL0BTCtzr0kzih6dT4LaJYbmSnHINvLQ21PzUVu87JBr7NRGop1fXLHbUC5yg== X-Received: by 2002:a17:90b:2703:b0:2ee:ed1c:e451 with SMTP id 98e67ed59e1d1-2f2e91db281mr2864827a91.15.1734503731353; Tue, 17 Dec 2024 22:35:31 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:3bcc:36cc:b9fe:9379]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2f2ed52c3bdsm587770a91.10.2024.12.17.22.35.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Dec 2024 22:35:30 -0800 (PST) From: Sergey Senozhatsky To: Andrew Morton Cc: Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv2 3/7] zram: factor out ZRAM_SAME write Date: Wed, 18 Dec 2024 15:34:20 +0900 Message-ID: <20241218063513.297475-4-senozhatsky@chromium.org> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog In-Reply-To: <20241218063513.297475-1-senozhatsky@chromium.org> References: <20241218063513.297475-1-senozhatsky@chromium.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 43B8320008 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: p4jng5sxredggg1m9wr4m3pwb39oqmob X-HE-Tag: 1734503718-485882 X-HE-Meta: U2FsdGVkX1/n172lR/xDZtMp9wQSWgWwlLVqwOdpCsK9ehEb1xNc7knEgvi6PDp1Lx9mWwjXgKmTrfykhzTE9X0wclyB1TFXQRZ9VTfue9/4VjO/UweyWk8X5Cdd+OxSxGgXzdMYqMj80s6vPP+j90UC67mJDdevHUr9+FOLw3ghxkmrjeBTWH2Qn74/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r57mLeD3TkM4b9Pu/4Qcd+cpGszyA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.033798, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Handling of ZRAM_SAME now uses a goto to the final stages of zram_write_page() plus it introduces a branch and flags variable, which is not making the code any simpler. In reality, we can handle ZRAM_SAME immediately when we detect such pages and remove a goto and a branch. Factor out ZRAM_SAME handling into a separate routine to simplify zram_write_page(). Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 37 ++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 8c71ddd17024..89f3aaa23329 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1624,6 +1624,20 @@ static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec, return zram_read_page(zram, bvec->bv_page, index, bio); } +static int write_same_filled_page(struct zram *zram, unsigned long fill, + u32 index) +{ + zram_slot_lock(zram, index); + zram_set_flag(zram, index, ZRAM_SAME); + zram_set_handle(zram, index, fill); + zram_slot_unlock(zram, index); + + atomic64_inc(&zram->stats.same_pages); + atomic64_inc(&zram->stats.pages_stored); + + return 0; +} + static int zram_write_page(struct zram *zram, struct page *page, u32 index) { int ret = 0; @@ -1633,7 +1647,7 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 index) void *src, *dst, *mem; struct zcomp_strm *zstrm; unsigned long element = 0; - enum zram_pageflags flags = 0; + bool same_filled; /* First, free memory allocated to this slot (if any) */ zram_slot_lock(zram, index); @@ -1641,14 +1655,10 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 index) zram_slot_unlock(zram, index); mem = kmap_local_page(page); - if (page_same_filled(mem, &element)) { - kunmap_local(mem); - /* Free memory associated with this sector now. */ - flags = ZRAM_SAME; - atomic64_inc(&zram->stats.same_pages); - goto out; - } + same_filled = page_same_filled(mem, &element); kunmap_local(mem); + if (same_filled) + return write_same_filled_page(zram, element, index); compress_again: zstrm = zcomp_stream_get(zram->comps[ZRAM_PRIMARY_COMP]); @@ -1727,7 +1737,7 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 index) zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP]); zs_unmap_object(zram->mem_pool, handle); atomic64_add(comp_len, &zram->stats.compr_data_size); -out: + zram_slot_lock(zram, index); if (comp_len == PAGE_SIZE) { zram_set_flag(zram, index, ZRAM_HUGE); @@ -1735,13 +1745,8 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 index) atomic64_inc(&zram->stats.huge_pages_since); } - if (flags) { - zram_set_flag(zram, index, flags); - zram_set_handle(zram, index, element); - } else { - zram_set_handle(zram, index, handle); - zram_set_obj_size(zram, index, comp_len); - } + zram_set_handle(zram, index, handle); + zram_set_obj_size(zram, index, comp_len); zram_slot_unlock(zram, index); /* Update stats */