how to use the memory allocated in kernel?

夏业添 summerxyt at gmail.com
Wed Apr 18 06:00:03 EDT 2012


Hi Dave,

Thanks for reply. My English is not very good, and so I want to ask about a
term:map. Does map mean that create a relationship between the virtual
space and physical memory?

Thanks again!

在 2012年4月18日 下午4:17,Dave Hylands <dhylands at gmail.com>写道:

> Hi ,
>
> On Wed, Apr 18, 2012 at 12:44 AM, 夏业添 <summerxyt at gmail.com> wrote:
> > Hi everyone,
> >
> > there are some functions can alloc memory in kernel, but it seems that I
> > cannot use it directly. Here is my code:
> >
> > static int mytest_vm(){
> >
> >         struct vm_struct *v_start;
> >
> >         v_start=alloc_vm_area(PAGE_SIZE,NULL); //the kernel api has
> changed,
> > I don't understand why there is a second parameter
> >         if(v_start==NULL){
> >                 printk("cannot alloc page\n");
> >                 return -1;
> >         }
> >
> >         sprintf((char *)v_start->addr,"this is a test.\n");
> >         printk("after sprintk:%s",(char *)v_start->addr);
> >
> >         free_vm_area(v_start);
> >
> >         return 0;
> > }
> > module_init(mytest_vm);
> >
> > but it just got a kernel Oops. Can anyone explain this to me? Thanks very
> > much!
>
> If my understanding of things is correct, this just allocates virtual
> space. That virtual space isn't backed by any physical pages.
>
> The normal kernel allocators are things like kmalloc and vmalloc.
>
> --
> Dave Hylands
> Shuswap, BC, Canada
> http://www.davehylands.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120418/60e6aa51/attachment.html 


More information about the Kernelnewbies mailing list