Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp392692rdb; Fri, 6 Oct 2023 06:47:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGmBd1C9uTFiLvFL7SwlCoEGpFf6kQ72URyEvQ89tk09GU97x9raKNw2LpMt3hjYzTCDe8X X-Received: by 2002:a05:6358:3601:b0:143:2f7e:9b with SMTP id v1-20020a056358360100b001432f7e009bmr7064059rwd.16.1696600027061; Fri, 06 Oct 2023 06:47:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696600027; cv=none; d=google.com; s=arc-20160816; b=JBHy5dNZZYbyX3xdAg2WNL6f6TpidyUdymsNecX6b2EWH0vU9eXlbXavYhOquUkbGt 6uAoYo7vIXtTd3/DMsgRkYspaPBIrLsvHbKDrokpyZAcE1cp+q5MFReUnzt/zt31GgFH geZjYzPcdJ7Cgt8XwHMiAU1t2FORzCYdeLd6RIPM2Q2bs+qGjRFv4qm4IK7MMbkYey8Q noP5XKM3a+P9qLd+b3JmGO2by+3NdVFV0f2Hf4Xy8zNPJRnqtldrKlL98lCoZF1ZN18q v4JIwawpgYFGKGvRS2Vopc54Alvlk1GCoFLf97POxtdezPBS8+qgJDROLtCVcGb8N2Rr P0gA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=OtrAKvkMflYTL+omQBnC5NvMsnVi6sQ3TFEd0qd0ZG0=; fh=GHXKbtOfxidcL5p0HTnB6bho9FCoS3xq7NN3kpYT/tU=; b=GF0q+TLYt/ZRKH4tcWzzC8lpd1Aw9M0llG8Ec5FGP6gzXpAV4OjAWE8M5y9ZfqaT28 DQniL5xNAJvKB6uCHfWG0YRUV/FuU9pDNFtgaw+jhSPAh6NlW7wDA4CRgoZmTxGMXOCy TbkuZd+VQ/5y+F55YfpW82/srb5V0oSqSU2ArKN6MoLM7VEO11530+zDK8ZWgSVpxhrU TSJqJuNA6datnSbg3j+AP34z7Cr3uOQNsMprhPd9M7uVph4c2jfaOke97dEIOAcWZVTI lXffBxEn2xaEIfyVakN9WDy3xrLx5xlG9nH7cfq94aWd3M7r0uKIMOgiD2QM3LfsFXSE jlyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="O4T9lU/m"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id cu13-20020a17090afa8d00b002681fea6d14si5874273pjb.79.2023.10.06.06.47.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 06:47:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="O4T9lU/m"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 9933C804ACFE; Fri, 6 Oct 2023 06:46:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232565AbjJFNp4 (ORCPT + 99 others); Fri, 6 Oct 2023 09:45:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232545AbjJFNps (ORCPT ); Fri, 6 Oct 2023 09:45:48 -0400 Received: from mail-wr1-x449.google.com (mail-wr1-x449.google.com [IPv6:2a00:1450:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F397181 for ; Fri, 6 Oct 2023 06:45:35 -0700 (PDT) Received: by mail-wr1-x449.google.com with SMTP id ffacd0b85a97d-3217fdf913dso1583510f8f.3 for ; Fri, 06 Oct 2023 06:45:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696599933; x=1697204733; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=OtrAKvkMflYTL+omQBnC5NvMsnVi6sQ3TFEd0qd0ZG0=; b=O4T9lU/mURNyyyqIs88yj3Vtxog5kQ6+cPcru/PnqPMoyolZ6wtZtc8rQo4JLpRKc9 +mMS9cDF3VNgS3AAXQAtgZgwPDaGKRIKg3+xBZWlck3tHQzYGT7xeKY12NBzfIzyqV0e HkkJ0PKYvKlHsJLyBnyojVrtm6jIx+0gx8OkvZcuIh3e7dQ/ORcN3HeVh57MFyzzi7zO DlFakDhbZqzgZqJP/P0eMOT6ZCD8g/Ep7VcWgBRlGLsrm9mXFpqX4s7YDTF7K1OR3ZpL i+Vl4XdO6bT0VdZE5MwTTMZ6hVoYYAKqWs0aHXiAVhQCVAwA0KA7XpOhKQoJxPZofw8e B9Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696599933; x=1697204733; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=OtrAKvkMflYTL+omQBnC5NvMsnVi6sQ3TFEd0qd0ZG0=; b=QK6OchyUsxw4k9jLEhnPHcA3/ChKJaxy45O22R7Gk8WiE4I3jKrWpNnD6PzjbJInH+ XI0tVLAQDSiIyyq5xNlsmhkX2QDJxoKNiKRRk9l+vCn05MLLMlozWhHwFv8NLV9aSBvl eaqQj5E9GpBU8Z7wpz600Tg2PkXZWbXh625n7ZHLT0p/RPvhXcYVFCixPJn9RUJFC4CF ps6s89bndMmHAGYi3SuG5UI+pdljhedbVBZ4YD2okpFhM+OSjFuDrOHxM75sVFn6mtzw RconZ6gTkkUIeLmUHAztzKyfrNhv1K2G77weT20vKhEvEvbstG/Rx4NkVNpNCB5BOAi+ FVDg== X-Gm-Message-State: AOJu0Yy7duGhlwpI3Pm6/7Gpq2hLTJyDmk8h1AOiwUFZ0xMx/YaOj5Y8 aq7pgOiKSeDRRYYrDSW+OzbDeyRwUCk= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:2691:23e9:f01f:964]) (user=glider job=sendgmr) by 2002:a5d:6549:0:b0:319:8430:f801 with SMTP id z9-20020a5d6549000000b003198430f801mr52714wrv.2.1696599933422; Fri, 06 Oct 2023 06:45:33 -0700 (PDT) Date: Fri, 6 Oct 2023 15:45:24 +0200 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.609.gbb76f46606-goog Message-ID: <20231006134529.2816540-1-glider@google.com> Subject: [PATCH v6 0/5] Implement MTE tag compression for swapped pages From: Alexander Potapenko To: glider@google.com, catalin.marinas@arm.com, will@kernel.org, pcc@google.com, andreyknvl@gmail.com, andriy.shevchenko@linux.intel.com, aleksander.lobakin@intel.com, linux@rasmusvillemoes.dk, yury.norov@gmail.com Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, eugenis@google.com, syednwaris@gmail.com, william.gray@linaro.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 06 Oct 2023 06:46:00 -0700 (PDT) Currently, when MTE pages are swapped out, the tags are kept in the memory, occupying PAGE_SIZE/32 bytes per page. This is especially problematic for devices that use zram-backed in-memory swap, because tags stored uncompressed in the heap effectively reduce the available amount of swap memory. The RLE-based algorithm suggested by Evgenii Stepanov and implemented in this patch series is able to efficiently compress fixed-size tag buffers, resulting in practical compression ratio between 2.5x and 4x. In most cases it is possible to store the compressed data in 63-bit Xarray values, resulting in no extra memory allocations. Our measurements show that the proposed algorithm provides better compression than existing kernel compression algorithms (LZ4, LZO, LZ4HC, ZSTD) can offer. To implement compression/decompression, we also extend with methods to read/write bit values at arbitrary places in the map. We refactor arch/arm64/mm/mteswap.c to support both the compressed (CONFIG_ARM64_MTE_COMP) and non-compressed case. For the former, in addition to tag compression, we move tag allocation from kmalloc() to separate kmem caches, providing greater locality and relaxing the alignment requirements. v6: - fixed comments by Yury Norov - fixed handling of sizes divisible by MTE_GRANULES_PER_PAGE / 2 (caught while testing on a real device) v5: - fixed comments by Andy Shevchenko, Catalin Marinas, and Yury Norov - added support for 16K- and 64K pages - more efficient bitmap_write() implementation v4: - fixed a bunch of comments by Andy Shevchenko and Yury Norov - added Documentation/arch/arm64/mte-tag-compression.rst v3: - as suggested by Andy Shevchenko, use bitmap_get_value()/bitmap_set_value() written by Syed Nayyar Waris - switched to unsigned long to reduce typecasts - simplified the compression code v2: - as suggested by Yuri Norov, replace the poorly implemented struct bitq with Alexander Potapenko (4): lib/test_bitmap: add tests for bitmap_{read,write}() arm64: mte: implement CONFIG_ARM64_MTE_COMP arm64: mte: add a test for MTE tags compression arm64: mte: add compression support to mteswap.c Syed Nayyar Waris (1): lib/bitmap: add bitmap_{read,write}() Documentation/arch/arm64/index.rst | 1 + .../arch/arm64/mte-tag-compression.rst | 266 +++++++++ arch/arm64/Kconfig | 21 + arch/arm64/include/asm/mtecomp.h | 13 + arch/arm64/mm/Makefile | 7 + arch/arm64/mm/mtecomp.c | 524 ++++++++++++++++++ arch/arm64/mm/mtecomp.h | 12 + arch/arm64/mm/mteswap.c | 20 +- arch/arm64/mm/mteswap.h | 12 + arch/arm64/mm/mteswap_comp.c | 60 ++ arch/arm64/mm/mteswap_nocomp.c | 38 ++ arch/arm64/mm/test_mtecomp.c | 377 +++++++++++++ include/linux/bitmap.h | 68 +++ lib/test_bitmap.c | 118 ++++ 14 files changed, 1526 insertions(+), 11 deletions(-) create mode 100644 Documentation/arch/arm64/mte-tag-compression.rst create mode 100644 arch/arm64/include/asm/mtecomp.h create mode 100644 arch/arm64/mm/mtecomp.c create mode 100644 arch/arm64/mm/mtecomp.h create mode 100644 arch/arm64/mm/mteswap.h create mode 100644 arch/arm64/mm/mteswap_comp.c create mode 100644 arch/arm64/mm/mteswap_nocomp.c create mode 100644 arch/arm64/mm/test_mtecomp.c -- 2.42.0.609.gbb76f46606-goog