From mboxrd@z Thu Jan 1 00:00:00 1970 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 E61B6C27C4F for ; Fri, 31 May 2024 10:13:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 66EFF6B008A; Fri, 31 May 2024 06:13:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 61E096B0095; Fri, 31 May 2024 06:13:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 533626B009A; Fri, 31 May 2024 06:13:13 -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 3484B6B008A for ; Fri, 31 May 2024 06:13:13 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A929E1416D1 for ; Fri, 31 May 2024 10:13:12 +0000 (UTC) X-FDA: 82178278224.27.D1EA5A7 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) by imf09.hostedemail.com (Postfix) with ESMTP id 7500114000F for ; Fri, 31 May 2024 10:13:09 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=J3sf852S; spf=pass (imf09.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=1717150391; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=4u3Py3hl45dIuxCPAqHpFkSudYL9AInU3+rNe13UhMI=; b=8TgOBfWTxvOFK+jwCndUD6dfVSKqy/RvZ4jkaCBazz5bVHJpyGwd2qvI/+bJzyhTYDilCD 6lQrPszbO/6Amgacv4HNMyhyjq2UajNdnNW2mo6LND2irec/X9hgRe+bNcKlSEi0mMS70h 9AVdCzFKWjLDrVzZPqDefV6WnAaOpNU= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=J3sf852S; spf=pass (imf09.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=1717150391; a=rsa-sha256; cv=none; b=bd9SkhZGsHAQUpDWWxcN/EgdHIlalApYmEqKrsnkC1dqJNTTO/jCriL+x1meAS2xVQqMUW wqwrmni0ewuZVRIckz3w2ZHLcCDFfzQd6pz/MrQFRof1xI9SAN6PSEjZ68ckgFIW8Im5oa fDA3LAcnvrTj62uC71SRt3ZKAtUCzBk= DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1717150386; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=4u3Py3hl45dIuxCPAqHpFkSudYL9AInU3+rNe13UhMI=; b=J3sf852S7ea4wzm7ZgAG6FZwUAoGgAbnIuB8ryGPJ3djmRK4bZP78Av4vetAl3v4b1cDNN6pHi+GpSFbyr9Es+toLgLAX0yupIwfnbIZAb556q8ki6gpmeX9EyerxQpefZGqUqXrB5IeB79mItVUuziKG6jzYrMxMBYOUZDsSB8= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037067113;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=15;SR=0;TI=SMTPD_---0W7ZXhau_1717150384; Received: from 30.97.56.62(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W7ZXhau_1717150384) by smtp.aliyun-inc.com; Fri, 31 May 2024 18:13:04 +0800 Message-ID: Date: Fri, 31 May 2024 18:13:03 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 0/6] add mTHP support for anonymous shmem To: David Hildenbrand , akpm@linux-foundation.org, hughd@google.com Cc: willy@infradead.org, 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, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: From: Baolin Wang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 7500114000F X-Stat-Signature: ku5bcutgjuyxwppyf9gb5oyh8ecfeih8 X-HE-Tag: 1717150389-620871 X-HE-Meta: U2FsdGVkX19GnRIKxnBwjdnTWr61Cr9Yppc5coFi29IOY2I/axD1dyaKsRtx4uYwK2Ct+HlHwDt+sCgTzXLmsm38Kj3RThKg3MWUNKQ6zMFRSXFpiNxLifkd8hy3B0FAqVKWIuZUtgZOxJutaVb76JCcKpB7bPUWQYcEbU82X1MFXOq6MhLR66esR3JMtwalSy5M/tJsUG/nrGLXBSMaxPelQt9hmxlG7R1gJbyQDPNA1veRDbLZUmwdZsD9x/JlpOX23aSsHFnoUZJBOCHyCTIdcHYg225n3ZFzCr46jAEM/Y4nwDTFHNI9rj3dEQaZAFxORQsHaRUgJ+ypnEidxB5toALm4n7xqCjZgLkJQms/rryt62+OgnvPjn7GzjUc4OOYl98KKEtuHyk3Zn1nJazYHkQ5FPbXTfl3Zp05J5vWd57/Girh9CS/xPNO+LIJgzNWpMiwYv8MuQ68BizkT0hZ2JufN4VZOOdlB5+LFXCy9rrGOevNvKKSeRExsyoz7ZsxlnU+eG+4fr7foem9o54kvjgzKbrZJjQFbHaqfqKFdEBA1HxwXNd4/QTLE37/VHh9XRC5OPmBgVJ31xC2mADfljddJcHB7XIax2jU8iVMCJVzabSRHTSdnp7xfcOtaprn+/hqOlsu6iKmvo8yIOESDlycpEObiHr6bevUvSpKTvH2Hkjvg1byKpTVj79+UTwp9u6mwCTDxDr9lSHWX7YK1IVJGxxL7CfOFmVcZIus0aBZx8jzPXUebqL+GGbsW+qVEPOwCANIDvElJSFSAzgLoYWHeGerDL5anT1BD/4U/fGjSwkvjGficsgtb9Ip5CpNUKojTGdr14owxJSrB+Wp2UAZe8eVhcz1Qy58Y7kEmFKJM0+DTSCXHiBiH2MZXHtCEjzJzGUjvj825IVqtg9+oliLumi+IhRrqp6QmzBqxnmq+/kl1ipoWdBaJKoty9ORKW4ia/X0Drj6HOG gavhypQV LRPEHlOFuXV+B4PvJtd9bd9hYKvqz34cD7qq0oh7cpQoizeTnPUtY2HiVRqRr3qB6YbWeEsHm+CsYBFj6v0oGNVQREpXz8FxQhXB6hq2pxDLz8z124vdNsty0KoV0iWq5TG5CHqOJZGpbxrqPFtb6iysqG2+ghs5RZW4AQUAO019Gahp0WZ4f8mBY9V7izCgmWZBr1MV4P+gPzjfXXiP6nfYh4Fk9fUwfoArrtVRIaOrtsz+kMqs/FiBaOOOae7ncMdp4VvEWxQpR9GI2wFaJJlzpjJw4LxAiOJWTumwLFe4LBNh5u6ultzjS5El+8D08rG/rV6e5nYdJ8Kw= 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: On 2024/5/31 17:35, David Hildenbrand wrote: > On 30.05.24 04:04, Baolin Wang wrote: >> 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. > > Let me summarize the takeaway from the bi-weekly MM meeting as I > understood it, that includes Hugh's feedback on per-block tracking vs. Thanks David for the summarization. > mTHP: > > (1) Per-block tracking > > Per-block tracking is currently considered unwarranted complexity in > shmem.c. We should try to get it done without that. For any test cases > that fail, we should consider if they are actually valid for shmem. > > To optimize FALLOC_FL_PUNCH_HOLE for the cases where splitting+freeing > is not possible at fallcoate() time, detecting zeropages later and > retrying to split+free might be an option, without per-block tracking. > > (2) mTHP controls > > As a default, we should not be using large folios / mTHP for any shmem, > just like we did with THP via shmem_enabled. This is what this series > currently does, and is aprt of the whole mTHP user-space interface design. > > Further, the mTHP controls should control all of shmem, not only > "anonymous shmem". Yes, that's what I thought and in my TODO list. > > Also, we should properly fallback within the configured sizes, and not > jump "over" configured sizes. Unless there is a good reason. > > (3) khugepaged > > khugepaged needs to handle larger folios properly as well. Until fixed, > using smaller THP sizes as fallback might prohibit collapsing a > PMD-sized THP later. But really, khugepaged needs to be fixed to handle > that. > > (4) force/disable > > These settings are rather testing artifacts from the old ages. We should > not add them to the per-size toggles. We might "inherit" it from the > global one, though. Sorry, I missed this. So I thould remove the 'force' and 'deny' option for each mTHP, right? > > "within_size" might have value, and especially for consistency, we > should have them per size. > > > > So, this series only tackles anonymous shmem, which is a good starting > point. Ideally, we'd get support for other shmem (especially during > fault time) soon afterwards, because we won't be adding separate toggles > for that from the interface POV, and having inconsistent behavior > between kernel versions would be a bit unfortunate. > > > @Baolin, this series likely does not consider (4) yet. And I suggest we > have to take a lot of the "anonymous thp" terminology out of this > series, especially when it comes to documentation. Sure. I will remove the "anonymous thp" terminology from the documentation, but want to still keep it in the commit message, cause I want to start from the anonymous shmem. > > @Daniel, Pankaj, what are your plans regarding that? It would be great > if we could get an understanding on the next steps on !anon shmem. >