Re: [PATCHv9 03/14] mm/page_alloc: Fake unaccepted memory

Kirill A. Shutemov
2023-04-03T14:56:25Z

On Mon, Apr 03, 2023 at 04:43:08PM +0200, David Hildenbrand wrote:
> On 30.03.23 13:49, Kirill A. Shutemov wrote:
> > For testing purposes, it is useful to fake unaccepted memory in the
> > system. It helps to understand unaccepted memory overhead to the page
> > allocator.
> >
> > The patch allows to treat memory above the specified physical memory
> > address as unaccepted.
> >
> > The change only fakes unaccepted memory for page allocator. Memblock is
> > not affected.
> >
> > It also assumes that arch-provided accept_memory() on already accepted
> > memory is a nop.
> >
> > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> > ---
> > mm/page_alloc.c | 21 +++++++++++++++++++++
> > 1 file changed, 21 insertions(+)
> >
> > diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> > index d62fcb2f28bd..509a93b7e5af 100644
> > --- a/mm/page_alloc.c
> > +++ b/mm/page_alloc.c
> > @@ -7213,6 +7213,8 @@ static DEFINE_STATIC_KEY_FALSE(zones_with_unaccepted_pages);
> > static bool lazy_accept = true;
> > +static unsigned long fake_unaccepted_start = -1UL;
> > +
> > static int __init accept_memory_parse(char *p)
> > {
> > if (!strcmp(p, "lazy")) {
> > @@ -7227,11 +7229,30 @@ static int __init accept_memory_parse(char *p)
> > }
> > early_param("accept_memory", accept_memory_parse);
> > +static int __init fake_unaccepted_start_parse(char *p)
> > +{
> > + if (!p)
> > + return -EINVAL;
> > +
> > + fake_unaccepted_start = memparse(p, &p);
> > +
> > + if (*p != '\0') {
> > + fake_unaccepted_start = -1UL;
> > + return -EINVAL;
> > + }
> > +
> > + return 0;
> > +}
> > +early_param("fake_unaccepted_start", fake_unaccepted_start_parse);
> > +
> > static bool page_contains_unaccepted(struct page *page, unsigned int order)
> > {
> > phys_addr_t start = page_to_phys(page);
> > phys_addr_t end = start + (PAGE_SIZE << order);
> > + if (start >= fake_unaccepted_start)
> > + return true;
> > +
> > return range_contains_unaccepted_memory(start, end);
> > }
>
> The "unpleasant" thing about this is, that page_contains_unaccepted() could
> not be used for sanity checks because the result is static.
>
> For example, something like
>
> if (page_contains_unaccepted(page, 0))
> accept_memory(page, 0);
> BUG_ON(!page_contains_unaccepted(page, 0));
>
> Would work on real hardware, however, not for the fake variant.

Need for raw_page_contains_unaccepted()? :P

--
Kiryl Shutsemau / Kirill A. Shutemov