Sponsored Content
Top Forums Programming Code to write the heap into a file Post 302417621 by holla4ni on Friday 30th of April 2010 07:08:26 AM
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;

 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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

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

7. 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

8. 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

9. 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
FETCH(9)						   BSD Kernel Developer's Manual						  FETCH(9)

NAME
fetch, fubyte, fuibyte, fuiword, fulong, fuulong, fuword -- fetch data from user-space SYNOPSIS
#include <sys/types.h> #include <sys/time.h> #include <sys/systm.h> #include <sys/resourcevar.h> int fubyte(const user_addr_t addr); int fuibyte(const user_addr_t addr); int fuiword(user_addr_t addr); int64_t fulong(user_addr_t addr); uint64_t fuulong(user_addr_t addr); int fuword(user_addr_t addr); DESCRIPTION
The fetch functions are designed to copy small amounts of data from user-space. The fetch routines provide the following functionality: fubyte() Fetches a byte of data from the user-space address addr. fuibyte() Fetches a byte of data from the user-space address addr. This function is safe to call during an interrupt context. fuiword() Fetches a word of data from the user-space address addr. This function is safe to call during an interrupt context. fulong() Fetches a long word of data from the user-space address addr. fuulong() Fetches a unsigned long word of data from the user-space address addr. fuword() Fetches a word of data from the user-space address addr. RETURN VALUES
The fetch functions return the data fetched or -1 on failure. SEE ALSO
copy(9), store(9) BSD
December 16, 2004 BSD
All times are GMT -4. The time now is 04:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy