diff mbox series

mm: Disable zsmalloc on PREEMPT_RT

Message ID 20210923170121.1860133-1-bigeasy@linutronix.de (mailing list archive)
State New
Headers show
Series mm: Disable zsmalloc on PREEMPT_RT | expand

Commit Message

Sebastian Andrzej Siewior Sept. 23, 2021, 5:01 p.m. UTC
For efficiency reasons, zsmalloc is using a slim `handle'. The value is
the address of a memory allocation of 4 or 8 bytes depending on the size
of the long data type. The lowest bit in that allocated memory is used
as a bit spin lock.
The usage of the bit spin lock is problematic because with the bit spin
lock held zsmalloc acquires a rwlock_t and spinlock_t which are both
sleeping locks on PREEMPT_RT and therefore must not be acquired with
disabled preemption.

There is a patch which extends the handle on PREEMPT_RT so that a full
spinlock_t fits (even with lockdep enabled) and then eliminates the bit
spin lock. I'm not sure how sensible zsmalloc on PREEMPT_RT is given
that it is used to store compressed user memory.

Disable ZSMALLOC on PREEMPT_RT. If there is need for it, we can try to
get it to work.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 mm/Kconfig | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Minchan Kim Sept. 23, 2021, 11:06 p.m. UTC | #1
On Thu, Sep 23, 2021 at 07:01:21PM +0200, Sebastian Andrzej Siewior wrote:
> For efficiency reasons, zsmalloc is using a slim `handle'. The value is
> the address of a memory allocation of 4 or 8 bytes depending on the size
> of the long data type. The lowest bit in that allocated memory is used
> as a bit spin lock.
> The usage of the bit spin lock is problematic because with the bit spin
> lock held zsmalloc acquires a rwlock_t and spinlock_t which are both
> sleeping locks on PREEMPT_RT and therefore must not be acquired with
> disabled preemption.

I am not sure how long the preemption disabled section takes since it
just disable for a page copy mostly.

> 
> There is a patch which extends the handle on PREEMPT_RT so that a full
> spinlock_t fits (even with lockdep enabled) and then eliminates the bit
> spin lock. I'm not sure how sensible zsmalloc on PREEMPT_RT is given
> that it is used to store compressed user memory.

I don't see what's relation between PREEMPT_RT and compressed user
memory so you can reach such conclustion. Disable zsmalloc also makes
disable zram. I think in-compress memory swap rather than storage
swap/block sometimes would be useful for even RT.

> 
> Disable ZSMALLOC on PREEMPT_RT. If there is need for it, we can try to
> get it to work.

Please send the patch which extends handle with spin_lock rather than
simply disabing.

> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
>  mm/Kconfig | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/Kconfig b/mm/Kconfig
> index 9f1e0098522c2..541371e64c477 100644
> --- a/mm/Kconfig
> +++ b/mm/Kconfig
> @@ -640,6 +640,7 @@ config ZSWAP_ZPOOL_DEFAULT_Z3FOLD
>  
>  config ZSWAP_ZPOOL_DEFAULT_ZSMALLOC
>  	bool "zsmalloc"
> +	depends on !PREEMPT_RT
>  	select ZSMALLOC
>  	help
>  	  Use the zsmalloc allocator as the default allocator.
> @@ -690,7 +691,7 @@ config Z3FOLD
>  
>  config ZSMALLOC
>  	tristate "Memory allocator for compressed pages"
> -	depends on MMU
> +	depends on MMU && !PREEMPT_RT
>  	help
>  	  zsmalloc is a slab-based memory allocator designed to store
>  	  compressed RAM pages.  zsmalloc uses virtual memory mapping
> -- 
> 2.33.0
> 
>
Sebastian Andrzej Siewior Sept. 24, 2021, 7:08 a.m. UTC | #2
On 2021-09-23 16:06:58 [-0700], Minchan Kim wrote:
> On Thu, Sep 23, 2021 at 07:01:21PM +0200, Sebastian Andrzej Siewior wrote:
> > For efficiency reasons, zsmalloc is using a slim `handle'. The value is
> > the address of a memory allocation of 4 or 8 bytes depending on the size
> > of the long data type. The lowest bit in that allocated memory is used
> > as a bit spin lock.
> > The usage of the bit spin lock is problematic because with the bit spin
> > lock held zsmalloc acquires a rwlock_t and spinlock_t which are both
> > sleeping locks on PREEMPT_RT and therefore must not be acquired with
> > disabled preemption.
> 
> I am not sure how long the preemption disabled section takes since it
> just disable for a page copy mostly.

after the bit-spin-lock, there are sleeping locks. These are
problematic.

> > 
> > There is a patch which extends the handle on PREEMPT_RT so that a full
> > spinlock_t fits (even with lockdep enabled) and then eliminates the bit
> > spin lock. I'm not sure how sensible zsmalloc on PREEMPT_RT is given
> > that it is used to store compressed user memory.
> 
> I don't see what's relation between PREEMPT_RT and compressed user
> memory so you can reach such conclustion. Disable zsmalloc also makes
> disable zram. I think in-compress memory swap rather than storage
> swap/block sometimes would be useful for even RT.

The only user of zsmalloc I found was zswap which compressed user pages.
Maybe I didn't collect all the dots.

> > Disable ZSMALLOC on PREEMPT_RT. If there is need for it, we can try to
> > get it to work.
> 
> Please send the patch which extends handle with spin_lock rather than
> simply disabing.

Okay. I will clean it up a little and post it then.

Sebastian
diff mbox series

Patch

diff --git a/mm/Kconfig b/mm/Kconfig
index 9f1e0098522c2..541371e64c477 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -640,6 +640,7 @@  config ZSWAP_ZPOOL_DEFAULT_Z3FOLD
 
 config ZSWAP_ZPOOL_DEFAULT_ZSMALLOC
 	bool "zsmalloc"
+	depends on !PREEMPT_RT
 	select ZSMALLOC
 	help
 	  Use the zsmalloc allocator as the default allocator.
@@ -690,7 +691,7 @@  config Z3FOLD
 
 config ZSMALLOC
 	tristate "Memory allocator for compressed pages"
-	depends on MMU
+	depends on MMU && !PREEMPT_RT
 	help
 	  zsmalloc is a slab-based memory allocator designed to store
 	  compressed RAM pages.  zsmalloc uses virtual memory mapping