From patchwork Mon Apr 22 07:02:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13637716 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 2AF84C05023 for ; Mon, 22 Apr 2024 07:03:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8EAF76B0089; Mon, 22 Apr 2024 03:03:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 89BF76B008A; Mon, 22 Apr 2024 03:03:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 71A456B0092; Mon, 22 Apr 2024 03:03:05 -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 39DE96B0089 for ; Mon, 22 Apr 2024 03:03:05 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 89EFBA0B29 for ; Mon, 22 Apr 2024 07:03:04 +0000 (UTC) X-FDA: 82036275888.12.64E0FC5 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) by imf14.hostedemail.com (Postfix) with ESMTP id 542BE100016 for ; Mon, 22 Apr 2024 07:03:00 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=pXaD6oHa; spf=pass (imf14.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.113 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=1713769382; 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=EzoH5/TP5PtYl4wtjV6rpqRZK0tNrBnQaBo2IsOMKmA=; b=xxqjCbd0ylBG5SoUtuh0IMOBHo8WwPVC144s6/ZDl6adsi1pzNUeLoSyrY7Ij4q2zE9KRF rydgWtUxcDBHsKvHJIsiqstR15MHhRkOR3RjGwlqSQtOdsfy423dI19Oru7qBdizgDLtkV ylnApRo2Byci+BpwFnrmFezDdMsqTx4= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=pXaD6oHa; spf=pass (imf14.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.113 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=1713769382; a=rsa-sha256; cv=none; b=0RdudIl98+C6t9VP4jOWi9XrSNnGIcKdOO2aJZZCQSX2++6LnBltk5aLETK2LgCSXNamtJ x9AjCXsqqJsnH+WljYL7eZZSQPzeBf0pQVWAJqnbxDcsfEn4H2QpIDtm6AoxNjpSeI6G3c 8kcn6Le8gnSVbRiLAan8mbsrLeV8rq4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1713769377; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=EzoH5/TP5PtYl4wtjV6rpqRZK0tNrBnQaBo2IsOMKmA=; b=pXaD6oHafPyNRdOFmU6L6BUWJucQO4gyxKeSQlEFBQlQZYRpt70ysI9JdxKTrbIf1NrstIMNbQUmCm6FEq3FyX32kIzA5wmzgwXdQ+ribbo2YBTUKLOIC3z5etW+54gj7EAwIrd8h55X6QG8UBLFuEh4axh0z/BtMzVCxLzvf+Q= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R561e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046060;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0W5.T-Xb_1713769374; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W5.T-Xb_1713769374) by smtp.aliyun-inc.com; Mon, 22 Apr 2024 15:02:55 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: willy@infradead.org, david@redhat.com, wangkefeng.wang@huawei.com, 21cnbao@gmail.com, ryan.roberts@arm.com, ying.huang@intel.com, shy828301@gmail.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 0/5] add mTHP support for anonymous share pages Date: Mon, 22 Apr 2024 15:02:38 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Stat-Signature: zxpktu56sqad11a45yn7y5zkbej6j3ef X-Rspamd-Queue-Id: 542BE100016 X-Rspamd-Server: rspam02 X-Rspam-User: X-HE-Tag: 1713769380-953666 X-HE-Meta: U2FsdGVkX1/a8erG5UXRpCm5+De4ouomWaHUOZqEJdl95g1JLU5JdIfcKCOOJyztnC+UYmqL/QaIQFV8Wc+RU2tDwNfdaI7wf+Q580B0md9Yt0Da9d6kdQzr+z5FD6H3cbvCa96sPCtHu2YP42XBJ2KARDz8eBtIELtvsOf1LS6LTzIGt1666/tv7I7CBgkIjitlAcPFJYw+pVnSU5Jz5ri6tSmgiBwA6hCDO9gd+rMLM3tSRc9AW4F2783q3ElnR+JCE/Aquj/m/2Y/si+Z1ez32NTBE20rg+qv8irHw8eq6qaaFyZMhsbFdQOL9kBFfs5uBUA+RTsMWNG5meaBU4zbf3Xsi2q2/UspASDWnGbID2tKAaty/jwXLFsXWSChC+e1HaANsKiHTO95/jxQrolubcVJ3quuwKtSmqbY2GGtHjTG+508JoQG5x05PyoxkuByydsAog2oWRhxhc5fnYujskMxh9+PQMBFWF8xZy3Z5HK8WKlcnRb4294adbW8UMoaxgf2hz4trhmm/oqh3pO6+eS4Job4t81fA3y6S/aAPrPARL62z635qmCOhkevJWYY9Z62cbV262XvKurpw0UmgYegFSYl4BNMWHI/vN2LeiJO1wOm0j7Ue8Z8bn/TxRxwSNYKylwYF1XgoSojdIlICxEeshxhUQfL+HUgrPGJQ0AOD5dHWK3QNtA/fiSg/eIRBmFRmWBk1dVg42r/tLYlqle0nhW7McqeG94fJRrX/3bqHbTMCukKG5jithn96DmIQhqNfNGGkXgoLGMmeAB5WgJY/BSajE0VZlqGuBwAPUiAZnfu2u3AMYdMVQcTi0/uyE60+20zu2R94pedRkuzteqzfAuZrBQ1ubnJ3MER7OJPn7ze2u2fa5qUfvupuiBCUrOXS5sEPHGeKgqug99FFAR2GUG0tOz510bOhXFFVadIyG0kG960DaNw1bKoiBwSSAwjkhQCdgEVm79 rL8OuXqr Xxgf5XIj470lSLA1yjPQ86BijYmb4zo1StO1+6OHem/2Em9p8L2rXxzpB5XXrQJUSOcKl33pdku7NL2a1QbACEEWEUuxxNgEMI11/By5ztClg0I2U9qBDEvc40hW8tXtTdt0DLpRvvmwsPBDIyYeiuZJTb1gIncxXRkyap3eeujlZb2MzTxJUhSuN9FawHtWdro2vb1Rr18JUKSL/1cI8V7WWrQ== 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 that, the use of huge pages for anonymous shared pages still follows the global control determined by the mount option "huge=" parameter or the sysfs interface at '/sys/kernel/mm/transparent_hugepage/shmem_enabled'. The utilization of mTHP is allowed only when the global 'huge' switch is enabled. Subsequently, the mTHP sysfs interface (/sys/kernel/mm/transparent_hugepage/hugepage-XXkb/enabled) is checked to determine the mTHP size that can be used for large folio allocation for these anonymous shared pages. TODO: - More testing and provide some performance data. - Need more discussion about the large folio allocation strategy for a 'regular file' operation created by memfd_create(), for example using ftruncate(fd) to specify the 'file' size, which need to follow the anonymous mTHP rule too? - Do not split the large folio when share memory swap out. - Can swap in a large folio for share memory. Baolin Wang (5): 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 mTHP support for anonymous share pages mm: shmem: add anonymous share mTHP counters include/linux/huge_mm.h | 4 +- mm/huge_memory.c | 8 ++- mm/memory.c | 25 +++++++--- mm/shmem.c | 107 ++++++++++++++++++++++++++++++---------- 4 files changed, 108 insertions(+), 36 deletions(-)