From patchwork Mon Sep 2 04:41:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13786700 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98BC5C54FC6 for ; Mon, 2 Sep 2024 04:41:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A50D18D006D; Mon, 2 Sep 2024 00:41:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A024D8D0065; Mon, 2 Sep 2024 00:41:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A1C68D006D; Mon, 2 Sep 2024 00:41:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 6B9118D0065 for ; Mon, 2 Sep 2024 00:41:35 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id D737781955 for ; Mon, 2 Sep 2024 04:41:34 +0000 (UTC) X-FDA: 82518549708.30.05B3D76 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf19.hostedemail.com (Postfix) with ESMTP id 361DB1A0009 for ; Mon, 2 Sep 2024 04:41:33 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="Tbm/JmYu"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf19.hostedemail.com: domain of 3_EHVZgYKCBMBDAx6uz77z4x.v75416DG-553Etv3.7Az@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3_EHVZgYKCBMBDAx6uz77z4x.v75416DG-553Etv3.7Az@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725252070; a=rsa-sha256; cv=none; b=OaY7qAZbhbmHbz6v42qC95cFhYySMPt6tXBfZNR8PnF0n9rOYhjNAXHmCVPdERMxUf55Rj nJD7BN6Y9DYOcfK//WqbqNKZ6mJ6ZpL+80qypPM4boCM6/en3Hiewo1oPpcjXHU4pfu0jB Ms9DVS1uYTqcAZR/DoQFjSDEVffkgxc= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="Tbm/JmYu"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf19.hostedemail.com: domain of 3_EHVZgYKCBMBDAx6uz77z4x.v75416DG-553Etv3.7Az@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3_EHVZgYKCBMBDAx6uz77z4x.v75416DG-553Etv3.7Az@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725252070; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=T+xLud21hrQ5yA1EN2qeiMEzMSrTdr6OveRNrXJfwOw=; b=MNO9XcyZocpHoPAxKKspbAMCnLWfJrYV8vEtyEFsjSyHykpmSP0Vk7C5d/vARdUKuJBI9+ VREvnfJlpvw4j8MMqvFPttT3Sp5N08r72iuORfDwIs/wvAY2rD2afGZLGatKsChNmhESXi dKVlw2tAN5JGmdqVUIhcVyuKfJq6UJI= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e1aa7ef2c65so1848954276.3 for ; Sun, 01 Sep 2024 21:41:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725252092; x=1725856892; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=T+xLud21hrQ5yA1EN2qeiMEzMSrTdr6OveRNrXJfwOw=; b=Tbm/JmYunwBPPqXK3yx9ctIxt2MqYSfLFyq2dJ3XSgQZUSlK1UCRh1Df0qzcDWrfFI 2VBT2Ar5Mxr+yejW8QzMYO1jYfsX0XeEponcx9HGFkV1l3OoDhk/EIdtjvn5z1u59Rn4 f7yMxoy9rznAIxdFn4LZlyvb14GBC9SO2M7pAc4au78Paq+NRMNOyFgR0NG84mC7SGrm BwLP3VFEFR+kW2ZTzp81Ied70k35xKRudt17B0o2iJKVegb+ngVaLwOKIW4cZlX77VDu /DyCNDdAw9lxjlQ17/1BiWmmuE+hmDx8uwXni/0Ca/UD3Tl8miJ6RXEECZBMTcVrwagn u4AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725252092; x=1725856892; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=T+xLud21hrQ5yA1EN2qeiMEzMSrTdr6OveRNrXJfwOw=; b=C/AtgWT5BGGwZ/gKT5JmHm0nM/IUau/J+KeE6N5xrjiomvyqE1iKRSlnl4rDWVr9F/ u9zgNprGZVDrpGrxBUide261pIBZDaR1SYMFQzdLkSscAZYglY0EuWDd1BrQ/DFwUPP3 vKQ45f65Rzgy8d0m0TfhzDmj4k04t/mYqs8aX4NiXuuLcwaRzzWp+MOsexoiCB7jEcXt Cvjdk0y51NSHjc1ijula45UNe7yY75zkGE22zXTovFOILjMX1ec336Hc9os0xUYag/Gx mnSoSECEzgkpq+PY3EQVWfGpS9M4/qm++47Cz/Ly5JITLQAUAMvEDuYOuC6RlvmIRxb3 DsDg== X-Forwarded-Encrypted: i=1; AJvYcCUcsCVUn6gy9ZBrM0nCv4jFuF4S+nnHFs37L/d2KrDtjsVowKV7KtWSazQDTciDF+M0wK34DHUo0Q==@kvack.org X-Gm-Message-State: AOJu0YwnDV+2Gqew5txpHAa3XNtaxJTapSQG2N8EZRhjdhY2mibsPLzA 615eX37x2mZHNSaAEq/1/9xcJG0gpflzyjLWZRT3MB7dlTz5518L7wih7GYIYvaKXxdGT6G78C9 mbg== X-Google-Smtp-Source: AGHT+IEtE0kPr6IIFRldaKi06F+5QIrTC4yNkT2oW719Q3CsdKB0l7HveLeFNrmbQ3s+nnJWshQtc5hKBEM= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:7343:ecd2:aed:5b8f]) (user=surenb job=sendgmr) by 2002:a25:99c3:0:b0:e0e:87f7:f6d3 with SMTP id 3f1490d57ef6-e1a7a1cfec1mr370503276.11.1725252092109; Sun, 01 Sep 2024 21:41:32 -0700 (PDT) Date: Sun, 1 Sep 2024 21:41:22 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Message-ID: <20240902044128.664075-1-surenb@google.com> Subject: [PATCH v2 0/6] page allocation tag compression From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: kent.overstreet@linux.dev, corbet@lwn.net, arnd@arndb.de, mcgrof@kernel.org, rppt@kernel.org, paulmck@kernel.org, thuth@redhat.com, tglx@linutronix.de, bp@alien8.de, xiongwei.song@windriver.com, ardb@kernel.org, david@redhat.com, vbabka@suse.cz, mhocko@suse.com, hannes@cmpxchg.org, roman.gushchin@linux.dev, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, pasha.tatashin@soleen.com, souravpanda@google.com, keescook@chromium.org, dennis@kernel.org, jhubbard@nvidia.com, yuzhao@google.com, vvvvvv@google.com, rostedt@goodmis.org, iamjoonsoo.kim@lge.com, rientjes@google.com, minchan@google.com, kaleshsingh@google.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, kernel-team@android.com, surenb@google.com X-Rspam-User: X-Rspamd-Queue-Id: 361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PwtYzvup8uCN0KdL5x1jDK22nk9sul4rDUXjZMskYCFiVCeyoZ1t+2ugMdsFzSmrb0vZUB+IPfumqilhWE5Wt4O2i3VjlD2c1WkYD1DIJokbicrWP3vGK0mOrW+Lb5T8V10+M0uZ2gWTjq5WrCNlIwlpwA1eKtP6mHDRSSeNOPrdVeOWl6hWAAFB90oaydbYmeIub67gQ1D5/cm39bTQHH1d9zWhPI5J9eO6EfrfAdYRsb6egJigb32qjNs5m2jloUt+JVSWKVJARMHfhUIu1ry7x8CcuC34WVl8GT7cHp3r0nLofz/fJRgpbKifRi7tXu5SAA4dV/wnzWb22eATDBu7eRtGAAP4KFjviS3bfcYI1rPDRmZmFJgj9hEgSbC42E6MshMK79qsNsauaLV9wFZ17SRLteZ37A2GSvbFu5v33FMJp0j/+oHs9QV2EVwZtiLABGmObAco2QaD32Fwn64gDbZq1tekJJkGy2dNdZGiE96bFqPGzahf37ABodknrRvML9lafLAHhuBy+a1u33UkZp/dkxHxFhfjQjmx3lUTLWY6vzev0+JQEHTlSC4KZVN0x X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: This patchset implements several improvements: 1. Gracefully handles module unloading while there are used allocations allocated from that module; 2. Provides an option to reduce memory overhead from storing page allocation references by indexing allocation tags; 3. Provides an option to store page allocation tag references in the page flags, removing dependency on page extensions and eliminating the memory overhead from storing page allocation references (~0.2% of total system memory). 4. Improves page allocation performance when CONFIG_MEM_ALLOC_PROFILING is enabled by eliminating page extension lookup. Page allocation performance overhead is reduced from 14% to 5.5%. Patch #1 introduces mas_for_each_rev() helper function. Patch #2 copies module tags into virtually contiguous memory which serves two purposes: - Lets us deal with the situation when module is unloaded while there are still live allocations from that module. Since we are using a copy version of the tags we can safely unload the module. Space and gaps in this contiguous memory are managed using a maple tree. - Enables simple indexing of the tags in the later patches. Preallocated virtually contiguous memory size can be configured using max_module_alloc_tags kernel parameter. Patch #3 is a code cleanup to simplify later changes. Patch #4 abstracts page allocation tag reference to simplify later changes. Patch #5 lets us control page allocation tag reference sizes and introduces tag indexing. Patch #6 adds a config to store page allocation tag references inside page flags if they fit. Patchset applies to mm-unstable. Changes since v1 [1]: - introduced mas_for_each_rev() and use it, per Liam Howlett - use advanced maple_tree API to minimize lookups, per Liam Howlett - fixed CONFIG_MODULES=n configuration build, per kernel test robot [1] https://lore.kernel.org/all/20240819151512.2363698-1-surenb@google.com/ Suren Baghdasaryan (6): maple_tree: add mas_for_each_rev() helper alloc_tag: load module tags into separate continuous memory alloc_tag: eliminate alloc_tag_ref_set alloc_tag: introduce pgalloc_tag_ref to abstract page tag references alloc_tag: make page allocation tag reference size configurable alloc_tag: config to store page allocation tag refs in page flags .../admin-guide/kernel-parameters.txt | 4 + include/asm-generic/codetag.lds.h | 19 ++ include/linux/alloc_tag.h | 46 ++- include/linux/codetag.h | 40 ++- include/linux/maple_tree.h | 14 + include/linux/mmzone.h | 3 + include/linux/page-flags-layout.h | 10 +- include/linux/pgalloc_tag.h | 287 +++++++++++++--- kernel/module/main.c | 67 ++-- lib/Kconfig.debug | 36 +- lib/alloc_tag.c | 321 ++++++++++++++++-- lib/codetag.c | 104 +++++- mm/mm_init.c | 1 + mm/page_ext.c | 2 +- scripts/module.lds.S | 5 +- 15 files changed, 826 insertions(+), 133 deletions(-) base-commit: 18d35b7e30d5a217ff1cc976bb819e1aa2873301