nfsd: give out fewer session slots as limit approaches [Linux 4.4.187]

This Linux kernel change "nfsd: give out fewer session slots as limit approaches" is included in the Linux 4.4.187 release. This change is authored by J. Bruce Fields <bfields [at]> on Tue Sep 19 19:25:41 2017 -0400. The commit for this change in Linux stable tree is 728009f (patch) which is from upstream commit de766e5. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream de766e5.

nfsd: give out fewer session slots as limit approaches

[ Upstream commit de766e570413bd0484af0b580299b495ada625c3 ]

Instead of granting client's full requests until we hit our DRC size
limit and then failing CREATE_SESSIONs (and hence mounts) completely,
start granting clients smaller slot tables as we approach the limit.

The factor chosen here is pretty much arbitrary.

Signed-off-by: J. Bruce Fields <>
Signed-off-by: Sasha Levin <>

There are 5 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 fs/nfsd/nfs4state.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index ba27a5f..eb0f8af 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -1396,6 +1396,11 @@ static u32 nfsd4_get_drc_mem(struct nfsd4_channel_attrs *ca)
    avail = min((unsigned long)NFSD_MAX_MEM_PER_SESSION,
            nfsd_drc_max_mem - nfsd_drc_mem_used);
+   /*
+    * Never use more than a third of the remaining memory,
+    * unless it's the only way to give this client a slot:
+    */
+   avail = clamp_t(int, avail, slotsize, avail/3);
    num = min_t(int, num, avail / slotsize);
    nfsd_drc_mem_used += num * slotsize;

Leave a Reply

Your email address will not be published. Required fields are marked *