From: Muchun Song <muchun.song@linux.dev>
To: John Hubbard <jhubbard@nvidia.com>
Cc: Sidhartha Kumar <sidhartha.kumar@oracle.com>,
Mike Kravetz <mike.kravetz@oracle.com>,
Matthew Wilcox <willy@infradead.org>,
linux-kernel@vger.kernel.org,
Linux Memory Management List <linux-mm@kvack.org>,
Andrew Morton <akpm@linux-foundation.org>,
Muchun Song <songmuchun@bytedance.com>,
tsahu@linux.ibm.com, David Hildenbrand <david@redhat.com>
Subject: Re: [PATCH mm-unstable] mm: clarify folio_set_compound_order() zero support
Date: Fri, 9 Dec 2022 22:27:38 +0800 [thread overview]
Message-ID: <00222280-DBDD-49A3-92A5-05112359AE30@linux.dev> (raw)
In-Reply-To: <7d72778e-7305-18e9-edf4-ed55a98aa7e2@nvidia.com>
> On Dec 9, 2022, at 06:39, John Hubbard <jhubbard@nvidia.com> wrote:
>
> On 12/8/22 14:33, Sidhartha Kumar wrote:
>> On 12/8/22 2:14 PM, John Hubbard wrote:
>>> On 12/8/22 14:12, Sidhartha Kumar wrote:
>>>> On 12/8/22 2:01 PM, John Hubbard wrote:
>>>>> On 12/8/22 13:58, Sidhartha Kumar wrote:
>>>>>> Thanks John, Mike, Matthew, and Muchun for the feedback.
>>>>>>
>>>>>> To summarize this discussion and outline the next version of this patch, the changes I'll make include:
>>>>>>
>>>>>> 1) change the name of folio_set_compound_order() to folio_set_order()
>>>>>> 2) change the placement of this function from mm.h to mm/internal.h
>>>>>> 3) folio_set_order() will set both _folio_order and _folio_nr_pages and handle the zero order case correctly.
>>>>>> 4) remove the comment about hugetlb's specific use for zero orders
>>>>>> 5) improve the style of folio_set_order() by removing ifdefs from inside the function to doing
>>>>>>
>>>>>> #ifdef CONFIG_64BIT
>>>>>> static inline void folio_set_order(struct folio *folio,
>>>>>> unsigned int order)
>>>>>> {
>>>>>> VM_BUG_ON_FOLIO(!folio_test_large(folio), folio);
>>>>>
>>>>> Sounds good, except for this part: why is a function named
>>>>> folio_set_order() BUG-ing on a non-large folio? The naming
>>>>> is still wrong, perhaps?
>>>>>
>>>>
>>>> This is because the _folio_nr_pages and _folio_order fields are part of the first tail page in the folio. folio_test_large returns if the folio is larger than one page which would be required for setting the fields.
>>>
>>> OK, but then as I said, the name is wrong. One can either:
>>>
>>> a) handle the non-large case, or
>>>
>>> b) rename the function to indicate that it only works on large folios.
>>>
>> Discussed here[1], the BUG_ON line seemed more appropriate over
>> if (!folio_test_large(folio))
>> return;
>> as the misuse would not be silent. I think I would be against renaming the function as I don't see any large folio specific function names for other accessors of tail page fields. Would both the BUG_ON and return on non-large folio be included then?
>
> Actually, if you want the "misuse to not be silent", today's guidelines
> would point more toward WARN and return, instead of BUG, btw.
From you advise, I think we can remove VM_BUG_ON and handle non-zero
order page, something like:
static inline void folio_set_order(struct folio *folio,
unsigned int order)
{
if (!folio_test_large(folio)) {
WARN_ON(order);
return;
}
folio->_folio_order = order;
#ifdef CONFIG_64BIT
folio->_folio_nr_pages = order ? 1U << order : 0;
#endif
}
In this case,
1) we can handle both non-zero and zero (folio_order() works as well
for this case) order page.
2) it can prevent OOB for non-large folio and warn unexpected users.
3) Do not BUG.
4) No need to rename folio_set_order.
What do you think?
Thanks.
>
> I don't think that a survey of existing names is really the final word on what
> to name this. Names should be accurate, even if other names are less so. How
> about something like:
>
> large_folio_set_order()
>
> ?
>
>> [1]: https://lore.kernel.org/linux-mm/20221129225039.82257-1-sidhartha.kumar@oracle.com/T/#m98cf80bb21ae533b7385f2e363c602e2c9e2802d
>>>
>>> thanks,
>
> thanks,
> --
> John Hubbard
> NVIDIA
next prev parent reply other threads:[~2022-12-09 14:28 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-07 22:37 Sidhartha Kumar
2022-12-08 0:38 ` John Hubbard
2022-12-08 1:42 ` Sidhartha Kumar
2022-12-08 2:27 ` John Hubbard
2022-12-08 4:41 ` Muchun Song
2022-12-08 18:06 ` Sidhartha Kumar
2022-12-08 19:32 ` Mike Kravetz
2022-12-08 19:33 ` Matthew Wilcox
2022-12-08 19:56 ` John Hubbard
2022-12-08 20:01 ` Mike Kravetz
2022-12-08 21:58 ` Sidhartha Kumar
2022-12-08 22:01 ` John Hubbard
2022-12-08 22:12 ` Sidhartha Kumar
2022-12-08 22:14 ` John Hubbard
2022-12-08 22:33 ` Sidhartha Kumar
2022-12-08 22:39 ` John Hubbard
2022-12-09 14:27 ` Muchun Song [this message]
2022-12-09 21:10 ` John Hubbard
2022-12-09 21:20 ` John Hubbard
2022-12-14 3:00 ` Muchun Song
2022-12-08 22:04 ` Matthew Wilcox
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=00222280-DBDD-49A3-92A5-05112359AE30@linux.dev \
--to=muchun.song@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=jhubbard@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mike.kravetz@oracle.com \
--cc=sidhartha.kumar@oracle.com \
--cc=songmuchun@bytedance.com \
--cc=tsahu@linux.ibm.com \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox