lkml.org 
[lkml]   [2021]   [Mar]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2 2/2] mm/memcg: set memcg when split page
On Thu, Mar 11, 2021 at 09:37:02AM +0100, Michal Hocko wrote:
> Johannes, Hugh,
>
> what do you think about this approach? If we want to stick with
> split_page approach then we need to update the missing place Matthew has
> pointed out.

I find the __free_pages() code quite tricky as well. But for that
reason I would actually prefer to initiate the splitting in there,
since that's the place where we actually split the page, rather than
spread the handling of this situation further out.

The race condition shouldn't be hot, so I don't think we need to be as
efficient about setting page->memcg_data only on the higher-order
buddies as in Willy's scratch patch. We can call split_page_memcg(),
which IMO should actually help document what's happening to the page.

I think that function could also benefit a bit more from step-by-step
documentation about what's going on. The kerneldoc is helpful, but I
don't think it does justice to how tricky this race condition is.

Something like this?

void __free_pages(struct page *page, unsigned int order)
{
/*
* Drop the base reference from __alloc_pages and free. In
* case there is an outstanding speculative reference, from
* e.g. the page cache, it will put and free the page later.
*/
if (likely(put_page_testzero(page))) {
free_the_page(page, order);
return;
}

/*
* The speculative reference will put and free the page.
*
* However, if the speculation was into a higher-order page
* that isn't marked compound, the other side will know
* nothing about our buddy pages and only free the order-0
* page at the start of our chunk! We must split off and free
* the buddy pages here.
*
* The buddy pages aren't individually refcounted, so they
* can't have any pending speculative references themselves.
*/
if (!PageHead(page) && order > 0) {
split_page_memcg(page, 1 << order);
while (order-- > 0)
free_the_page(page + (1 << order), order);
}
}

\
 
 \ /
  Last update: 2021-03-11 16:22    [W:6.369 / U:0.032 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site