| From: Barry Song <v-songbaohua@oppo.com> |
| Subject: mm: wake_up only when swapcache_wq waitqueue is active |
| Date: Tue, 8 Oct 2024 20:18:27 +0800 |
| |
| wake_up() will acquire spinlock even waitqueue is empty. This might |
| involve cache sync overhead. Let's only call wake_up() when waitqueue |
| is active. |
| |
| Link: https://lkml.kernel.org/r/20241008130807.40833-1-21cnbao@gmail.com |
| Signed-off-by: Barry Song <v-songbaohua@oppo.com> |
| Suggested-by: "Huang, Ying" <ying.huang@intel.com> |
| Cc: Chris Li <chrisl@kernel.org> |
| Cc: David Hildenbrand <david@redhat.com> |
| Cc: Hugh Dickins <hughd@google.com> |
| Cc: Johannes Weiner <hannes@cmpxchg.org> |
| Cc: Kairui Song <kasong@tencent.com> |
| Cc: Kalesh Singh <kaleshsingh@google.com> |
| Cc: Matthew Wilcox (Oracle) <willy@infradead.org> |
| Cc: Michal Hocko <mhocko@suse.com> |
| Cc: Minchan Kim <minchan@kernel.org> |
| Cc: Oven Liyang <liyangouwen1@oppo.com> |
| Cc: SeongJae Park <sj@kernel.org> |
| Cc: Suren Baghdasaryan <surenb@google.com> |
| Cc: Yosry Ahmed <yosryahmed@google.com> |
| Cc: Yu Zhao <yuzhao@google.com> |
| Signed-off-by: Andrew Morton <akpm@linux-foundation.org> |
| --- |
| |
| mm/memory.c | 6 ++++-- |
| 1 file changed, 4 insertions(+), 2 deletions(-) |
| |
| --- a/mm/memory.c~mm-avoid-unconditional-one-tick-sleep-when-swapcache_prepare-fails-fix |
| +++ a/mm/memory.c |
| @@ -4611,7 +4611,8 @@ out: |
| /* Clear the swap cache pin for direct swapin after PTL unlock */ |
| if (need_clear_cache) { |
| swapcache_clear(si, entry, nr_pages); |
| - wake_up(&swapcache_wq); |
| + if (waitqueue_active(&swapcache_wq)) |
| + wake_up(&swapcache_wq); |
| } |
| if (si) |
| put_swap_device(si); |
| @@ -4629,7 +4630,8 @@ out_release: |
| } |
| if (need_clear_cache) { |
| swapcache_clear(si, entry, nr_pages); |
| - wake_up(&swapcache_wq); |
| + if (waitqueue_active(&swapcache_wq)) |
| + wake_up(&swapcache_wq); |
| } |
| if (si) |
| put_swap_device(si); |
| _ |