Skip to content

Commit 1fa8064

Browse files
Trond MyklebustTrond Myklebust
authored andcommitted
NFSv4.1: Try to eliminate outliers when updating target_highest_slotid
Look for sudden changes in the first and second derivatives in order to eliminate outlier changes to target_highest_slotid (which are due to out-of-order RPC replies). Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
1 parent c05eecf commit 1fa8064

2 files changed

Lines changed: 60 additions & 5 deletions

File tree

‎fs/nfs/nfs4session.c‎

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ static void nfs4_reset_slot_table(struct nfs4_slot_table *tbl,
178178
tbl->highest_used_slotid = NFS4_NO_SLOT;
179179
tbl->target_highest_slotid = server_highest_slotid;
180180
tbl->server_highest_slotid = server_highest_slotid;
181+
tbl->d_target_highest_slotid = 0;
182+
tbl->d2_target_highest_slotid = 0;
181183
tbl->max_slotid = server_highest_slotid;
182184
}
183185

@@ -292,6 +294,8 @@ void nfs41_set_target_slotid(struct nfs4_slot_table *tbl,
292294
{
293295
spin_lock(&tbl->slot_tbl_lock);
294296
nfs41_set_target_slotid_locked(tbl, target_highest_slotid);
297+
tbl->d_target_highest_slotid = 0;
298+
tbl->d2_target_highest_slotid = 0;
295299
spin_unlock(&tbl->slot_tbl_lock);
296300
}
297301

@@ -307,16 +311,65 @@ static void nfs41_set_server_slotid_locked(struct nfs4_slot_table *tbl,
307311
tbl->server_highest_slotid = highest_slotid;
308312
}
309313

314+
static s32 nfs41_derivative_target_slotid(s32 s1, s32 s2)
315+
{
316+
s1 -= s2;
317+
if (s1 == 0)
318+
return 0;
319+
if (s1 < 0)
320+
return (s1 - 1) >> 1;
321+
return (s1 + 1) >> 1;
322+
}
323+
324+
static int nfs41_sign_s32(s32 s1)
325+
{
326+
if (s1 > 0)
327+
return 1;
328+
if (s1 < 0)
329+
return -1;
330+
return 0;
331+
}
332+
333+
static bool nfs41_same_sign_or_zero_s32(s32 s1, s32 s2)
334+
{
335+
if (!s1 || !s2)
336+
return true;
337+
return nfs41_sign_s32(s1) == nfs41_sign_s32(s2);
338+
}
339+
340+
/* Try to eliminate outliers by checking for sharp changes in the
341+
* derivatives and second derivatives
342+
*/
343+
static bool nfs41_is_outlier_target_slotid(struct nfs4_slot_table *tbl,
344+
u32 new_target)
345+
{
346+
s32 d_target, d2_target;
347+
bool ret = true;
348+
349+
d_target = nfs41_derivative_target_slotid(new_target,
350+
tbl->target_highest_slotid);
351+
d2_target = nfs41_derivative_target_slotid(d_target,
352+
tbl->d_target_highest_slotid);
353+
/* Is first derivative same sign? */
354+
if (nfs41_same_sign_or_zero_s32(d_target, tbl->d_target_highest_slotid))
355+
ret = false;
356+
/* Is second derivative same sign? */
357+
if (nfs41_same_sign_or_zero_s32(d2_target, tbl->d2_target_highest_slotid))
358+
ret = false;
359+
tbl->d_target_highest_slotid = d_target;
360+
tbl->d2_target_highest_slotid = d2_target;
361+
return ret;
362+
}
363+
310364
void nfs41_update_target_slotid(struct nfs4_slot_table *tbl,
311365
struct nfs4_slot *slot,
312366
struct nfs4_sequence_res *res)
313367
{
314368
spin_lock(&tbl->slot_tbl_lock);
315-
if (tbl->generation != slot->generation)
316-
goto out;
317-
nfs41_set_server_slotid_locked(tbl, res->sr_highest_slotid);
318-
nfs41_set_target_slotid_locked(tbl, res->sr_target_highest_slotid);
319-
out:
369+
if (!nfs41_is_outlier_target_slotid(tbl, res->sr_target_highest_slotid))
370+
nfs41_set_target_slotid_locked(tbl, res->sr_target_highest_slotid);
371+
if (tbl->generation == slot->generation)
372+
nfs41_set_server_slotid_locked(tbl, res->sr_highest_slotid);
320373
spin_unlock(&tbl->slot_tbl_lock);
321374
}
322375

‎fs/nfs/nfs4session.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ struct nfs4_slot_table {
3838
* op for dynamic resizing */
3939
u32 target_highest_slotid; /* Server max_slot target */
4040
u32 server_highest_slotid; /* Server highest slotid */
41+
s32 d_target_highest_slotid; /* Derivative */
42+
s32 d2_target_highest_slotid; /* 2nd derivative */
4143
unsigned long generation; /* Generation counter for
4244
target_highest_slotid */
4345
struct completion complete;

0 commit comments

Comments
 (0)