Author: adrian.chadd
Date: Mon Jul 20 00:08:36 2009
New Revision: 14216

Modified:
    playpen/LUSCA_HEAD_storework/app/coss_rebuild/coss_build_dir.c
    playpen/LUSCA_HEAD_storework/app/coss_rebuild/coss_rebuild.c
    playpen/LUSCA_HEAD_storework/app/ufs_rebuild/ufs_build_dir.c
    playpen/LUSCA_HEAD_storework/app/ufs_rebuild/ufs_build_log.c
    playpen/LUSCA_HEAD_storework/app/ufs_rebuild/ufs_rebuild.c
    playpen/LUSCA_HEAD_storework/libsqstore/rebuild_entry.c
    playpen/LUSCA_HEAD_storework/libsqstore/rebuild_entry.h
    playpen/LUSCA_HEAD_storework/libsqstore/store_log.c
    playpen/LUSCA_HEAD_storework/libsqstore/store_log.h

Log:
Migrate the coss and ufs rebuild helpers to use fwrite() and large write
buffers rather than write()'ing individual entries to stdout.

This dramatically reduces the CPU used by both the helpers and the main
lusca process.

I'll investigate replacing the read-side buffer hack I've done with
calls to fread() at a later date.



Modified: playpen/LUSCA_HEAD_storework/app/coss_rebuild/coss_build_dir.c
==============================================================================
--- playpen/LUSCA_HEAD_storework/app/coss_rebuild/coss_build_dir.c       
(original)
+++ playpen/LUSCA_HEAD_storework/app/coss_rebuild/coss_build_dir.c      Mon Jul 
 
20 00:08:36 2009
@@ -64,8 +64,7 @@

                re.swap_filen = (off_t) j / (off_t) blocksize + (off_t) 
((off_t)  
stripeid * (off_t) stripesize / (off_t) blocksize);

-
-               if (! write_swaplog_entry(1, &re)) {
+               if (! write_swaplog_entry(stdout, &re)) {
                        rebuild_entry_done(&re);
                        return -1;
                }
@@ -107,7 +106,7 @@
                return 0;
        }

-       storeSwapLogPrintHeader(1);     
+       storeSwapLogPrintHeader(stdout);        

        for(blksize_bits = 0;((blocksize >> blksize_bits) > 0);blksize_bits++) {
                if( ((blocksize >> blksize_bits) > 0) &&
@@ -122,7 +121,7 @@
        for (cur_stripe = 0; cur_stripe < numstripes; cur_stripe++) {
                getCurrentTime();
                debug(85, 5) ("COSS: %s: STRIPE: %d\n", file, cur_stripe);
-               storeSwapLogPrintProgress(1, cur_stripe, numstripes);
+               storeSwapLogPrintProgress(stdout, cur_stripe, numstripes);
                if (cur_stripe % report_interval == 0) {
                        debug(85, 1) ("COSS[%d]: %s: Rebuilding %.2f%% complete 
(%d out of %d  
stripes)\n",
                            pid, file, (float) cur_stripe / (float) numstripes 
* 100.0,  
cur_stripe, numstripes);
@@ -141,7 +140,8 @@
                        break;
        }
        close(fd);
-       storeSwapLogPrintCompleted(1);  
+       storeSwapLogPrintCompleted(stdout);     
+       fflush(stdout);

        safe_free(buf);
        return 1;

Modified: playpen/LUSCA_HEAD_storework/app/coss_rebuild/coss_rebuild.c
==============================================================================
--- playpen/LUSCA_HEAD_storework/app/coss_rebuild/coss_rebuild.c        
(original)
+++ playpen/LUSCA_HEAD_storework/app/coss_rebuild/coss_rebuild.c        Mon Jul 
20  
00:08:36 2009
@@ -11,6 +11,8 @@

  int shutting_down = 0;        /* needed for libiapp */

+#define        WRITE_BUFFER_LEN        65536
+
  int
  main(int argc, const char *argv[])
  {
@@ -19,12 +21,19 @@
        int block_size;
        size_t stripe_size;
        int num_stripes;
+       char * wbuf = NULL;
+

        if (argc < 5) {
                printf("Usage: %s <command> <path> <block size> <stripe size> 
<number of  
stripes>\n", argv[0]);
                printf("  where the block and stripe sizes are in bytes\n");
                printf("  and <command> is, for now, 'rebuild'\n");
                exit(127);
+       }
+
+       wbuf = malloc(WRITE_BUFFER_LEN);
+       if (wbuf) {
+               setbuffer(stdout, wbuf, WRITE_BUFFER_LEN);
        }

        /* Setup the debugging library */

Modified: playpen/LUSCA_HEAD_storework/app/ufs_rebuild/ufs_build_dir.c
==============================================================================
--- playpen/LUSCA_HEAD_storework/app/ufs_rebuild/ufs_build_dir.c        
(original)
+++ playpen/LUSCA_HEAD_storework/app/ufs_rebuild/ufs_build_dir.c        Mon Jul 
20  
00:08:36 2009
@@ -102,7 +102,7 @@
        for (i = 0; i < store_ufs_l1(sd); i++) {
                for (j = 0; j < store_ufs_l2(sd); j++) {
                        (void) store_ufs_createDir(sd, i, j, dir);
-                       if (! storeSwapLogPrintProgress(1, (sd->l2 * i) + j, 
(sd->l1 * sd->l2)))
+                       if (! storeSwapLogPrintProgress(stdout, (sd->l2 * i) + 
j, (sd->l1 *  
sd->l2)))
                                return;

                        getCurrentTime();
@@ -133,7 +133,7 @@
                                rebuild_entry_init(&re);
                                (void) read_file(path, &re);
                                re.swap_filen = fn;
-                               if (! write_swaplog_entry(1, &re)) {
+                               if (! write_swaplog_entry(stdout, &re)) {
                                        debug(47, 1) ("read_dir: write() 
failed: (%d) %s\n", errno,  
xstrerror());
                                        rebuild_entry_done(&re);
                                        return;

Modified: playpen/LUSCA_HEAD_storework/app/ufs_rebuild/ufs_build_log.c
==============================================================================
--- playpen/LUSCA_HEAD_storework/app/ufs_rebuild/ufs_build_log.c        
(original)
+++ playpen/LUSCA_HEAD_storework/app/ufs_rebuild/ufs_build_log.c        Mon Jul 
20  
00:08:36 2009
@@ -50,7 +50,7 @@
  {
        struct stat sb;
        if (0 == fstat(fileno(fp), &sb)) {
-               if (! storeSwapLogPrintProgress(1, num_objects, (int) 
sb.st_size / s))
+               if (! storeSwapLogPrintProgress(stdout, num_objects, (int) 
sb.st_size /  
s))
                        return 0;
        }
        return 1;
@@ -158,7 +158,7 @@
        }

        /* begin echo'ing the log info */
-       storeSwapLogPrintHeader(1);     /* to stdout */
+       storeSwapLogPrintHeader(stdout);

        /* Now - loop over until eof or error */
        while (! feof(fp)) {

Modified: playpen/LUSCA_HEAD_storework/app/ufs_rebuild/ufs_rebuild.c
==============================================================================
--- playpen/LUSCA_HEAD_storework/app/ufs_rebuild/ufs_rebuild.c  (original)
+++ playpen/LUSCA_HEAD_storework/app/ufs_rebuild/ufs_rebuild.c  Mon Jul 20  
00:08:36 2009
@@ -16,6 +16,8 @@
  #include "ufs_build_dir.h"
  #include "ufs_build_log.h"

+#define        WRITE_BUFFER_LEN        65536
+
  int shutting_down = 0;

  typedef enum {
@@ -46,10 +48,7 @@
        const char *cmd;
        store_ufs_dir_t store_ufs_info;
        rebuild_type_t rebuild_type;
-
-       /* Setup the debugging library */
-       _db_init("ALL,1");
-       _db_set_stderr_debug(1);
+       char *wbuf = NULL;

        if (argc < 5) {
                usage(argv[0]);
@@ -57,6 +56,16 @@
        }
        cmd = argv[1];

+       wbuf = malloc(WRITE_BUFFER_LEN);
+       if (wbuf) {
+               setbuffer(stdout, wbuf, WRITE_BUFFER_LEN);
+       }
+
+       /* Setup the debugging library */
+       _db_init("ALL,1");
+       _db_set_stderr_debug(1);
+
+
        store_ufs_init(&store_ufs_info, argv[2], atoi(argv[3]), atoi(argv[4]),  
argv[5]);

        if (strcmp(cmd, "rebuild-dir") == 0) {
@@ -71,7 +80,7 @@
        }

        /* Output swap header to stdout */
-       (void) storeSwapLogPrintHeader(1);
+       (void) storeSwapLogPrintHeader(stdout);

        if (rebuild_type == REBUILD_DISK)
                rebuild_from_dir(&store_ufs_info);
@@ -79,7 +88,8 @@
                rebuild_from_log(&store_ufs_info);

        store_ufs_done(&store_ufs_info);
-       (void) storeSwapLogPrintCompleted(1);
+       (void) storeSwapLogPrintCompleted(stdout);
+       fflush(stdout);

        return 0;
  }

Modified: playpen/LUSCA_HEAD_storework/libsqstore/rebuild_entry.c
==============================================================================
--- playpen/LUSCA_HEAD_storework/libsqstore/rebuild_entry.c     (original)
+++ playpen/LUSCA_HEAD_storework/libsqstore/rebuild_entry.c     Mon Jul 20  
00:08:36 2009
@@ -113,7 +113,7 @@
  }

  int
-write_swaplog_entry(int fd, rebuild_entry_t *re)
+write_swaplog_entry(FILE *fp, rebuild_entry_t *re)
  {
        storeSwapLogData sd;

@@ -128,7 +128,7 @@
        sd.flags = re->mi.flags;

        memcpy(&sd.key, re->md5_key, sizeof(sd.key));
-       if (write(fd, &sd, sizeof(sd)) <= 0)
+       if (fwrite(&sd, sizeof(sd), 1, fp) < 1)
                return 0;
        return 1;
  }

Modified: playpen/LUSCA_HEAD_storework/libsqstore/rebuild_entry.h
==============================================================================
--- playpen/LUSCA_HEAD_storework/libsqstore/rebuild_entry.h     (original)
+++ playpen/LUSCA_HEAD_storework/libsqstore/rebuild_entry.h     Mon Jul 20  
00:08:36 2009
@@ -16,6 +16,6 @@
  extern void rebuild_entry_done(rebuild_entry_t *re);
  extern void rebuild_entry_init(rebuild_entry_t *re);
  extern int parse_header(char *buf, int len, rebuild_entry_t *re);
-extern int write_swaplog_entry(int fd, rebuild_entry_t *re);
+extern int write_swaplog_entry(FILE *fp, rebuild_entry_t *re);

  #endif

Modified: playpen/LUSCA_HEAD_storework/libsqstore/store_log.c
==============================================================================
--- playpen/LUSCA_HEAD_storework/libsqstore/store_log.c (original)
+++ playpen/LUSCA_HEAD_storework/libsqstore/store_log.c Mon Jul 20 00:08:36  
2009
@@ -42,7 +42,7 @@
  }

  int
-storeSwapLogPrintHeader(int fd)
+storeSwapLogPrintHeader(FILE *fp)
  {
      char buf[sizeof(storeSwapLogData)];
      storeSwapLogHeader *sh = (storeSwapLogHeader *) buf;
@@ -51,22 +51,26 @@
      sh->op = SWAP_LOG_VERSION;
      sh->version = 1;
      sh->record_size = sizeof(storeSwapLogData);
-    return write(1, sh, sizeof(storeSwapLogData));
+    if (fwrite(buf, sizeof(storeSwapLogData), 1, fp) < 1)
+        return 0;
+    return 1;
  }

  int
-storeSwapLogPrintCompleted(int fd)
+storeSwapLogPrintCompleted(FILE *fp)
  {
      char buf[sizeof(storeSwapLogData)];
      storeSwapLogCompleted *sh = (storeSwapLogCompleted *) buf;

      bzero(buf, sizeof(buf));
      sh->op = SWAP_LOG_COMPLETED;
-    return write(1, sh, sizeof(storeSwapLogData));
+    if (fwrite(buf, sizeof(storeSwapLogData), 1, fp) < 1)
+        return 0;
+    return 1;
  }

  int
-storeSwapLogPrintProgress(int fd, u_int32_t progress, u_int32_t total)
+storeSwapLogPrintProgress(FILE *fp, u_int32_t progress, u_int32_t total)
  {
          char buf[128];
          storeSwapLogProgress *sp = (storeSwapLogProgress *) buf;
@@ -77,7 +81,7 @@
          sp->progress = progress;

          /* storeSwapLogData is the record size */
-        if (write(1, buf, sizeof(storeSwapLogData)) <= 0)
+        if (fwrite(buf, sizeof(storeSwapLogData), 1, fp) < 1)
                  return 0;
          return 1;
  }

Modified: playpen/LUSCA_HEAD_storework/libsqstore/store_log.h
==============================================================================
--- playpen/LUSCA_HEAD_storework/libsqstore/store_log.h (original)
+++ playpen/LUSCA_HEAD_storework/libsqstore/store_log.h Mon Jul 20 00:08:36  
2009
@@ -66,8 +66,8 @@
  extern const char * swap_log_op_str[];

  extern int storeSwapLogUpgradeEntry(storeSwapLogData *dst,  
storeSwapLogDataOld *src);
-extern int storeSwapLogPrintHeader(int fd);
-extern int storeSwapLogPrintProgress(int fd, u_int32_t progress, u_int32_t  
total);
-extern int storeSwapLogPrintCompleted(int fd);
+extern int storeSwapLogPrintHeader(FILE *fp);
+extern int storeSwapLogPrintProgress(FILE *fp, u_int32_t progress,  
u_int32_t total);
+extern int storeSwapLogPrintCompleted(FILE *fp);

  #endif

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"lusca-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/lusca-commit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to