Skip to content

Commit

Permalink
mm: thp: make split queue lock safe when LRU pages are reparented
Browse files Browse the repository at this point in the history
Similar to the lruvec lock, we use the same approach to make the split
queue lock safe when LRU pages are reparented.

Signed-off-by: Muchun Song <songmuchun@bytedance.com>
  • Loading branch information
Muchun Song authored and intel-lab-lkp committed Aug 14, 2021
1 parent 3460bcf commit f19b75e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions mm/huge_memory.c
Expand Up @@ -535,9 +535,22 @@ static struct deferred_split *folio_split_queue_lock(struct folio *folio)
{
struct deferred_split *queue;

rcu_read_lock();
retry:
queue = folio_split_queue(folio);
spin_lock(&queue->split_queue_lock);

if (unlikely(split_queue_memcg(queue) != folio_memcg(folio))) {
spin_unlock(&queue->split_queue_lock);
goto retry;
}

/*
* Preemption is disabled in the internal of spin_lock, which can serve
* as RCU read-side critical sections.
*/
rcu_read_unlock();

return queue;
}

Expand All @@ -546,9 +559,19 @@ folio_split_queue_lock_irqsave(struct folio *folio, unsigned long *flags)
{
struct deferred_split *queue;

rcu_read_lock();
retry:
queue = folio_split_queue(folio);
spin_lock_irqsave(&queue->split_queue_lock, *flags);

if (unlikely(split_queue_memcg(queue) != folio_memcg(folio))) {
spin_unlock_irqrestore(&queue->split_queue_lock, *flags);
goto retry;
}

/* See the comments in folio_split_queue_lock(). */
rcu_read_unlock();

return queue;
}

Expand Down

0 comments on commit f19b75e

Please sign in to comment.