From patchwork Wed Aug 24 11:31:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Romanov X-Patchwork-Id: 12953307 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 DD905C00140 for ; Wed, 24 Aug 2022 11:31:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 449CB940007; Wed, 24 Aug 2022 07:31:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F90C6B0074; Wed, 24 Aug 2022 07:31:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C0E9940007; Wed, 24 Aug 2022 07:31:31 -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 1A1346B0073 for ; Wed, 24 Aug 2022 07:31:31 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E6A74AC1B3 for ; Wed, 24 Aug 2022 11:31:30 +0000 (UTC) X-FDA: 79834270740.12.03187A6 Received: from mail.sberdevices.ru (mail.sberdevices.ru [45.89.227.171]) by imf06.hostedemail.com (Postfix) with ESMTP id 2046B180035 for ; Wed, 24 Aug 2022 11:31:29 +0000 (UTC) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mail.sberdevices.ru (Postfix) with ESMTP id 174345FD0C; Wed, 24 Aug 2022 14:31:28 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1661340688; bh=9a3LG75heqpVyPTgK4IjcsiLYbZXVWbG8+l83iknq/U=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=XkmEd4qmaLG7oYQlqb7HPFZS8rXaOic64jmLQU+q7fitA/zKznETHS/WMIV82oGDl TZMSyaDc11KMeAUglxMuz+2JYPGgmdVjqpSm2yaICNbpn+yfgCykSBZwDTP3O0tmst pX9u3iQKoJDXKYSZWGscL4nr2OgxXflepL1V5MC6t805kqK0EDUaJQFagLKvTk1qyI 4CAgf6IrIkvaoVI0jfZ2iyp25AsaOzwgGwxgZNSeyBS6OMVXRGiHeWsJr1tbgTdGgm QlE919zDf1rYSKOncH4OFggTCyYvLkRfhb44crf5BqGMEsOfZM9Pk2SClFGhmD1pH2 3+/9/QnCUIHvw== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mail.sberdevices.ru (Postfix) with ESMTP; Wed, 24 Aug 2022 14:31:26 +0300 (MSK) From: Alexey Romanov To: , , , CC: , , , Alexey Romanov , Dmitry Rokosov Subject: [PATCH v2] zram: don't retry compress incompressible page Date: Wed, 24 Aug 2022 14:31:17 +0300 Message-ID: <20220824113117.78849-1-avromanov@sberdevices.ru> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH01.sberdevices.ru (172.16.1.4) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2022/08/24 08:05:00 #20147978 X-KSMG-AntiVirus-Status: Clean, skipped ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661340690; 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-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=9a3LG75heqpVyPTgK4IjcsiLYbZXVWbG8+l83iknq/U=; b=fYosl+9y3LpjnPlEHasY8NUj+/IqVtPhKJamNvcjxzuRDA8A7UKr8vFLQnkX6Fa7wXHBdl a1ckzA5/2olfzZlCLePcbH9iGZQytcwJDjWjnMO15fRAtWrq9s1c7iXTK0rVnzuJ2F7l6o PFM9HyI1jo4RK7s+Aqy7KXBCXNJzCnk= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=sberdevices.ru header.s=mail header.b=XkmEd4qm; spf=pass (imf06.hostedemail.com: domain of AVRomanov@sberdevices.ru designates 45.89.227.171 as permitted sender) smtp.mailfrom=AVRomanov@sberdevices.ru; dmarc=pass (policy=quarantine) header.from=sberdevices.ru ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661340690; a=rsa-sha256; cv=none; b=FtvrbIx+b5QPS3T1e8FaIec3SQqpcb0Xk6GFzpVX3kGNjZLxoJbUZo0gi20PU1GaEQ+Fbc mVwUlyqaKyUjoInEnoEpq5STEV9mdMyTTBf7IIKgcgVo9Z2ELlDTisF9E0ZCDK6bSRbOQP MRDhG3q+7UzHBxfZo3IkADHHWfQVjKA= Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=sberdevices.ru header.s=mail header.b=XkmEd4qm; spf=pass (imf06.hostedemail.com: domain of AVRomanov@sberdevices.ru designates 45.89.227.171 as permitted sender) smtp.mailfrom=AVRomanov@sberdevices.ru; dmarc=pass (policy=quarantine) header.from=sberdevices.ru X-Rspam-User: X-Stat-Signature: dh1jnafkfsek9a43igk7pedwyo9chmwi X-Rspamd-Queue-Id: 2046B180035 X-Rspamd-Server: rspam10 X-HE-Tag: 1661340689-556038 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: It doesn't make sense for us to retry to compress an uncompressible page (comp_len == PAGE_SIZE) in zsmalloc slowpath, because we will be storing it uncompressed anyway. We can avoid wasting time on another compression attempt. It is enough to take lock (zcomp_stream_get) and execute the code below. Signed-off-by: Alexey Romanov Signed-off-by: Dmitry Rokosov Reviewed-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 226ea76cc819..3bd8d5e27041 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1410,9 +1410,19 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, handle = zs_malloc(zram->mem_pool, comp_len, GFP_NOIO | __GFP_HIGHMEM | __GFP_MOVABLE); - if (!IS_ERR((void *)handle)) + if (IS_ERR((void *)handle)) + return PTR_ERR((void *)handle); + + if (comp_len != PAGE_SIZE) goto compress_again; - return PTR_ERR((void *)handle); + /* + * If the page is not compressible, you need to acquire the lock and + * execute the code below. The zcomp_stream_get() call is needed to + * disable the cpu hotplug and grab the zstrm buffer back. + * It is necessary that the dereferencing of the zstrm variable below + * occurs correctly. + */ + zstrm = zcomp_stream_get(zram->comp); } alloced_pages = zs_get_total_pages(zram->mem_pool);