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 900BFEB64DC for ; Tue, 11 Jul 2023 14:33:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233070AbjGKOdw (ORCPT ); Tue, 11 Jul 2023 10:33:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232810AbjGKOdt (ORCPT ); Tue, 11 Jul 2023 10:33:49 -0400 Received: from mail-ed1-x549.google.com (mail-ed1-x549.google.com [IPv6:2a00:1450:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10B33BB for ; Tue, 11 Jul 2023 07:33:48 -0700 (PDT) Received: by mail-ed1-x549.google.com with SMTP id 4fb4d7f45d1cf-514b3b99882so3633704a12.2 for ; Tue, 11 Jul 2023 07:33:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689086026; x=1691678026; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=VGRLS9PZfnsNdW8E7+rt3QYOMitkf0dfb3D8ONqanVU=; b=ACM+cmGPaftl+r3a03wCYTyz2PTNsij/STVLE0V1vKEw3eDekfjR2QqscyUvAcrHV3 QGkpbdnQNoqC975Ln+UEnAT8MAFdiF7vk8wpKVcOjwCMJPgCiUT3Z4Loe0Qrcu0RgJkt cMhJU1XgJyJznWvlLYniCeM+vUrEe1caZbLfkbgRFTu2S0OvU1IS+QOIfUAhO9o7et0A i5oKV90GR6Av8ruuPsx32GRhKe4GRqhxmdmkntNNXPEIqb7g/fjMNp+Wd5jatboPFKjA fus/lzZ24m9bSMyr98fSmlv1TxZOLLqGkAmuMg815NfxzMDvgWaEgBcrghFvygJFuET1 OZZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689086026; x=1691678026; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=VGRLS9PZfnsNdW8E7+rt3QYOMitkf0dfb3D8ONqanVU=; b=LW8IuVOg7dte/qTZDsriI/5XqsJ2WPQn0/NPnEy1zr3r8LeseZ7IMAB9P1XEGfeU0r Fi75lEyaDOYWhHuYBcN71CT8Tiby80KibHeFYTQyu1z2qMJSjA6hqyO+Y6LCIcVl1Gp0 MxCLfo95lEWWWQVT/03yzjdmdg5EZbiye/QaN3B6Zx+/RgBtdrldzzI5VhjJIXRtL2e4 MPIsSGkfBRRt/skR4G3lEmc1yz2BGMIM1rrcG62gpMiITqJBqsRq17hgktvK+aKke+I0 1wRx01B5AFVXKsECj6HL8B01gWVt0r5LANVedf3N2llYWtLLDNlvYdG3jfU605SKvEVP cwGA== X-Gm-Message-State: ABy/qLZSGNwPIpXSCJGEKa/9OblQ9HHJXknFj/jij42wrXTSolokB8qL KC7buPSi62bLLAvEzcZVQfWO18or1w0= X-Google-Smtp-Source: APBJJlEc2CXHpERZgeEynf388KWaCCGl5zbXJJ2YYem5Q9YuIP0R6kODxnUyy5vGIV8WQAS14Zxnx8YEWQg= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:564d:3aaa:6b5f:4419]) (user=glider job=sendgmr) by 2002:a50:bb67:0:b0:51e:164c:5444 with SMTP id y94-20020a50bb67000000b0051e164c5444mr48540ede.8.1689086026234; Tue, 11 Jul 2023 07:33:46 -0700 (PDT) Date: Tue, 11 Jul 2023 16:33:27 +0200 Mime-Version: 1.0 X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230711143337.3086664-1-glider@google.com> Subject: [PATCH 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 Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, eugenis@google.com, yury.norov@gmail.com 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 128 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 EA0 algorithm suggested by Evgenii Stepanov and implemented in this patch series is able to efficiently compress 128-byte tag buffers, resulting in practical compression ratio between 2.5x and 20x. 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 EA0 provides better compression than existing kernel compression algorithms (LZ4, LZO, LZ4HC, ZSTD) can offer, because EA0 specifically targets 128-byte buffers. To implement compression/decompression, we introduce , which provides a simple bit queue interface. 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. Alexander Potapenko (5): linux/bitqueue.h: add a KUnit test for bitqueue.h arm64: mte: implement CONFIG_ARM64_MTE_COMP arm64: mte: add a test for MTE tags compression arm64: mte: add compression support to mteswap.c fixup mteswap arch/arm64/Kconfig | 20 ++ arch/arm64/include/asm/mtecomp.h | 60 +++++ arch/arm64/mm/Makefile | 7 + arch/arm64/mm/mtecomp.c | 398 +++++++++++++++++++++++++++++++ arch/arm64/mm/mteswap.c | 19 +- arch/arm64/mm/mteswap.h | 12 + arch/arm64/mm/mteswap_comp.c | 50 ++++ arch/arm64/mm/mteswap_nocomp.c | 37 +++ arch/arm64/mm/test_mtecomp.c | 175 ++++++++++++++ lib/Kconfig.debug | 8 + lib/Makefile | 1 + lib/test_bitqueue.c | 244 +++++++++++++++++++ 12 files changed, 1020 insertions(+), 11 deletions(-) create mode 100644 arch/arm64/include/asm/mtecomp.h create mode 100644 arch/arm64/mm/mtecomp.c 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 create mode 100644 lib/test_bitqueue.c -- 2.41.0.255.g8b1d071c50-goog