2020-04-22 00:16:04

by Michel Lespinasse

[permalink] [raw]
Subject: [PATCH v5 01/10] mmap locking API: initial implementation as rwsem wrappers

This change wraps the existing mmap_sem related rwsem calls into a new
mmap locking API. There are two justifications for the new API:

- At first, it provides an easy hooking point to instrument mmap_sem
locking latencies independently of any other rwsems.

- In the future, it may be a starting point for replacing the rwsem
implementation with a different one, such as range locks.

Signed-off-by: Michel Lespinasse <[email protected]>
Reviewed-by: Daniel Jordan <[email protected]>
Reviewed-by: Davidlohr Bueso <[email protected]>
---
include/linux/mm.h | 1 +
include/linux/mmap_lock.h | 54 +++++++++++++++++++++++++++++++++++++++
2 files changed, 55 insertions(+)
create mode 100644 include/linux/mmap_lock.h

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 5a323422d783..051ec782bdbb 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -15,6 +15,7 @@
#include <linux/atomic.h>
#include <linux/debug_locks.h>
#include <linux/mm_types.h>
+#include <linux/mmap_lock.h>
#include <linux/range.h>
#include <linux/pfn.h>
#include <linux/percpu-refcount.h>
diff --git a/include/linux/mmap_lock.h b/include/linux/mmap_lock.h
new file mode 100644
index 000000000000..97ac53b66052
--- /dev/null
+++ b/include/linux/mmap_lock.h
@@ -0,0 +1,54 @@
+#ifndef _LINUX_MMAP_LOCK_H
+#define _LINUX_MMAP_LOCK_H
+
+static inline void mmap_init_lock(struct mm_struct *mm)
+{
+ init_rwsem(&mm->mmap_sem);
+}
+
+static inline void mmap_write_lock(struct mm_struct *mm)
+{
+ down_write(&mm->mmap_sem);
+}
+
+static inline int mmap_write_lock_killable(struct mm_struct *mm)
+{
+ return down_write_killable(&mm->mmap_sem);
+}
+
+static inline bool mmap_write_trylock(struct mm_struct *mm)
+{
+ return down_write_trylock(&mm->mmap_sem) != 0;
+}
+
+static inline void mmap_write_unlock(struct mm_struct *mm)
+{
+ up_write(&mm->mmap_sem);
+}
+
+static inline void mmap_write_downgrade(struct mm_struct *mm)
+{
+ downgrade_write(&mm->mmap_sem);
+}
+
+static inline void mmap_read_lock(struct mm_struct *mm)
+{
+ down_read(&mm->mmap_sem);
+}
+
+static inline int mmap_read_lock_killable(struct mm_struct *mm)
+{
+ return down_read_killable(&mm->mmap_sem);
+}
+
+static inline bool mmap_read_trylock(struct mm_struct *mm)
+{
+ return down_read_trylock(&mm->mmap_sem) != 0;
+}
+
+static inline void mmap_read_unlock(struct mm_struct *mm)
+{
+ up_read(&mm->mmap_sem);
+}
+
+#endif /* _LINUX_MMAP_LOCK_H */
--
2.26.1.301.g55bc3eb7cb9-goog


2020-05-18 09:30:20

by Vlastimil Babka

[permalink] [raw]
Subject: Re: [PATCH v5 01/10] mmap locking API: initial implementation as rwsem wrappers

On 4/22/20 2:14 AM, Michel Lespinasse wrote:
> This change wraps the existing mmap_sem related rwsem calls into a new
> mmap locking API. There are two justifications for the new API:
>
> - At first, it provides an easy hooking point to instrument mmap_sem
> locking latencies independently of any other rwsems.
>
> - In the future, it may be a starting point for replacing the rwsem
> implementation with a different one, such as range locks.
>
> Signed-off-by: Michel Lespinasse <[email protected]>
> Reviewed-by: Daniel Jordan <[email protected]>
> Reviewed-by: Davidlohr Bueso <[email protected]>

Reviewed-by: Vlastimil Babka <[email protected]>

2020-05-18 13:25:31

by Laurent Dufour

[permalink] [raw]
Subject: Re: [PATCH v5 01/10] mmap locking API: initial implementation as rwsem wrappers

Le 22/04/2020 à 02:14, Michel Lespinasse a écrit :
> This change wraps the existing mmap_sem related rwsem calls into a new
> mmap locking API. There are two justifications for the new API:
>
> - At first, it provides an easy hooking point to instrument mmap_sem
> locking latencies independently of any other rwsems.
>
> - In the future, it may be a starting point for replacing the rwsem
> implementation with a different one, such as range locks.
>
> Signed-off-by: Michel Lespinasse <[email protected]>
> Reviewed-by: Daniel Jordan <[email protected]>
> Reviewed-by: Davidlohr Bueso <[email protected]>

Reviewed-by: Laurent Dufour <[email protected]>

> ---
> include/linux/mm.h | 1 +
> include/linux/mmap_lock.h | 54 +++++++++++++++++++++++++++++++++++++++
> 2 files changed, 55 insertions(+)
> create mode 100644 include/linux/mmap_lock.h
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 5a323422d783..051ec782bdbb 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -15,6 +15,7 @@
> #include <linux/atomic.h>
> #include <linux/debug_locks.h>
> #include <linux/mm_types.h>
> +#include <linux/mmap_lock.h>
> #include <linux/range.h>
> #include <linux/pfn.h>
> #include <linux/percpu-refcount.h>
> diff --git a/include/linux/mmap_lock.h b/include/linux/mmap_lock.h
> new file mode 100644
> index 000000000000..97ac53b66052
> --- /dev/null
> +++ b/include/linux/mmap_lock.h
> @@ -0,0 +1,54 @@
> +#ifndef _LINUX_MMAP_LOCK_H
> +#define _LINUX_MMAP_LOCK_H
> +
> +static inline void mmap_init_lock(struct mm_struct *mm)
> +{
> + init_rwsem(&mm->mmap_sem);
> +}
> +
> +static inline void mmap_write_lock(struct mm_struct *mm)
> +{
> + down_write(&mm->mmap_sem);
> +}
> +
> +static inline int mmap_write_lock_killable(struct mm_struct *mm)
> +{
> + return down_write_killable(&mm->mmap_sem);
> +}
> +
> +static inline bool mmap_write_trylock(struct mm_struct *mm)
> +{
> + return down_write_trylock(&mm->mmap_sem) != 0;
> +}
> +
> +static inline void mmap_write_unlock(struct mm_struct *mm)
> +{
> + up_write(&mm->mmap_sem);
> +}
> +
> +static inline void mmap_write_downgrade(struct mm_struct *mm)
> +{
> + downgrade_write(&mm->mmap_sem);
> +}
> +
> +static inline void mmap_read_lock(struct mm_struct *mm)
> +{
> + down_read(&mm->mmap_sem);
> +}
> +
> +static inline int mmap_read_lock_killable(struct mm_struct *mm)
> +{
> + return down_read_killable(&mm->mmap_sem);
> +}
> +
> +static inline bool mmap_read_trylock(struct mm_struct *mm)
> +{
> + return down_read_trylock(&mm->mmap_sem) != 0;
> +}
> +
> +static inline void mmap_read_unlock(struct mm_struct *mm)
> +{
> + up_read(&mm->mmap_sem);
> +}
> +
> +#endif /* _LINUX_MMAP_LOCK_H */
>