diff options
| -rw-r--r-- | libglusterfs/src/iobuf.c | 35 | ||||
| -rw-r--r-- | libglusterfs/src/iobuf.h | 4 | ||||
| -rw-r--r-- | xlators/storage/posix/src/posix.c | 43 | 
3 files changed, 50 insertions, 32 deletions
diff --git a/libglusterfs/src/iobuf.c b/libglusterfs/src/iobuf.c index a4d36691cd0..b2df0dc9a3a 100644 --- a/libglusterfs/src/iobuf.c +++ b/libglusterfs/src/iobuf.c @@ -679,6 +679,36 @@ unlock:  }  struct iobuf * +iobuf_get_page_aligned (struct iobuf_pool *iobuf_pool, size_t page_size, +                        size_t align_size) +{ +        size_t              req_size     = 0; +        struct iobuf       *iobuf        = NULL; + +        req_size = page_size; + +        if (req_size == 0) { +                req_size = iobuf_pool->default_page_size; +        } + +        iobuf = iobuf_get2 (iobuf_pool, req_size + align_size); +        /* If std allocation was used, then free_ptr will be non-NULL. In this +         * case, we do not want to modify the original free_ptr. +         * On the other hand, if the buf was gotten through the available +         * arenas, then we use iobuf->free_ptr to store the original +         * pointer to the offset into the mmap'd block of memory and in turn +         * reuse iobuf->ptr to hold the page-aligned address. And finally, in +         * iobuf_put(), we copy iobuf->free_ptr into iobuf->ptr - back to where +         * it was originally when __iobuf_get() returned this iobuf. +         */ +        if (!iobuf->free_ptr) +                iobuf->free_ptr = iobuf->ptr; +        iobuf->ptr = GF_ALIGN_BUF (iobuf->ptr, align_size); + +        return iobuf; +} + +struct iobuf *  iobuf_get (struct iobuf_pool *iobuf_pool)  {          struct iobuf       *iobuf        = NULL; @@ -745,6 +775,11 @@ __iobuf_put (struct iobuf *iobuf, struct iobuf_arena *iobuf_arena)          list_del_init (&iobuf->list);          iobuf_arena->active_cnt--; +        if (iobuf->free_ptr) { +                iobuf->ptr = iobuf->free_ptr; +                iobuf->free_ptr = NULL; +        } +          list_add (&iobuf->list, &iobuf_arena->passive.list);          iobuf_arena->passive_cnt++; diff --git a/libglusterfs/src/iobuf.h b/libglusterfs/src/iobuf.h index 7e5cfe37a28..1578ceb84dd 100644 --- a/libglusterfs/src/iobuf.h +++ b/libglusterfs/src/iobuf.h @@ -169,4 +169,8 @@ void   iobuf_stats_dump (struct iobuf_pool *iobuf_pool);  struct iobuf *  iobuf_get2 (struct iobuf_pool *iobuf_pool, size_t page_size); + +struct iobuf * +iobuf_get_page_aligned (struct iobuf_pool *iobuf_pool, size_t page_size, +                        size_t align_size);  #endif /* !_IOBUF_H_ */ diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c index 7290905807b..836e90614f1 100644 --- a/xlators/storage/posix/src/posix.c +++ b/xlators/storage/posix/src/posix.c @@ -2985,8 +2985,6 @@ posix_readv (call_frame_t *frame, xlator_t *this,          int32_t                op_ret     = -1;          int32_t                op_errno   = 0;          int                    _fd        = -1; -        char                 *buf         = NULL; -        char                 *alloc_buf   = NULL;          struct posix_private * priv       = NULL;          struct iobuf         * iobuf      = NULL;          struct iobref        * iobref     = NULL; @@ -3018,42 +3016,24 @@ posix_readv (call_frame_t *frame, xlator_t *this,                  goto out;          } -        iobuf = iobuf_get2 (this->ctx->iobuf_pool, size); +        iobuf = iobuf_get_page_aligned (this->ctx->iobuf_pool, size, +                                        ALIGN_SIZE);          if (!iobuf) {                  op_errno = ENOMEM;                  goto out;          }          _fd = pfd->fd; -        if (pfd->flags & O_DIRECT) { -                alloc_buf = _page_aligned_alloc (size, &buf); -                if (!alloc_buf) { -                        op_ret = -1; -                        op_errno = errno; -                        goto out; -                } -                op_ret = pread (_fd, buf, size, offset); -                if (op_ret == -1) { -                        op_errno = errno; -                        gf_msg (this->name, GF_LOG_ERROR, errno, -                                P_MSG_READ_FAILED, "read failed on gfid=%s, " -                                "fd=%p, offset=%"PRIu64" size=%"GF_PRI_SIZET", " -                                "buf=%p", uuid_utoa (fd->inode->gfid), fd, -                                offset, size, buf); -                        goto out; -                } -                memcpy(iobuf->ptr, buf, size); -        } else { -                op_ret = pread (_fd, iobuf->ptr, size, offset); -                if (op_ret == -1) { -                        op_errno = errno; -                        gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_READ_FAILED, -                                "read failed on gfid=%s, fd=%p, offset=%"PRIu64" " -                                "size=%"GF_PRI_SIZET"", uuid_utoa (fd->inode->gfid), fd, -                                offset, size); -                        goto out; -                } +        op_ret = pread (_fd, iobuf->ptr, size, offset); +        if (op_ret == -1) { +                op_errno = errno; +                gf_msg (this->name, GF_LOG_ERROR, errno, +                        P_MSG_READ_FAILED, "read failed on gfid=%s, " +                        "fd=%p, offset=%"PRIu64" size=%"GF_PRI_SIZET", " +                        "buf=%p", uuid_utoa (fd->inode->gfid), fd, +                        offset, size, iobuf->ptr); +                goto out;          }          LOCK (&priv->lock); @@ -3096,7 +3076,6 @@ out:                  iobref_unref (iobref);          if (iobuf)                  iobuf_unref (iobuf); -        GF_FREE (alloc_buf);          return 0;  }  | 
