Uploaded image for project: 'Couchbase Server'
  1. Couchbase Server
  2. MB-16278

thread.c cqi_new never uses one of ITEMS_PER_ALLOC allocated CQ_ITEMs

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Fix
    • Minor
    • None
    • 3.1.0
    • moxi
    • Security Level: Public
    • None
    • Untriaged
    • Unknown

    Description

      Current code allocates but never uses cq_item[0].

      Here
      https://github.com/couchbase/moxi/blob/master/src/thread.c#L146
      currently...

              for (i = 2; i < ITEMS_PER_ALLOC; i++)
      ...
      cqi_freelist = &cq_item[1];
      

      ...I feel it should be

              for (i = 1; i < ITEMS_PER_ALLOC; i++)
      cqi_freelist = &cq_item[0];
      

              /* Allocate a bunch of items at once to reduce fragmentation */
              cq_item = malloc(sizeof(CQ_ITEM) * ITEMS_PER_ALLOC);
              if (NULL == cq_item)
                  return NULL;
       
              /*
               * Link together all the new items except the first one
               * (which we'll return to the caller) for placement on
               * the freelist.
               */
              for (i = 2; i < ITEMS_PER_ALLOC; i++)
                  cq_item[i - 1].next = &cq_item[i];
       
       
              cb_mutex_enter(&cqi_freelist_lock);
              cq_item[ITEMS_PER_ALLOC - 1].next = cqi_freelist;
              cqi_freelist = &cq_item[1];
      

      No harm done. Just 1/64 memory is not used effectively here.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            steve Steve Yen
            paf Alexander Petrossian (PAF)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty