Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp334124lqo; Wed, 8 May 2024 00:44:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX9A1WtJh+xVe2ofnV06LaNd43hDU9UNbaJ3/TrjF2rxBygoNlAQ2VeEb+D+YWmAwaNi4oPnUYv2lRDExSTu014ewzMPqGlp66IezXldA== X-Google-Smtp-Source: AGHT+IGPgvLzn0ldHg4fQB5wTAuDz9l92NJSud9OPNQi2lx0oRvUtY3Fb82MZ9I3ByFofuFtv1TJ X-Received: by 2002:aa7:8a54:0:b0:6ed:41f3:431d with SMTP id d2e1a72fcca58-6f49c0bea51mr1804100b3a.0.1715154244601; Wed, 08 May 2024 00:44:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715154244; cv=pass; d=google.com; s=arc-20160816; b=CDJpwmC75DOMjFQAE9HTr4rlKgwegf342jqKLqCoX6CnEEPd1hSG2Yvcf2OnSN4Sdm jmSzsqaAdbsopW45qp18vKMRQCs0wJwNDxXbl9kpqhWKrVUkRyMR/iI+fUJ1CYkNoYVR A7/TTYfxvpm4qJtuTeyaN7yH6HkAFYRijaTLtBQ+3AeRGV4px3aWBzKLSWK2izcFmKh2 t8IwZa4TrSEXkSp0qVIU6+cK7jvyw4ooxkQxD65HsgJufvf481wtxULzSvHN4x1xGWuk 1TbEuDcKfdBjRBDTjtrlsy+Lwjws/YSoksuY951nm3LxB+PgaHdIomzvYpAAogzXconu NL9A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=306fFAUpRl7xfsQbZN30LaodlrzrhLsXw6qfeFlE0HY=; fh=UKstJvjqAQ3P/Vkvglih02Z8FmmRnlaJbql9clnU9dw=; b=yh8kHeYkTzQcSH8wFsEJrI5hKsbQf02FPHtZE/3RuFbudSpCPxEqy/FJi5HPAn/zWf DXOjh7VMgD2tCSO9QiZN4K8PhMl3CkZJddfPvy7vlOBa+u5DQV+1sK2fhxWtB/Vo91sJ gXF6B44CU+fvRN8qdCCm30gliHwxGMQjOISGSmQYiEJcs2LdbyD6J1XgTVhfwooOCvJt FkEem2559+1skfexEYlqKHhZ63cv4fumQAj9flTdBELsdaF1+LPtb73QkT2OVqOYtWcC 1VBAlT1KDQxZvck+y1v39b1bxiazrwFzytkI9WyR+D8EGwe252aHYHinlxW2I33rVje7 gsfA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=gi7UOxxv; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-172830-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172830-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id m6-20020a056a00080600b006f4808ec2d7si5450900pfk.103.2024.05.08.00.44.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 00:44:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-172830-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=gi7UOxxv; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-172830-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172830-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 2AF79B23360 for ; Wed, 8 May 2024 07:42:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2B09D364A5; Wed, 8 May 2024 07:42:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="gi7UOxxv" Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 327A12C6B9 for ; Wed, 8 May 2024 07:42:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715154157; cv=none; b=gzoSgNBkjFCDznnZ0EOrQ5FtAmrgodbDcUZt4xRSsfyVLE/dCjf3KA+KM76ogd1hQ5TljZMn9QJz1HsVDkrRkS9X0Q7hR4AGOPgiYdqH2JKLNpZDcfZ+iNJHdTfGAJ6vkGhdedbbHQGClaE89s30ORyyCFcLULxRNKFHbjpS7vY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715154157; c=relaxed/simple; bh=eB82leL4MRWAJ3wXFubLY3J8xZ4NRhewKRY93691gcc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=qTKxXOulYxWzCm+tKbTpqlzSelDRXnA3/Qr0MfRykQjaKsnzHj/rCE8y7IR9KMdDP2z7SYlg+lXUKoPXUvGcyGDHPwSxlqVDBUYSH1L2N+Tr0QQYL5IaQQnSioSgCvucpNMzbwtGLHwaYnVUKoHd+dYRSXJ09iJftM9eeUtzIQA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=gi7UOxxv; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6ed3cafd766so3131552b3a.0 for ; Wed, 08 May 2024 00:42:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1715154154; x=1715758954; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=306fFAUpRl7xfsQbZN30LaodlrzrhLsXw6qfeFlE0HY=; b=gi7UOxxvuWzaJPfxQ3EgScNgq8kDiC2JE4YgD2t6pB0vPtUIkKyqL+q0tE5cVqX1k0 hSBAl4heKeWUGeb1gUCFoqMf3JK/1xlTPfu8VZFmaEny1hvDELmc6P6fzXPAJuVkEIfl twkkUloPUUyvUJwxertHUua87AP59uRTtdVWQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715154154; x=1715758954; 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=306fFAUpRl7xfsQbZN30LaodlrzrhLsXw6qfeFlE0HY=; b=F/Ep49dURd0ukWCMfBVc7Snpd99ueY9mQHfkWkHweX7qPBh2ld7Q9KH5Lgau1rTW5M LOs95qMEYD3GdyQjAyGMgV+K4SkaG0/Y0Vg/A3H7rxluYvxrDn9bsBurP8TOXhi4hI5q YqPqXG/HE3ryKhINsbao+cCaZA07vfPjlshgh7vI/ifF1gaMyRrNu+SgeBfecZ07AeyM hXNSmXWnJd0VKUrUZBi05Q7F1xkL5yngThqVQ4RgTwUCx3GRl92vgvRl1apQMeVXH96H KS48JfoGWcumNyvnmHcxMKxlZCwR5eo3AUm6o9FhtUhtwtiSTjrwGKkoHnpdj50iKyog PBrg== X-Gm-Message-State: AOJu0YyusSuSwzV+NBx2gid5a2m0iszQYTw/JnKe9geFUSRI15rM0s1A 4uyHsfUiRxdMcee024qF9Yf3VKIt/w+DbyH9TOgYgC6pHxfEw/hO/OwwdOgcVE00PYZmHa92m3U = X-Received: by 2002:a05:6a20:72a6:b0:1af:a617:86ac with SMTP id adf61e73a8af0-1afc8e04b3fmr2309870637.53.1715154154562; Wed, 08 May 2024 00:42:34 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:ad4d:5f6c:6699:2da4]) by smtp.gmail.com with ESMTPSA id l5-20020a17090aec0500b002b328adaa40sm780011pjy.17.2024.05.08.00.42.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 00:42:34 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv3 00/19] zram: convert to custom compression API and allow algorithms tuning Date: Wed, 8 May 2024 16:41:53 +0900 Message-ID: <20240508074223.652784-1-senozhatsky@chromium.org> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This patch set moves zram from crypto API to a custom compression API which allows us to tune and configure compression algorithms, something that crypto API, unfortunately, doesn't support. Basically, this seroes brings back the bits of comp "backend" code that we had many years ago. This means that if we want zram to support new compression algorithms we need to implement corresponding backends. Currently, zram supports a pretty decent number of comp backends: lzo, lzorle, lz4, lz4hc, 842, deflate, zstd At this point we handle 2 parameters: a compression level and a pre-trained compression dictionary. Which seems like a good enough start. The list will be extended in the future. Examples: - changes default compression level echo "algo=zstd level=11" > /sys/block/zram0/comp_algorithm - passes path to a pre-trained dictionary echo "algo=zstd dict=/etc/dictionary" > /sys/block/zram0/comp_algorithm Benchmarks ========== *** zstd /sys/block/zram0/mm_stat 1750302720 504600204 514416640 0 514416640 1 0 34204 34204 *** zstd level=5 /sys/block/zram0/mm_stat 1750331392 488449001 497905664 0 497905664 1 0 34204 34204 *** zstd dict=/etc/dictionary /sys/block/zram0/mm_stat 1750335488 464838883 474210304 0 474210304 1 0 34204 34204 *** zstd level=5 dict=/etc/dictionary /sys/block/zram0/mm_stat 1750319104 451907185 461299712 0 461299712 1 0 34204 34204 *** lz4 /sys/block/zram0/mm_stat 1750319104 664253635 676859904 0 676859904 1 0 34288 34288 *** lz4 dict=/etc/dictionary /sys/block/zram0/mm_stat 1750319104 620602911 632705024 0 632705024 1 0 34288 34288 *** lz4hc /sys/block/zram0/mm_stat 1750315008 609004936 621092864 0 621092864 1 0 34288 34288 *** lz4hc level=5 dict=/etc/dictionary /sys/block/zram0/mm_stat 1750323200 501315128 511303680 0 511303680 1 0 34288 34288 v3: -- support pre-trained dictionary in lz4 -- support pre-trained dictionary in lz4hc v2: -- forcibly select LZO when none backeneds were selected (Masahiro Yamada) -- add 842 compression backend -- added comp config preprocessing and caching -- reworked zstd dict handling Sergey Senozhatsky (19): zram: move from crypto API to custom comp backends API zram: add lzo and lzorle compression backends support zram: add lz4 compression backend support zram: add lz4hc compression backend support zram: add zstd compression backend support zram: pass estimated src size hint to zstd zram: add zlib compression backend support zram: add 842 compression backend support zram: check that backends array has at least one backend zram: introduce zcomp_config structure zram: extend comp_algorithm attr write handling zram: support compression level comp config zram: add support for dict comp config zram: add dictionary support to zstd backend zram: add config init/release backend callbacks zram: share dictionaries between per-CPU contexts zram: add dictionary support to lz4 zram: add dictionary support to lz4hc Documentation/zram: add documentation for algorithm parameters Documentation/admin-guide/blockdev/zram.rst | 38 +++- drivers/block/zram/Kconfig | 76 +++++-- drivers/block/zram/Makefile | 8 + drivers/block/zram/backend_842.c | 79 +++++++ drivers/block/zram/backend_842.h | 10 + drivers/block/zram/backend_deflate.c | 143 +++++++++++++ drivers/block/zram/backend_deflate.h | 10 + drivers/block/zram/backend_lz4.c | 123 +++++++++++ drivers/block/zram/backend_lz4.h | 10 + drivers/block/zram/backend_lz4hc.c | 128 ++++++++++++ drivers/block/zram/backend_lz4hc.h | 10 + drivers/block/zram/backend_lzo.c | 55 +++++ drivers/block/zram/backend_lzo.h | 10 + drivers/block/zram/backend_lzorle.c | 55 +++++ drivers/block/zram/backend_lzorle.h | 10 + drivers/block/zram/backend_zstd.c | 221 ++++++++++++++++++++ drivers/block/zram/backend_zstd.h | 10 + drivers/block/zram/zcomp.c | 155 +++++++------- drivers/block/zram/zcomp.h | 42 +++- drivers/block/zram/zram_drv.c | 120 ++++++++++- drivers/block/zram/zram_drv.h | 1 + 21 files changed, 1203 insertions(+), 111 deletions(-) create mode 100644 drivers/block/zram/backend_842.c create mode 100644 drivers/block/zram/backend_842.h create mode 100644 drivers/block/zram/backend_deflate.c create mode 100644 drivers/block/zram/backend_deflate.h create mode 100644 drivers/block/zram/backend_lz4.c create mode 100644 drivers/block/zram/backend_lz4.h create mode 100644 drivers/block/zram/backend_lz4hc.c create mode 100644 drivers/block/zram/backend_lz4hc.h create mode 100644 drivers/block/zram/backend_lzo.c create mode 100644 drivers/block/zram/backend_lzo.h create mode 100644 drivers/block/zram/backend_lzorle.c create mode 100644 drivers/block/zram/backend_lzorle.h create mode 100644 drivers/block/zram/backend_zstd.c create mode 100644 drivers/block/zram/backend_zstd.h -- 2.45.0.rc1.225.g2a3ae87e7f-goog