From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 87CB8CD4F2E for ; Fri, 22 Sep 2023 08:09:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: Mime-Version:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=/0L1MOSW8JXTcX/p9VkV4LnHlbhAn3b/wgUeInVu6hw=; b=qFV zBweqntv7YUlwD8anlxM0zEJkCpukhvX/mFhvfuRTZIFmQgKZYFIN0BArpy/wwVoOg30tLbAYjdSc fJYME/scvkzIpmwTz5quGyxTuLzllE092pzpneWdoMXcDEI8+ebhh4TD1t111je0N7X7g1wntI6Sl 9++BHtC1B6LuoS/28k+2JANxv/bA0t9se2MVktEegtNxW5Fc/ttSNienZQMw+CkNSuRHjv08fabu/ cy15z06lniG3menwynnmoYE34eeA0KAJC+E/PzZ/zWmPvLnn7qUOsiG2JstvgTNA4t0aZ/sThJlc0 tRki9FY4Jf44JW6CtV6cDWXlXh72L3Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qjbDd-008LdQ-2O; Fri, 22 Sep 2023 08:08:57 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qjbDa-008Lb3-1j for linux-arm-kernel@lists.infradead.org; Fri, 22 Sep 2023 08:08:56 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-59e758d6236so26959027b3.1 for ; Fri, 22 Sep 2023 01:08:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695370132; x=1695974932; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=R4vswqebvpspbaowrRGzYOJlYeKRdv743foMaraS4cU=; b=cgal/bqQQyVHopXiGUEbnefph/gWjBJhUDsk2H6U8lFkC1JdgmtskOJGgPrpS1VDbv 2IDz0B/tm4X9AuDK8cc/QFP5HK0GPplCgWfQI4pgiFvfVVGvs9IDuSR57Lm3STRhyyNh d3+VxkwPuaJH3l3jv3LA3BjB73uJksWOn6AS+ZkK575IiK0p0E5ODMjZuqEl6Bdz6HJi vZMixp7Vl8D88FafUjouu4sHVdiQtPKruzPMZ/UBCXj2jZzotYKkYq1rKP3QFKHHCVhh ODVsL5HCR0p8VvMqWK1dQTCWLgGK55M/vcDHLhncosPboW6A6oUZKQ9xLaBdCKyU+MGH HwMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695370132; x=1695974932; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=R4vswqebvpspbaowrRGzYOJlYeKRdv743foMaraS4cU=; b=JwOmPCM8IIM3jHPKcyaazZNmi9NTAOBWoAv6vUq6TXFn09BVSrS1rQ/TsTceE7a1Gs Sn1pIdkMmjTQNddybGjVM0Bbu/1JkObOrvjv2xQvbhZEt+dbAFtRhiOhUkVZ6f4Zls2F CKYAvne01UNgRiUebOD3PNLwi4mAA3RK2LU9rQX5i9wfqOHDQeoHygGwYTJ3PH3cMuMe 0nbs4xddIHDmp2TqWfaPIZ2p4imH3cdTQEi1Jz8D5CM6aVTbEZEudRvR8uhG66HCxvFf TNfch1LBQEPabnSrcazN9m2Ys8Aezb1qjzy89FeMMrkf8Y8zl1OxQROEdgaXUQQ1LmRU 1LAg== X-Gm-Message-State: AOJu0YwN93KlVkCN50m1U9HvVAJB9/YZVmyDxKl4zA4bGDgvROz3F7HA GDc4YAYyCe7Ks09CNZuBACQCwf95re4= X-Google-Smtp-Source: AGHT+IGiDnMlo8gIzd5NqRZ/HkqDSPWlC0atM2jbQjQWc3jmvV9CTqTdBrKz6RhUPrTffre1wurvCgcosPs= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:4da0:80d4:9480:7d5c]) (user=glider job=sendgmr) by 2002:a81:ae68:0:b0:59b:e663:23b9 with SMTP id g40-20020a81ae68000000b0059be66323b9mr113127ywk.1.1695370132027; Fri, 22 Sep 2023 01:08:52 -0700 (PDT) Date: Fri, 22 Sep 2023 10:08:42 +0200 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.515.g380fc7ccd1-goog Message-ID: <20230922080848.1261487-1-glider@google.com> Subject: [PATCH v5 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, 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230922_010854_575947_90B9337D X-CRM114-Status: GOOD ( 16.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. 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 | 245 +++++++++ arch/arm64/Kconfig | 21 + arch/arm64/include/asm/mtecomp.h | 13 + arch/arm64/mm/Makefile | 7 + arch/arm64/mm/mtecomp.c | 467 ++++++++++++++++++ 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 | 287 +++++++++++ include/linux/bitmap.h | 68 +++ lib/test_bitmap.c | 115 +++++ 14 files changed, 1355 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.515.g380fc7ccd1-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0306BCD4F2B for ; Fri, 22 Sep 2023 08:08:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232265AbjIVIJB (ORCPT ); Fri, 22 Sep 2023 04:09:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231888AbjIVII7 (ORCPT ); Fri, 22 Sep 2023 04:08:59 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC812197 for ; Fri, 22 Sep 2023 01:08:52 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-59e758d6236so26959007b3.1 for ; Fri, 22 Sep 2023 01:08:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695370132; x=1695974932; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=R4vswqebvpspbaowrRGzYOJlYeKRdv743foMaraS4cU=; b=HWFEGK1dWuF3ovte4SwuuaomIvyhgIyv83FNLdlXLzPz89rOcGKvc7mujLW2vekAon BgtmpmnOUJkOntvzzN/dKUKmIhw68PWwv1TW07Gx/bZIRk8gmzryXtOa+S+V7/7HRZRL iRFTKYob260qJWlz23fbvcyiMgVh0CCG9HS2P7NqTFy12+nI9hjbSYUyJdJAlQMXPy1D YA7hu2RT0yM8CGqjXGdFhvDcM6TASUqSZXg/jfT/UTKt8uN3v7DwvPVvKDp3vTcqM3jZ 7mu9E7tJzeufyeeb7qGxDl+bQHjhk4b12vXEmiFzJBKweMtFIaS7cJOLIvxmY6Kbd/Hh eAmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695370132; x=1695974932; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=R4vswqebvpspbaowrRGzYOJlYeKRdv743foMaraS4cU=; b=YYBCQAtZ6zAT1XZVdVnorFFWuiq2uKKlpVKN9r+CSgOFxtNIYfVCdkAiaOZ/LHhvNY 8stWAxgC8Q206dFIQsGEDzv86vBQ3qpqAihgl28z5WhB9GDsFj7C0gqU4eTJgDq7CC9i 5ZsZK4tr5ysOlKC2N1CDlxQPfTHwDWRHtPg9USEqZdGTn6TKoGJdSasuyMsMYl4CCroO KgefIilUGGd00DuHKe/xCI9KJms8OwHY13tEcU7dQHZi6U821zMbZ01iEkvJLuXDjlBK wGCHyrkvCpNI3XlmVy3wKhNfbXBT7BmnsQ5wFKNXstcKiWY03tUA9reQHDW3pu2wDkvP A5xA== X-Gm-Message-State: AOJu0Yxs5sm7BIvbQF4TotRAFNkPtP47BlH/cgQQH9E3hgYqkXK6CyE3 pD4yKHxJuItObsc7XqcziJbbi+HNjX8= X-Google-Smtp-Source: AGHT+IGiDnMlo8gIzd5NqRZ/HkqDSPWlC0atM2jbQjQWc3jmvV9CTqTdBrKz6RhUPrTffre1wurvCgcosPs= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:4da0:80d4:9480:7d5c]) (user=glider job=sendgmr) by 2002:a81:ae68:0:b0:59b:e663:23b9 with SMTP id g40-20020a81ae68000000b0059be66323b9mr113127ywk.1.1695370132027; Fri, 22 Sep 2023 01:08:52 -0700 (PDT) Date: Fri, 22 Sep 2023 10:08:42 +0200 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.515.g380fc7ccd1-goog Message-ID: <20230922080848.1261487-1-glider@google.com> Subject: [PATCH v5 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, 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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 | 245 +++++++++ arch/arm64/Kconfig | 21 + arch/arm64/include/asm/mtecomp.h | 13 + arch/arm64/mm/Makefile | 7 + arch/arm64/mm/mtecomp.c | 467 ++++++++++++++++++ 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 | 287 +++++++++++ include/linux/bitmap.h | 68 +++ lib/test_bitmap.c | 115 +++++ 14 files changed, 1355 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.515.g380fc7ccd1-goog