From patchwork Fri Nov 3 16:03:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 13444678 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 31C62C4332F for ; Fri, 3 Nov 2023 16:04:27 +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=vgGgA82BMTE5W4XamjWiuMQHx3QJrwGJcDFOBmlLvRU=; b=hbd SiZHgbV6BQKSiA3h2p1VE5WSOQ23EH+CEWxa+NCQFk2ogyTkcVTQK3GYWmttzQaqiepDcV/daeToh DoeHzw1CPKdDbxVsfckLteTXJga2ZjLPP1ytX2JH8hp7WVZ5DdclWqkaIrY8tX9KNrMLf9RwGA7uP QRcMRFxscGqxUUs2ItbnoXVOp8mcMxEWvllL9npXWO+Ue4tEWl5u9ZoqqvRl1pXeqKHDmHZcQQ3/s wMWi+dfVcp0msOYZAcPCIwJzWMHNErL0VVcPF6EXYfP9RQuo94PI0+BXqvOTxd1Qpd7JA1GnopjmP fAHl8iROeAlrLmbb4+on2hWXlzG2BeA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qyweA-00BkpB-1H; Fri, 03 Nov 2023 16:03:46 +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 1qywe6-00BknN-28 for linux-arm-kernel@lists.infradead.org; Fri, 03 Nov 2023 16:03:44 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5b053454aeeso31081197b3.0 for ; Fri, 03 Nov 2023 09:03:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1699027419; x=1699632219; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=gTzXxPv+gObuuXQua2/KBmP4Hxk1HM7FnDHk5jUfbw4=; b=pgJS/+jgpX/YpOgbcTXvWGDonN/m0LzUgZEZ3psaSZkFrfIirUDzuARyhnxSk0pkcM dOYE5JuHJjmkbplmZnxS08gfKJRAlcb1Il4TtUlzNgR1TpGgj28gvlIjrquAAzn4oQH3 vzaOCSSp8qMQ9YV2qZu6JIr+BoPWh6m+NybpQGOUhoQGUpccMT0Trj22PRzkwVxDnJxr lIxJfvanLqFYh+lKoh2ehjxTs6iemfTqgy15IJZK7wAxVcUPW9jGk5sAm3DBrQB5qXF7 GsSscQYrh9WIvjLEOn85hgJClbXCk73Hc+444cS9PLB4rXMHx3V60S/m2xg/CkCzSyaA u5Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699027419; x=1699632219; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=gTzXxPv+gObuuXQua2/KBmP4Hxk1HM7FnDHk5jUfbw4=; b=fbJAgaPG5hHTqIRHTX1KkghCSza1IE2CG/z1C9lcWeC0OjaXyOkSjMJPWoOSv9+McD S8KNT/wxkAs82kdD3pocv1leKp9PerGiyqOHAPUCVKvarwbPZaDdfWJqFRyKuOytiLVU wZhEAfIJbyp05SZbTsY1KihTXuYcNJsr4xyK7TQr7j8W+4Jhde8qUS/MJaTrg+Gz/MlK kCUx09Nv1ft+w/USFujponWyvsh8Jz4skSFCLIcy/pxZrwH4Rsn5oIwfeEYM0R5mL2Hd 1VzR9A0NCdeoCEqvh8iteSje1tqFZXiw2spm8i//XAnPi7e2cgnJrpaTnYtXMMntHIFD P/Vw== X-Gm-Message-State: AOJu0YxBKfwAXx23/Gbcl3tmNhrHjVZJQX49B+6Y8vL9CGub6QxZqpl3 lpsCCBLVSXC1YjwnAtH/TjraCk+aV8E= X-Google-Smtp-Source: AGHT+IHMdfpUDNksgB/Anwg08XNWUFG0UAqwDQelIsUFZSICwXGPRzrG+IYrnbhm1ObmCNhZXQ0QXsqhIJY= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:74c:1f8e:4661:7aaa]) (user=glider job=sendgmr) by 2002:a25:488:0:b0:da0:5452:29f7 with SMTP id 130-20020a250488000000b00da0545229f7mr425792ybe.4.1699027419431; Fri, 03 Nov 2023 09:03:39 -0700 (PDT) Date: Fri, 3 Nov 2023 17:03:32 +0100 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Message-ID: <20231103160335.2464561-1-glider@google.com> Subject: [PATCH v8 0/3] 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, alexandru.elisei@arm.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-20231103_090342_697600_6273D036 X-CRM114-Status: GOOD ( 15.86 ) 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: , 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 of 2x. In many cases it is possible to store the compressed data in 63-bit Xarray values, resulting in no extra memory allocations. This patch series depends on "lib/bitmap: add bitmap_{read,write}()" (https://lore.kernel.org/linux-arm-kernel/20231030153210.139512-1-glider@google.com/T/) that is mailed separately. v8: - split off the bitmap_read()/bitmap_write() series - simplified the compression logic (only compress data if it fits into a pointer) v7: - fixed comments by Yury Norov, Andy Shevchenko, Rasmus Villemoes - added perf tests for bitmap_read()/bitmap_write() - more efficient bitmap_write() implementation (meant to be sent in v5) 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 (3): arm64: mte: implement CONFIG_ARM64_MTE_COMP arm64: mte: add a test for MTE tags compression arm64: mte: add compression support to mteswap.c Documentation/arch/arm64/index.rst | 1 + .../arch/arm64/mte-tag-compression.rst | 154 ++++++++ arch/arm64/Kconfig | 21 + arch/arm64/include/asm/mtecomp.h | 39 ++ arch/arm64/mm/Makefile | 2 + arch/arm64/mm/mtecomp.c | 257 +++++++++++++ arch/arm64/mm/mtecomp.h | 12 + arch/arm64/mm/mteswap.c | 88 ++++- arch/arm64/mm/test_mtecomp.c | 364 ++++++++++++++++++ 9 files changed, 934 insertions(+), 4 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/test_mtecomp.c