From: David Hildenbrand <david@redhat.com>
To: Huang Ying <ying.huang@intel.com>,
Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Hugh Dickins <hughd@google.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Matthew Wilcox <willy@infradead.org>,
Michal Hocko <mhocko@suse.com>, Minchan Kim <minchan@kernel.org>,
Tim Chen <tim.c.chen@linux.intel.com>,
Yang Shi <shy828301@gmail.com>, Yu Zhao <yuzhao@google.com>
Subject: Re: [PATCH] swap: cleanup get/put_swap_device usage
Date: Tue, 16 May 2023 13:06:03 +0200 [thread overview]
Message-ID: <d1b054d0-d083-d35c-e547-7e8756fd802a@redhat.com> (raw)
In-Reply-To: <20230516052957.175432-1-ying.huang@intel.com>
On 16.05.23 07:29, Huang Ying wrote:
> The general rule to use a swap entry is as follows.
>
> When we get a swap entry, if there isn't some other way to prevent
> swapoff, such as page lock for swap cache, page table lock, etc., the
> swap entry may become invalid because of swapoff. Then, we need to
> enclose all swap related functions with get_swap_device() and
> put_swap_device(), unless the swap functions call
> get/put_swap_device() by themselves.
>
> Add the rule as comments of get_swap_device(), and cleanup some
> functions which call get/put_swap_device().
>
> 1. Enlarge the get/put_swap_device() protection range in
> __read_swap_cache_async(). This makes the function a little easier to
> be understood because we don't need to consider swapoff. And this
> makes it possible to remove get/put_swap_device() calling in some
> function called by __read_swap_cache_async().
>
> 2. Remove get/put_swap_device() in __swap_count(). Which is call in
> do_swap_page() only, which encloses the call with get/put_swap_device()
> already.
>
> 3. Remove get/put_swap_device() in __swp_swapcount(). Which is call
> in __read_swap_cache_async() only, which encloses the call with
> get/put_swap_device() already.
>
> 4. Remove get/put_swap_device() in __swap_duplicate(). Which is called
> by
>
> - swap_shmem_alloc(): the swap cache is locked.
>
> - copy_nonpresent_pte() -> swap_duplicate() and try_to_unmap_one() ->
> swap_duplicate(): the page table lock is held.
>
> - __read_swap_cache_async() -> swapcache_prepare(): enclosed with
> get/put_swap_device() already.
>
> Other get/put_swap_device() usages are checked too.
I suggest splitting this patch up into logical pieces as outlined here
by you already.
--
Thanks,
David / dhildenb
next prev parent reply other threads:[~2023-05-16 11:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-16 5:29 [PATCH] swap: cleanup get/put_swap_device usage Huang Ying
2023-05-16 11:06 ` David Hildenbrand [this message]
2023-05-17 0:23 ` Huang, Ying
2023-05-20 16:40 ` Chris Li
2023-05-22 1:26 ` Huang, Ying
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=d1b054d0-d083-d35c-e547-7e8756fd802a@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=minchan@kernel.org \
--cc=shy828301@gmail.com \
--cc=tim.c.chen@linux.intel.com \
--cc=willy@infradead.org \
--cc=ying.huang@intel.com \
--cc=yuzhao@google.com \
/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).