Message ID | 20221018020519.never.337-kees@kernel.org |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1739799wrs; Mon, 17 Oct 2022 19:22:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM72OR+mEoTa4vqbkB+3QgSITMxD0sTYdeXa/BXv8w+T7KGBSf31jfkIu+pMAPJZ6lI1ej+a X-Received: by 2002:a17:907:628f:b0:72f:58fc:3815 with SMTP id nd15-20020a170907628f00b0072f58fc3815mr520913ejc.719.1666059761932; Mon, 17 Oct 2022 19:22:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666059761; cv=none; d=google.com; s=arc-20160816; b=wS3V/PWvYlyapGxLIgSbV6g9JoRi6DoGTOT9ioz18OHtqUDIjKR9vZDXvTwy3jmJwj HtuMW5ZAlwqR93PiT2wOqkPcI6wdDJDB9YgbQ0pT7Ybz/j37l9OG1tTV9NpguotdMsge heL7BYwGRkicl53N3f0QAK/mj7Fge1d4bpiFklTX2KM3emeSYFfYGMfFVlTl2fibJj/Z ztPM0Cyiel5dIqyv0jjzxHobdIvWDtiHiiFjAz1/G4R4K7FyVHU1mGdsOXq95UvZdWtB qYhVLIrqdo4GlEwl4ERET8VhcQfEIM1WkcY4DxlaIk29uxM7qbnVUpXB8kXWyAztKy/y um1Q== 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=eMGLJhsH5Znj23nG3H7PM8Z7rLjzyLqci0sjskq69co=; b=yh5F/GtNKt8nVuec0CwGRIJa+gEFmfrwsGAzU47LhNLqHBY2EEw/6L8/W0Mynl0lIK Ks93m2aaWF/eEDfgVJ3Dur0apdSbNTiwdzoryzvbVtlHrQvubAKn0lVHgjgurNbr7qyN C0QnEZjSqm6h+Hnz0pgWAZ5XufDG9KQJkixaQklExSIsxlksGBO3j/prAJAgOaM/tTU8 dvNZfD5GI/B9NwGsJBGhU6l8y3n5v61ra2QupeQoDVgy4+adyLtiDPprCvliFQ/C6TIp 2zkgiLUT6ak5e/ek3VjbcnlCVMbfqH/eCvIqTT0XraeD7fnlQ3PFmAXFT4Sq3jmYGQDI t82w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=jIR8Rx7X; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fy34-20020a1709069f2200b007806c141214si7159360ejc.153.2022.10.17.19.22.17; Mon, 17 Oct 2022 19:22:41 -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=@chromium.org header.s=google header.b=jIR8Rx7X; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230262AbiJRCJi (ORCPT <rfc822;carlos.wei.hk@gmail.com> + 99 others); Mon, 17 Oct 2022 22:09:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231265AbiJRCIx (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 17 Oct 2022 22:08:53 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40A4223383 for <linux-kernel@vger.kernel.org>; Mon, 17 Oct 2022 19:08:31 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id 67so12747926pfz.12 for <linux-kernel@vger.kernel.org>; Mon, 17 Oct 2022 19:08:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=eMGLJhsH5Znj23nG3H7PM8Z7rLjzyLqci0sjskq69co=; b=jIR8Rx7Xdu0BB/CQVKV+iKXCUQm0ZoDJ06X+DKrmakASyAN7SOLbpajdRFE+kj3elS Y7UflznwLWeF6yg32V5J9I2DQ60k8PUSiN0JcqSA/YVzKm7ZrYoJ2i0f5stmJjKoBG/P gLfBbCewyXppSPJwOnBQU973OkO/oKJsrIe88= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=eMGLJhsH5Znj23nG3H7PM8Z7rLjzyLqci0sjskq69co=; b=KYRV8dwAcmKNoK6IxkrBEpIToaO1XRunlUrXWZB6+6nYiMAR+dpjj1Sm+MilmATalu VHc9qjvekD0nw50eHSkq2ATCdQJtDasqgSrjPVcr86gOs4rfQNYEhMVdepWyCxP2vljf gDYU/V9Y+1LRcpMlN+0PUxgVUHBfMoewH3fWXFtuI4urLjtXQ/aOcKsLXthx4SRlPm/e 2t1zRwEFKshcmWtA9M4civymHDYSE/Zk7MGfllSjCQlVTOahQYQJBfO8laiz2BujxSOt 33LJE/AhxyZi3El2PBih761bWbIJFtN6vQEntgrTJk6QRpWTMOJGklkpRgsjToJvoAbc HVSA== X-Gm-Message-State: ACrzQf3d5t8ElP8Kbeumqo5M3GzUUYP1iaB9ibdd8NoQtvuXJmfB0tcA oZbKZZmf0JQM/EOqJT6JobqUIw== X-Received: by 2002:a63:5d4e:0:b0:41d:dcc3:aa85 with SMTP id o14-20020a635d4e000000b0041ddcc3aa85mr666329pgm.324.1666058898927; Mon, 17 Oct 2022 19:08:18 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id 5-20020a630205000000b00442c70b659esm6756041pgc.91.2022.10.17.19.08.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 19:08:17 -0700 (PDT) From: Kees Cook <keescook@chromium.org> To: Ard Biesheuvel <ardb@kernel.org> Cc: Kees Cook <keescook@chromium.org>, Tony Luck <tony.luck@intel.com>, "Guilherme G. Piccoli" <gpiccoli@igalia.com>, Nick Terrell <terrelln@fb.com>, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH 0/5] pstore: Use zstd directly by default for compression Date: Mon, 17 Oct 2022 19:08:08 -0700 Message-Id: <20221018020519.never.337-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=828; h=from:subject:message-id; bh=Pon2y+0FdKP13fO9/56Jz7YH/A3wnJVWtLmrRXXJ4qA=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBjTgqM20Cw4i60mqZOM8N+yMRC05rSUMUamOJrPgMM n+AqTqiJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCY04KjAAKCRCJcvTf3G3AJn+1D/ 4tC5SgPiHimrKXK3Xn/1iDGsylDDtUAhPxWiwEmg0px4dNtSIWVBGhyh1GyLnJ3+R9DRqyhTrGTek5 ShB5qgCPv9tXpEE5k8xYDK4mWExYrcS+5KVHVog43CLeJylg2SmXvxpudJAMdCYDTmXGsunJmSSkr7 vjhdo6f4YUIY45vf0/ijrvcsjQ6pnQXpldTNgByBF6HReveguP9+ZjZBItZpq3hBVA1hdBjLlVIp58 vLJWsvPgpi9lDCJ3PvOKP9o5rCyaSZTY9EMAER2Nb1oh5Jv08+/uEOeLR0IaTKBhvBGVux56vY0J5Y i2VELQXAiALW2k6U6wx6f+rO/URUkP8Z53sT67tX3sdfg0aKNTyBNM2M0y8RAdU6PeWsvKKZhxADVA pudi6G530iTASmQJJekS0N+yP7ML4qCgbEGpvLNtmkq1wkhzKuKuKSXdjFD029jLEzlzt67zlsB9xD kHQErcy58aP1Pi447WCzhWRhG9C//3VqN+V7NF8oc/qIWaKphMqkll5Pxc+VwWC2xu/+NlzO1td0Sk TH2JcDUipo/LERQcRuU6FQ6UuZ9ZZj36goPVFOE3kOgNY5HssXtxd8VZGqYcS3NSyPvLAV3vPnmvV9 PCcB7EOaFUUbcdeFJKcEVkv8EwsAxOl3sIR2ekoDYi3cnIwAyK+HBGYSFBmA== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746990209540027211?= X-GMAIL-MSGID: =?utf-8?q?1746990280947659576?= |
Series |
pstore: Use zstd directly by default for compression
|
|
Message
Kees Cook
Oct. 18, 2022, 2:08 a.m. UTC
Hi, Okay, here is a very lightly tested version of using zstd directly, which should save 128KB per CPU compare to using crypto API. This leaves the crypto API available, though, if someone wants to use it instead. Even supporting both, this is a net reduction in code, due to dropping all the zbufsize logic. How does this look? -Kees Kees Cook (5): pstore: Remove worse-case compression size logic pstore: Allow for arbitrary compression algorithm pstore: Use size_t for compress/decompression type widths pstore: Refactor compression initialization pstore: Use zstd directly by default for compression fs/pstore/Kconfig | 131 +++++----------- fs/pstore/platform.c | 358 ++++++++++++++++++++----------------------- 2 files changed, 209 insertions(+), 280 deletions(-)
Comments
On Tue, 18 Oct 2022 at 04:08, Kees Cook <keescook@chromium.org> wrote: > > Hi, > > Okay, here is a very lightly tested version of using zstd directly, which > should save 128KB per CPU compare to using crypto API. This leaves the > crypto API available, though, if someone wants to use it instead. Even > supporting both, this is a net reduction in code, due to dropping all > the zbufsize logic. > > How does this look? > The code changes all look correct and reasonable to me. As for supporting both the library and the crypto API interface: I did a little digging, and it turns out all additional compression modes were added by the same contributor, with no justification other than 'this might be useful to some people' (see below) However, I did a quick experiment with the output of dmesg on my workstation, and these are the results I am getting Input file: -rw-r--r-- 1 ard ard 111792 Oct 18 09:23 uncompressed Default compression -rw-r--r-- 1 ard ard 21810 Oct 18 09:23 uncompressed.gz -rw-r--r-- 1 ard ard 33923 Oct 18 09:23 uncompressed.lz4 -rw-r--r-- 1 ard ard 34238 Oct 18 09:23 uncompressed.lzo -rw-r--r-- 1 ard ard 21599 Oct 18 09:23 uncompressed.zst Max compression (-9) -rw-r--r-- 1 ard ard 21589 Oct 18 09:23 uncompressed.gz -rw-r--r-- 1 ard ard 28848 Oct 18 09:25 uncompressed.lz4 (== lz4hc?) -rw-r--r-- 1 ard ard 26917 Oct 18 09:23 uncompressed.lzo -rw-r--r-- 1 ard ard 19883 Oct 18 09:23 uncompressed.zst So the patches in question don't actually fulfill their claim of improving the compression ratio. Only zstd, which was added later, improves upon zlib, but not significantly unless you override the compression level (which we don't). So I seriously doubt that those patches were inspired by the need to solve an actual problem anyone was experiencing at the time, given that they don't. It just seems that nobody bothered to ask the 'why?' question. So again, I suggest to simply drop this non-feature, and standardize on either zlib or zstd using the library interface exclusively. If someone present a compelling use case, we can always consider adding it back in some form. As for the choice of algorithm, given the equal performance using the default compression level, and the difference in code size, I don't see why zstd should be preferred here. If anything, it only increases the likelihood of hitting another error if we are panicking due to some memory corruption issue. $ size lib/zstd/zstd_compress.ko lib/zlib_deflate/zlib_deflate.ko text data bss dec hex filename 218411 768 0 219179 3582b lib/zstd/zstd_compress.ko 16231 876 2288 19395 4bc3 lib/zlib_deflate/zlib_deflate.ko commit 8cfc8ddc99df9509a46043b14af81f5c6a223eab Author: Geliang Tang <geliangtang@163.com> AuthorDate: Thu Feb 18 22:04:22 2016 +0800 Commit: Kees Cook <keescook@chromium.org> CommitDate: Thu Jun 2 10:59:31 2016 -0700 pstore: add lzo/lz4 compression support Like zlib compression in pstore, this patch added lzo and lz4 compression support so that users can have more options and better compression ratio. commit 239b716199d9aff0d09444b0086e23aacd6bd445 Author: Geliang Tang <geliangtang@gmail.com> AuthorDate: Tue Feb 13 14:40:39 2018 +0800 Commit: Kees Cook <keescook@chromium.org> CommitDate: Tue Mar 6 15:06:11 2018 -0800 pstore: Add lz4hc and 842 compression support > > Kees Cook (5): > pstore: Remove worse-case compression size logic > pstore: Allow for arbitrary compression algorithm > pstore: Use size_t for compress/decompression type widths > pstore: Refactor compression initialization > pstore: Use zstd directly by default for compression > > fs/pstore/Kconfig | 131 +++++----------- > fs/pstore/platform.c | 358 ++++++++++++++++++++----------------------- > 2 files changed, 209 insertions(+), 280 deletions(-) > > -- > 2.34.1 >
On 18/10/2022 05:20, Ard Biesheuvel wrote: > [...] > So again, I suggest to simply drop this non-feature, and standardize > on either zlib or zstd using the library interface exclusively. If > someone present a compelling use case, we can always consider adding > it back in some form. > > As for the choice of algorithm, given the equal performance using the > default compression level, and the difference in code size, I don't > see why zstd should be preferred here. If anything, it only increases > the likelihood of hitting another error if we are panicking due to > some memory corruption issue. I think it's a good argument - would zlib be simpler in code than zstd? I've checked the zstd patch from Kees - not complex per se, but would be great if we could have a simple mechanism, without the need of the ifdef there for example... Cheers, Guilherme
On Tue, 18 Oct 2022 at 16:11, Guilherme G. Piccoli <gpiccoli@igalia.com> wrote: > > On 18/10/2022 05:20, Ard Biesheuvel wrote: > > [...] > > So again, I suggest to simply drop this non-feature, and standardize > > on either zlib or zstd using the library interface exclusively. If > > someone present a compelling use case, we can always consider adding > > it back in some form. > > > > As for the choice of algorithm, given the equal performance using the > > default compression level, and the difference in code size, I don't > > see why zstd should be preferred here. If anything, it only increases > > the likelihood of hitting another error if we are panicking due to > > some memory corruption issue. > > I think it's a good argument - would zlib be simpler in code than zstd? I think it should be rather straight-forward. Note that this is what we had before 2016 when all the 'features' were starting to get added. > I've checked the zstd patch from Kees - not complex per se, but would be > great if we could have a simple mechanism, without the need of the ifdef > there for example... > > Cheers, > > > Guilherme