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 21DD9C30658 for ; Fri, 5 Jul 2024 08:58:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A98616B009C; Fri, 5 Jul 2024 04:58:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A473C6B009D; Fri, 5 Jul 2024 04:58:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C02E6B009E; Fri, 5 Jul 2024 04:58:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 691ED6B009C for ; Fri, 5 Jul 2024 04:58:09 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 270141216E4 for ; Fri, 5 Jul 2024 08:58:09 +0000 (UTC) X-FDA: 82305097098.26.2043C67 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) by imf18.hostedemail.com (Postfix) with ESMTP id 481EB1C0011 for ; Fri, 5 Jul 2024 08:58:04 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=HROtLVqi; spf=pass (imf18.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.131 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=1720169874; 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=/b2CH/0osx3Zqy3K9+ynEPiLNGlIv+mnOfWfcW761j4=; b=PxL3iSpcqRWxGYY1lS9FtV4nZMToBni2EqzlxwWCPiLLx7VAgX12rhtdt7b+v3G4P7a7WH V+Ir4xGxSe8mAdPwC2rdknF6OJxVuDWBAWKlLpE4vTTyrgTdBGSVMuAvrziFt+Uqj8T8KT wcesJ21q1WDQtFYS0i31cLCaEjkq+6Y= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=HROtLVqi; spf=pass (imf18.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.131 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=1720169874; a=rsa-sha256; cv=none; b=x85xZikb7Uzk+qvZhnE08j5oUv37Lw2rCpEzGUoiGxj+jqs1siSLGNnsF/E1Evdr0FWA5S qrphyUAlWPvW3Jfh4dI3ZF9MjBMC2AEVoKtOr9CI9wNMX04IyzV0tFDu16oZD2nlMXXQOO /eJGl65Y4PV6tV1LU4ywq4is7CAf9lY= DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1720169882; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=/b2CH/0osx3Zqy3K9+ynEPiLNGlIv+mnOfWfcW761j4=; b=HROtLVqiFcztkybnJQzBQhgU8h0QYOx8V5M6m9TDB8qFhrHFolKOjaqP4ZxgEo+xkCqQwSqL24lUzL0jY4zUHgso7T02dkgOBymdL5rnKg9Eqeq8UklZeGfYFZdbozYcSFOM9To4wiHRfllA4oM5InNRGl/W+Trf5/QC2ckVVec= 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-contentspam033045220184;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0W9uQFI._1720169879; Received: from 30.97.56.65(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W9uQFI._1720169879) by smtp.aliyun-inc.com; Fri, 05 Jul 2024 16:58:00 +0800 Message-ID: <545e23ab-e40a-4f13-8167-c9aa85a34b19@linux.alibaba.com> Date: Fri, 5 Jul 2024 16:57:59 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 4/6] mm: shmem: add mTHP support for anonymous shmem To: Ryan Roberts , Bang Li , 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, 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: <65796c1e72e51e15f3410195b5c2d5b6c160d411.1718090413.git.baolin.wang@linux.alibaba.com> <65c37315-2741-481f-b433-cec35ef1af35@arm.com> <475332ea-a80b-421c-855e-a663d1d5bfc7@linux.alibaba.com> <076550c4-0e8a-4344-9f8a-31ae9e1051b5@linux.alibaba.com> <96625631-ef7d-44a2-ad5f-f7beb64f0ed0@arm.com> From: Baolin Wang In-Reply-To: <96625631-ef7d-44a2-ad5f-f7beb64f0ed0@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 481EB1C0011 X-Stat-Signature: dfa7tgmwt4qmgt14t69m36p9gwcc8y34 X-HE-Tag: 1720169884-654511 X-HE-Meta: U2FsdGVkX1+2mN/RMrJgtkYV98Plb1pjd/8R2IIouHYVN/QVJRXZMQNzkyrX/6GIT5S/LsE16houGJiBWbpgl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ytraUCfslqp7+z/KMzcM7Yp74KHLIH1co4sv/nElAHm1sAlR42KhZcXTTWMlC10l9Br7yeIuVSwG42iKjKU6yy1f1Lb43HLYo6QrIgztau6b31Dae1zB+4TbHZJfL5kyySJtF+81E7n0RaVuZ77p7A8xxNWeizkEYMz5XFZJjQc3MQrwvKi/KqTgxJMRTv2RG6lL86zlQgxSeOr3SU= 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/7/5 16:42, Ryan Roberts wrote: > On 05/07/2024 04:01, Baolin Wang wrote: >> >> >> On 2024/7/4 22:46, Bang Li wrote: >>> Hi Bao lin, >>> >>> On 2024/7/4 19:15, Baolin Wang wrote: >>>> >>>>>> + >>>>>> +    /* >>>>>> +     * Only allow inherit orders if the top-level value is 'force', which >>>>>> +     * means non-PMD sized THP can not override 'huge' mount option now. >>>>>> +     */ >>>>>> +    if (shmem_huge == SHMEM_HUGE_FORCE) >>>>>> +        return READ_ONCE(huge_shmem_orders_inherit); >>>>> >>>>> I vaguely recall that we originally discussed that trying to set 'force' on the >>>>> top level control while any per-size controls were set to 'inherit' would be an >>>>> error, and trying to set 'force' on any per-size control except the PMD-size >>>>> would be an error? >>>> >>>> Right. >>>> >>>>> I don't really understand this logic. Shouldn't we just be looking at the >>>>> per-size control settings (or the top-level control as a proxy for every >>>>> per-size control that has 'inherit' set)? >>>> >>>> ‘force’ will apply the huge orders for anon shmem and tmpfs, so now we only >>>> allow pmd-mapped THP to be forced. We should not look at per-size control >>>> settings for tmpfs now (mTHP for tmpfs will be discussed in future). >>>> >>>>> >>>>> Then for tmpfs, which doesn't support non-PMD-sizes yet, we just always use the >>>>> PMD-size control for decisions. >>>>> >>>>> I'm also really struggling with the concept of shmem_is_huge() existing along >>>>> side shmem_allowable_huge_orders(). Surely this needs to all be refactored into >>>>> shmem_allowable_huge_orders()? >>>> >>>> I understood. But now they serve different purposes: shmem_is_huge() will be >>>> used to check the huge orders for the top level, for *tmpfs* and anon shmem; >>>> whereas shmem_allowable_huge_orders() will only be used to check the per-size >>>> huge orders for anon shmem (excluding tmpfs now). However, as I plan to add >>>> mTHP support for tmpfs, I think we can perform some cleanups. >>> >>> Please count me in, I'd be happy to contribute to the cleanup and enhancement >>> process if I can. >> >> Good. If you have time, I think you can look at the shmem khugepaged issue from >> the previous discussion [1], which I don't have time to look at now. >> >> " >> (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. >> " > > khugepaged can already collapse "folios of any order less then PMD-size" to > PMD-size, for anon memory. Infact I modified the selftest to be able to test > that in commit 9f0704eae8a4 ("selftests/mm/khugepaged: enlighten for multi-size > THP"). I'd be surprised if khugepaged can't alreay handle the same for shmem? I did not test this, but from the comment in hpage_collapse_scan_file(), seems that compacting small mTHP into a single PMD-mapped THP is not supported yet. /* * TODO: khugepaged should compact smaller compound pages * into a PMD sized page */ if (folio_test_large(folio)) { result = folio_order(folio) == HPAGE_PMD_ORDER && folio->index == start /* Maybe PMD-mapped */ ? SCAN_PTE_MAPPED_HUGEPAGE : SCAN_PAGE_COMPOUND; /* * For SCAN_PTE_MAPPED_HUGEPAGE, further processing * by the caller won't touch the page cache, and so * it's safe to skip LRU and refcount checks before * returning. */ break; } > Although the test will definitely want to be extended to test it. Right.