NFS: Charge open/lock file contexts to kmemcg
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Sat, 29 Jan 2022 18:04:10 +0000 (13:04 -0500)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Fri, 25 Feb 2022 23:50:12 +0000 (18:50 -0500)
Allow kmemcg to limit the number of open/lock file contexts, in the same
way that it limits the parent file descriptors.

Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
fs/nfs/dir.c
fs/nfs/inode.c

index 75cb1cb..fbb4a52 100644 (file)
@@ -73,7 +73,7 @@ static struct nfs_open_dir_context *alloc_nfs_open_dir_context(struct inode *dir
 {
        struct nfs_inode *nfsi = NFS_I(dir);
        struct nfs_open_dir_context *ctx;
-       ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
+       ctx = kmalloc(sizeof(*ctx), GFP_KERNEL_ACCOUNT);
        if (ctx != NULL) {
                ctx->duped = 0;
                ctx->attr_gencount = nfsi->attr_gencount;
index d96baa4..34209ab 100644 (file)
@@ -952,7 +952,7 @@ struct nfs_lock_context *nfs_get_lock_context(struct nfs_open_context *ctx)
        res = __nfs_find_lock_context(ctx);
        rcu_read_unlock();
        if (res == NULL) {
-               new = kmalloc(sizeof(*new), GFP_KERNEL);
+               new = kmalloc(sizeof(*new), GFP_KERNEL_ACCOUNT);
                if (new == NULL)
                        return ERR_PTR(-ENOMEM);
                nfs_init_lock_context(new);
@@ -1030,7 +1030,7 @@ struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry,
 {
        struct nfs_open_context *ctx;
 
-       ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
+       ctx = kmalloc(sizeof(*ctx), GFP_KERNEL_ACCOUNT);
        if (!ctx)
                return ERR_PTR(-ENOMEM);
        nfs_sb_active(dentry->d_sb);