From: "Huang, Ying" <ying.huang@intel.com>
To: Ryan Roberts <ryan.roberts@arm.com>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@redhat.com>,
Matthew Wilcox <willy@infradead.org>,
Gao Xiang <xiang@kernel.org>, Yu Zhao <yuzhao@google.com>,
Yang Shi <shy828301@gmail.com>, Michal Hocko <mhocko@suse.com>,
Kefeng Wang <wangkefeng.wang@huawei.com>,
Barry Song <21cnbao@gmail.com>, Chris Li <chrisl@kernel.org>,
<linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v4 4/6] mm: swap: Allow storage of all mTHP orders
Date: Fri, 22 Mar 2024 10:39:42 +0800 [thread overview]
Message-ID: <87plvnq9ap.fsf@yhuang6-desk2.ccr.corp.intel.com> (raw)
In-Reply-To: <b22a222b-7fd8-4648-84a7-21d35f529f27@arm.com> (Ryan Roberts's message of "Thu, 21 Mar 2024 12:21:46 +0000")
Ryan Roberts <ryan.roberts@arm.com> writes:
> On 21/03/2024 04:39, Huang, Ying wrote:
>> Ryan Roberts <ryan.roberts@arm.com> writes:
>>
>>> Hi Huang, Ying,
>>>
>>>
>>> On 12/03/2024 07:51, Huang, Ying wrote:
>>>> Ryan Roberts <ryan.roberts@arm.com> writes:
>>> [...]
>>>
>>>>> @@ -905,17 +961,18 @@ static int scan_swap_map_slots(struct swap_info_struct *si,
>>>>> }
>>>>>
>>>>> if (si->swap_map[offset]) {
>>>>> + VM_WARN_ON(order > 0);
>>>>> unlock_cluster(ci);
>>>>> if (!n_ret)
>>>>> goto scan;
>>>>> else
>>>>> goto done;
>>>>> }
>>>>> - WRITE_ONCE(si->swap_map[offset], usage);
>>>>> - inc_cluster_info_page(si, si->cluster_info, offset);
>>>>> + memset(si->swap_map + offset, usage, nr_pages);
>>>>
>>>> Add barrier() here corresponds to original WRITE_ONCE()?
>>>> unlock_cluster(ci) may be NOP for some swap devices.
>>>
>>> Looking at this a bit more closely, I'm not sure this is needed. Even if there
>>> is no cluster, the swap_info is still locked, so unlocking that will act as a
>>> barrier. There are a number of other callsites that memset(si->swap_map) without
>>> an explicit barrier and with the swap_info locked.
>>>
>>> Looking at the original commit that added the WRITE_ONCE() it was worried about
>>> a race with reading swap_map in _swap_info_get(). But that site is now annotated
>>> with a data_race(), which will suppress the warning. And I don't believe there
>>> are any places that read swap_map locklessly and depend upon observing ordering
>>> between it and other state? So I think the si unlock is sufficient?
>>>
>>> I'm not planning to add barrier() here. Let me know if you disagree.
>>
>> swap_map[] may be read locklessly in swap_offset_available_and_locked()
>> in parallel. IIUC, WRITE_ONCE() here is to make the writing take effect
>> as early as possible there.
>
> Afraid I'm not convinced by that argument; if it's racing, it's racing - the
It's not a race.
> lockless side needs to be robust (it is). Adding the compiler barrier limits the
> compiler's options which could lead to slower code in this path. If your
> argument is that you want to reduce the window where
> swap_offset_available_and_locked() could observe a free swap slot but then see
> that its taken after it gets the si lock, that seems like a micro-optimization
> to me, which we should avoid if we can.
Yes. I think that it is a micro-optimization too. I had thought that
it is a common practice to use WRITE_ONCE()/READ_ONCE() or barrier() in
intentional racy data accessing to make the change available as soon as
possible. But I may be wrong here.
> By remnoving the WRITE_ONCE() and using memset, the lockless reader could
> observe tearing though. I don't think that should cause a problem (because
> everything is rechecked with under the lock), but if we want to avoid it, then
> perhaps we just need to loop over WRITE_ONCE() here instead of using memset?
IIUC, in practice that isn't necessary, because type of si->swap_map[]
is "unsigned char". It isn't possible to tear "unsigned char". In
theory, it may be better to use WRITE_ONCE() because we may change the
type of si->swap_map[] at some time (who knows). I don't have a strong
opinion here.
>>>>> + add_cluster_info_page(si, si->cluster_info, offset, nr_pages);
>>>>> unlock_cluster(ci);
--
Best Regards,
Huang, Ying
next prev parent reply other threads:[~2024-03-22 2:41 UTC|newest]
Thread overview: 73+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-11 15:00 [PATCH v4 0/6] Swap-out mTHP without splitting Ryan Roberts
2024-03-11 15:00 ` [PATCH v4 1/6] mm: swap: Remove CLUSTER_FLAG_HUGE from swap_cluster_info:flags Ryan Roberts
2024-03-11 15:00 ` [PATCH v4 2/6] mm: swap: free_swap_and_cache_nr() as batched free_swap_and_cache() Ryan Roberts
2024-03-20 11:10 ` Ryan Roberts
2024-03-20 14:13 ` David Hildenbrand
2024-03-20 14:21 ` Ryan Roberts
2024-03-11 15:00 ` [PATCH v4 3/6] mm: swap: Simplify struct percpu_cluster Ryan Roberts
2024-03-12 7:52 ` Huang, Ying
2024-03-12 8:51 ` Ryan Roberts
2024-03-13 1:34 ` Huang, Ying
2024-03-11 15:00 ` [PATCH v4 4/6] mm: swap: Allow storage of all mTHP orders Ryan Roberts
2024-03-12 7:51 ` Huang, Ying
2024-03-12 9:40 ` Ryan Roberts
2024-03-13 1:33 ` Huang, Ying
2024-03-20 12:22 ` Ryan Roberts
2024-03-21 4:39 ` Huang, Ying
2024-03-21 12:21 ` Ryan Roberts
2024-03-22 2:38 ` Can you help us on memory barrier usage? (was Re: [PATCH v4 4/6] mm: swap: Allow storage of all mTHP orders) Huang, Ying
2024-03-22 9:23 ` Ryan Roberts
2024-03-25 3:20 ` Huang, Ying
2024-03-22 13:19 ` Chris Li
2024-03-23 2:11 ` Akira Yokosawa
2024-03-25 0:01 ` Paul E. McKenney
2024-03-25 3:16 ` Huang, Ying
2024-03-26 17:08 ` Ryan Roberts
2024-03-25 3:00 ` Huang, Ying
2024-03-22 2:39 ` Huang, Ying [this message]
2024-03-22 9:39 ` [PATCH v4 4/6] mm: swap: Allow storage of all mTHP orders Ryan Roberts
2024-03-11 15:00 ` [PATCH v4 5/6] mm: vmscan: Avoid split during shrink_folio_list() Ryan Roberts
2024-03-11 22:30 ` Barry Song
2024-03-12 8:12 ` Ryan Roberts
2024-03-12 8:40 ` Barry Song
2024-03-15 10:43 ` David Hildenbrand
2024-03-15 10:49 ` Ryan Roberts
2024-03-15 11:12 ` David Hildenbrand
2024-03-15 11:38 ` Ryan Roberts
2024-03-18 2:16 ` Huang, Ying
2024-03-18 10:00 ` Yin, Fengwei
2024-03-18 10:05 ` David Hildenbrand
2024-03-18 15:35 ` Ryan Roberts
2024-03-18 15:36 ` Ryan Roberts
2024-03-19 2:20 ` Yin Fengwei
2024-03-19 14:40 ` Ryan Roberts
2024-03-19 2:31 ` Yin Fengwei
2024-03-11 15:00 ` [PATCH v4 6/6] mm: madvise: Avoid split during MADV_PAGEOUT and MADV_COLD Ryan Roberts
2024-03-13 7:19 ` Barry Song
2024-03-13 9:03 ` Ryan Roberts
2024-03-13 9:16 ` Barry Song
2024-03-13 9:36 ` Ryan Roberts
2024-03-13 10:37 ` Barry Song
2024-03-13 11:08 ` Ryan Roberts
2024-03-13 11:37 ` Barry Song
2024-03-13 12:02 ` Ryan Roberts
2024-03-13 9:19 ` Lance Yang
2024-03-13 14:02 ` Lance Yang
2024-03-20 13:49 ` Ryan Roberts
2024-03-20 14:35 ` Lance Yang
2024-03-20 17:38 ` Ryan Roberts
2024-03-21 1:38 ` Lance Yang
2024-03-21 13:38 ` Ryan Roberts
2024-03-21 14:55 ` Lance Yang
2024-03-21 15:24 ` Ryan Roberts
2024-03-22 0:56 ` Lance Yang
[not found] ` <ffeee7da-e625-40dc-8da8-b70e4e6ef935@redhat.com>
2024-03-15 10:55 ` Ryan Roberts
2024-03-15 11:13 ` David Hildenbrand
2024-03-20 13:57 ` Ryan Roberts
2024-03-20 14:09 ` David Hildenbrand
2024-03-12 8:01 ` [PATCH v4 0/6] Swap-out mTHP without splitting Huang, Ying
2024-03-12 8:49 ` Ryan Roberts
2024-03-12 13:56 ` Ryan Roberts
2024-03-13 1:15 ` Huang, Ying
2024-03-13 8:50 ` Ryan Roberts
2024-03-12 8:45 ` Ryan Roberts
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=87plvnq9ap.fsf@yhuang6-desk2.ccr.corp.intel.com \
--to=ying.huang@intel.com \
--cc=21cnbao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=chrisl@kernel.org \
--cc=david@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=ryan.roberts@arm.com \
--cc=shy828301@gmail.com \
--cc=wangkefeng.wang@huawei.com \
--cc=willy@infradead.org \
--cc=xiang@kernel.org \
--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