lkml.org 
[lkml]   [2021]   [Nov]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v3] shmem: fix a race between shmem_unused_huge_shrink and shmem_evict_inode
On Wed, Nov 24, 2021 at 05:43:16PM +0800, Gang Li wrote:
> +move_back:
> + /* inodes that are on @list and will not be deleted must be moved back to
> + * global list before iput for two reasons:
> + * 1. iput in lock: iput call shmem_evict_inode, then cause deadlock.
> + * 2. iput before lock: shmem_evict_inode may grab the inode on @list,
> + * which will cause race.
> + */
> + spin_lock(&sbinfo->shrinklist_lock);
> + list_move(&info->shrinklist, &sbinfo->shrinklist);
> + sbinfo->shrinklist_len++;
> + spin_unlock(&sbinfo->shrinklist_lock);
> +put:
> iput(inode);
> }
>
> - spin_lock(&sbinfo->shrinklist_lock);
> - list_splice_tail(&list, &sbinfo->shrinklist);
> - sbinfo->shrinklist_len -= removed;
> - spin_unlock(&sbinfo->shrinklist_lock);
> -
> return split;
> }

Okay, I guess it works. Locking is not pretty, but well..

Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>

--
Kirill A. Shutemov

\
 
 \ /
  Last update: 2021-11-24 21:06    [W:0.040 / U:0.008 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site