Add a few fields to the seg_info structure to store the starting address
and size of the extracopy area for use by the next patch to drop
pagecache pages. If the extra_vaddr field is NULL, then the pagecache
dropping code assumes this means there was no extracopy area. This
method uses the start address and size to represent the extracopy area.

Signed-off-by: Nishanth Aravamudan <[EMAIL PROTECTED]>
---
 elflink.c |   50 ++++++++++++++++++++++++++------------------------
 1 files changed, 26 insertions(+), 24 deletions(-)

diff --git a/elflink.c b/elflink.c
index 5a57358..780d87c 100644
--- a/elflink.c
+++ b/elflink.c
@@ -186,8 +186,8 @@ static char share_path[PATH_MAX+1];
 #define MAX_HTLB_SEGS  2
 
 struct seg_info {
-       void *vaddr;
-       unsigned long filesz, memsz;
+       void *vaddr, *extra_vaddr;
+       unsigned long filesz, memsz, extrasz;
        int prot;
        int fd;
        int phdr;
@@ -497,8 +497,7 @@ static inline int keep_symbol(Elf_Sym *s, void *start, void 
*end)
  * include these initialized variables in our copy.
  */
 
-static void get_extracopy(struct seg_info *seg, void **extra_start,
-                                                       void **extra_end)
+static void get_extracopy(struct seg_info *seg)
 {
        Elf_Dyn *dyntab;        /* dynamic segment table */
        Elf_Sym *symtab = NULL; /* dynamic symbol table */
@@ -511,7 +510,7 @@ static void get_extracopy(struct seg_info *seg, void 
**extra_start,
        end_orig = seg->vaddr + seg->memsz;
        start_orig = seg->vaddr + seg->filesz;
        if (seg->filesz == seg->memsz)
-               goto bail2;
+               return;
        if (!minimal_copy)
                goto bail2;
 
@@ -557,23 +556,20 @@ static void get_extracopy(struct seg_info *seg, void 
**extra_start,
 
        if (found_sym) {
                /* Return the copy window */
-               *extra_start = start;
-               *extra_end = end;
-               return;
-       } else {
-               /* No need to copy anything */
-               *extra_start = start_orig;
-               *extra_end = start_orig;
-               goto bail3;
+               seg->extra_vaddr = start;
+               seg->extrasz = end - start;
        }
+       /*
+        * else no need to copy anything, so leave seg->extra_vaddr as
+        * NULL
+        */
+       return;
 
 bail:
        DEBUG("Unable to perform minimal copy\n");
 bail2:
-       *extra_start = start_orig;
-       *extra_end = end_orig;
-bail3:
-       return;
+       seg->extra_vaddr = start_orig;
+       seg->extrasz = end_orig - start_orig;
 }
 
 /*
@@ -584,7 +580,7 @@ bail3:
 static int prepare_segment(struct seg_info *seg)
 {
        int hpage_size = gethugepagesize();
-       void *p, *extra_start, *extra_end;
+       void *p;
        unsigned long gap;
        unsigned long size;
 
@@ -592,9 +588,14 @@ static int prepare_segment(struct seg_info *seg)
         * Calculate the BSS size that we must copy in order to minimize
         * the size of the shared mapping.
         */
-       get_extracopy(seg, &extra_start, &extra_end);
-       size = ALIGN((unsigned long)extra_end - (unsigned long)seg->vaddr,
+       get_extracopy(seg);
+       if (seg->extra_vaddr) {
+               size = ALIGN((unsigned long)seg->extra_vaddr +
+                               seg->extrasz - (unsigned long)seg->vaddr,
                                hpage_size);
+       } else {
+               size = ALIGN(seg->filesz, hpage_size);
+       }
 
        /* Prepare the hugetlbfs file */
 
@@ -617,11 +618,12 @@ static int prepare_segment(struct seg_info *seg)
        memcpy(p, seg->vaddr, seg->filesz);
        DEBUG_CONT("done\n");
 
-       if (extra_end > extra_start) {
+       if (seg->extra_vaddr) {
                DEBUG("Copying extra %#0lx bytes from %p...",
-                       (unsigned long)(extra_end - extra_start), extra_start);
-               gap = extra_start - (seg->vaddr + seg->filesz);
-               memcpy((p + seg->filesz + gap), extra_start, (extra_end - 
extra_start));
+                                       seg->extrasz, seg->extra_vaddr);
+               gap = seg->extra_vaddr - (seg->vaddr + seg->filesz);
+               memcpy((p + seg->filesz + gap), seg->extra_vaddr,
+                                                       seg->extrasz);
                DEBUG_CONT("done\n");
        }

-- 
Nishanth Aravamudan <[EMAIL PROTECTED]>
IBM Linux Technology Center

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Libhugetlbfs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel

Reply via email to