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 45E30CD4847 for ; Wed, 4 Sep 2024 10:47:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 99E306B014E; Wed, 4 Sep 2024 06:47:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 94D638D0250; Wed, 4 Sep 2024 06:47:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 83B596B014F; Wed, 4 Sep 2024 06:47:35 -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 66A806B014C for ; Wed, 4 Sep 2024 06:47:35 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9BA62160EBE for ; Wed, 4 Sep 2024 10:47:34 +0000 (UTC) X-FDA: 82526729628.24.7088A5B Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf29.hostedemail.com (Postfix) with ESMTP id 7AD7B12001B for ; Wed, 4 Sep 2024 10:47:32 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725446777; 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; bh=I8FUvQ0WtvWevDF4JUHm68oZ7dAPU8aasPX4u2oxzBw=; b=YBnWyglLhqEMe8tl8X6fA4A9C76DrOSyHVqpTiyaR3TmY8vhwhxItm4ySbXkoOlCu+x+tH WrTwP7RpZuSOBv+hIlPWFtICGjBcIevPD8pgvV42juDR1kwL6eE7zjdBLH5c+lDlMmvn6P xbBpKf6E5mqnHx2Fs5NrbuRXZX+XcLM= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725446777; a=rsa-sha256; cv=none; b=aj7kJiaPckExITS7QmVWu2Nup9KSTFnBHdFB/WK6Lk/02pe3B57PcrlLrHCpLbElpUlL3w Vlr0E6NSHE+CQc/dqgXti+HwHSuK8pNYwnhktxK/N129nw3cxHQlWtcHfnXZ1zLVizqTEW LnHqvJGFvsSpBF4tvCIAvpsNTIK1Qn0= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 19CA7FEC; Wed, 4 Sep 2024 03:47:58 -0700 (PDT) Received: from [10.57.87.65] (unknown [10.57.87.65]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6D4423F73B; Wed, 4 Sep 2024 03:47:30 -0700 (PDT) Message-ID: Date: Wed, 4 Sep 2024 11:47:29 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 2/2] mm: Tidy up shmem mTHP controls and stats Content-Language: en-GB To: Baolin Wang , 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> <747d1319-f746-4379-bf88-a0f6c3f558b4@linux.alibaba.com> From: Ryan Roberts In-Reply-To: <747d1319-f746-4379-bf88-a0f6c3f558b4@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Stat-Signature: rcnmz9okhtagw35bib3e7sd5kp86qep5 X-Rspam-User: X-Rspamd-Queue-Id: 7AD7B12001B X-Rspamd-Server: rspam02 X-HE-Tag: 1725446852-430149 X-HE-Meta: U2FsdGVkX1+q5jXhwf2xM0+gedWVUOl/P/9u//FXdhW+h2GgsYiXYmtyEizlUKxTRySjWiCn2iqEmyp0ArVs5Tov/Zxnof+RXpQX837COXiCsDW3gfGSvzlznX1kscAp8vSVske1sJJLKeyNNVnGzV8MYsbBlGDqZ2g6G7FVHM+zl38jMj9OlxoNqectAdj7joDJviaSxB5vEceOsey5jjfPvNv8dIc7Sy53b0bUuexEgH/Bo5izFp24PDAr8TegWtgt1/T4RFoVdIErFG8gIB3ifBHItBbq1Q5HTk56F32vXavvMIti+LYTjQU0UqNnH1t9QcOx6tL+Q7iBvHOUJHEt+99cDlFPeE0lP9he1218jvOc9pgsi2pzCzapmBq+MuxCarRTp5L2XOIK8xuc5kfkCMSW1dtXE+JwM3ynePzUczV1hUx0rlqoTf/SkKjgwAofAgpOdsf9qdR6Mbaipcv61M1vxkfF/8pR9j2Coe9HFPupZPG2v1ak6DByWwmvof3uGY2sxev+o5Y6I+CfOjpFAgKlNMlg5zhbrf4XKyYgDiQdWEgGcITCJMfOHC8DbRP7zu5DsebCoyfWQE7zMADxr+cU+Zl8NtTxqojSnNcBMvA5Cm2yZbbmmSBUdZ8ThH1IG3ig4YyINgHVlbden9zHiuXe5RwhKhsrhoW/Cj9qTI6woCwkFObUw+BiFHRaZIebU6rF7dZpaMonYoYbUnHxiRyNCBKFBFq1Xj2G4yYacl1aYPB8/gqijxK3WWmSLMj51d5vJwP0UjOnyAe+4Aap59PcnuiDzmrkUtlmck6R5YOWjqNhG5J8bdAhk9J+tSnM13R3GlsFRukEOU2ZNB2G6b8eqrSoSEdO5aohOZmaPzgbWgzXHh3yn4SZ9+TkH30htUJjXy1i4K9Hy++wRs8odJ0HKj6UhC8h7dzzgJ0uu2bQZXodN73cgeE3EUXafSc+HOmP4ypYkRx/8VT WFhKvuQB bSN43Sz3ZOtQO2CpXk+QFj8C/T32bXTCK14G1vgJROfeqtpuSPDAmJWyQCrkKsntp57f1AkwRPm2qCamWC33Y6Ea2Rb7kwGBJddXp1R/lJV2uDaaJO16tfR2pPmDlyTtBV593+jUZGi7Vn5HnFZzfBGZ2p4XRz1PROW62HAMwfyfH1U8a8EIxd4eyJUiCCWuX0JP4PXtdUo0lHp9oDeA9zpSe9DT0LRsbSSOIXecaV2Yh4NU= 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: Hi Andrew, On 09/08/2024 09:31, Baolin Wang wrote: > > > 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, > }; Could you please squash the following into this patch, which is already in mm-unstable? I'm hoping this sufficient and I don't need to send a whole new revision since there are changes on top of this in mm-unstable, which makes things tricky. ----8<----- diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 382938e46f96f..5905957b1f70d 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -631,8 +631,6 @@ static struct attribute *anon_stats_attrs[] = { &swpout_attr.attr, &swpout_fallback_attr.attr, #endif - &split_attr.attr, - &split_failed_attr.attr, &split_deferred_attr.attr, &nr_anon_attr.attr, &nr_anon_partially_mapped_attr.attr, @@ -663,6 +661,8 @@ static struct attribute *any_stats_attrs[] = { &swpout_attr.attr, &swpout_fallback_attr.attr, #endif + &split_attr.attr, + &split_failed_attr.attr, NULL, }; ----8<----- Thanks, Ryan