Skip to contentSkip to conversation

how to purposfully fragment memory?

DISCUSSION Chris Friesen 2 participants 2 messages Mar 20, 2007 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

I'm trying to test code paths dealing with fragmented memory, so I'd like to have a simple way to cause fragmented memory in the kernel. Is there any API in the kernel that would let me allocate two contiguous pages, then free one of them?

I tried the following, but it triggers an oops in free_page():

unsigned long addr =

	__get_free_pages(GFP_KERNEL|__GFP_NORETRY|__GFP_NOWARN, 1);
if (!addr)
	break;

free_page(addr+4096);

Thanks,

Chris

#3 lore raw
In reply to a message not in the archive
Quoted 8 lines · Chris Friesen
Quoted 1 line · Asgard

btw, can you describe your aim in details?

I'm doing some work on a network device driver. We were having jumbo frame issues after being up for a month or so because it couldn't allocate enough contiguous memory.

Quoted 6 lines

We've got a new code path now that doesn't need large contiguous allocations, so I'd like to demonstrate it by forcing the system to become severely fragmented.

Chris

and by the way, you can try to use void split_page(struct page *page, unsigned int order) function, but keep in mind, that it's not recommended to use it in drivers:
/*
* split_page takes a non-compound higher-order page, and splits it into
* n (1<<order) sub-pages: page[0..n]
* Each sub-page must be freed individually.
*
* Note: this is probably too low level an operation for use in drivers.
* Please consult with lkml before using this in your driver. */
void split_page(struct page *page, unsigned int order)

Good luck.
Dan.