* [PATCH] fs/affs: Replace binary semaphores with mutexes
@ 2019-10-27 22:01 Davidlohr Bueso
2019-10-30 11:32 ` David Sterba
0 siblings, 1 reply; 2+ messages in thread
From: Davidlohr Bueso @ 2019-10-27 22:01 UTC (permalink / raw)
To: dsterba; +Cc: dave, linux-kernel, Davidlohr Bueso
At a slight footprint cost (24 vs 32 bytes), mutexes are more optimal
than semaphores; it's also a nicer interface for mutual exclusion,
which is why they are encouraged over binary semaphores, when possible.
For both i_link_lock and i_ext_lock (and hence i_hash_lock which I
annotated for the hash lock mapping hackery for lockdep), their semantics
imply traditional lock ownership; that is, the lock owner is the same for
both lock/unlock operations and does not run in irq context. Therefore
it is safe to convert.
Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
---
Compile tested only.
fs/affs/affs.h | 16 ++++++++--------
fs/affs/super.c | 4 ++--
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/fs/affs/affs.h b/fs/affs/affs.h
index a92eb6ae2ae2..a755bef7c4c7 100644
--- a/fs/affs/affs.h
+++ b/fs/affs/affs.h
@@ -43,8 +43,8 @@ struct affs_ext_key {
*/
struct affs_inode_info {
atomic_t i_opencnt;
- struct semaphore i_link_lock; /* Protects internal inode access. */
- struct semaphore i_ext_lock; /* Protects internal inode access. */
+ struct mutex i_link_lock; /* Protects internal inode access. */
+ struct mutex i_ext_lock; /* Protects internal inode access. */
#define i_hash_lock i_ext_lock
u32 i_blkcnt; /* block count */
u32 i_extcnt; /* extended block count */
@@ -293,30 +293,30 @@ affs_adjust_bitmapchecksum(struct buffer_head *bh, u32 val)
static inline void
affs_lock_link(struct inode *inode)
{
- down(&AFFS_I(inode)->i_link_lock);
+ mutex_lock(&AFFS_I(inode)->i_link_lock);
}
static inline void
affs_unlock_link(struct inode *inode)
{
- up(&AFFS_I(inode)->i_link_lock);
+ mutex_unlock(&AFFS_I(inode)->i_link_lock);
}
static inline void
affs_lock_dir(struct inode *inode)
{
- down(&AFFS_I(inode)->i_hash_lock);
+ mutex_lock_nested(&AFFS_I(inode)->i_hash_lock, SINGLE_DEPTH_NESTING);
}
static inline void
affs_unlock_dir(struct inode *inode)
{
- up(&AFFS_I(inode)->i_hash_lock);
+ mutex_unlock(&AFFS_I(inode)->i_hash_lock);
}
static inline void
affs_lock_ext(struct inode *inode)
{
- down(&AFFS_I(inode)->i_ext_lock);
+ mutex_lock(&AFFS_I(inode)->i_ext_lock);
}
static inline void
affs_unlock_ext(struct inode *inode)
{
- up(&AFFS_I(inode)->i_ext_lock);
+ mutex_unlock(&AFFS_I(inode)->i_ext_lock);
}
diff --git a/fs/affs/super.c b/fs/affs/super.c
index cc463ae47c12..9fcff55c65af 100644
--- a/fs/affs/super.c
+++ b/fs/affs/super.c
@@ -121,8 +121,8 @@ static void init_once(void *foo)
{
struct affs_inode_info *ei = (struct affs_inode_info *) foo;
- sema_init(&ei->i_link_lock, 1);
- sema_init(&ei->i_ext_lock, 1);
+ mutex_init(&ei->i_link_lock);
+ mutex_init(&ei->i_ext_lock);
inode_init_once(&ei->vfs_inode);
}
--
2.16.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] fs/affs: Replace binary semaphores with mutexes
2019-10-27 22:01 [PATCH] fs/affs: Replace binary semaphores with mutexes Davidlohr Bueso
@ 2019-10-30 11:32 ` David Sterba
0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2019-10-30 11:32 UTC (permalink / raw)
To: Davidlohr Bueso; +Cc: dsterba, linux-kernel, Davidlohr Bueso
On Sun, Oct 27, 2019 at 03:01:43PM -0700, Davidlohr Bueso wrote:
> At a slight footprint cost (24 vs 32 bytes), mutexes are more optimal
> than semaphores; it's also a nicer interface for mutual exclusion,
> which is why they are encouraged over binary semaphores, when possible.
>
> For both i_link_lock and i_ext_lock (and hence i_hash_lock which I
> annotated for the hash lock mapping hackery for lockdep), their semantics
> imply traditional lock ownership; that is, the lock owner is the same for
> both lock/unlock operations and does not run in irq context. Therefore
> it is safe to convert.
>
> Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
Thanks, I'll add it to affs queue.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-10-30 11:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-27 22:01 [PATCH] fs/affs: Replace binary semaphores with mutexes Davidlohr Bueso
2019-10-30 11:32 ` David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).