Merge tag 'memblock-v5.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock
Pull memblock updates from Mike Rapoport: "Test suite and a small cleanup: - A small cleanup of unused variable in __next_mem_pfn_range_in_zone - Initial test suite to simulate memblock behaviour in userspace" * tag 'memblock-v5.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock: (27 commits) memblock tests: Add TODO and README files memblock tests: Add memblock_alloc_try_nid tests for bottom up memblock tests: Add memblock_alloc_try_nid tests for top down memblock tests: Add memblock_alloc_from tests for bottom up memblock tests: Add memblock_alloc_from tests for top down memblock tests: Add memblock_alloc tests for bottom up memblock tests: Add memblock_alloc tests for top down memblock tests: Add simulation of physical memory memblock tests: Split up reset_memblock function memblock tests: Fix testing with 32-bit physical addresses memblock: __next_mem_pfn_range_in_zone: remove unneeded local variable nid memblock tests: Add memblock_free tests memblock tests: Add memblock_add_node test memblock tests: Add memblock_remove tests memblock tests: Add memblock_reserve tests memblock tests: Add memblock_add tests memblock tests: Add memblock reset function memblock tests: Add skeleton of the memblock simulator tools/include: Add debugfs.h stub tools/include: Add pfn.h stub ...
This commit is contained in:
38
tools/lib/slab.c
Normal file
38
tools/lib/slab.c
Normal file
@@ -0,0 +1,38 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <urcu/uatomic.h>
|
||||
#include <linux/slab.h>
|
||||
#include <malloc.h>
|
||||
#include <linux/gfp.h>
|
||||
|
||||
int kmalloc_nr_allocated;
|
||||
int kmalloc_verbose;
|
||||
|
||||
void *kmalloc(size_t size, gfp_t gfp)
|
||||
{
|
||||
void *ret;
|
||||
|
||||
if (!(gfp & __GFP_DIRECT_RECLAIM))
|
||||
return NULL;
|
||||
|
||||
ret = malloc(size);
|
||||
uatomic_inc(&kmalloc_nr_allocated);
|
||||
if (kmalloc_verbose)
|
||||
printf("Allocating %p from malloc\n", ret);
|
||||
if (gfp & __GFP_ZERO)
|
||||
memset(ret, 0, size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void kfree(void *p)
|
||||
{
|
||||
if (!p)
|
||||
return;
|
||||
uatomic_dec(&kmalloc_nr_allocated);
|
||||
if (kmalloc_verbose)
|
||||
printf("Freeing %p to malloc\n", p);
|
||||
free(p);
|
||||
}
|
||||
Reference in New Issue
Block a user