Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 60827
b: refs/heads/master
c: c2f1a55
h: refs/heads/master
i:
  60825: dda051a
  60823: 9a5faf7
v: v3
  • Loading branch information
Meelap Shah authored and Linus Torvalds committed Jul 17, 2007
1 parent cce4d17 commit 4c32a83
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 1e5140279f31e47d58ed6036ee61ba7a65710e63
refs/heads/master: c2f1a551dea8b37c2e0cb886885c250fb703e9d8
26 changes: 25 additions & 1 deletion trunk/fs/nfsd/nfs4state.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include <linux/nfsd/state.h>
#include <linux/nfsd/xdr4.h>
#include <linux/namei.h>
#include <linux/swap.h>
#include <linux/mutex.h>
#include <linux/lockd/bind.h>
#include <linux/module.h>
Expand Down Expand Up @@ -150,6 +151,7 @@ get_nfs4_file(struct nfs4_file *fi)
}

static int num_delegations;
unsigned int max_delegations;

/*
* Open owner state (share locks)
Expand Down Expand Up @@ -193,7 +195,7 @@ alloc_init_deleg(struct nfs4_client *clp, struct nfs4_stateid *stp, struct svc_f
struct nfs4_callback *cb = &stp->st_stateowner->so_client->cl_callback;

dprintk("NFSD alloc_init_deleg\n");
if (num_delegations > STATEID_HASH_SIZE * 4)
if (num_delegations > max_delegations)
return NULL;
dp = kmem_cache_alloc(deleg_slab, GFP_KERNEL);
if (dp == NULL)
Expand Down Expand Up @@ -3197,6 +3199,27 @@ get_nfs4_grace_period(void)
return max(user_lease_time, lease_time) * HZ;
}

/*
* Since the lifetime of a delegation isn't limited to that of an open, a
* client may quite reasonably hang on to a delegation as long as it has
* the inode cached. This becomes an obvious problem the first time a
* client's inode cache approaches the size of the server's total memory.
*
* For now we avoid this problem by imposing a hard limit on the number
* of delegations, which varies according to the server's memory size.
*/
static void
set_max_delegations(void)
{
/*
* Allow at most 4 delegations per megabyte of RAM. Quick
* estimates suggest that in the worst case (where every delegation
* is for a different inode), a delegation could take about 1.5K,
* giving a worst case usage of about 6% of memory.
*/
max_delegations = nr_free_buffer_pages() >> (20 - 2 - PAGE_SHIFT);
}

/* initialization to perform when the nfsd service is started: */

static void
Expand All @@ -3212,6 +3235,7 @@ __nfs4_state_start(void)
grace_time/HZ);
laundry_wq = create_singlethread_workqueue("nfsd4");
queue_delayed_work(laundry_wq, &laundromat_work, grace_time);
set_max_delegations();
}

int
Expand Down
1 change: 1 addition & 0 deletions trunk/include/linux/nfsd/nfsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ extern int nfsd_max_blksize;
* NFSv4 State
*/
#ifdef CONFIG_NFSD_V4
extern unsigned int max_delegations;
void nfs4_state_init(void);
int nfs4_state_start(void);
void nfs4_state_shutdown(void);
Expand Down
1 change: 1 addition & 0 deletions trunk/mm/page_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,7 @@ unsigned int nr_free_buffer_pages(void)
{
return nr_free_zone_pages(gfp_zone(GFP_USER));
}
EXPORT_SYMBOL_GPL(nr_free_buffer_pages);

/*
* Amount of free RAM allocatable within all zones
Expand Down

0 comments on commit 4c32a83

Please sign in to comment.