From patchwork Tue Jun 11 10:11:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13693372 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 B23A8C27C5E for ; Tue, 11 Jun 2024 10:11:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B7616B00A0; Tue, 11 Jun 2024 06:11:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C97F6B00A3; Tue, 11 Jun 2024 06:11:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 243A16B00A4; Tue, 11 Jun 2024 06:11:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id E0EA76B00A3 for ; Tue, 11 Jun 2024 06:11:24 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8FA09C13E6 for ; Tue, 11 Jun 2024 10:11:24 +0000 (UTC) X-FDA: 82218190488.09.A6C4C1F Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) by imf25.hostedemail.com (Postfix) with ESMTP id 34CE8A000B for ; Tue, 11 Jun 2024 10:11:21 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=X4gAMBdI; spf=pass (imf25.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.99 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718100682; a=rsa-sha256; cv=none; b=AS8U6w/yOzhOb87Ihlc6iGPrNEAE7ZHlAhxWaM4HA/ZKlZdlXU8dxDqvP65eAS/mMqIsIq ilegcFGzuV4CjypVj5hneiqeKIpu/c7WcxTe0g5AZXQ7FbBfcBIasOkpb9FE44aNCGweV3 bF2pmXkX9jxEM8+97CJ9NkbXA4Cfgnk= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=X4gAMBdI; spf=pass (imf25.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.99 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718100682; 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=UejwwPwOxMBtGoIPmc4qXddgYNZAKKSFUqrAwuYbAKM=; b=itsQ1v+SqOZqX4l7LaObe7hoOkUBZRYGa1WU1g8SYFsAfU1EQ44lqnQ1r3n+jxQiU+OXL6 RwLxITIfXxfc0/rpSMrTxowrWH0H2Vhx4jEjKkX+XfwA/4uUidEl7+8m9AQ8Qt/YbsyZ52 afTvovpUsaeWQITOS9XQdf1FdIYb2lg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1718100676; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=UejwwPwOxMBtGoIPmc4qXddgYNZAKKSFUqrAwuYbAKM=; b=X4gAMBdIo004YHhsKuISX3z9e1ZhLgYY+JE7VeDkXT563GUKDw9eRnxW3QVJCUU+NU0qG/IpHsyJSDCwjzznoo49Up8+uf41MJLnOhGF2o0y4eiHIGGP3w9ji6Ep3CcDbKaSAzm5SFkyPnHZUyIP5jiIQmIfq+hYHymRd6Xce+Y= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R271e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037067110;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0W8G1Jpi_1718100674; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W8G1Jpi_1718100674) by smtp.aliyun-inc.com; Tue, 11 Jun 2024 18:11:15 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: willy@infradead.org, david@redhat.com, wangkefeng.wang@huawei.com, ying.huang@intel.com, 21cnbao@gmail.com, ryan.roberts@arm.com, shy828301@gmail.com, ziy@nvidia.com, ioworker0@gmail.com, da.gomez@samsung.com, p.raghav@samsung.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 0/6] add mTHP support for anonymous shmem Date: Tue, 11 Jun 2024 18:11:04 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Stat-Signature: kmn3j6pp3cf8ke6x5e3t3bmoub76pbjq X-Rspamd-Queue-Id: 34CE8A000B X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1718100681-386090 X-HE-Meta: U2FsdGVkX1+ZwglnSaKC1z9k97Y8M3j7ghvKUNBUL+xxbL7ljw/YF5tuc4Dk/1x3llHuzcbxOZvhfyV6B1o+KZaGTCbsmUgofz7+WD7CESVnDYIofX/WWqMb+NDXCPbEZ0t8tWmxfnhl72+t5zZ70M8aJ64QKEaoZkhfC+Hl/Rcww7Dv6St81JCm3mGX2F5O5nhLgWxqeQMzwTQtG2Bn3NaLA7VcBBBA8Q2CvcVFb7A4sB5k8URMqMiC/dZ8jqq6Ny0dDleyxVnLyxAdGSSiEEdl7TURfs9TQBboHKuD+PlO+CrN8d6yn0NXBzu4NjW5bWFlynp40/rEqfDSsEdcVgqpHvrsU9NdCiBoQDTS/OYyIp3QijAjAnTX6klCOSaQSRPmdu3hcT5nD+bqd1g3bBj7v0L81lBi3FG8Sr+GyIzzXC38UTghQTqYM0Yfo7qWk8RiWhOggvkboeTtcs8bnI7SKkR+LcPfTvtQGDkKkFtrIA5jqjz3OGphUSl7KC+CJc+uEhNXoFwOcwip75dIfoGc0vlIHgG5EMYL4OXcIZ93tONiTXWMG6c+zfOKXzfkvC3Y8rreTnYaP1B6S8SdjVdNIL32LjNioFli9PNkxwt0votCRS1kb7WcaLbqPwcPIg+DQK8tiNiada7/0aeZbbPM9hTWhfdl5irJM/BfE3ouTTwkU69ekB9dyj4Ck1CfOT3JDZJB8BIPh9t1kPTBq7hVddUyqDMwVa8LK+ZgfK8wl1NPHXJ8rd5CRZmGnmosYyInIu04zsZ39foWVVNbR2F6Xy7kDLrQhDrmTw4xtnf85pIXx11NiQNCmsLmqg3UBy7/0ZX2GeozcShsYerAfAQn/3VYk7KN7QEz8/cD9J/2R5Da6xlgQH0FMYbOAND73JM2kjw9cXBkfFtE+wlaBnXElf+J86uvKflSFZeb1JbR4qyYy3LExkQ+CzQRMluQkWq9S3EEIDsOYbanNzu cWlq5iUj /Ccws8G1j+ml2pTjNWbRSh4Mh7IeaHv3wSBEc4AkQm7wQpVx2qQEy+HSqzigKFdPZ29+SYtha1XLJFSdd3h4Sr67UCv6SuEhQJXdnfTzz20EceKZZc9AI+RiJlOy2Hk7aRtXy7aezplNo1B1uw0z2txxnjMYfYQCOAHIBvKp9kuzStuhjtHfM/tSUuMslov7PdHTv3A4VPWWLkAIlTSPVtk+qTahTIy8Za4fN6p+ESnzEGsdR1QXKG25/sLVFFIiBcIJHZi+XBoPqGaK92zhGo0IbFk2znY/7Gpwb0VIkoh/LgTo= 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. As discussed in the bi-weekly MM meeting[1], the mTHP controls should control all of shmem, not only anonymous shmem, but support will be added iteratively. Therefore, this patch set starts with support for anonymous shmem. The primary strategy is similar to supporting anonymous mTHP. Introduce a new interface '/mm/transparent_hugepage/hugepage-XXkb/shmem_enabled', which can have almost the same values as the top-level '/sys/kernel/mm/transparent_hugepage/shmem_enabled', with adding a new additional "inherit" option and dropping the testing options 'force' and 'deny'. 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. [1] https://lore.kernel.org/all/f1783ff0-65bd-4b2b-8952-52b6822a0835@redhat.com/ Changes from v4: - Fix the unused variable warning reported by kernel test robot. - Drop the 'anon' prefix for variables and functions, per Daniel. Changes from v3: - Drop 'force' and 'deny' testing options for each mTHP. - Use new helper update_mmu_tlb_range(), per Lance. - Update documentation to drop "anonymous thp" terminology, per David. - Initialize the 'suitable_orders' in shmem_alloc_and_add_folio(), reported by kernel test robot. - Fix the highest mTHP order in shmem_get_unmapped_area(). - Update some commit message. Changes from v2: - Rebased to mm/mm-unstable. - Remove 'huge' parameter for shmem_alloc_and_add_folio(), per Lance. 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 (6): mm: memory: extend finish_fault() to support large folio 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 | 23 ++ include/linux/huge_mm.h | 23 ++ mm/huge_memory.c | 17 +- mm/memory.c | 57 +++- mm/shmem.c | 344 ++++++++++++++++++--- 5 files changed, 403 insertions(+), 61 deletions(-)