Results 1 to 6 of 6
I want to write a loop that sucks up all the 2mb slugs of memory I can get in the kernel. However, I want to leave "some" free space (say ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 05-05-2010 #1Just Joined!
- Join Date
- May 2010
- Posts
- 3
How to determine Amount of free kernel memory and problem with __get_free_pages()
I want to write a loop that sucks up all the 2mb slugs of memory I can get in the kernel. However, I want to leave "some" free space (say 20% of the machine's total phys mem). So, how can I do that? I have a loop now something like as an experiment to get all the mem I can and then release enough for the system to continue running but the kernel hangs:
for( i = 0; i < MAX_SLUGS; ++i )
{
if(( pMemSlugs[ i ] = __get_free_pages( GFP_KERNEL | __GFP_HIGHMEM | __GFP_NORETRY, 9)) == 0 )
{
break;
}
InfoLOG("Got page 0x%lx, PA=0x%lx\n", pMemSlugs[ i ], virt_to_phys((volatile void * )pMemSlugs[ i ]) );
}
If I make MAX_SLUGS too big, the kernel either panics or hangs (I haven't looked at which since the machine has no console). If I keep MAX_SLUGS small enough, the loop works (FYI, I release all this memory right after this loop since this is just an experiment). I have tried various flavors of the flags (GFP_KERNEL, etc.) to no avail.
So, why does this hang the system? I have seen similar samples of code allocating all slugs of order N as a test and presumably, these worked.
Second question, is there another way to do this? Could I instead loop allocating my 2mb slugs and then make another call and monitor the free memory and then stop allocating at some threshold.
All help is appreciated.
Scott
- 05-07-2010 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 10,141
Remember, Linux is a multi-tasking system with a reintrant kernel. When you suck up all the memory available to the kernel, other operations that need memory will fail, resulting in the expected panic and/or hang. Unfortunately I don't know enough right at the moment to tell you if there is a function to tell you how many pages are available, although there is in linux/slab.h the function slab_is_available(void) which returns an int indicating if there is kernel memory available.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 05-07-2010 #3Just Joined!
- Join Date
- May 2010
- Posts
- 3
- 05-07-2010 #4
- 05-07-2010 #5Just Joined!
- Join Date
- May 2010
- Posts
- 3
I do now. I didn't know about it when I made the original post! What I really want is to know how many "slugs" of order "N" are still available at any point in time (like what /proc/buddyinfo shows). I am poking around in the kernel now seeing how to get that in my driver.
- 05-07-2010 #6Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 10,141
Ah. Delving into the mysteries of The Kernel! Black Magic of the highest order, for sure! Watch out, or pretty soon someone will recruit you as a kernel maintainer...
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote

