Re: [PATCH] mm: reduce spinlock contention in release_pages()

From: Michal Hocko
Date: Wed Nov 24 2021 - 11:32:03 EST


On Wed 24-11-21 15:19:15, Hao Lee wrote:
> When several tasks are terminated simultaneously, lots of pages will be
> released, which can cause severe spinlock contention. Other tasks which
> are running on the same core will be seriously affected. We can yield
> cpu to fix this problem.

How does this actually address the problem? You are effectivelly losing
fairness completely. We do batch currently so no single task should be
able to monopolize the cpu for too long. Why this is not sufficient?

> diff --git a/mm/swap.c b/mm/swap.c
> index e8c9dc6d0377..91850d51a5a5 100644
> --- a/mm/swap.c
> +++ b/mm/swap.c
> @@ -960,8 +960,14 @@ void release_pages(struct page **pages, int nr)
> if (PageLRU(page)) {
> struct lruvec *prev_lruvec = lruvec;
>
> - lruvec = folio_lruvec_relock_irqsave(folio, lruvec,
> +retry:
> + lruvec = folio_lruvec_tryrelock_irqsave(folio, lruvec,
> &flags);
> + if (!lruvec) {
> + cond_resched();
> + goto retry;
> + }
> +
> if (prev_lruvec != lruvec)
> lock_batch = 0;
>
> --
> 2.31.1

--
Michal Hocko
SUSE Labs