[Devel] [PATCH rh7] fs/locks: Remove legacy UB_NUMFLOCKS
Andrey Ryabinin
aryabinin at virtuozzo.com
Fri Apr 24 21:22:30 MSK 2020
The accounting of the UB_NUMFLOCKS looks fishy and probably doesn't work
right causing lots of 'kernel: Uncharging too much 1 h 0, res numflock ub 0'
The scheme with transitioning the charge from one lock to another looks
suspicious.
Let's remove UB_NUMFLOCKS as the use-case for this limit is unclear.
file_lock structures are accounted into container's memory, so flocks
are still limited by the memory limit.
The 'numlocks' row in the /proc/bc/resources still remains for compatibility
with userspace utilites, but show zeros all the time.
https://jira.sw.ru/browse/PSBM-102022
Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
---
fs/fuse/kio/pcs/pcs_auth.c | 2 +-
fs/locks.c | 73 ++++++++------------------------------
fs/nfsd/nfs4layouts.c | 2 +-
fs/nfsd/nfs4state.c | 8 ++---
include/bc/misc.h | 10 ------
include/linux/fs.h | 6 +---
kernel/bc/misc.c | 27 --------------
7 files changed, 22 insertions(+), 106 deletions(-)
diff --git a/fs/fuse/kio/pcs/pcs_auth.c b/fs/fuse/kio/pcs/pcs_auth.c
index 9256cac40437..45d361f88fd2 100644
--- a/fs/fuse/kio/pcs/pcs_auth.c
+++ b/fs/fuse/kio/pcs/pcs_auth.c
@@ -156,7 +156,7 @@ static struct file *lock_key_file(char *cluster_name)
if (IS_ERR(f))
return f;
- lock = locks_alloc_lock(1);
+ lock = locks_alloc_lock();
if (!lock) {
filp_close(f, NULL);
return ERR_PTR(-ENOMEM);
diff --git a/fs/locks.c b/fs/locks.c
index d1cf9a6d704d..27df05ee3793 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -135,9 +135,6 @@
#include <asm/uaccess.h>
-#include <bc/beancounter.h>
-#include <bc/misc.h>
-
#define IS_POSIX(fl) (fl->fl_flags & FL_POSIX)
#define IS_FLOCK(fl) (fl->fl_flags & FL_FLOCK)
#define IS_LEASE(fl) (fl->fl_flags & (FL_LEASE|FL_DELEG|FL_LAYOUT))
@@ -221,26 +218,10 @@ static void locks_init_lock_heads(struct file_lock *fl)
}
/* Allocate an empty lock structure. */
-struct file_lock *locks_alloc_lock(int charge)
+struct file_lock *locks_alloc_lock(void)
{
- struct file_lock *fl;
+ struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
- fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
-#ifdef CONFIG_BEANCOUNTERS
- if (fl == NULL)
- goto out;
- fl->fl_ub = get_beancounter(get_exec_ub());
- fl->fl_charged = 0;
- if (!charge)
- goto out;
- if (!ub_flock_charge(fl, 1))
- goto out;
-
- put_beancounter(fl->fl_ub);
- kmem_cache_free(filelock_cache, fl);
- fl = NULL;
-out:
-#endif
if (fl)
locks_init_lock_heads(fl);
@@ -274,11 +255,7 @@ void locks_free_lock(struct file_lock *fl)
BUG_ON(!list_empty(&fl->fl_block));
BUG_ON(!hlist_unhashed(&fl->fl_link));
- ub_flock_uncharge(fl);
locks_release_private(fl);
-#ifdef CONFIG_BEANCOUNTERS
- put_beancounter(fl->fl_ub);
-#endif
kmem_cache_free(filelock_cache, fl);
}
EXPORT_SYMBOL(locks_free_lock);
@@ -382,7 +359,7 @@ static int flock_make_lock(struct file *filp, struct file_lock **lock,
if (type < 0)
return type;
- fl = locks_alloc_lock(type != F_UNLCK);
+ fl = locks_alloc_lock();
if (fl == NULL)
return -ENOMEM;
@@ -507,7 +484,7 @@ static int lease_init(struct file *filp, long type, struct file_lock *fl)
/* Allocate a file_lock initialised to this type of lease */
static struct file_lock *lease_alloc(struct file *filp, long type)
{
- struct file_lock *fl = locks_alloc_lock(1);
+ struct file_lock *fl = locks_alloc_lock();
int error = -ENOMEM;
if (fl == NULL)
@@ -869,12 +846,7 @@ static int flock_lock_inode(struct inode *inode, struct file_lock *request)
LIST_HEAD(dispose);
if (!(request->fl_flags & FL_ACCESS) && (request->fl_type != F_UNLCK)) {
- /*
- * Nont F_UNLCK request must be already charged in
- * flock_make_lock(). Actually new_fl must be charged not the
- * request, but we try to fail earlier.
- */
- new_fl = locks_alloc_lock(0);
+ new_fl = locks_alloc_lock();
if (!new_fl)
return -ENOMEM;
}
@@ -923,9 +895,6 @@ find_conflict:
if (request->fl_flags & FL_ACCESS)
goto out;
- set_flock_charged(new_fl);
- unset_flock_charged(request);
-
locks_copy_lock(new_fl, request);
locks_insert_lock(before, new_fl);
new_fl = NULL;
@@ -960,11 +929,8 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
if (!(request->fl_flags & FL_ACCESS) &&
(request->fl_type != F_UNLCK ||
request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
- if (request->fl_type != F_UNLCK)
- new_fl = locks_alloc_lock(1);
- else
- new_fl = NULL;
- new_fl2 = locks_alloc_lock(0);
+ new_fl = locks_alloc_lock();
+ new_fl2 = locks_alloc_lock();
}
spin_lock(&inode->i_lock);
@@ -1117,7 +1083,7 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
* done below this, so it's safe yet to bail out.
*/
error = -ENOLCK; /* "no luck" */
- if (right && left == right && !(request->fl_type == F_UNLCK || new_fl2))
+ if (right && left == right && !new_fl2)
goto out;
error = 0;
@@ -1128,32 +1094,23 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
goto out;
}
- error = -ENOLCK;
- if (!new_fl)
- goto out;
- if (right && (left == right) && ub_flock_charge(new_fl, 1))
+ if (!new_fl) {
+ error = -ENOLCK;
goto out;
+ }
locks_copy_lock(new_fl, request);
locks_insert_lock(before, new_fl);
new_fl = NULL;
- error = 0;
}
if (right) {
if (left == right) {
/* The new lock breaks the old one in two pieces,
* so we have to use the second new lock.
*/
- error = -ENOLCK;
- if (added && ub_flock_charge(new_fl2,
- request->fl_type != F_UNLCK))
- goto out;
- /* FIXME move all fl_charged manipulations in ub code */
- set_flock_charged(new_fl2);
left = new_fl2;
new_fl2 = NULL;
locks_copy_lock(left, right);
locks_insert_lock(before, left);
- error = 0;
}
right->fl_start = request->fl_end + 1;
locks_wake_up_blocks(right);
@@ -2049,7 +2006,7 @@ int fcntl_getlk(struct file *filp, unsigned int cmd, struct flock *flock)
struct file_lock *fl;
int error;
- fl = locks_alloc_lock(0);
+ fl = locks_alloc_lock();
if (fl == NULL)
return -ENOMEM;
error = -EINVAL;
@@ -2173,7 +2130,7 @@ check_fmode_for_setlk(struct file_lock *fl)
int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd,
struct flock *flock)
{
- struct file_lock *file_lock = locks_alloc_lock(0);
+ struct file_lock *file_lock = locks_alloc_lock();
struct inode *inode = locks_inode(filp);
struct file *f;
int error;
@@ -2262,7 +2219,7 @@ int fcntl_getlk64(struct file *filp, unsigned int cmd, struct flock64 *flock)
struct file_lock *fl;
int error;
- fl = locks_alloc_lock(0);
+ fl = locks_alloc_lock();
if (fl == NULL)
return -ENOMEM;
@@ -2303,7 +2260,7 @@ out:
int fcntl_setlk64(unsigned int fd, struct file *filp, unsigned int cmd,
struct flock64 *flock)
{
- struct file_lock *file_lock = locks_alloc_lock(0);
+ struct file_lock *file_lock = locks_alloc_lock();
struct inode *inode = locks_inode(filp);
struct file *f;
int error;
diff --git a/fs/nfsd/nfs4layouts.c b/fs/nfsd/nfs4layouts.c
index 90e46afe28a1..c6d1d5eb2f1f 100644
--- a/fs/nfsd/nfs4layouts.c
+++ b/fs/nfsd/nfs4layouts.c
@@ -174,7 +174,7 @@ nfsd4_layout_setlease(struct nfs4_layout_stateid *ls)
struct file_lock *fl;
int status;
- fl = locks_alloc_lock(1);
+ fl = locks_alloc_lock();
if (!fl)
return -ENOMEM;
locks_init_lock(fl);
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index d6e35920581a..43b4c8eb98aa 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -4171,7 +4171,7 @@ static struct file_lock *nfs4_alloc_init_lease(struct nfs4_file *fp, int flag)
{
struct file_lock *fl;
- fl = locks_alloc_lock(1);
+ fl = locks_alloc_lock();
if (!fl)
return NULL;
fl->fl_lmops = &nfsd_lease_mng_ops;
@@ -5913,7 +5913,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
file_lock->fl_end = last_byte_offset(lock->lk_offset, lock->lk_length);
nfs4_transform_lock_offset(file_lock);
- conflock = locks_alloc_lock(1);
+ conflock = locks_alloc_lock();
if (!conflock) {
dprintk("NFSD: %s: unable to allocate lock!\n", __func__);
status = nfserr_jukebox;
@@ -6033,7 +6033,7 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
if ((status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0)))
goto out;
- file_lock = locks_alloc_lock(1);
+ file_lock = locks_alloc_lock();
if (!file_lock) {
dprintk("NFSD: %s: unable to allocate lock!\n", __func__);
status = nfserr_jukebox;
@@ -6110,7 +6110,7 @@ nfsd4_locku(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
status = nfserr_lock_range;
goto put_stateid;
}
- file_lock = locks_alloc_lock(1);
+ file_lock = locks_alloc_lock();
if (!file_lock) {
dprintk("NFSD: %s: unable to allocate lock!\n", __func__);
status = nfserr_jukebox;
diff --git a/include/bc/misc.h b/include/bc/misc.h
index c9e4cee30b42..3d4ba162ffae 100644
--- a/include/bc/misc.h
+++ b/include/bc/misc.h
@@ -30,14 +30,4 @@ UB_DECLARE_VOID_FUNC(ub_task_put(struct task_struct *task))
UB_DECLARE_FUNC(int, ub_pty_charge(struct tty_struct *tty))
UB_DECLARE_VOID_FUNC(ub_pty_uncharge(struct tty_struct *tty))
-#ifdef CONFIG_BEANCOUNTERS
-#define set_flock_charged(fl) do { (fl)->fl_charged = 1; } while (0)
-#define unset_flock_charged(fl) do { \
- WARN_ON((fl)->fl_charged == 0); \
- (fl)->fl_charged = 0; \
- } while (0)
-#else
-#define set_flock_charged(fl) do { } while (0)
-#define unset_flock_charged(fl) do { } while (0)
-#endif
#endif
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 014a7056af31..727ad0f6c1b0 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1275,10 +1275,6 @@ struct file_lock {
fl_owner_t fl_owner;
unsigned int fl_flags;
unsigned char fl_type;
-#ifdef CONFIG_BEANCOUNTERS
- unsigned char fl_charged;
- struct user_beancounter *fl_ub;
-#endif
unsigned int fl_pid;
int fl_link_cpu; /* what cpu's list is this on? */
struct pid *fl_nspid;
@@ -1355,7 +1351,7 @@ extern int fcntl_getlease(struct file *filp);
/* fs/locks.c */
void locks_free_lock(struct file_lock *fl);
extern void locks_init_lock(struct file_lock *);
-extern struct file_lock * locks_alloc_lock(int charge);
+extern struct file_lock * locks_alloc_lock(void);
extern void locks_copy_lock(struct file_lock *, struct file_lock *);
extern void locks_copy_conflock(struct file_lock *, struct file_lock *);
extern void __locks_copy_lock(struct file_lock *, const struct file_lock *);
diff --git a/kernel/bc/misc.c b/kernel/bc/misc.c
index 6ff243f73369..eee8e1884164 100644
--- a/kernel/bc/misc.c
+++ b/kernel/bc/misc.c
@@ -69,33 +69,6 @@ void ub_file_uncharge(struct file *f)
put_beancounter(ub);
}
-int ub_flock_charge(struct file_lock *fl, int hard)
-{
- struct user_beancounter *ub;
- int err;
-
- ub = fl->fl_ub;
- if (ub == NULL)
- return 0;
-
- err = charge_beancounter(ub, UB_NUMFLOCK, 1, hard ? UB_HARD : UB_SOFT);
- if (!err)
- fl->fl_charged = 1;
- return err;
-}
-
-void ub_flock_uncharge(struct file_lock *fl)
-{
- struct user_beancounter *ub;
-
- ub = fl->fl_ub;
- if (ub == NULL || !fl->fl_charged)
- return;
-
- uncharge_beancounter(ub, UB_NUMFLOCK, 1);
- fl->fl_charged = 0;
-}
-
/*
* Signal handling
*/
--
2.26.2
More information about the Devel
mailing list