[Groonga-commit] groonga/groonga at 3a43f10 [master] Remove broken AIO support

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Nov 15 16:51:35 JST 2013


Kouhei Sutou	2013-11-15 16:51:35 +0900 (Fri, 15 Nov 2013)

  New Revision: 3a43f109cce524af951b896b04846a0a12f62b74
  https://github.com/groonga/groonga/commit/3a43f109cce524af951b896b04846a0a12f62b74

  Message:
    Remove broken AIO support
    
    AIO support was tried but it was not completed. We couldn't bring out
    AIO performance.
    
    The try was too old. We couldn't restart the current
    implementation. So we remove the current broken implementation.
    
    fixes #2054
    
    Reported by sho MINAGAWA. Thanks!!!

  Modified files:
    configure.ac
    lib/ctx.c
    lib/ii.c
    lib/io.c

  Modified: configure.ac (+0 -12)
===================================================================
--- configure.ac    2013-11-15 11:25:29 +0900 (00e1eef)
+++ configure.ac    2013-11-15 16:51:35 +0900 (602e840)
@@ -329,18 +329,6 @@ if test "x$grn_debug" != "xno"; then
 fi
 AC_SUBST(grn_debug)
 
-# AIO
-AC_ARG_ENABLE(aio,
-  [AS_HELP_STRING([--enable-aio],
-                  [use aio/dio based cache. [default=no]])],
-  ,
-  [enable_aio="no"])
-if test "x$enable_aio" != "xno"; then
-  AC_DEFINE(_XOPEN_SOURCE, [600], [Define to 600 for use AIO.])
-  AC_SEARCH_LIBS(nanosleep, rt, [], [AC_MSG_ERROR("No librt found")])
-  AC_DEFINE(USE_AIO, [1], [use AIO/DIO])
-fi
-
 AC_SEARCH_LIBS(log, m, [], [AC_MSG_ERROR("No libm found")])
 AC_MSG_CHECKING([for fpclassify])
 AC_LINK_IFELSE(

  Modified: lib/ctx.c (+0 -15)
===================================================================
--- lib/ctx.c    2013-11-15 11:25:29 +0900 (5d3fcf3)
+++ lib/ctx.c    2013-11-15 16:51:35 +0900 (96e342a)
@@ -1259,21 +1259,6 @@ grn_init(void)
     GRN_LOG(ctx, GRN_LOG_CRIT, "pagesize=%x", grn_pagesize);
   }
   // expand_stack();
-#ifdef USE_AIO
-  if (getenv("GRN_DEBUG_PRINT")) {
-    grn_debug_print = atoi(getenv("GRN_DEBUG_PRINT"));
-  } else {
-    grn_debug_print = 0;
-  }
-  if (getenv("GRN_AIO_ENABLED")) {
-    grn_aio_enabled = atoi(getenv("GRN_AIO_ENABLED"));
-  } else {
-    grn_aio_enabled = 0;
-  }
-  if (grn_aio_enabled) {
-    GRN_LOG(ctx, GRN_LOG_NOTICE, "AIO and DIO enabled");
-  }
-#endif /* USE_AIO */
 #ifdef USE_FAIL_MALLOC
   if (getenv("GRN_FMALLOC_PROB")) {
     grn_fmalloc_prob = strtod(getenv("GRN_FMALLOC_PROB"), 0) * RAND_MAX;

  Modified: lib/ii.c (+0 -114)
===================================================================
--- lib/ii.c    2013-11-15 11:25:29 +0900 (c95bb68)
+++ lib/ii.c    2013-11-15 16:51:35 +0900 (98a481d)
@@ -4090,79 +4090,6 @@ exit :
   return c;
 }
 
-#ifdef USE_AIO
-grn_ii_cursor *
-grn_ii_cursor_openv1(grn_ii *ii, grn_id tid)
-{
-  grn_ii_cursor *c  = NULL;
-  uint32_t pos, *a = array_at(ctx, ii, tid);
-  if (!a) { return NULL; }
-  if (!(pos = a[0])) { goto exit; }
-  if (!(c = GRN_MALLOC(sizeof(grn_ii_cursor)))) { goto exit; }
-  memset(c, 0, sizeof(grn_ii_cursor));
-  c->ii = ii;
-  if (pos & 1) {
-    c->stat = 0;
-    if ((ii->header->flags & GRN_OBJ_WITH_SECTION)) {
-      c->pb.rid = BIT31_12(pos);
-      c->pb.sid = BIT11_01(pos);
-    } else {
-      c->pb.rid = pos >> 1;
-      c->pb.sid = 1;
-    }
-    c->pb.tf = 1;
-    c->pb.weight = 0;
-    c->pb.pos = a[1];
-  } else {
-    buffer_term *bt;
-    c->pb.rid = 0; c->pb.sid = 0;
-    if ((c->buffer_pseg = buffer_open(ctx, ii, pos, &bt, &c->buf)) == NOT_ASSIGNED) {
-      GRN_FREE(c);
-      c = NULL;
-      goto exit;
-    }
-    c->iw.io = ii->chunk;
-    c->iw.mode = grn_io_rdonly;
-    c->iw.segment = c->buf->header.chunk;
-    c->iw.offset = bt->pos_in_chunk;
-    c->iw.size = bt->size_in_chunk;
-    c->nextb = bt->pos_in_buffer;
-    c->stat = CHUNK_USED|BUFFER_USED;
-  }
-exit :
-  array_unref(ii, tid);
-  return c;
-}
-
-grn_rc
-grn_ii_cursor_openv2(grn_ctx *ctx, grn_ii_cursor **cursors, int ncursors)
-{
-  grn_rc rc = GRN_SUCCESS;
-  int i, j = 0;
-  grn_ii_cursor *c;
-  grn_io_win **iws = GRN_MALLOC(sizeof(grn_io_win *) * ncursors);
-  if (!iws) { return GRN_NO_MEMORY_AVAILABLE; }
-  for (i = 0; i < ncursors; i++) {
-    c = cursors[i];
-    if (c->stat && c->iw.size && c->iw.segment != NOT_ASSIGNED) {
-      iws[j++] = &c->iw;
-    }
-  }
-  if (j) { rc = grn_io_win_mapv(iws, ctx, j); }
-  for (i = 0; i < ncursors; i++) {
-    c = cursors[i];
-    if (c->iw.addr) {
-      c->cp = c->iw.addr + c->iw.diff;
-      c->cpe = c->cp + c->iw.size;
-      c->pc.rid = 0;
-      c->pc.sid = 0;
-    }
-  }
-  GRN_FREE(iws);
-  return rc;
-}
-#endif /* USE_AIO */
-
 grn_ii_posting *
 grn_ii_cursor_next(grn_ctx *ctx, grn_ii_cursor *c)
 {
@@ -4548,15 +4475,6 @@ cursor_heap_push(grn_ctx *ctx, cursor_heap *h, grn_ii *ii, grn_id tid, uint32_t
     h->n_bins = max;
     h->bins = bins;
   }
-#ifdef USE_AIO
-  if (grn_aio_enabled) {
-    if (!(c = grn_ii_cursor_openv1(ii, tid))) {
-      GRN_LOG(ctx, GRN_LOG_ERROR, "cursor open failed");
-      return ctx->rc;
-    }
-    h->bins[h->n_entries++] = c;
-  } else
-#endif /* USE_AIO */
   {
     if (!(c = grn_ii_cursor_open(ctx, ii, tid, GRN_ID_NIL, GRN_ID_MAX,
                                  ii->n_elements, 0))) {
@@ -4589,38 +4507,6 @@ static inline grn_rc
 cursor_heap_push2(cursor_heap *h)
 {
   grn_rc rc = GRN_SUCCESS;
-#ifdef USE_AIO
-  if (grn_aio_enabled) {
-    int i, j, n, n2;
-    grn_ii_cursor *c, *c2;
-    if (h && h->n_entries) {
-      rc = grn_ii_cursor_openv2(ctx, h->bins, h->n_entries);
-      GRN_ASSERT(rc);
-      for (i = 0, j = 0; i < h->n_entries; i++) {
-        c = h->bins[i];
-        if (!grn_ii_cursor_next(ctx, c)) {
-          grn_ii_cursor_close(ctx, c);
-          continue;
-        }
-        if (!grn_ii_cursor_next_pos(ctx, c)) {
-          GRN_LOG(ctx, GRN_LOG_ERROR, "invalid ii_cursor b");
-          grn_ii_cursor_close(ctx, c);
-          continue;
-        }
-        n = j++;
-        while (n) {
-          n2 = (n - 1) >> 1;
-          c2 = h->bins[n2];
-          if (GRN_II_CURSOR_CMP(c, c2)) { break; }
-          h->bins[n] = c2;
-          n = n2;
-        }
-        h->bins[n] = c;
-      }
-      h->n_entries = j;
-    }
-  }
-#endif /* USE_AIO */
   return rc;
 }
 

  Modified: lib/io.c (+0 -177)
===================================================================
--- lib/io.c    2013-11-15 11:25:29 +0900 (2253705)
+++ lib/io.c    2013-11-15 16:51:35 +0900 (87a7853)
@@ -940,160 +940,6 @@ grn_io_win_map(grn_io *io, grn_ctx *ctx, grn_io_win *iw, uint32_t segment,
   return iw->addr;
 }
 
-#ifdef USE_AIO
-grn_rc
-grn_io_win_mapv(grn_io_win **list, grn_ctx *ctx, int nent)
-{
-  int i;
-  grn_io_win *iw;
-  struct aiocb *iocbs[MAX_REQUEST];
-  struct aiocb iocb[MAX_REQUEST];
-  CacheIOOper oper[MAX_REQUEST];
-  int count = 0;
-
-  grn_io_win **clist = list;
-  int cl = 0;
-
-retry:
-  for (i = 0; i < nent; i++) {
-    iw = list[i];
-    if (grn_aio_enabled && iw->mode == grn_io_rdonly) {
-        /* this block is same as grn_io_win_map() */
-        grn_io *io = iw->io;
-        uint32_t segment = iw->segment, offset = iw->offset, size = iw->size;
-        byte *p;
-        off_t pos, base;
-        int fno;
-        uint32_t nseg, bseg;
-        uint32_t segment_size = io->header->segment_size;
-        uint32_t segments_per_file = GRN_IO_FILE_SIZE / segment_size;
-        fileinfo *fi;
-        iw->diff = 0;
-        if (offset >= segment_size) {
-            segment += offset / segment_size;
-            offset = offset % segment_size;
-        }
-        nseg = (offset + size + segment_size - 1) / segment_size;
-        bseg = segment + io->base_seg;
-        fno = bseg / segments_per_file;
-        base = fno ? 0 : io->base - (uint64_t)segment_size * io->base_seg;
-        pos = (uint64_t)segment_size * (bseg % segments_per_file) + offset + base;
-        if (!size || !io || segment + nseg > io->header->max_segment ||
-            fno != (bseg + nseg - 1) / segments_per_file) {
-          return GRN_FILE_CORRUPT;
-        }
-        fi = &io->fis[fno];
-        if (!grn_opened(fi)) {
-            char path[PATH_MAX];
-            gen_pathname(io->path, path, fno);
-            if (grn_open(ctx, fi, path, O_RDWR|O_CREAT|O_DIRECT, GRN_IO_FILE_SIZE)) {
-                return ctx->rc;
-            }
-        }
-        {
-            /* AIO + DIO + cache hack */
-            /* calc alignment */
-            // todo : calculate curr_size.
-            off_t voffset = pos - (pos % MEM_ALIGN);
-            uint32_t vsize = pos + size;
-
-            vsize = ((vsize - 1) / MEM_ALIGN + 1) * MEM_ALIGN;
-            vsize = vsize - voffset;
-
-            /* diff of aligned offset */
-            iw->diff = pos - voffset;
-
-            dp ("pos: %lu, allocate: %d, really needed: %d\n", voffset, vsize, size);
-            memset(&oper[count], 0, sizeof(CacheIOOper));
-            memset(&iocb[count], 0, sizeof(struct aiocb));
-            oper[count].iocb = &iocb[count];
-            iocb[count].aio_fildes = fi->fd;
-            iocb[count].aio_lio_opcode = LIO_READ;
-
-            if (vsize <= MEM_ALIGN &&
-                (p = grn_cache_read (&oper[count], fi->dev, fi->inode, voffset, vsize)) != NULL) {
-                /* use cache process  */
-                iw->cached = oper[count].cd->num;
-
-                /* Cache require aio_read() or
-                   already aio_read() by other process */
-                if (oper[count].read == 1) {
-                    iocbs[count] = &iocb[count];
-                    count++; /* aio count */
-                } else if (oper[count].cd->flag == CACHE_READ) {
-                    /* this iw is ignored in this loop.
-                       should re-check after AIO */
-                    clist[cl++] = iw;
-                }
-            } else {
-                /* This size cannot use Cache */
-                dp ("Wont use cache offset=%lu size=%u\n", voffset, vsize);
-
-                /* allocate aligned memory */
-                if (posix_memalign(&p, MEM_ALIGN, vsize) != 0) {
-                  SERR("posix_memalign");
-                  return ctx->rc;
-                }
-                iocb[count].aio_buf = p;
-                iocb[count].aio_nbytes = vsize;
-                iocb[count].aio_offset = voffset;
-                iocbs[count] = &iocb[count];
-
-                /* This is not cached  */
-                oper[count].cd = NULL;
-                iw->cached = -1;
-
-                /* aio count up */
-                count++;
-            }
-            iw->addr = p;
-            iw->segment = segment;
-            iw->offset = offset;
-            iw->nseg = nseg;
-            iw->size = size;
-            iw->pos = pos;
-        } /* End  AIO + DIO + cache hack */
-    } else {
-        if (!grn_io_win_map(iw->io, ctx, iw, iw->segment, iw->offset, iw->size, iw->mode)) {
-            return ctx->rc;
-        }
-    }
-  }
-
-  if (grn_aio_enabled) {
-      if (count > 0) {
-          int c;
-
-          /* aio_read () */
-          if (lio_listio (LIO_WAIT, iocbs, count, NULL) < 0) {
-              SERR("lio_listio");
-              return ctx->rc;
-          }
-          for (c=0;c<count;c++) {
-              /* cache data is now VALID */
-              if (oper[c].cd) oper[c].cd->flag = CACHE_VALID;
-          }
-      }
-      if (cl > 0) {
-          /*
-           *  if previous loop have CACHE_READ CacheData,
-           *  it should retry.
-           */
-          dp ("-- Validate Reading state CacheData (%d) --\n", cl);
-          /* update list and nent for loop */
-          list = clist; /* list of iw which use CACHE_READ CacheData */
-          nent = cl;    /* number of iw */
-          cl = 0;
-          count = 0;
-          grn_nanosleep(1000);
-          goto retry;
-      } else
-          dp("-- No Reading state CacheData. --\n");
-  }
-  return GRN_SUCCESS;
-}
-#endif /* USE_AIO */
-
 grn_rc
 grn_io_win_unmap(grn_io_win *iw)
 {
@@ -1105,18 +951,7 @@ grn_io_win_unmap(grn_io_win *iw)
   int nseg = iw->nseg;
   switch (iw->mode) {
   case grn_io_rdonly:
-#ifdef USE_AIO
-    /* VA hack */
-    if (!grn_aio_enabled || (iw->cached < 0 && iw->addr)) { GRN_FREE(iw->addr); }
-    else if (iw->cached >= 0){
-      /* this data is cached */
-      grn_cache_data_unref (iw->cached);
-      iw->cached = -1;
-    }
-    /* end VA hack */
-#else /* USE_AIO */
     if (iw->addr) { GRN_FREE(iw->addr); }
-#endif /* USE_AIO */
     iw->addr = NULL;
     break;
   case grn_io_rdwr:
@@ -1129,13 +964,6 @@ grn_io_win_unmap(grn_io_win *iw)
       } else {
         //GRN_IO_SEG_UNREF(io, iw->segment);
       }
-#ifdef USE_AIO
-      if (grn_aio_enabled) {
-        int fno = (iw->segment + io->base_seg) / segments_per_file;
-        fileinfo *fi = &io->fis[fno];
-        grn_cache_mark_invalid(fi->dev, fi->inode, iw->pos, iw->size);
-      }
-#endif /* USE_AIO */
     }
     iw->addr = NULL;
     break;
@@ -1157,11 +985,6 @@ grn_io_win_unmap(grn_io_win *iw)
           if (!iw->cached) { GRN_FREE(iw->addr); }
           iw->addr = NULL;
         }
-#ifdef USE_AIO
-        if (grn_aio_enabled) {
-          grn_cache_mark_invalid(fi->dev, fi->inode, iw->pos, iw->size);
-        }
-#endif /* USE_AIO */
       }
     }
     break;
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index