summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/iobuf.c
diff options
context:
space:
mode:
authorAnand Avati <avati@redhat.com>2013-11-25 03:08:19 -0800
committerAnand Avati <avati@redhat.com>2013-11-26 10:31:17 -0800
commitc9579c4501a5d316f71fc44fd46a53060a4eed0c (patch)
tree67e8be358ba357f9f2e3be1fd49cd3a5a3713ebd /libglusterfs/src/iobuf.c
parent9da4958b7853f36a137c80493bec932b79d85e84 (diff)
iobufs: make iobref container size dynamic
With gfapi we can receive read/write size beyond the natural limits of FUSE and NFS server. iobref was hardcoded to hold iobuf refs up to 16 in count, which imposes a natural limit of 2MB with 128KB page sizes of read-ahead and io-cache. Fix this by making iobref's iobuf ref container size dynamic. Change-Id: I93d88104d6c5e7af96cc9f1bfcc870d80fa81dad BUG: 1034398 Signed-off-by: Anand Avati <avati@redhat.com> Reviewed-on: http://review.gluster.org/6348 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Amar Tumballi <amarts@gmail.com>
Diffstat (limited to 'libglusterfs/src/iobuf.c')
-rw-r--r--libglusterfs/src/iobuf.c49
1 files changed, 44 insertions, 5 deletions
diff --git a/libglusterfs/src/iobuf.c b/libglusterfs/src/iobuf.c
index a89e96267..82ffe2dd8 100644
--- a/libglusterfs/src/iobuf.c
+++ b/libglusterfs/src/iobuf.c
@@ -773,6 +773,16 @@ iobref_new ()
if (!iobref)
return NULL;
+ iobref->iobrefs = GF_CALLOC (sizeof (*iobref->iobrefs),
+ 16, gf_common_mt_iobrefs);
+ if (!iobref->iobrefs) {
+ GF_FREE (iobref);
+ return NULL;
+ }
+
+ iobref->alloced = 16;
+ iobref->used = 0;
+
LOCK_INIT (&iobref->lock);
iobref->ref++;
@@ -805,7 +815,7 @@ iobref_destroy (struct iobref *iobref)
GF_VALIDATE_OR_GOTO ("iobuf", iobref, out);
- for (i = 0; i < GF_IOBREF_IOBUF_COUNT; i++) {
+ for (i = 0; i < iobref->alloced; i++) {
iobuf = iobref->iobrefs[i];
iobref->iobrefs[i] = NULL;
@@ -813,6 +823,7 @@ iobref_destroy (struct iobref *iobref)
iobuf_unref (iobuf);
}
+ GF_FREE (iobref->iobrefs);
GF_FREE (iobref);
out:
@@ -848,7 +859,7 @@ iobref_clear (struct iobref *iobref)
GF_VALIDATE_OR_GOTO ("iobuf", iobref, out);
- for (; i < GF_IOBREF_IOBUF_COUNT; i++) {
+ for (; i < iobref->alloced; i++) {
if (iobref->iobrefs[i] != NULL) {
iobuf_unref (iobref->iobrefs[i]);
} else {
@@ -864,6 +875,24 @@ iobref_clear (struct iobref *iobref)
}
+static void
+__iobref_grow (struct iobref *iobref)
+{
+ void *newptr = NULL;
+ int i = 0;
+
+ newptr = GF_REALLOC (iobref->iobrefs,
+ iobref->alloced * 2 * (sizeof (*iobref->iobrefs)));
+ if (newptr) {
+ iobref->iobrefs = newptr;
+ iobref->alloced *= 2;
+
+ for (i = iobref->used; i < iobref->alloced; i++)
+ iobref->iobrefs[i] = NULL;
+ }
+}
+
+
int
__iobref_add (struct iobref *iobref, struct iobuf *iobuf)
{
@@ -873,9 +902,19 @@ __iobref_add (struct iobref *iobref, struct iobuf *iobuf)
GF_VALIDATE_OR_GOTO ("iobuf", iobref, out);
GF_VALIDATE_OR_GOTO ("iobuf", iobuf, out);
- for (i = 0; i < GF_IOBREF_IOBUF_COUNT; i++) {
+ if (iobref->used == iobref->alloced) {
+ __iobref_grow (iobref);
+
+ if (iobref->used == iobref->alloced) {
+ ret = -ENOMEM;
+ goto out;
+ }
+ }
+
+ for (i = 0; i < iobref->alloced; i++) {
if (iobref->iobrefs[i] == NULL) {
iobref->iobrefs[i] = iobuf_ref (iobuf);
+ iobref->used++;
ret = 0;
break;
}
@@ -917,7 +956,7 @@ iobref_merge (struct iobref *to, struct iobref *from)
LOCK (&from->lock);
{
- for (i = 0; i < GF_IOBREF_IOBUF_COUNT; i++) {
+ for (i = 0; i < from->alloced; i++) {
iobuf = from->iobrefs[i];
if (!iobuf)
@@ -969,7 +1008,7 @@ iobref_size (struct iobref *iobref)
LOCK (&iobref->lock);
{
- for (i = 0; i < GF_IOBREF_IOBUF_COUNT; i++) {
+ for (i = 0; i < iobref->alloced; i++) {
if (iobref->iobrefs[i])
size += iobuf_size (iobref->iobrefs[i]);
}