NFSD: Use DEFINE_SPINLOCK() for spinlock
Subsystems (2)
PATCH 1/1 NFSD: Use DEFINE_SPINLOCK() for spinlock
From: Guobin Huang <[email protected]>
spinlock can be initialized automatically with DEFINE_SPINLOCK() rather than explicitly calling spin_lock_init().
--- fs/nfsd/nfssvc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/nfsd/nfssvc.c +1 -2
@@ -84,7 +84,7 @@ DEFINE_MUTEX(nfsd_mutex);* version 4.1 DRC caches. * nfsd_drc_pages_used tracks the current version 4.1 DRC memory usage. */ -spinlock_t nfsd_drc_lock; +DEFINE_SPINLOCK (nfsd_drc_lock);unsigned long nfsd_drc_max_mem;unsigned long nfsd_drc_mem_used;
@@ -563,7 +563,6 @@ static void set_max_drc(void) nfsd_drc_max_mem = (nr_free_buffer_pages () >>NFSD_DRC_SIZE_SHIFT ) *PAGE_SIZE ; nfsd_drc_mem_used =0 ; -spin_lock_init (&nfsd_drc_lock);dprintk ("%s nfsd_drc_max_mem %lu \n" , __func__, nfsd_drc_max_mem); }
Quoted 11 lines · Huang Guobin
From: Guobin Huang <[email protected]>
spinlock can be initialized automatically with
DEFINE_SPINLOCK()rather than explicitly callingspin_lock_init().Reported-by Hulk Robot <[email protected]>Signed-off-by Guobin Huang <[email protected]>
This same patch was sent last July, without the Reported-by:
https://lore.kernel.org/linux-nfs/[email protected]/T/#u
If I'm reading the code correctly, it appears that set_max_drc() can be called more than once by user space API functions via nfsd_create_serv().
It seems to me we want to guarantee that nfsd_drc_lock is initialized exactly once, and using DEFINE_SPINLOCK() would do just that.
Likewise, re-initializing nfsd_drc_mem_used is probably not good to do either, but clobbering a spinlock like that might lead to a crash.
Bruce, any further thoughts?
Quoted 19 lines
---
fs/nfsd/nfssvc.c| 3 +--1 file changed, 1 insertion(+), 2 deletions(-)fs/nfsd/nfssvc.c +1
-1@@ -84,7 +84,7 @@ DEFINE_MUTEX(nfsd_mutex);* version 4.1 DRC caches. * nfsd_drc_pages_used tracks the current version 4.1 DRC memory usage. */ -spinlock_t nfsd_drc_lock; +DEFINE_SPINLOCK (nfsd_drc_lock);unsigned long nfsd_drc_max_mem;unsigned long nfsd_drc_mem_used;
fs/nfsd/nfssvc.c static void set_max_drc(void) · line 568
Quoted 7 lines
fs/nfsd/nfssvc.c +0
-1@@ -563,7 +563,6 @@ static void set_max_drc(void) nfsd_drc_max_mem = (nr_free_buffer_pages () >>NFSD_DRC_SIZE_SHIFT ) *PAGE_SIZE ; nfsd_drc_mem_used =0 ; -spin_lock_init (&nfsd_drc_lock);dprintk ("%s nfsd_drc_max_mem %lu \n" , __func__, nfsd_drc_max_mem); }
--
Chuck Lever
Quoted 24 lines · Chuck Lever III
Quoted 11 lines · Huang Guobin
From: Guobin Huang <[email protected]>
spinlock can be initialized automatically with
DEFINE_SPINLOCK()rather than explicitly callingspin_lock_init().Reported-by Hulk Robot <[email protected]>Signed-off-by Guobin Huang <[email protected]>This same patch was sent last July, without the Reported-by:
https://lore.kernel.org/linux-nfs/[email protected]/T/#u
If I'm reading the code correctly, it appears that
set_max_drc()can be called more than once by user space API functions vianfsd_create_serv().It seems to me we want to guarantee that
nfsd_drc_lockis initialized exactly once, and usingDEFINE_SPINLOCK()would do just that.
Quoted 5 lines
Likewise, re-initializing
nfsd_drc_mem_usedis probably not good to do either, but clobbering a spinlock like that might lead to a crash.Bruce, any further thoughts?
The other nfsd_drc_lock users run in nfsd threads, which shouldn't be running yet at the point we call set_max_drc.
Reinitializing the lock each time is pretty weird, though, ACK to the patch even if it's just cleanup.
--b.
Quoted 33 lines
Quoted 21 lines
---
fs/nfsd/nfssvc.c| 3 +--1 file changed, 1 insertion(+), 2 deletions(-)fs/nfsd/nfssvc.c +1
-1@@ -84,7 +84,7 @@ DEFINE_MUTEX(nfsd_mutex);* version 4.1 DRC caches. * nfsd_drc_pages_used tracks the current version 4.1 DRC memory usage. */ -spinlock_t nfsd_drc_lock; +DEFINE_SPINLOCK (nfsd_drc_lock);unsigned long nfsd_drc_max_mem;unsigned long nfsd_drc_mem_used;fs/nfsd/nfssvc.c static void set_max_drc(void) · line 568
Quoted 7 lines
fs/nfsd/nfssvc.c +0
-1@@ -563,7 +563,6 @@ static void set_max_drc(void) nfsd_drc_max_mem = (nr_free_buffer_pages () >>NFSD_DRC_SIZE_SHIFT ) *PAGE_SIZE ; nfsd_drc_mem_used =0 ; -spin_lock_init (&nfsd_drc_lock);dprintk ("%s nfsd_drc_max_mem %lu \n" , __func__, nfsd_drc_max_mem); }--
Chuck Lever
Hello-
Quoted 9 lines · Huang Guobin
From: Guobin Huang <[email protected]>
spinlock can be initialized automatically with
DEFINE_SPINLOCK()rather than explicitly callingspin_lock_init().Reported-by Hulk Robot <[email protected]>Signed-off-by Guobin Huang <[email protected]>
This change has been pushed to the for-next topic branch in
git://git.kernel.org/pub/scm/linux/kernel/git/cel/linux.git
Quoted 19 lines
---
fs/nfsd/nfssvc.c| 3 +--1 file changed, 1 insertion(+), 2 deletions(-)fs/nfsd/nfssvc.c +1
-1@@ -84,7 +84,7 @@ DEFINE_MUTEX(nfsd_mutex);* version 4.1 DRC caches. * nfsd_drc_pages_used tracks the current version 4.1 DRC memory usage. */ -spinlock_t nfsd_drc_lock; +DEFINE_SPINLOCK (nfsd_drc_lock);unsigned long nfsd_drc_max_mem;unsigned long nfsd_drc_mem_used;
fs/nfsd/nfssvc.c static void set_max_drc(void) · line 568
Quoted 7 lines
fs/nfsd/nfssvc.c +0
-1@@ -563,7 +563,6 @@ static void set_max_drc(void) nfsd_drc_max_mem = (nr_free_buffer_pages () >>NFSD_DRC_SIZE_SHIFT ) *PAGE_SIZE ; nfsd_drc_mem_used =0 ; -spin_lock_init (&nfsd_drc_lock);dprintk ("%s nfsd_drc_max_mem %lu \n" , __func__, nfsd_drc_max_mem); }
--
Chuck Lever