From patchwork Mon May 13 05:08:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13663019 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 893AAC25B78 for ; Mon, 13 May 2024 05:08:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 289266B00A5; Mon, 13 May 2024 01:08:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 212726B00C9; Mon, 13 May 2024 01:08:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 064746B00CB; Mon, 13 May 2024 01:08:42 -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 B6E216B00A5 for ; Mon, 13 May 2024 01:08:42 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5DD92140B96 for ; Mon, 13 May 2024 05:08:42 +0000 (UTC) X-FDA: 82112192484.10.B647276 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) by imf06.hostedemail.com (Postfix) with ESMTP id DFBF1180008 for ; Mon, 13 May 2024 05:08:37 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=bpwSKqrh; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf06.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=1715576920; 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=xdtBc1vqqikYIoQW8+5vZcG1Vcx66O2ep2Lcqt4Iijg=; b=i79us/PXMaxiQc78GtraEGj2jlr/G7G4CEzzxqSTQxIxEYwQcE8a5DqsAa8WJLLxE4SfpR P/NGfGPK3mHXSJwtPIlxkQMV8Hl4IfMEgTd1LrXRcNKSIolh3HYNXFnuWxHweJpu1tTyuC RzZkdVzIVUHn5S3NywM+dGbt03DVIAE= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=bpwSKqrh; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf06.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715576920; a=rsa-sha256; cv=none; b=x+amNwcObHMy8Ij/rm63QsnCtFfIYzJe+kQ/buUCT7xwe1bAEuDZk0HTU0hg0PraT8Cqj8 KmlDUrI3YQHCMnJmLse3/G8eHURpeuEVtCQ8+0rb2Jj/cBvuLQ3SDcxL4YVz4zwIXwQFuI Q+j2ck0G/B5X1zarauHyoJFwSy1BJmE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1715576915; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=xdtBc1vqqikYIoQW8+5vZcG1Vcx66O2ep2Lcqt4Iijg=; b=bpwSKqrhfKs4u6PtuT19dS7H1pOQq46eO54MU9xqkCE/GTlaxUp/3y5R0NLd2Gv00aRhlpGGDqpl9Cjrko0JD+dI5WVRci3+N0tSZ27sZIC8/6Z+9ylh7VJIikEj7RY9TEvHzu0blt5vOLzBVLs5pa2reUz6qaIKB9/Wilqe660= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037067112;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=14;SR=0;TI=SMTPD_---0W6HN0NG_1715576912; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W6HN0NG_1715576912) by smtp.aliyun-inc.com; Mon, 13 May 2024 13:08:33 +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 v2 0/7] add mTHP support for anonymous shmem Date: Mon, 13 May 2024 13:08:10 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: DFBF1180008 X-Stat-Signature: ghru8gbyy3biou4f6t8xjfu43t18zoht X-HE-Tag: 1715576917-63003 X-HE-Meta: U2FsdGVkX18zS8TEkDkzONDEFA7urwmdOTffo1RmPPjSu2GysU/57vOUw23EqMFSRC3ld2Me4tDrtRw9sQgPjUiWkJsBO3UrrwkW79f/fOUS1rhwn+EolruDjagwg4M4ra+E5ESs4kg5DUG/24LknZaY12TZIVbzGNdxbKPshqn+PI6cSlztkPh0PF5wJEBky8xrLWkkKuSX8jwPw760PO9Uo8plaZlOdF8fYv2I7CXBcVDX7okC94Bdkj7weDl+fMEisq9ru+LX/avStBPxeO6/44+83NqcuMrQtcZK/os3Eyo910LaXjBdU6a3j3mgEgNZsSbX5hlzMrsqlNcGAdLCdIN1MVbTKj07qvilYJO3IYkD5e1bHd8pVoPX7wLZmOocQEs1NCaA3dEcNkQQqblO3arEJHJy3ypBsFgNwRBxvMr+p8ih/vxktbW3U6ai9f4+U81v9f8E7cci3YsIH409MQDVXQ0wGKb3Rw+gwo4s5xK+8wEufQK8h1N9jkS92y6bEwcaBBGmGyxHUsVtcX/qdYOda1Z24wHvGBdHoucBgfJCwLA89ojHzHE426niJdFcqHljCzwRagZmOmtiZ3CWzrHJAK3JK1lxjze66p/CivevUyx5Jhnt20KXV85NasXVfnp5ecoHhfeD+QPRHMe/pc1Nb9D2/JWaxs9tU5hAsgu6LZZiv/on4FMb6Frmw+DGzKYbenD1fVR5L7Fkz3geBvUqBSidoihVOZTSkWx+mJZLUA9GcGfMhIhZpnlCPbuhAadAp4FHsndJRLYuTe5ShpMWKxIMgGet73EG/BV6LjYiTSy2iracG2FcwRBZ/E5h5uBhk1PkjFR12nIvy8XyZEUP6FTZ0Y6BnmfBPHmb1NZaLVSS7hzwaGT2CUt+9+ygAz1hEgGEOkb8YN3uIio0Jj/f6wH3UlrPeOobjSy8towvzuOgzcKO5POEPaEXubx60e+lkTjqW1KQgP6 zhyRQzXN 9awPG+bnOSOGzPGlZ/KbVcKB+EIppjW/nkOwsULOUz9BmcR8kB58+6vTVoLSGXzaBxwXsSwqAYiiR1z4BsClHjpx7A87gdFi1ASOuAwgPBeGdrEN/vMV1VkbrP9KcOCYgwdiejm+Pb27QY7BKW9pBfCrZ/Dvt2APT++9A 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 shmem 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 anonymous shmem enabled of the top level, meanwhile also allows independent control of anonymous 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 v1: - Drop the patch that re-arranges the position of highest_order() and next_order(), per Ryan. - Modify the finish_fault() to fix VA alignment issue, per Ryan and David. - Fix some building issues, reported by Lance and kernel test robot. - Update some commit message. 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 (7): 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 | 23 ++ mm/huge_memory.c | 17 +- mm/memory.c | 58 +++- mm/shmem.c | 338 ++++++++++++++++++--- 5 files changed, 403 insertions(+), 62 deletions(-)