From patchwork Mon May 6 08:46:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13655143 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 11800C25B5C for ; Mon, 6 May 2024 08:46:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5DB1D6B007B; Mon, 6 May 2024 04:46:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5B2096B0085; Mon, 6 May 2024 04:46:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 319E16B0082; Mon, 6 May 2024 04:46:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 0DCF16B0082 for ; Mon, 6 May 2024 04:46:52 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 84762A12B4 for ; Mon, 6 May 2024 08:46:51 +0000 (UTC) X-FDA: 82087340622.06.87E6AC4 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) by imf03.hostedemail.com (Postfix) with ESMTP id 1595620013 for ; Mon, 6 May 2024 08:46:48 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=t+giJnFs; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf03.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.99 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714985209; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=aUMYxLX2kFmWpJjpY9eym1HX2xADFAvHPfRUdrhEgnE=; b=6GNLCv256AAA3go4b58Tr9fwiwTJsv4bAm+xcHPyUnULaphYHDW7oBiswZrQChF7pXNOC8 oOAk/JjSDBhlOwTACKzkd84+yc/Ka9re2x+f6CPfIJYztFSTJDznY2HlroMXm4UfAbI58P enHurQeFule2V4lTb1EGrx1Uj4SwnnY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714985209; a=rsa-sha256; cv=none; b=V85XYcWmU0GvbnqZfmqxmkDx/G7RbryY0tbN8oFjuRmwy6lSFmi8zrTCT8EPs0OUjvUYKr I7vlrIyWMRYY2IoOwBMFjrSLduTrE4LpfyeHxbNFNaU3md2DezpRJHCYZw+omOb3CWpHY6 +f560/4HRHJwXXT1/N4dioPMMgqJlaA= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=t+giJnFs; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf03.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.99 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1714985205; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=aUMYxLX2kFmWpJjpY9eym1HX2xADFAvHPfRUdrhEgnE=; b=t+giJnFs/al3gDway/V6kd19m2l895VJ+FuYqCZ1CpSWSVS02mED7ZGrywBOnwV8VzjxqOCIdORk+mAJlUVYelBowf97LIV18Flnq+j6cbOaP+RxyDmBBlTFxahp9cYUjynce9Q74TBbIob5ZPZLNK8qqW3xwX/JEtvwNQTNmcY= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R341e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033068173054;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=14;SR=0;TI=SMTPD_---0W5weiIc_1714985202; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W5weiIc_1714985202) by smtp.aliyun-inc.com; Mon, 06 May 2024 16:46:43 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: willy@infradead.org, david@redhat.com, ioworker0@gmail.com, wangkefeng.wang@huawei.com, ying.huang@intel.com, 21cnbao@gmail.com, ryan.roberts@arm.com, shy828301@gmail.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 0/8] add mTHP support for anonymous shmem Date: Mon, 6 May 2024 16:46:24 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 1595620013 X-Stat-Signature: qot4wuozxhti7k4efewkhse78d3s36gw X-Rspam-User: X-HE-Tag: 1714985208-897830 X-HE-Meta: U2FsdGVkX1/VzSv1DnuXZ7ZY8T89vfGMIOy1uT0sGQ3oHVXR8IffBvGpRPcXPgq3RB4CCgargpH1n5Qm25ofdkWNN13mF7R4yiiVqXyDQ7dXY9MeppSnvgswZrpcTCF1iwoq2RKmm6sk0PqC5ATZouFhO1PwQztt//E7JjJxbyRh0WeovhBwbJHQczQVUHVouL4kGWDTOGK6WBIsKTtwDWYrlN47RqcCvfxsOHIat8hECkN/SV+DdZnLbpdWkE1zQE0KV4GTWEp/5tjc0Rgu8ylZBZQH2DErtz6OHPQM74xCTOk3GoSi8ybLOOQJQ/+/BJXxO+us1GiQA6Nju8SkVfrpDRDYws6lDcMBhrKqInO/A+re5C9QDwcNM8OCvapi70b5RR/xccRT3eOx/kvpH9TV3K//LgmXdImmsCOvUJf+xS0gnQoadwmivp7rpypMnJMMYgA0aK+KBM0IfI282s91CItwkW4ljetWor8ezK7FmUGCwEmAH1UqZKoEGyKcEpuHUc9dHmi7k1GqIxk2LlCd9hylbTQsZjlE6vBcw17LlyzjxCbq2orRLQna9SQZBnBmdFsdgJYwcLwrBDMc631QHMLyd62Mb2HJRQwTEAM0Kj+Gslvm+b9PQ++ZZtWaz2Jom4m2lGV/M6shMNse8clLa5PJNZ/zx+Ujbdq4y+KOhZiKc0uRBxC6hsEW39CPODt6I//BJ0LxhZFIKZ/sp1jlqjJDXcr5PKJqszse1mpD1OBSQFGpLH0yZCnwspaLbXsDALLkuo87MzegWuqdT0zP6TF4AyKCff0NNzBssB2WddDd5o2+QIx0vI/esupcU9uaMzQlGL0PiaqZaJapoMQsgXe2FtYMRo/Gaap+C3+PvpQyUwqyVy3fOd/QaSgYIT/Bl7O3XhTuy36hWXR4vUjOvVNlLSHPbygcPKVq0hFa+my0FAnrd9yQWSnEofDNj9Gg0g8r7kemZxpvHF7 Fgrggsom NHu5dpcqG9cIGOiwPTvSOEbc6Yw8DCMAdMLZs/mRvRFGtqZjz2JkUOPF7QA7v+oUmFHPhzpF4whRgIB1MA1bK6Xy21VPfZ3BgC7B/3MyWqwmes1tOIv1gC59iZ24vi6AVFEY5PXqcLtlHA7lchmCn+GJtUGjWPKQ9/JYh 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: Anonymous pages have already been supported for multi-size (mTHP) allocation through commit 19eaf44954df, that can allow THP to be configured through the sysfs interface located at '/sys/kernel/mm/transparent_hugepage/hugepage-XXkb/enabled'. However, the anonymous shared pages will ignore the anonymous mTHP rule configured through the sysfs interface, and can only use the PMD-mapped THP, that is not reasonable. Many implement anonymous page sharing through mmap(MAP_SHARED | MAP_ANONYMOUS), especially in database usage scenarios, therefore, users expect to apply an unified mTHP strategy for anonymous pages, also including the anonymous shared pages, in order to enjoy the benefits of mTHP. For example, lower latency than PMD-mapped THP, smaller memory bloat than PMD-mapped THP, contiguous PTEs on ARM architecture to reduce TLB miss etc. The primary strategy is similar to supporting anonymous mTHP. Introduce a new interface '/mm/transparent_hugepage/hugepage-XXkb/shmem_enabled', which can have all the same values as the top-level '/sys/kernel/mm/transparent_hugepage/shmem_enabled', with adding a new additional "inherit" option. By default all sizes will be set to "never" except PMD size, which is set to "inherit". This ensures backward compatibility with the shmem enabled of the top level, meanwhile also allows independent control of shmem enabled for each mTHP. Use the page fault latency tool to measure the performance of 1G anonymous shmem with 32 threads on my machine environment with: ARM64 Architecture, 32 cores, 125G memory: base: mm-unstable user-time sys_time faults_per_sec_per_cpu faults_per_sec 0.04s 3.10s 83516.416 2669684.890 mm-unstable + patchset, anon shmem mTHP disabled user-time sys_time faults_per_sec_per_cpu faults_per_sec 0.02s 3.14s 82936.359 2630746.027 mm-unstable + patchset, anon shmem 64K mTHP enabled user-time sys_time faults_per_sec_per_cpu faults_per_sec 0.08s 0.31s 678630.231 17082522.495 From the data above, it is observed that the patchset has a minimal impact when mTHP is not enabled (some fluctuations observed during testing). When enabling 64K mTHP, there is a significant improvement of the page fault latency. TODO: - Support mTHP for tmpfs. - Do not split the large folio when share memory swap out. - Can swap in a large folio for share memory. Changes from RFC: - Rebase the patch set against the new mm-unstable branch, per Lance. - Add a new patch to export highest_order() and next_order(). - Add a new patch to align mTHP size in shmem_get_unmapped_area(). - Handle the uffd case and the VMA limits case when building mapping for large folio in the finish_fault() function, per Ryan. - Remove unnecessary 'order' variable in patch 3, per Kefeng. - Keep the anon shmem counters' name consistency. - Modify the strategy to support mTHP for anonymous shmem, discussed with Ryan and David. - Add reviewed tag from Barry. - Update the commit message. Baolin Wang (8): mm: move highest_order() and next_order() out of the THP config mm: memory: extend finish_fault() to support large folio mm: shmem: add an 'order' parameter for shmem_alloc_hugefolio() mm: shmem: add THP validation for PMD-mapped THP related statistics mm: shmem: add multi-size THP sysfs interface for anonymous shmem mm: shmem: add mTHP support for anonymous shmem mm: shmem: add mTHP size alignment in shmem_get_unmapped_area mm: shmem: add mTHP counters for anonymous shmem Documentation/admin-guide/mm/transhuge.rst | 29 ++ include/linux/huge_mm.h | 35 ++- mm/huge_memory.c | 17 +- mm/memory.c | 43 ++- mm/shmem.c | 335 ++++++++++++++++++--- 5 files changed, 387 insertions(+), 72 deletions(-) Tested-by: Lance Yang