From: "Kirill A. Shutemov" <kirill@shutemov.name>
To: Gang Li <ligang.bdlg@bytedance.com>
Cc: Hugh Dickins <hughd@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
stable@vger.kernel.org, songmuchun@bytedance.com,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] shmem: fix a race between shmem_unused_huge_shrink and shmem_evict_inode
Date: Wed, 24 Nov 2021 23:06:18 +0300 [thread overview]
Message-ID: <20211124200618.adaxuxuksrinkigv@box.shutemov.name> (raw)
In-Reply-To: <20211124094317.69719-1-ligang.bdlg@bytedance.com>
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
next prev parent reply other threads:[~2021-11-24 20:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-24 9:43 [PATCH v3] shmem: fix a race between shmem_unused_huge_shrink and shmem_evict_inode Gang Li
2021-11-24 20:06 ` Kirill A. Shutemov [this message]
2021-11-25 2:43 ` Muchun Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211124200618.adaxuxuksrinkigv@box.shutemov.name \
--to=kirill@shutemov.name \
--cc=akpm@linux-foundation.org \
--cc=hughd@google.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=ligang.bdlg@bytedance.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=songmuchun@bytedance.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).