Code to write the heap into a file


 
Thread Tools Search this Thread
Top Forums Programming Code to write the heap into a file
# 1  
Old 04-30-2010
Error Code to write the heap into a file

Hi everybody, i am doing a project on checkpoints, where in i need to write the heap area into a file. I have got a code which i need to analyze, also asked in the forum under solaris
libckpt

The heap is implemented as a link list given by the structure Dlist. As i am not so familiar with some concepts of heap, i need some suggestions regarding the following code: please help me in analzing this code

Code:
PAGESIZE 4096
DATASTART (char *)&etext;

typedef struct dlist {
  struct dlist *flink;
  struct dlist *blink;
  char *addr;
  char *stop;
  unsigned long size;
} *Dlist;

Dlist curptr, endptr; ( Dlist is a structure to create a link list)
  int no_chunks=0, pn;
  long size;
  caddr_t stop, addr;

  if(incremental){       /*-- variable used to check if incremental checkpointing on? --*/
    endptr = inc_list->main->flink;
 
    /*-- for each included chunk of the heap --*/
    for(curptr = inc_list->main->blink->blink;
        curptr != endptr; curptr = curptr->blink){

      /*-- write out the last page in the included chunk --*/
      stop = curptr->addr;
      pn = ((long)curptr->stop - (long)DATASTART) / PAGESIZE;

      if(isdirty(pn)){ /* function to check if the segment has been modified*/ 
        addr = (caddr_t)max((long)curptr->addr,
                            (long)((pn * PAGESIZE) + DATASTART));
        size = (long)curptr->stop - (long)addr;

        debug(stderr, "DEBUG: Writing heap from 0x%x to 0x%x, pn = %d\n",
                                                   addr, addr+size, pn);
        if(write_chunk(addr, size, map_fd, data_fd) == -1){ /* function to write a chunk to a file */
          return -1;
        }
        no_chunks++;
      }

      /*-- write out all the whole pages in the middle of the chunk --*/
      for(pn--; pn * PAGESIZE + DATASTART >= stop; pn--){
        if(isdirty(pn)){
          addr = (caddr_t)((pn * PAGESIZE) + DATASTART);
          debug(stderr, "DEBUG: Writing heap from 0x%x to 0x%x, pn = %d\n",
                                                 addr, addr+PAGESIZE, pn);
          if(write_chunk(addr, PAGESIZE, map_fd, data_fd) == -1){
            return -1;
          }
         
          }
          no_chunks++;
        }
      }

      /*-- write out the first page in the included chunk --*/
      addr = curptr->addr;
      size = ((pn+1) * PAGESIZE + DATASTART) - addr;

      if(size > 0 && (isdirty(pn))){
        debug(stderr, "DEBUG: Writing heap from 0x%x to 0x%x\n", addr, addr+size);
        if(write_chunk(addr, size, map_fd, data_fd) == -1){
          return -1;
        }

        
        }
        no_chunks++;
      }
    }
  }
  else{  /*-- incremental checkpointing off! --*/
    endptr = inc_list->main->blink;

    /*-- for each included chunk of the heap --*/
    for(curptr = inc_list->main->flink->flink;
        curptr != endptr; curptr = curptr->flink){
      debug(stderr, "DEBUG: saving memory from 0x%x to 0x%x\n", 
                         curptr->addr, curptr->addr+curptr->size);

      if(write_chunk(curptr->addr, curptr->size, map_fd, data_fd) == -1){
        return -1;
      }
  
      }
      no_chunks++;
    }
  }

  return no_chunks;

# 2  
Old 05-12-2010
Let me see the code first ...

I'll get back to you.
# 3  
Old 05-12-2010
I am closing this thread. This appears to be a duplicate thread by the same person masquerading as two different users. The discussion can be continued at libckpt
This User Gave Thanks to fpmurphy For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

can i have an optimal solution for this java code ? Facing Java heap space problem even at 3GB heaps

My desired output is run: for this 1 for this 2 for this 3 for this 4 for this 5 for this 1,2 1->2 for this 2,3 2->3 for this 3,4 3->4 for this 4,5 4->5 for this 1,2,3 1->2,3 (2 Replies)
Discussion started by: vaibhavkorde
2 Replies

2. HP-UX

Heap fragmentation on HPUX

Hi All, We are facing issues on HPUX with the C heap region growing. We use a product for CRM by name ClarifyCRM and it uses a native layer for DB access. so there are best practices in place to actual control memory. recently we have seen issues that the C heap region is growing faster than... (0 Replies)
Discussion started by: ramchand75
0 Replies

3. IP Networking

read/write,write/write lock with smbclient fails

Hi, We have smb client running on two of the linux boxes and smb server on another linux system. During a backup operation which uses smb, read of a file was allowed while write to the same file was going on.Also simultaneous writes to the same file were allowed.Following are the settings in the... (1 Reply)
Discussion started by: swatidas11
1 Replies

4. Programming

Java code to access the shared heap

Hi Help needed and forgive me as I dont know Java so please bare with me. I have searched this site and google but was unable to locate the information I need. An application that we use - is based on java and stores some performance counters etc internally in the shared JVM. They are not... (4 Replies)
Discussion started by: frustrated1
4 Replies

5. HP-UX

Heap fragementation on HPUX

The Resident size(as observed from top) of my process is increasing. But, the behaviour is very random. My process works on request reponse model. So when i put some request load on my process the memory starts increasing. For initial few hours (approx ~3 hrs) it increase at a rapid rate and after... (1 Reply)
Discussion started by: atgoel
1 Replies

6. Programming

How to write a code in C to search a file

Dear All, Plz give me some code that how can I search a file through a C program file may be in Present Directory or in its Sub-Directories and it should support Linux Platform. :mad: (6 Replies)
Discussion started by: krishna_sicsr
6 Replies

7. Programming

Heap and stack

Hi, I have a basic doubt here. Consider the following code snippet: main() { int *a; . . } Here the memory for a gets allocated in heap or stack. (5 Replies)
Discussion started by: naan
5 Replies

8. Filesystems, Disks and Memory

heap size for JVM!

Hi all, Thanks 'thehoghunter' and 'hugo' for the comments! I've to increase the size of the heap size for AIX 4.3.3. Now what's the command that I've and also is it something similar to growing the file system in Solaris (growfs) (1 Reply)
Discussion started by: i2admin
1 Replies

9. Filesystems, Disks and Memory

heap size!

I'm a new guy to this field and I'm learning a lot about UNIX! Can any explan to me what exactly does 'heap size' mean and how can i increase the size for AIX 4.3.3? (2 Replies)
Discussion started by: i2admin
2 Replies
Login or Register to Ask a Question