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 2DEC0C3DA4A for ; Fri, 9 Aug 2024 08:31:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BFFF26B0098; Fri, 9 Aug 2024 04:31:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BAFD66B009A; Fri, 9 Aug 2024 04:31:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A77F86B009C; Fri, 9 Aug 2024 04:31:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8B6CC6B0098 for ; Fri, 9 Aug 2024 04:31:29 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 472F4120A8C for ; Fri, 9 Aug 2024 08:31:29 +0000 (UTC) X-FDA: 82432037898.13.DEE7F66 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) by imf23.hostedemail.com (Postfix) with ESMTP id 65B9E14002C for ; Fri, 9 Aug 2024 08:31:26 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=DUqqn5jU; spf=pass (imf23.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=1723192221; 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=QlWlrLZQRR72Ij7XSLh+rxKaZg6CXu0jngWl55iBYM0=; b=45KtafcTeOd2Exu4ICYehhRYSzM/h05gHBl7DuwG5mfCpGbtoPkcWehwhKDpoOFtdzXYHC YGveq9bSTvM4JD/KGmdAFio6ZjdF4EPfI+kXRnq+f5duTmCuFLs6ljAcF4xAUwoTpf7NCG gAimcyirwFZLJ1A5lGi7ACud50wMVx8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723192221; a=rsa-sha256; cv=none; b=3C1KKPMpiWhhRjIEyiV5ISf0xD+URltvTngWwRlyvxDJkRwlNKmPOUHRUixSIM77gvZxQ9 0CKVkK37Qyuhrgf2jW1+KE95MubXlBtpBcJJ+nkcuqfin3TykClupMtlOIjf8RpgQGMxFm tQCgqHFj9PfnL46XqE6uHdQd9V04MTA= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=DUqqn5jU; spf=pass (imf23.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 DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1723192283; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=QlWlrLZQRR72Ij7XSLh+rxKaZg6CXu0jngWl55iBYM0=; b=DUqqn5jUAdjQBMGyZKwesVEwk2v0xhWpJyfxad6iW1pbQZyOEX5Bm7JITfjekF7L+AzlxgFXrmo9jn74L6/6vPOB/0JoHQ1HLEz0C1/UdpbWwE0qvjxGHuXF4v14H2WzW/nKRRIkmAIPkF1bfmXdKUp0vk5YXLMbzs0Hgl3OtPA= Received: from 30.97.56.60(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WCPMwMW_1723192281) by smtp.aliyun-inc.com; Fri, 09 Aug 2024 16:31:22 +0800 Message-ID: <747d1319-f746-4379-bf88-a0f6c3f558b4@linux.alibaba.com> Date: Fri, 9 Aug 2024 16:31:21 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 2/2] mm: Tidy up shmem mTHP controls and stats To: Ryan Roberts , Andrew Morton , Hugh Dickins , "Matthew Wilcox (Oracle)" , David Hildenbrand , Barry Song , Lance Yang , Gavin Shan Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20240808111849.651867-1-ryan.roberts@arm.com> <20240808111849.651867-3-ryan.roberts@arm.com> From: Baolin Wang In-Reply-To: <20240808111849.651867-3-ryan.roberts@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Stat-Signature: a5qmgtypcwrkamc73137ari8eautqb6k X-Rspamd-Queue-Id: 65B9E14002C X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1723192286-477661 X-HE-Meta: U2FsdGVkX18FYFigjnaxBzMpzi4k6ukaUUfyUgsaTV+sHtxi4WZSyCjvFNAuEphBQpazCUDSS3kZ7fqSUn16LeS3Bf0nYjOOGokSBgynl38hkaM87qPIJKd75LXWr5u5CwNjQO7XRWFDkq/Yg380TnZ827YU/o82CejIlXGjtnZ+XB5RhfJUq4+yvApUlXEGclS4c3M74y2Id2NZK0B9S9/tL5wVnVmzp+iJoQqFybBf1LWul12u22Ndq1I5kF7OwyIFFaW05L/hIzq8zSCa7PtDJ2wfSirJGqOYj6aW1SDVGoZvwGeeEMqqC56ULfbSwGK/D+eGyr2D5Ap1TLjNTucigKM4bcXYYa6OsKfXJxqOjHZ8aFHWRCFYqHHQIlgWUAvXWuWcwjvCZiWFHDcNVpgLpV6R8lbtuBaaR4U62PKoyiPfvAenT4rDOmyjF0oloFql2giKBLWmBRs+mG8IXfUYS31OwmevR0BAXCT1lTOVtX0DXFEL1sTGHXQPyYYd7W3KpFIGZEMAEOGG9RG6fWCRK2vmt5wF9heclEsOf2lezA3ZI80j0J1iL/epGcOvaon5WZ+t1LWo/8/g7dPpd+3b3UA0B2JLt8VlaoXorFl5K7fqcu19QLqK+zLnfU0zGW1d82lvH2XhHc0CspJXhKqJ5eZN1wu2nw7ViD1OP/av9zNEaO6IGGLVmGhh8Tbcf5oPDfbC3TC7jM0RCUMRktJaTYFE/+K2qubChJ7un48foHY2Df3IZFJqTnSecJdPDUeS2ZqfhFBERs8gvEeFJu+73qPYe761uEYpVjGfBoNKuPXII3DfLNgYc7/7FqyeBl4zAq7hysqwrUHwHDyjWHGSNA+39gopDOfv4kunl7DFFQh6rEB2qDKFkurwbxb9vhDP3AhCighLXGVUJtMjmWni2lbvFphdbLxk/zAP7Yt+zTRgZk7PJ+dwPp+dGTljo+e+bCOfT3XAk/v/nu0 o/Vi5TZi M67fsBRcCNCkTEASTlbuLT1clVIkAdJGtPL1XYXDFpgpV0bk/5KvP8VKfLrYs38MnpTdMJm6u11RevupGhCESXEZPSMYhoSmRNIMxL+lyeDMVlXOjbOCABu5hYNFV5ND+SjdSdaqXbSx/+mTpWMrzvMjyADz3SP5qq3uDVSCmz74u8L4HvIYrlMx1I0MgduQmmTf9zmvYzPSjxp7X/BP1BxnIZrMEUExJrtJt3xQkRTPUExZtWDJlxW5SXnrgnupoKk7cq+VEnAasHqlP6kH599ZfNqMnwzMDGbKu 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/8/8 19:18, Ryan Roberts wrote: > Previously we had a situation where shmem mTHP controls and stats were > not exposed for some supported sizes and were exposed for some > unsupported sizes. So let's clean that up. > > Anon mTHP can support all large orders [2, PMD_ORDER]. But shmem can > support all large orders [1, MAX_PAGECACHE_ORDER]. However, per-size > shmem controls and stats were previously being exposed for all the anon > mTHP orders, meaning order-1 was not present, and for arm64 64K base > pages, orders 12 and 13 were exposed but were not supported internally. > > Tidy this all up by defining ctrl and stats attribute groups for anon > and file separately. Anon ctrl and stats groups are populated for all > orders in THP_ORDERS_ALL_ANON and file ctrl and stats groups are > populated for all orders in THP_ORDERS_ALL_FILE_DEFAULT. > > Additionally, create "any" ctrl and stats attribute groups which are > populated for all orders in (THP_ORDERS_ALL_ANON | > THP_ORDERS_ALL_FILE_DEFAULT). swpout stats use this since they apply to > anon and shmem. > > The side-effect of all this is that different hugepage-*kB directories > contain different sets of controls and stats, depending on which memory > types support that size. This approach is preferred over the > alternative, which is to populate dummy controls and stats for memory > types that do not support a given size. > > Signed-off-by: Ryan Roberts > --- > mm/huge_memory.c | 144 +++++++++++++++++++++++++++++++++++++---------- > 1 file changed, 114 insertions(+), 30 deletions(-) > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index 0c3075ee00012..082d86b7c6c2f 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -482,8 +482,8 @@ static void thpsize_release(struct kobject *kobj); > static DEFINE_SPINLOCK(huge_anon_orders_lock); > static LIST_HEAD(thpsize_list); > > -static ssize_t thpsize_enabled_show(struct kobject *kobj, > - struct kobj_attribute *attr, char *buf) > +static ssize_t anon_enabled_show(struct kobject *kobj, > + struct kobj_attribute *attr, char *buf) > { > int order = to_thpsize(kobj)->order; > const char *output; > @@ -500,9 +500,9 @@ static ssize_t thpsize_enabled_show(struct kobject *kobj, > return sysfs_emit(buf, "%s\n", output); > } > > -static ssize_t thpsize_enabled_store(struct kobject *kobj, > - struct kobj_attribute *attr, > - const char *buf, size_t count) > +static ssize_t anon_enabled_store(struct kobject *kobj, > + struct kobj_attribute *attr, > + const char *buf, size_t count) > { > int order = to_thpsize(kobj)->order; > ssize_t ret = count; > @@ -544,19 +544,35 @@ static ssize_t thpsize_enabled_store(struct kobject *kobj, > return ret; > } > > -static struct kobj_attribute thpsize_enabled_attr = > - __ATTR(enabled, 0644, thpsize_enabled_show, thpsize_enabled_store); > +static struct kobj_attribute anon_enabled_attr = > + __ATTR(enabled, 0644, anon_enabled_show, anon_enabled_store); > > -static struct attribute *thpsize_attrs[] = { > - &thpsize_enabled_attr.attr, > +static struct attribute *anon_ctrl_attrs[] = { > + &anon_enabled_attr.attr, > + NULL, > +}; > + > +static const struct attribute_group anon_ctrl_attr_grp = { > + .attrs = anon_ctrl_attrs, > +}; > + > +static struct attribute *file_ctrl_attrs[] = { > #ifdef CONFIG_SHMEM > &thpsize_shmem_enabled_attr.attr, > #endif > NULL, > }; > > -static const struct attribute_group thpsize_attr_group = { > - .attrs = thpsize_attrs, > +static const struct attribute_group file_ctrl_attr_grp = { > + .attrs = file_ctrl_attrs, > +}; > + > +static struct attribute *any_ctrl_attrs[] = { > + NULL, > +}; > + > +static const struct attribute_group any_ctrl_attr_grp = { > + .attrs = any_ctrl_attrs, > }; I wonder why adding a NULL group? > > static const struct kobj_type thpsize_ktype = { > @@ -595,64 +611,132 @@ DEFINE_MTHP_STAT_ATTR(anon_fault_fallback, MTHP_STAT_ANON_FAULT_FALLBACK); > DEFINE_MTHP_STAT_ATTR(anon_fault_fallback_charge, MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE); > DEFINE_MTHP_STAT_ATTR(swpout, MTHP_STAT_SWPOUT); > DEFINE_MTHP_STAT_ATTR(swpout_fallback, MTHP_STAT_SWPOUT_FALLBACK); > +#ifdef CONFIG_SHMEM > DEFINE_MTHP_STAT_ATTR(shmem_alloc, MTHP_STAT_SHMEM_ALLOC); > DEFINE_MTHP_STAT_ATTR(shmem_fallback, MTHP_STAT_SHMEM_FALLBACK); > DEFINE_MTHP_STAT_ATTR(shmem_fallback_charge, MTHP_STAT_SHMEM_FALLBACK_CHARGE); > +#endif > DEFINE_MTHP_STAT_ATTR(split, MTHP_STAT_SPLIT); > DEFINE_MTHP_STAT_ATTR(split_failed, MTHP_STAT_SPLIT_FAILED); > DEFINE_MTHP_STAT_ATTR(split_deferred, MTHP_STAT_SPLIT_DEFERRED); > > -static struct attribute *stats_attrs[] = { > +static struct attribute *anon_stats_attrs[] = { > &anon_fault_alloc_attr.attr, > &anon_fault_fallback_attr.attr, > &anon_fault_fallback_charge_attr.attr, > +#ifndef CONFIG_SHMEM > &swpout_attr.attr, > &swpout_fallback_attr.attr, > - &shmem_alloc_attr.attr, > - &shmem_fallback_attr.attr, > - &shmem_fallback_charge_attr.attr, > +#endif > &split_attr.attr, > &split_failed_attr.attr, > &split_deferred_attr.attr, > NULL, > }; > > -static struct attribute_group stats_attr_group = { > +static struct attribute_group anon_stats_attr_grp = { > + .name = "stats", > + .attrs = anon_stats_attrs, > +}; > + > +static struct attribute *file_stats_attrs[] = { > +#ifdef CONFIG_SHMEM > + &shmem_alloc_attr.attr, > + &shmem_fallback_attr.attr, > + &shmem_fallback_charge_attr.attr, > +#endif > + NULL, > +}; > + > +static struct attribute_group file_stats_attr_grp = { > + .name = "stats", > + .attrs = file_stats_attrs, > +}; > + > +static struct attribute *any_stats_attrs[] = { > +#ifdef CONFIG_SHMEM > + &swpout_attr.attr, > + &swpout_fallback_attr.attr, > +#endif Sorry I did not point it out in early version. I think file pages and shmem can also be split, while 'split_deferred' is only for anonymous page. So I think the any_stats_attrs should be: static struct attribute *any_stats_attrs[] = { #ifdef CONFIG_SHMEM &swpout_attr.attr, &swpout_fallback_attr.attr, #endif &split_attr.attr, &split_failed_attr.attr, NULL, };