Commit df48a5f7 authored by Liam R. Howlett's avatar Liam R. Howlett Committed by Andrew Morton

mm/page_alloc: reduce potential fragmentation in make_alloc_exact()

Try to avoid using the left over split page on the next request for a page
by calling __free_pages_ok() with FPI_TO_TAIL.  This increases the
potential of defragmenting memory when it's used for a short period of
time.

Link: https://lkml.kernel.org/r/20220531185626.yvlmymbxyoe5vags@revolverSigned-off-by: default avatarLiam R. Howlett <Liam.Howlett@oracle.com>
Suggested-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 08ac8552
...@@ -5784,14 +5784,18 @@ static void *make_alloc_exact(unsigned long addr, unsigned int order, ...@@ -5784,14 +5784,18 @@ static void *make_alloc_exact(unsigned long addr, unsigned int order,
size_t size) size_t size)
{ {
if (addr) { if (addr) {
unsigned long alloc_end = addr + (PAGE_SIZE << order); unsigned long nr = DIV_ROUND_UP(size, PAGE_SIZE);
unsigned long used = addr + PAGE_ALIGN(size); struct page *page = virt_to_page((void *)addr);
struct page *last = page + nr;
split_page(virt_to_page((void *)addr), order);
while (used < alloc_end) { split_page_owner(page, 1 << order);
free_page(used); split_page_memcg(page, 1 << order);
used += PAGE_SIZE; while (page < --last)
} set_page_refcounted(last);
last = page + (1UL << order);
for (page += nr; page < last; page++)
__free_pages_ok(page, 0, FPI_TO_TAIL);
} }
return (void *)addr; return (void *)addr;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment