vmalloc latency in RT-Linux
I noticed in rt-linux, vmalloc has a large latency. This is because the free_vmap_area_lock is held for a long time in the function __purge_vmap_area_lazy.
In non-RT-Linux, because the function spin_is_contended is well implemented, so there will be no such problem.
But in RT-Linux, spin_is_contended simply returns 0. I don't understand why this function was implemented like this before, but in order to solve this problem, I thought of two ways.
The first is to modify the spin_is_contended definition in spinlock_rt.h as shown below, but I'm not sure if the change has side-effects:
-#define spin_is_contended(lock) (((void)(lock), 0))
+static inline int spin_is_contended(spinlock_t *lock) +{
+ unsigned long *p = (unsigned long *) &lock->lock.owner; +
+ return (READ_ONCE(*p) & RT_MUTEX_HAS_WAITERS); +}
The second is by reducing the number of lazy_max_pages, but it will lead to lower performance of vmalloc.
Guys, Do you have any good ideas?
Best regards,
Zhipeng
Quoted 22 lines · Zhipeng Shi
I noticed in rt-linux, vmalloc has a large latency. This is because the
free_vmap_area_lockis held for a long time in the function__purge_vmap_area_lazy.In non-RT-Linux, because the function
spin_is_contendedis well implemented, so there will be no such problem.But in RT-Linux,
spin_is_contendedsimply returns 0. I don't understand why this function was implemented like this before, but in order to solve this problem, I thought of two ways.The first is to modify the
spin_is_contendeddefinition inspinlock_rt.has shown below, but I'm not sure if the change has side-effects:(quoted diff) +6
-1-#define spin_is_contended(lock) (((void)(lock), 0)) +static inline int spin_is_contended(spinlock_t *lock) +{ + unsigned long *p = (unsigned long *) &lock->lock.owner; + + return (READ_ONCE(*p) & RT_MUTEX_HAS_WAITERS); +}
Quoted 2 lines
The second is by reducing the number of
lazy_max_pages, but it will lead to lower performance of vmalloc.
__purge_vmap_area_lazy() has cond_resched_lock() to reschedule and drop the lock. From your saying, it's spin_is_contended() which is not working well to make rescheduling happen during __purge_vmap_area_lazy() handling. Then the fixing should be done in lock side.
Quoted 6 lines
Guys, Do you have any good ideas?
Best regards,
Zhipeng
Quoted 23 lines · Baoquan He
Quoted 22 lines · Zhipeng Shi
I noticed in rt-linux, vmalloc has a large latency. This is because the
free_vmap_area_lockis held for a long time in the function__purge_vmap_area_lazy.In non-RT-Linux, because the function
spin_is_contendedis well implemented, so there will be no such problem.But in RT-Linux,
spin_is_contendedsimply returns 0. I don't understand why this function was implemented like this before, but in order to solve this problem, I thought of two ways.The first is to modify the
spin_is_contendeddefinition inspinlock_rt.has shown below, but I'm not sure if the change has side-effects:(quoted diff) +6
-1-#define spin_is_contended(lock) (((void)(lock), 0)) +static inline int spin_is_contended(spinlock_t *lock) +{ + unsigned long *p = (unsigned long *) &lock->lock.owner; + + return (READ_ONCE(*p) & RT_MUTEX_HAS_WAITERS); +}
Quoted 6 lines
Quoted 2 lines
The second is by reducing the number of
lazy_max_pages, but it will lead to lower performance of vmalloc.
__purge_vmap_area_lazy()hascond_resched_lock()to reschedule and drop the lock. From your saying, it'sspin_is_contended()which is not working well to make rescheduling happen during__purge_vmap_area_lazy()handling. Then the fixing should be done in lock side.
Sebastian had sent out patch last year to fix spin_is_contended().
https://lore.kernel.org/lkml/[email protected]/
However, there is no follow-up after some discussion and the patch wasn't merged.
Cheers,
Longman
Quoted 31 lines · Waiman Long
Quoted 23 lines · Baoquan He
Quoted 22 lines · Zhipeng Shi
I noticed in rt-linux, vmalloc has a large latency. This is because the
free_vmap_area_lockis held for a long time in the function__purge_vmap_area_lazy.In non-RT-Linux, because the function
spin_is_contendedis well implemented, so there will be no such problem.But in RT-Linux,
spin_is_contendedsimply returns 0. I don't understand why this function was implemented like this before, but in order to solve this problem, I thought of two ways.The first is to modify the
spin_is_contendeddefinition inspinlock_rt.has shown below, but I'm not sure if the change has side-effects:(quoted diff) +6
-1-#define spin_is_contended(lock) (((void)(lock), 0)) +static inline int spin_is_contended(spinlock_t *lock) +{ + unsigned long *p = (unsigned long *) &lock->lock.owner; + + return (READ_ONCE(*p) & RT_MUTEX_HAS_WAITERS); +}Quoted 6 lines
Quoted 2 lines
The second is by reducing the number of
lazy_max_pages, but it will lead to lower performance of vmalloc.
__purge_vmap_area_lazy()hascond_resched_lock()to reschedule and drop the lock. From your saying, it'sspin_is_contended()which is not working well to make rescheduling happen during__purge_vmap_area_lazy()handling. Then the fixing should be done in lock side.
Quoted 6 lines
Sebastian had sent out patch last year to fix
spin_is_contended().https://lore.kernel.org/lkml/[email protected]/
However, there is no follow-up after some discussion and the patch wasn't merged.
That's great. Thanks, Longman.
Then this is a good chance to reconsider it, maybe with a test from Zhipeng.
Quoted 34 lines · Baoquan He
Quoted 33 lines · Waiman Long
Quoted 23 lines · Baoquan He
Quoted 22 lines · Zhipeng Shi
I noticed in rt-linux, vmalloc has a large latency. This is because the
free_vmap_area_lockis held for a long time in the function__purge_vmap_area_lazy.In non-RT-Linux, because the function
spin_is_contendedis well implemented, so there will be no such problem.But in RT-Linux,
spin_is_contendedsimply returns 0. I don't understand why this function was implemented like this before, but in order to solve this problem, I thought of two ways.The first is to modify the
spin_is_contendeddefinition inspinlock_rt.has shown below, but I'm not sure if the change has side-effects:(quoted diff) +6
-1-#define spin_is_contended(lock) (((void)(lock), 0)) +static inline int spin_is_contended(spinlock_t *lock) +{ + unsigned long *p = (unsigned long *) &lock->lock.owner; + + return (READ_ONCE(*p) & RT_MUTEX_HAS_WAITERS); +}Quoted 6 lines
Quoted 2 lines
The second is by reducing the number of
lazy_max_pages, but it will lead to lower performance of vmalloc.
__purge_vmap_area_lazy()hascond_resched_lock()to reschedule and drop the lock. From your saying, it'sspin_is_contended()which is not working well to make rescheduling happen during__purge_vmap_area_lazy()handling. Then the fixing should be done in lock side.Sebastian had sent out patch last year to fix
spin_is_contended().
Quoted 8 lines
Quoted 4 lines
https://lore.kernel.org/lkml/[email protected]/
However, there is no follow-up after some discussion and the patch wasn't merged.
That's great. Thanks, Longman.
Then this is a good chance to reconsider it, maybe with a test from Zhipeng.
Before that, since I didn't find the patch that Sebastian sent before, I sent relevant patch for this problem (now it seems that Sebastian's changes are better than mine) and test scripts. please refer to the following links:
https://lore.kernel.org/lkml/20220608142457.GA2400218@ubuntu20/
With this patch, max-latency of vmalloc reduce from 10+ msec to 200+ usec, this because spin_lock is released halfway through __purge_vmap_area_lazy.
Best regards,
Zhipeng
Quoted 1 line · Baoquan He
Then this is a good chance to reconsider it, maybe with a test from Zhipeng.
I reconsidered and it was dropped purpose, see
https://lore.kernel.org/lkml/YT80AB8%[email protected]/
Sebastian
Quoted 4 lines · Sebastian Andrzej Siewior
Quoted 1 line · Baoquan He
Then this is a good chance to reconsider it, maybe with a test from Zhipeng.
I reconsidered and it was dropped purpose, see
https://lore.kernel.org/lkml/YT80AB8%[email protected]/
I do agree that is_contended may not that useful for rwlock, but it can be useful for spinlock. Will you consider a version just for rt_spinlock?
Cheers,
Longman