a3470f
From 712e62721d7d95c05d87510eb1fbe5d12381e1ab Mon Sep 17 00:00:00 2001
a3470f
From: Raghavendra G <rgowdapp@redhat.com>
a3470f
Date: Mon, 18 Sep 2017 16:01:34 +0530
a3470f
Subject: [PATCH 111/128] cluster/dht: don't overfill the buffer in readdir(p)
a3470f
a3470f
Superflous dentries that cannot be fit in the buffer size provided by
a3470f
kernel are thrown away by fuse-bridge. This means,
a3470f
a3470f
* the next readdir(p) seen by readdir-ahead would have an offset of a
a3470f
dentry returned in a previous readdir(p) response. When readdir-ahead
a3470f
detects non-monotonic offset it turns itself off which can result in
a3470f
poor readdir performance.
a3470f
a3470f
* readdirp can be cpu-intensive on brick and there is no point to read
a3470f
 all those dentries just to be thrown away by fuse-bridge.
a3470f
a3470f
So, the best strategy would be to fill the buffer optimally - neither
a3470f
overfill nor underfill.
a3470f
a3470f
Change-Id: Idb3d85dd4c08fdc4526b2df801d49e69e439ba84
a3470f
BUG: 1264911
a3470f
Signed-off-by: Raghavendra G <rgowdapp@redhat.com>
a3470f
upstream patch: https://review.gluster.org/18312
a3470f
Reviewed-on: https://code.engineering.redhat.com/gerrit/126504
a3470f
Tested-by: RHGS Build Bot <nigelb@redhat.com>
a3470f
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
a3470f
---
a3470f
 xlators/cluster/dht/src/dht-common.c | 21 ++++++++++++++++++---
a3470f
 1 file changed, 18 insertions(+), 3 deletions(-)
a3470f
a3470f
diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c
a3470f
index f611278..b55cb36 100644
a3470f
--- a/xlators/cluster/dht/src/dht-common.c
a3470f
+++ b/xlators/cluster/dht/src/dht-common.c
a3470f
@@ -5238,6 +5238,13 @@ list:
a3470f
         }
a3470f
 
a3470f
 done:
a3470f
+        if ((op_ret == 0) && op_errno != ENOENT) {
a3470f
+                /* remaining buffer size is not enough to hold even one
a3470f
+                 * dentry
a3470f
+                 */
a3470f
+                goto unwind;
a3470f
+        }
a3470f
+
a3470f
         if ((count == 0) || (local && (local->filled < local->size))) {
a3470f
                 if ((next_offset == 0) || (op_errno == ENOENT)) {
a3470f
                         next_offset = 0;
a3470f
@@ -5268,8 +5275,8 @@ done:
a3470f
 
a3470f
                 STACK_WIND_COOKIE (frame, dht_readdirp_cbk, next_subvol,
a3470f
                                    next_subvol, next_subvol->fops->readdirp,
a3470f
-                                   local->fd, local->size, next_offset,
a3470f
-                                   local->xattr);
a3470f
+                                   local->fd, (local->size - local->filled),
a3470f
+                                   next_offset, local->xattr);
a3470f
                 return 0;
a3470f
         }
a3470f
 
a3470f
@@ -5359,6 +5366,13 @@ dht_readdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
a3470f
         }
a3470f
 
a3470f
 done:
a3470f
+        if ((op_ret == 0) && op_errno != ENOENT) {
a3470f
+                /* remaining buffer size is not enough to hold even one
a3470f
+                 * dentry
a3470f
+                 */
a3470f
+                goto unwind;
a3470f
+        }
a3470f
+
a3470f
         if ((count == 0) || (local && (local->filled < local->size))) {
a3470f
                 if ((op_ret <= 0) || (op_errno == ENOENT)) {
a3470f
                         next_subvol = dht_subvol_next (this, prev);
a3470f
@@ -5372,7 +5386,8 @@ done:
a3470f
 
a3470f
                 STACK_WIND_COOKIE (frame, dht_readdir_cbk, next_subvol,
a3470f
                                    next_subvol, next_subvol->fops->readdir,
a3470f
-                                   local->fd, local->size, next_offset, NULL);
a3470f
+                                   local->fd, (local->size - local->filled),
a3470f
+                                   next_offset, NULL);
a3470f
                 return 0;
a3470f
         }
a3470f
 
a3470f
-- 
a3470f
1.8.3.1
a3470f