LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
LinkBack Search this Thread
Old 01-04-2011, 05:17 AM   #1
Deep Narayan Dubey
LQ Newbie
 
Registered: Dec 2010
Location: Allahabad, India
Posts: 11

Rep: Reputation: 8
Error while saving memory pages of a process- Sleeping in memory from invalid context


Hi,
I am trying to checkpoint process state in a file so that I can restore it later. I am able to save the registers, open files, signals of a process. I am also able to save the task->mm information and the vma start, end and offset but when I am trying to save pages I am getting following error -
Sleeping function is called from invalid context

My code for saving page is following -

Code:
/*
 * This function saves the memory pages in the region of memory specified by vma
 */
int save_pages(struct task_struct *task, struct vm_area_struct *vma, struct segments *seg) {

    int ret = 0;
    int len = PAGE_SIZE;

    struct mm_struct *mm;

    unsigned long addr;
    struct page *page;
    pte_t * pte;

    if(!(vma->vm_flags & VM_WRITE) || get_fd(task,vma->vm_file) != -1) {
        return(0);
    }

    mm = task->mm;

    if(!mm) {
        return -1;
    }

    for(addr = vma->vm_start ; addr < vma->vm_end ; addr = addr + PAGE_SIZE) {
		
    seg->num_pages++;

    pte = chkpt_get_pte(vma,addr);
		
    if(pte && pte_present(*pte)) {

       page = pfn_to_page(pte_pfn(*pte));

       if(page_mapped(page)) {

           if(addr + PAGE_SIZE > vma->vm_end) {
               len = vma->vm_end - addr;
           }
           else {
               len = PAGE_SIZE;
           }
           if(vma->vm_flags & VM_MAYREAD) {
               if(copy_from_user(buffer, (void *)addr, len) != 0) {
                   printk(KERN_ALERT "Error while copying pages from used addr %lu to buffer\n", addr);
                   return -1;
               }
               ret = chkpt_write(filp,&addr,sizeof(unsigned long));
               if(ret < 0) {
                   printk(KERN_ALERT "Error while saving the address = %lu\n", addr);
                   return(ret);
               }
               ret = chkpt_write(filp, buffer, PAGE_SIZE);
               if(ret < 0) {
                   printk(KERN_ALERT "Error while saving the page\n");
                      return(ret);
                   }
                }
            }
        }
    }
    return(ret);
}
I have created a lock before saving memory using down_read(&task->mm->mmap_sem);

The stack trace printed after the above error gives that the above error has occurred when copy_from_user() function is called. It internally invokes the might_sleep() function and this function prints the above error.

Please, help so that I can remove the above error and save the memory pages.

Thanks in advance for any help.
 
Old 04-05-2012, 02:58 PM   #2
Bibek1602
LQ Newbie
 
Registered: Mar 2012
Posts: 3

Rep: Reputation: Disabled
Quote:
Originally Posted by Deep Narayan Dubey View Post
Hi,
I am trying to checkpoint process state in a file so that I can restore it later. I am able to save the registers, open files, signals of a process. I am also able to save the task->mm information and the vma start, end and offset but when I am trying to save pages I am getting following error -
Sleeping function is called from invalid context

My code for saving page is following -

Code:
/*
 * This function saves the memory pages in the region of memory specified by vma
 */
int save_pages(struct task_struct *task, struct vm_area_struct *vma, struct segments *seg) {

    int ret = 0;
    int len = PAGE_SIZE;

    struct mm_struct *mm;

    unsigned long addr;
    struct page *page;
    pte_t * pte;

    if(!(vma->vm_flags & VM_WRITE) || get_fd(task,vma->vm_file) != -1) {
        return(0);
    }

    mm = task->mm;

    if(!mm) {
        return -1;
    }

    for(addr = vma->vm_start ; addr < vma->vm_end ; addr = addr + PAGE_SIZE) {
		
    seg->num_pages++;

    pte = chkpt_get_pte(vma,addr);
		
    if(pte && pte_present(*pte)) {

       page = pfn_to_page(pte_pfn(*pte));

       if(page_mapped(page)) {

           if(addr + PAGE_SIZE > vma->vm_end) {
               len = vma->vm_end - addr;
           }
           else {
               len = PAGE_SIZE;
           }
           if(vma->vm_flags & VM_MAYREAD) {
               if(copy_from_user(buffer, (void *)addr, len) != 0) {
                   printk(KERN_ALERT "Error while copying pages from used addr %lu to buffer\n", addr);
                   return -1;
               }
               ret = chkpt_write(filp,&addr,sizeof(unsigned long));
               if(ret < 0) {
                   printk(KERN_ALERT "Error while saving the address = %lu\n", addr);
                   return(ret);
               }
               ret = chkpt_write(filp, buffer, PAGE_SIZE);
               if(ret < 0) {
                   printk(KERN_ALERT "Error while saving the page\n");
                      return(ret);
                   }
                }
            }
        }
    }
    return(ret);
}
I have created a lock before saving memory using down_read(&task->mm->mmap_sem);

The stack trace printed after the above error gives that the above error has occurred when copy_from_user() function is called. It internally invokes the might_sleep() function and this function prints the above error.

Please, help so that I can remove the above error and save the memory pages.

Thanks in advance for any help.
Hi,we are new to Linux and the concept of checkpointing. As you have mentioned that you are able to save the contents of the process but facing problem in saving the pages, can you help us in doing what you have already done. We are not able to save the context of the process also. It will be grateful of you if you help us anyhow...

Thanks in advance for any help....
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sleeping function called from invalid context kushneeraj Programming 8 04-16-2013 08:25 PM
process, memory, swap, virtual memory wakatana Linux - Hardware 1 08-31-2009 07:55 AM
Difference between resident memory,shared memory and virtual memory in system monitor mathimca05 Linux - Newbie 1 11-11-2007 04:05 AM
how to transfer a register context to memory qqrilxk Programming 1 03-07-2005 11:46 PM
Help Configuring the Memory Used by a Process in RedHat? (Cache Memory on CPU) geogecko Linux - General 3 02-23-2005 03:32 PM


All times are GMT -5. The time now is 09:51 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration