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 95B5BC54E67 for ; Wed, 20 Mar 2024 12:22:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 079226B008A; Wed, 20 Mar 2024 08:22:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F1DA56B008C; Wed, 20 Mar 2024 08:22:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DBD946B0092; Wed, 20 Mar 2024 08:22:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C61376B008A for ; Wed, 20 Mar 2024 08:22:32 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0EA4016131D for ; Wed, 20 Mar 2024 12:22:32 +0000 (UTC) X-FDA: 81917330544.05.56155C7 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf20.hostedemail.com (Postfix) with ESMTP id C41A91C0020 for ; Wed, 20 Mar 2024 12:22:29 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; spf=pass (imf20.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=1710937350; 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=MEOx2jNfsKAZ6ZRh0uhKm/nw4gHclr6NawwDIaZdm60=; b=8HOrfxdMcuXdu0iB3ZJaRyzN6ko9GI05ABbXtsPqraTcoPIMwwZh0uMrPo57bxvnriv+yj kBOgLO3dW9scTyU6Goid0IliuvGcaivb+G/Fy5pRnqGPwjs09p2YmFjgstiayDcwpA3ic+ a3GIP4EashmXRsMSOXpIkOCFuLKLuqc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710937350; a=rsa-sha256; cv=none; b=QOI2NXqQVUq7fJ7X1Kj1y6faSJz9iFGSkPyANS4JPBc24oInoO80mlJCE+i1nqIqaQYB+f RHdu7nyMalNgWc6USpW3cBiq8ztuPEkNrEKlEvp2maLChX561uu5lM0rKmqcyuxztk/NWr CGSSBc+NG55CWYDGiQ23yjjDP1Xm4zs= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; spf=pass (imf20.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 4EC771007; Wed, 20 Mar 2024 05:22:57 -0700 (PDT) Received: from [10.57.72.78] (unknown [10.57.72.78]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 248603F762; Wed, 20 Mar 2024 05:22:20 -0700 (PDT) Message-ID: Date: Wed, 20 Mar 2024 12:22:18 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 4/6] mm: swap: Allow storage of all mTHP orders Content-Language: en-GB To: "Huang, Ying" Cc: Andrew Morton , David Hildenbrand , Matthew Wilcox , Gao Xiang , Yu Zhao , Yang Shi , Michal Hocko , Kefeng Wang , Barry Song <21cnbao@gmail.com>, Chris Li , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20240311150058.1122862-1-ryan.roberts@arm.com> <20240311150058.1122862-5-ryan.roberts@arm.com> <87jzm751n3.fsf@yhuang6-desk2.ccr.corp.intel.com> From: Ryan Roberts In-Reply-To: <87jzm751n3.fsf@yhuang6-desk2.ccr.corp.intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: C41A91C0020 X-Rspam-User: X-Stat-Signature: nergp6aoxxyqerrgg8uum6x3wb5ags56 X-Rspamd-Server: rspam03 X-HE-Tag: 1710937349-782506 X-HE-Meta: U2FsdGVkX1+/mARQX38lZwyRD1DgmelW2bkFq3w0PWn9ZEcg6/MyO86WcKQfbRAyS/UU42O2K169JvfVe93PkCdUWX0V51xk2pHsMmkQk2lOVOV5Q2w9EA0lnQw936w9kOkruC3d1oMT2scg5RxRlr3tFT95/PUprWiRXECDErcEWfhBnN0m1SSxjdgdrqpXx8BjFvi+Io9H9M4pILeXr011S2hU6r9+qY50Xo/NR8Z3TEYrZpZ8acO8qO588V3Al16Ug1eYZPuANDtihl4I5qJsq2nVdVOaNExr/TR3eEmwg7WqhK8g7MJPsJyDDJ934vGqa97MzruIi09ZuvcPgpm2LShz8Sbd6OH90fYGruvlYe+pNx0i8a9yAIbcJ6IiDE9qBUrIr90LhOjEdr6J1ukRy+PB8cRv6uKor9CCNU0X9XpimAh7D+mSGXezWASwJwMoFVzlgGjDOB7TLytWuysPN4frfyADRrNNWh3LehH3SCYAeeGf09y+3K1mO1MsSlw5ljEpV2hQt6ykbjx0kfoM+NvYV/K9wMlGD190g63fRUmCqGtQwqNGlobu1oGibXDCTSF1op9Fk/THcVQFMU+gREHUDEpfgYAK7NP9iGI9frqC+9NKdMOqHshbLDJEGD9jTmsutImqejfyTSMqfjuousZ8PWG8rFAQIQ1Ir9Iqwg0AAP5Zjs6EgvT0wKa/jAbnoNMdRtkVqaJNSkk5W27BkRu8yiQNACYJZIlgPMbc+YAfsPXTmKv+T9+EjadYalO/SW5Hv2ly3pYFsdORnZO8C+77Clcn10hcrXKVqnFHdPWsw8KmWhI9IceEinNVzI4vTSxnlSzW2KhYPldTSljLJznl9s/gT0dgKx2QNAsunxkiVyYbT6sVdhWwaOgkrjd9CDtXTQb+TpbpuxDRjE2m1VTSFzXAkgi2BRnvVDHXV+bJ1qkM2oUUX9jRcF/mcFaS9ZKMv5Wcqer9a1u 5izYdqH3 Then7xlYeD0zhKxzpsaReRA0JLCsrBF+yngGsJBEPMtxv0FTwbl/EoxVQf56yjdv/Pl2ygqeP59IxhOASXlZSdQk58KDilY6NC+t4Uh5i6z/DeeXirAamwbqj2mBTMbwqAEbwLRcJMZhplCmBQr3ZwvXizbzswco49AH5HLA03k5grvOCrMN539+LuqtdJc7zPJna5zgelZbgSx0= 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: Hi Huang, Ying, On 12/03/2024 07:51, Huang, Ying wrote: > Ryan Roberts writes: > >> Multi-size THP enables performance improvements by allocating large, >> pte-mapped folios for anonymous memory. However I've observed that on an >> arm64 system running a parallel workload (e.g. kernel compilation) >> across many cores, under high memory pressure, the speed regresses. This >> is due to bottlenecking on the increased number of TLBIs added due to >> all the extra folio splitting when the large folios are swapped out. >> >> Therefore, solve this regression by adding support for swapping out mTHP >> without needing to split the folio, just like is already done for >> PMD-sized THP. This change only applies when CONFIG_THP_SWAP is enabled, >> and when the swap backing store is a non-rotating block device. These >> are the same constraints as for the existing PMD-sized THP swap-out >> support. >> >> Note that no attempt is made to swap-in (m)THP here - this is still done >> page-by-page, like for PMD-sized THP. But swapping-out mTHP is a >> prerequisite for swapping-in mTHP. >> >> The main change here is to improve the swap entry allocator so that it >> can allocate any power-of-2 number of contiguous entries between [1, (1 >> << PMD_ORDER)]. This is done by allocating a cluster for each distinct >> order and allocating sequentially from it until the cluster is full. >> This ensures that we don't need to search the map and we get no >> fragmentation due to alignment padding for different orders in the >> cluster. If there is no current cluster for a given order, we attempt to >> allocate a free cluster from the list. If there are no free clusters, we >> fail the allocation and the caller can fall back to splitting the folio >> and allocates individual entries (as per existing PMD-sized THP >> fallback). >> >> The per-order current clusters are maintained per-cpu using the existing >> infrastructure. This is done to avoid interleving pages from different >> tasks, which would prevent IO being batched. This is already done for >> the order-0 allocations so we follow the same pattern. >> >> As is done for order-0 per-cpu clusters, the scanner now can steal >> order-0 entries from any per-cpu-per-order reserved cluster. This >> ensures that when the swap file is getting full, space doesn't get tied >> up in the per-cpu reserves. >> >> This change only modifies swap to be able to accept any order mTHP. It >> doesn't change the callers to elide doing the actual split. That will be >> done in separate changes. [...] >> @@ -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. Thanks, Ryan > >> + add_cluster_info_page(si, si->cluster_info, offset, nr_pages); >> unlock_cluster(ci);