Skip to content

Commit a2873f1

Browse files
committed
Revert "vmalloc: Optimize vfree"
This reverts commit d511c6d. Signed-off-by: Eric Naim <dnaim@cachyos.org>
1 parent af38e91 commit a2873f1

3 files changed

Lines changed: 10 additions & 45 deletions

File tree

include/linux/gfp.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,6 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int preferred_nid,
239239
struct page **page_array);
240240
#define __alloc_pages_bulk(...) alloc_hooks(alloc_pages_bulk_noprof(__VA_ARGS__))
241241

242-
void free_pages_bulk(struct page **page_array, unsigned long nr_pages);
243-
244242
unsigned long alloc_pages_bulk_mempolicy_noprof(gfp_t gfp,
245243
unsigned long nr_pages,
246244
struct page **page_array);

mm/page_alloc.c

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5214,44 +5214,6 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int preferred_nid,
52145214
}
52155215
EXPORT_SYMBOL_GPL(alloc_pages_bulk_noprof);
52165216

5217-
/*
5218-
* free_pages_bulk - Free an array of order-0 pages
5219-
* @page_array: Array of pages to free
5220-
* @nr_pages: The number of pages in the array
5221-
*
5222-
* Free the order-0 pages. Adjacent entries whose PFNs form a contiguous
5223-
* run are released with a single __free_contig_range() call.
5224-
*
5225-
* This assumes page_array is sorted in ascending PFN order. Without that,
5226-
* the function still frees all pages, but contiguous runs may not be
5227-
* detected and the freeing pattern can degrade to freeing one page at a
5228-
* time.
5229-
*
5230-
* Context: Sleepable process context only; calls cond_resched()
5231-
*/
5232-
void free_pages_bulk(struct page **page_array, unsigned long nr_pages)
5233-
{
5234-
unsigned long start_pfn = 0, pfn;
5235-
unsigned long i, nr_contig = 0;
5236-
5237-
for (i = 0; i < nr_pages; i++) {
5238-
pfn = page_to_pfn(page_array[i]);
5239-
if (!nr_contig) {
5240-
start_pfn = pfn;
5241-
nr_contig = 1;
5242-
} else if (start_pfn + nr_contig != pfn) {
5243-
__free_contig_range(start_pfn, nr_contig);
5244-
start_pfn = pfn;
5245-
nr_contig = 1;
5246-
cond_resched();
5247-
} else {
5248-
nr_contig++;
5249-
}
5250-
}
5251-
if (nr_contig)
5252-
__free_contig_range(start_pfn, nr_contig);
5253-
}
5254-
52555217
/*
52565218
* This is the 'heart' of the zoned buddy allocator.
52575219
*/

mm/vmalloc.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3468,12 +3468,17 @@ void vfree(const void *addr)
34683468
/* All pages of vm should be charged to same memcg, so use first one. */
34693469
if (vm->nr_pages && !(vm->flags & VM_MAP_PUT_PAGES))
34703470
mod_memcg_page_state(vm->pages[0], MEMCG_VMALLOC, -vm->nr_pages);
3471-
if (!(vm->flags & VM_MAP_PUT_PAGES)) {
3472-
for (i = 0; i < vm->nr_pages; i++)
3473-
mod_lruvec_page_state(vm->pages[i], NR_VMALLOC, -1);
3474-
}
3475-
free_pages_bulk(vm->pages, vm->nr_pages);
3471+
for (i = 0; i < vm->nr_pages; i++) {
3472+
struct page *page = vm->pages[i];
34763473

3474+
BUG_ON(!page);
3475+
/*
3476+
* High-order allocs for huge vmallocs are split, so
3477+
* can be freed as an array of order-0 allocations
3478+
*/
3479+
__free_page(page);
3480+
cond_resched();
3481+
}
34773482
if (!(vm->flags & VM_MAP_PUT_PAGES))
34783483
atomic_long_sub(vm->nr_pages, &nr_vmalloc_pages);
34793484
kvfree(vm->pages);

0 commit comments

Comments
 (0)