From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38B16C54E58 for ; Mon, 18 Mar 2024 15:35:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BAA806B007B; Mon, 18 Mar 2024 11:35:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B5AA56B0088; Mon, 18 Mar 2024 11:35:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A24826B0089; Mon, 18 Mar 2024 11:35:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 8F31F6B007B for ; Mon, 18 Mar 2024 11:35:51 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id BFE3C1206E2 for ; Mon, 18 Mar 2024 15:35:50 +0000 (UTC) X-FDA: 81910560060.30.98149FF Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf13.hostedemail.com (Postfix) with ESMTP id D1B9E2001E for ; Mon, 18 Mar 2024 15:35:48 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; spf=pass (imf13.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710776149; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ir8x0vtSenhU961B19rO75gT8KLy8XdMPebvsoZ4FsM=; b=MxHfRRGfTn4SZ3tGvEtpoWk6tofjHhyc7SIity9X3aTz/EnD2zlLOC+V/mF1XINvfep2MD 1at4KLEaOHmEOhdkS2sfbBCVleANylr+jT2QLFMebdmQdsCN8Mp3yJk5Z+DA+gg6XUezyF Nsw61b+5e6O0evVOW4BTJ4TOcv2YFqQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710776149; a=rsa-sha256; cv=none; b=jkAynfC/9MHfdeynTDAMQeKJhm+RRMv2kQqLTkvZHUok36YCHGgueItIjyGVQsDhGUosbW qboMmaA0gVUlIppv49ekWJZC/0iJyXbYptU2EFqJx3YcIk0faT1JWnnnp9MNveF5AHOPH4 viKg18YYMUs41aIKbmRDHQbSeKM8Plw= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; spf=pass (imf13.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BDD97DA7; Mon, 18 Mar 2024 08:36:22 -0700 (PDT) Received: from [10.57.68.51] (unknown [10.57.68.51]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 256453F67D; Mon, 18 Mar 2024 08:35:44 -0700 (PDT) Message-ID: Date: Mon, 18 Mar 2024 15:35:43 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 5/6] mm: vmscan: Avoid split during shrink_folio_list() Content-Language: en-GB To: David Hildenbrand , "Yin, Fengwei" , "Huang, Ying" Cc: "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , Andrew Morton , Matthew Wilcox , Gao Xiang , Yu Zhao , Yang Shi , Michal Hocko , Kefeng Wang , Barry Song <21cnbao@gmail.com>, Chris Li References: <20240311150058.1122862-1-ryan.roberts@arm.com> <20240311150058.1122862-6-ryan.roberts@arm.com> <1db242d3-5ff1-4ef5-b20a-578a317fa859@arm.com> <5cc147fa-492e-46c3-963d-2f6e6680dce9@arm.com> <878r2gwahg.fsf@yhuang6-desk2.ccr.corp.intel.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: D1B9E2001E X-Rspam-User: X-Stat-Signature: 5cbui8jndem5wbww5wmwoghayw9iipys X-Rspamd-Server: rspam03 X-HE-Tag: 1710776148-806999 X-HE-Meta: U2FsdGVkX19boc7MQaaxseeYKL4iAoUC9gAW0qVa6g0qONU08Tec4BQL3Si1aKL9jvpFramLZkg+ymZqV/e3t/yTscaUT/IwMaXwMOeTrG754cpyYAOnA1bUP2YFtn4Oh3x6OfjwHEfXjWb5xaldS1n5uhvvlN1l7qxd+ElQdXCTK5V/73+/MxnC+bgPtB58vpnDyzPkLFlHYkcfOXM1KqUVia/dT0qmETJY0JhJwCvufiSagkH81k+Hi0wTqZ/KELsx9HYVoQJ8Xz4DZFSvvOi4uKwkrhbaDT21DqRD871+Kg25ECX7CO8X9pC9fYilEzPg6fB5JHDl+LV9PDPNV8/WPChVK/xDYgc2+2aNAyph1qEZpGecLT92E5sLlohujK4zMpIMGT36xNaAmSeYH03gJb2V4HzKX0j9eexJ2NzIaokrOznCSc1WJulNXr2qPp2K4qWT82trvNhNTx8lINHq4np6uuDLuxGL+zOD2SZlbCNkdBhF44jIinzeNMPYeWCANgs+H8TqaRo89SGAqAKHizgSMsjfpG1fK9Gm5Ts48yV0kX7sC8KJOi3RIyD1U7DfUixccJkz9gi4+m20rpmzvZBJn8SrDnUVQeIhpkJaL6ghyT2sgi6UtNMTlCJj9bYeuG/QnHfeJBRxwq1O2ybJgYIL3LiN0JUjGnY/pT6zREF+ybUE9kmi14a81VL2eOlNq9GxAtxWR/gUCwjJzh9FOUp4AKqmSZSAqNhQlTnwQnvp4ce4IWQYQc6h+P9bUsqWYZIFo3DS8kQOni5hGEzdiW+1tAjL7diwY+09MBDZxittvTLBCSK2PKL0nzZn72xmpGcqkQFLTdIGLopMvv2fUnyYpTJ5xezPZAejb4sVFN7fVeXk22dj9VUCB1E1f44e4euf9e7Q4lMhx0jcmSywOFY8Pus9ffL8Jt9r4BRPrIkJRbZjew== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 18/03/2024 10:05, David Hildenbrand wrote: > On 18.03.24 11:00, Yin, Fengwei wrote: >> >> >> On 3/18/2024 10:16 AM, Huang, Ying wrote: >>> Ryan Roberts writes: >>> >>>> Hi Yin Fengwei, >>>> >>>> On 15/03/2024 11:12, David Hildenbrand wrote: >>>>> On 15.03.24 11:49, Ryan Roberts wrote: >>>>>> On 15/03/2024 10:43, David Hildenbrand wrote: >>>>>>> On 11.03.24 16:00, Ryan Roberts wrote: >>>>>>>> Now that swap supports storing all mTHP sizes, avoid splitting large >>>>>>>> folios before swap-out. This benefits performance of the swap-out path >>>>>>>> by eliding split_folio_to_list(), which is expensive, and also sets us >>>>>>>> up for swapping in large folios in a future series. >>>>>>>> >>>>>>>> If the folio is partially mapped, we continue to split it since we want >>>>>>>> to avoid the extra IO overhead and storage of writing out pages >>>>>>>> uneccessarily. >>>>>>>> >>>>>>>> Signed-off-by: Ryan Roberts >>>>>>>> --- >>>>>>>>      mm/vmscan.c | 9 +++++---- >>>>>>>>      1 file changed, 5 insertions(+), 4 deletions(-) >>>>>>>> >>>>>>>> diff --git a/mm/vmscan.c b/mm/vmscan.c >>>>>>>> index cf7d4cf47f1a..0ebec99e04c6 100644 >>>>>>>> --- a/mm/vmscan.c >>>>>>>> +++ b/mm/vmscan.c >>>>>>>> @@ -1222,11 +1222,12 @@ static unsigned int shrink_folio_list(struct >>>>>>>> list_head >>>>>>>> *folio_list, >>>>>>>>                          if (!can_split_folio(folio, NULL)) >>>>>>>>                              goto activate_locked; >>>>>>>>                          /* >>>>>>>> -                     * Split folios without a PMD map right >>>>>>>> -                     * away. Chances are some or all of the >>>>>>>> -                     * tail pages can be freed without IO. >>>>>>>> +                     * Split partially mapped folios map >>>>>>>> +                     * right away. Chances are some or all >>>>>>>> +                     * of the tail pages can be freed >>>>>>>> +                     * without IO. >>>>>>>>                           */ >>>>>>>> -                    if (!folio_entire_mapcount(folio) && >>>>>>>> +                    if (!list_empty(&folio->_deferred_list) && >>>>>>>>                              split_folio_to_list(folio, >>>>>>>>                                      folio_list)) >>>>>>>>                              goto activate_locked; >>>>>>> >>>>>>> Not sure if we might have to annotate that with data_race(). >>>>>> >>>>>> I asked that exact question to Matthew in another context bt didn't get a >>>>>> response. There are examples of checking if the deferred list is empty >>>>>> with and >>>>>> without data_race() in the code base. But list_empty() is implemented like >>>>>> this: >>>>>> >>>>>> static inline int list_empty(const struct list_head *head) >>>>>> { >>>>>>       return READ_ONCE(head->next) == head; >>>>>> } >>>>>> >>>>>> So I assumed the READ_ONCE() makes everything safe without a lock? Perhaps >>>>>> not >>>>>> sufficient for KCSAN? >> I don't think READ_ONCE() can replace the lock. But it doesn't ensure we get a consistent value and that the compiler orders the load correctly. There are lots of patterns in the kernel that use READ_ONCE() without a lock and they don't use data_race() - e.g. ptep_get_lockless(). It sounds like none of us really understand what data_race() is for, so I guess I'll just do a KCSAN build and invoke the code path to see if it complains. >> >>>>> >>>>> Yeah, there is only one use of data_race with that list. >>>>> >>>>> It was added in f3ebdf042df4 ("THP: avoid lock when check whether THP is in >>>>> deferred list"). >>>>> >>>>> Looks like that was added right in v1 of that change [1], so my best guess is >>>>> that it is not actually required. >>>>> >>>>> If not required, likely we should just cleanup the single user. >>>>> >>>>> [1] >>>>> https://lore.kernel.org/linux-mm/20230417075643.3287513-2-fengwei.yin@intel.com/ >>>> >>>> Do you have any recollection of why you added the data_race() markup? >>> >>> Per my understanding, this is used to mark that the code accesses >>> folio->_deferred_list without lock intentionally, while >>> folio->_deferred_list may be changed in parallel.  IIUC, this is what >>> data_race() is used for.  Or, my understanding is wrong? >> Yes. This is my understanding also. > > Why don't we have a data_race() in deferred_split_folio() then, before taking > the lock? > > It's used a bit inconsistently here. >