From: Miaohe Lin <linmiaohe@huawei.com>
To: NeilBrown <neilb@suse.de>
Cc: <akpm@linux-foundation.org>, <willy@infradead.org>,
<vbabka@suse.cz>, <dhowells@redhat.com>, <apopple@nvidia.com>,
<david@redhat.com>, <surenb@google.com>, <peterx@redhat.com>,
<naoya.horiguchi@nec.com>, <linux-mm@kvack.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 11/15] mm/swap: add helper swap_offset_available()
Date: Tue, 10 May 2022 10:03:19 +0800 [thread overview]
Message-ID: <9319a62b-f43d-8ee9-77b9-a1afee7dbc10@huawei.com> (raw)
In-Reply-To: <165214355418.14782.13896859043718755300@noble.neil.brown.name>
On 2022/5/10 8:45, NeilBrown wrote:
> On Mon, 09 May 2022, Miaohe Lin wrote:
>> Add helper swap_offset_available() to remove some duplicated codes.
>> Minor readability improvement.
>
> I don't think that putting the spin_lock() inside the inline helper is
> good for readability.
> If the function was called
> swap_offset_available_and_locked()
Yes, swap_offset_available_and_locked should be more suitable as we do the spin_lock
inside it. Will do this in next version.
Thanks!
>
> it might be ok. Otherwise I would rather the spin_lock() was called
> when the function returned true.
>
> Thanks,
> NeilBrown
>
>>
>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
>> ---
>> mm/swapfile.c | 33 +++++++++++++++++----------------
>> 1 file changed, 17 insertions(+), 16 deletions(-)
>>
>> diff --git a/mm/swapfile.c b/mm/swapfile.c
>> index c90298a0561a..d5d3e2d03d28 100644
>> --- a/mm/swapfile.c
>> +++ b/mm/swapfile.c
>> @@ -776,6 +776,21 @@ static void set_cluster_next(struct swap_info_struct *si, unsigned long next)
>> this_cpu_write(*si->cluster_next_cpu, next);
>> }
>>
>> +static inline bool swap_offset_available(struct swap_info_struct *si, unsigned long offset)
>> +{
>> + if (data_race(!si->swap_map[offset])) {
>> + spin_lock(&si->lock);
>> + return true;
>> + }
>> +
>> + if (vm_swap_full() && READ_ONCE(si->swap_map[offset]) == SWAP_HAS_CACHE) {
>> + spin_lock(&si->lock);
>> + return true;
>> + }
>> +
>> + return false;
>> +}
>> +
>> static int scan_swap_map_slots(struct swap_info_struct *si,
>> unsigned char usage, int nr,
>> swp_entry_t slots[])
>> @@ -953,15 +968,8 @@ static int scan_swap_map_slots(struct swap_info_struct *si,
>> scan:
>> spin_unlock(&si->lock);
>> while (++offset <= READ_ONCE(si->highest_bit)) {
>> - if (data_race(!si->swap_map[offset])) {
>> - spin_lock(&si->lock);
>> + if (swap_offset_available(si, offset))
>> goto checks;
>> - }
>> - if (vm_swap_full() &&
>> - READ_ONCE(si->swap_map[offset]) == SWAP_HAS_CACHE) {
>> - spin_lock(&si->lock);
>> - goto checks;
>> - }
>> if (unlikely(--latency_ration < 0)) {
>> cond_resched();
>> latency_ration = LATENCY_LIMIT;
>> @@ -970,15 +978,8 @@ static int scan_swap_map_slots(struct swap_info_struct *si,
>> }
>> offset = si->lowest_bit;
>> while (offset < scan_base) {
>> - if (data_race(!si->swap_map[offset])) {
>> - spin_lock(&si->lock);
>> + if (swap_offset_available(si, offset))
>> goto checks;
>> - }
>> - if (vm_swap_full() &&
>> - READ_ONCE(si->swap_map[offset]) == SWAP_HAS_CACHE) {
>> - spin_lock(&si->lock);
>> - goto checks;
>> - }
>> if (unlikely(--latency_ration < 0)) {
>> cond_resched();
>> latency_ration = LATENCY_LIMIT;
>> --
>> 2.23.0
>>
>>
> .
>
next prev parent reply other threads:[~2022-05-10 2:03 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-09 13:14 [PATCH 00/15] A few cleanup patches for swap Miaohe Lin
2022-05-09 13:14 ` [PATCH 01/15] mm/swap: use helper is_swap_pte() in swap_vma_readahead Miaohe Lin
2022-05-12 13:26 ` David Hildenbrand
2022-05-18 8:31 ` Oscar Salvador
2022-05-09 13:14 ` [PATCH 02/15] mm/swap: use helper macro __ATTR_RW Miaohe Lin
2022-05-12 13:28 ` David Hildenbrand
2022-05-18 8:46 ` Oscar Salvador
2022-05-09 13:14 ` [PATCH 03/15] mm/swap: fold __swap_info_get() into its sole caller Miaohe Lin
2022-05-12 13:29 ` David Hildenbrand
2022-05-18 8:56 ` Oscar Salvador
2022-05-09 13:14 ` [PATCH 04/15] mm/swap: remove unneeded return value of free_swap_slot Miaohe Lin
2022-05-12 13:30 ` David Hildenbrand
2022-05-18 9:00 ` Oscar Salvador
2022-05-09 13:14 ` [PATCH 05/15] mm/swap: print bad swap offset entry in get_swap_device Miaohe Lin
2022-05-12 13:32 ` David Hildenbrand
2022-05-18 9:36 ` Oscar Salvador
2022-05-09 13:14 ` [PATCH 06/15] mm/swap: remove buggy cache->nr check in refill_swap_slots_cache Miaohe Lin
2022-05-12 13:37 ` David Hildenbrand
2022-05-16 2:00 ` Miaohe Lin
2022-05-17 23:39 ` Andrew Morton
2022-05-18 9:37 ` Oscar Salvador
2022-05-09 13:14 ` [PATCH 07/15] mm/swap: remove unneeded p != NULL check in __swap_duplicate Miaohe Lin
2022-05-12 13:37 ` David Hildenbrand
2022-05-18 9:40 ` Oscar Salvador
2022-05-09 13:14 ` [PATCH 08/15] mm/swap: make page_swapcount and __lru_add_drain_all Miaohe Lin
2022-05-12 13:39 ` David Hildenbrand
2022-05-18 9:46 ` Oscar Salvador
2022-05-19 1:54 ` Miaohe Lin
2022-05-09 13:14 ` [PATCH 09/15] mm/swap: avoid calling swp_swap_info when try to check SWP_STABLE_WRITES Miaohe Lin
2022-05-10 0:28 ` NeilBrown
2022-05-10 2:21 ` Miaohe Lin
2022-05-17 23:39 ` Andrew Morton
2022-05-09 13:14 ` [PATCH 10/15] mm/swap: break the loop if matching device is found Miaohe Lin
2022-05-09 21:16 ` Andrew Morton
2022-05-10 2:10 ` Miaohe Lin
2022-05-09 13:14 ` [PATCH 11/15] mm/swap: add helper swap_offset_available() Miaohe Lin
2022-05-10 0:45 ` NeilBrown
2022-05-10 2:03 ` Miaohe Lin [this message]
2022-05-17 23:39 ` Andrew Morton
2022-05-09 13:14 ` [PATCH 12/15] mm/swap: fix the obsolete comment for SWP_TYPE_SHIFT Miaohe Lin
2022-05-12 13:41 ` David Hildenbrand
2022-05-09 13:14 ` [PATCH 13/15] mm/swap: clean up the comment of find_next_to_unuse Miaohe Lin
2022-05-12 13:42 ` David Hildenbrand
2022-05-09 13:14 ` [PATCH 14/15] mm/swap: fix the comment of get_kernel_pages Miaohe Lin
2022-05-12 13:45 ` David Hildenbrand
2022-05-13 6:15 ` Miaohe Lin
2022-05-17 23:39 ` Andrew Morton
2022-05-09 13:14 ` [PATCH 15/15] mm/swap: fix comment about swap extent Miaohe Lin
2022-05-17 23:42 ` [PATCH 00/15] A few cleanup patches for swap Andrew Morton
2022-05-18 1:52 ` Miaohe Lin
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=9319a62b-f43d-8ee9-77b9-a1afee7dbc10@huawei.com \
--to=linmiaohe@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=david@redhat.com \
--cc=dhowells@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=naoya.horiguchi@nec.com \
--cc=neilb@suse.de \
--cc=peterx@redhat.com \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
--cc=willy@infradead.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