Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp496533rwe; Wed, 24 Aug 2022 04:46:50 -0700 (PDT) X-Google-Smtp-Source: AA6agR5hV3NlzJnJiolrr14B91ybFTl49fLRdbgdUcLMxElCxow/IkWl5k0e0a4ivBgzjtWPxGnm X-Received: by 2002:a17:902:ec8c:b0:172:f018:4b37 with SMTP id x12-20020a170902ec8c00b00172f0184b37mr12105447plg.62.1661341609787; Wed, 24 Aug 2022 04:46:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661341609; cv=none; d=google.com; s=arc-20160816; b=om3s/o7kW6X+dUNp5J6smBUVuUY5scvI5b0PUuQm5129lB1RoMDGjT5TGzQZr02frx qhGjIDoGJd+rf9iBdFr0R5LG5wr7e1QFhWduecpBitUWN0UjU1EMrIBSOix4niOAUNSH TG0aYmrSwifE0D8nR90nacGVMJBaLYtGl07vWh3zvYLQAkOAovGQH1Y+e7b/4QG8ddmW LStEQymqKXbhsipkiwUKmsMB845t52HpI5mhAKek+9xfeulov/xx75n7y1RLF4CAtNn5 ATWpph1ZgJyXTnKzYjr0+sNIT4dxbc3d99xs+WaLzTWJZW9DJ1rWI5oJxQtCSlXTRtIA TcNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=9a3LG75heqpVyPTgK4IjcsiLYbZXVWbG8+l83iknq/U=; b=eIhWeW4Jqb28lH0NGdInb9L1xNRCAZBJ1VpmFVpwtYfnaDXSXWvM2CrSFfTXwKuS9C h814QOy2NQxqjYvkOGU/jcagnJFha+T+soekcC38m7pZuRrlYmQA3I2fJzYWLaL9W2iD Ee5XK3XWlGEY8HiTCnyDmO3tWAYVXUEdXzuCThMrlK+GDuWsqvSxMpC/tKNzEl0FPqyP A+EFWRLTuNES7J3w8XtEz5LsJhfwg+RTHGM0skUokslJ1x/b7IGGjpW/lJlE7VaMRmOg 16Sixpl+eu/dbmoYFRLe5iqDsO4okSR/W5yDBZe69SihPZIgsbg3OTwuj06k4UwSzKXV oMwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=XkmEd4qm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s4-20020a170902ea0400b00171554b0e73si19169788plg.361.2022.08.24.04.46.38; Wed, 24 Aug 2022 04:46:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=XkmEd4qm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236554AbiHXLbh (ORCPT + 99 others); Wed, 24 Aug 2022 07:31:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235265AbiHXLbf (ORCPT ); Wed, 24 Aug 2022 07:31:35 -0400 Received: from mail.sberdevices.ru (mail.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CFDA7CB53 for ; Wed, 24 Aug 2022 04:31:31 -0700 (PDT) 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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); -- 2.25.1