Re: Difference between kmalloc and __get_free_pages
From: vishpat (vishpat_at_gmail.com)
Date: 07/09/04
- Next message: Vikram: "Re: finding correct vendor-id , product-id"
- Previous message: Larry I Smith: "Re: pthread_join() core dump"
- In reply to: Kasper Dupont: "Re: Difference between kmalloc and __get_free_pages"
- Next in thread: nikhil bhargav: "Re: Difference between kmalloc and __get_free_pages"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 9 Jul 2004 09:00:48 -0700
Nikhil
I am sorry but I can't post the code until it has been officially
released. However check the website
http://public.lanl.gov/radiant/software/magnet.html
where the patch will be officially released in about a month
- Vishal
Kasper Dupont <remove.invalid@nospam.lir.dk.invalid> wrote in message news:<40EAF741.9822423A@nospam.lir.dk.invalid>...
> vishpat wrote:
> >
> > Hello World
> >
> > I know that the __get_free_pages is used to allocate KERNEL memory in
> > terms of PAGES while kmalloc is used to allocate arbitrary sized
> > CONTINOUS KERNEL memory.
>
> Actually kmalloc use gfp to get the memory. The most
> important advantage of kmalloc is, that it can fit
> multiple small allocations into a single page.
>
> Calling gfp directly will allow you to use different
> options, for example to allocate high memory, which
> is not possible with kmalloc.
>
> >
> > However I was facing a problem when I was using "kmalloc" which got
> > solved when I switched over to "__get_free_pages". Even though I am
> > done with the problem I am curious about what was I doing wrong while
> > using "kmalloc". Perhaps some one can catch the flaw and let me know.
> >
> > I have written a CHAR device driver which I use to export some
> > information from the kernel to the user space programs. Initially I
> > was allocating FIVE pages of kernel memory using "kmalloc"
>
> kmalloc will round up the size you request to one of
> the supported sizes. You can see the sizes in
> /proc/slabinfo. An unmodified kernel will support
> only sizes that are a power of two. That means you
> have actually allocated eight pages.
>
> > and then
> > locking these pages using the function "SetPageReserved". I then
> > memory mapped the memory in the user space. However SOMETIMES whenever
> > I tried reading data from the kernel my machine hung. However this
> > problem got solved when I switched over to "__get_free_pages" and then
> > could easily read the required data from the kernel.
>
> Well, it certainly sounds like a case where kmalloc
> should not be used. When you allocate using kmalloc
> you really don't own the pages, kmalloc owns the
> pages, you are just allowed to use the memory. I'm
> not even sure you are guaranteed that the allocation
> will be page aligned (though I know that is the case
> with the current kmalloc implementation).
>
> I'm not sure exactly what happened, but you may have
> different parts of the kernel accessing the page
> struct each thinking they own it.
>
> Using gfp directly you cannot allocate five pages,
> what you specify is the power, which means 2 is 4
> pages and 3 is 8 pages. If you actually specified
> 5 as the argument you were in fact requesting 32
> pages. If you happen to write beyond the 8 allocated
> pages, the extra pages could explain why it works
> with gfp and not kmalloc. This is of course based on
> a lot of assumptions I can't really know anything
> about without seeing the code.
- Next message: Vikram: "Re: finding correct vendor-id , product-id"
- Previous message: Larry I Smith: "Re: pthread_join() core dump"
- In reply to: Kasper Dupont: "Re: Difference between kmalloc and __get_free_pages"
- Next in thread: nikhil bhargav: "Re: Difference between kmalloc and __get_free_pages"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|