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 70C30CD1297 for ; Tue, 9 Apr 2024 09:25:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 304466B0088; Tue, 9 Apr 2024 05:25:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B3DF6B008A; Tue, 9 Apr 2024 05:25:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 107FD6B008C; Tue, 9 Apr 2024 05:25:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id C5A3A6B0088 for ; Tue, 9 Apr 2024 05:25:01 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9401BC02A0 for ; Tue, 9 Apr 2024 09:25:01 +0000 (UTC) X-FDA: 81989459202.27.86401BA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf16.hostedemail.com (Postfix) with ESMTP id 1669218000C for ; Tue, 9 Apr 2024 09:24:58 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YUiWR0pM; spf=pass (imf16.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712654699; a=rsa-sha256; cv=none; b=Kdg97sTdAGke6a8ZFojxpIMNRAQx5REXaZvgr3UIzoXJkB/P1uSc2If6PQqhZhN5OTLptT PXP3nlgJ5YZ9YevxlWDoHpWeBWjw8FJ3XJ+JEQqdNgryu1DTyThxwb/kA4a+Ub4U6vdegs B62BThgj+9JBf6/fx9+YyWcQbeC4yEM= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YUiWR0pM; spf=pass (imf16.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712654699; 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:dkim-signature; bh=/okR9rpbpzeXAqNCBO5VwYD3JhIXUF7Gq9tuXdmOn7g=; b=SIGwDFgRwReHy3x7WgwTXVq4DlXLGGFke1Gq3bkK6GU7RPHcCg35tG3KKBc/rHCOKpjAQ0 FnwYo92KbI0QxDi4oBddczUsrboEadIu/Kh6Z9B8hz+tXoTaWzwwbQiFoKksK/EzLgQJ6K tjoprJwh02enk5saHt/QGdUavbLrT4g= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712654698; h=from:from: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:autocrypt:autocrypt; bh=/okR9rpbpzeXAqNCBO5VwYD3JhIXUF7Gq9tuXdmOn7g=; b=YUiWR0pMHJ6o+SaCc9OqlJCXQecW2pBmgq9JzXB+2qORUY2V5tb1KhKbBNJZWFZEnyz1Mb vMTZinSNERwGiSYCkcMT9X2LJAr7SsWowmrM/jeekaHoh2cp+jdseAfsKJttxvCOYC6bz5 HKiarLBoYmC8d067+ESg+s+zfprKY74= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-694-BHlzI2X3Nv2J3dgGN8afhg-1; Tue, 09 Apr 2024 05:24:56 -0400 X-MC-Unique: BHlzI2X3Nv2J3dgGN8afhg-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4147f17da12so27140635e9.0 for ; Tue, 09 Apr 2024 02:24:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712654696; x=1713259496; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=/okR9rpbpzeXAqNCBO5VwYD3JhIXUF7Gq9tuXdmOn7g=; b=arSZAmZ55zVhvnKaSPcQwRRCl24nh3v09Q3zL6/Lz9RVNdpEb4YXb7iUNtCgt4VJsf dQVLZkc7ahFSxEYPHcD+UCcPKE+K3coj6YxPcoLVeNUPFxQ48UJkSJVUkBMtz5zIszJj L7Kdy/eCQCgoRawzs/j9dGlLf8GsH1Sa18JRaRsCjph5v/fpiGjH7gXHb8Ta9CP9gJa2 irKjljCIyQ6VtqW2HcnY3NkDHMZjgv8DTavTNDVW84wNgvyZAlUG9N15F1SQDnIlUaHe arMnZxKSzGkjtr1XLbI5BFIgifF9JhZVutlNMX76mgakt1cp76QCh/oqCYcYEmCG5GBG C0RQ== X-Forwarded-Encrypted: i=1; AJvYcCXG8jiKGGUzhzh74+bOVvZ2u9n8TUZcNIDZnELWNLLa/QyJ2+O28rmlbUZYOeU5vit/8+4pbL4VZu+HVb1ay+SuOAk= X-Gm-Message-State: AOJu0YwIPyr55vXgHFG2zelGJ0MJQedMnoCRlj9STme1gDUpgmLheide h+KxRuW/iGSLAM+Egf7GvXdn0Os4ryQgnvgj7BlL+diNMCF7Civ/h6rA0o9E6JpL9rqp3LjWp/h g+TuawPpvgoc5eeIHADcPXyr0bdByjiWdMbfya+J+4/vJY6Lh X-Received: by 2002:a05:600c:4505:b0:414:22e:1761 with SMTP id t5-20020a05600c450500b00414022e1761mr8003615wmo.16.1712654695628; Tue, 09 Apr 2024 02:24:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGUOslcXQbtIvT5Ov24AsfuqYxkkP3X08eqFbplh4Jw409YR6hjDmpWJiRssTpWkrZB8YvNpg== X-Received: by 2002:a05:600c:4505:b0:414:22e:1761 with SMTP id t5-20020a05600c450500b00414022e1761mr8003600wmo.16.1712654695190; Tue, 09 Apr 2024 02:24:55 -0700 (PDT) Received: from ?IPV6:2003:cb:c70a:be00:a285:bc76:307d:4eaa? (p200300cbc70abe00a285bc76307d4eaa.dip0.t-ipconnect.de. [2003:cb:c70a:be00:a285:bc76:307d:4eaa]) by smtp.gmail.com with ESMTPSA id r7-20020a05600c458700b00416b035c2d8sm969514wmo.3.2024.04.09.02.24.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 09 Apr 2024 02:24:54 -0700 (PDT) Message-ID: <44e23a4d-97e7-4d84-848a-f9325b7b76c0@redhat.com> Date: Tue, 9 Apr 2024 11:24:53 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v7 2/7] mm: swap: free_swap_and_cache_nr() as batched free_swap_and_cache() To: Barry Song <21cnbao@gmail.com>, Ryan Roberts Cc: Andrew Morton , Matthew Wilcox , Huang Ying , Gao Xiang , Yu Zhao , Yang Shi , Michal Hocko , Kefeng Wang , Chris Li , Lance Yang , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20240408183946.2991168-1-ryan.roberts@arm.com> <20240408183946.2991168-3-ryan.roberts@arm.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/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frf4Gusdqx8nPEpfOqCtbbwJMATbHyqLt7/oz/5deGuwxgb65pWIzufa N7eop7uh+6bezi+rugUI+w6DABEBAAHCwXwEGAEIACYCGwwWIQQb2cqtc1xMOkYN/MpN3hD3 AP+DWgUCXw7HsgUJEqkpoQAKCRBN3hD3AP+DWrrpD/4qS3dyVRxDcDHIlmguXjC1Q5tZTwNB boaBTPHSy/Nksu0eY7x6HfQJ3xajVH32Ms6t1trDQmPx2iP5+7iDsb7OKAb5eOS8h+BEBDeq 3ecsQDv0fFJOA9ag5O3LLNk+3x3q7e0uo06XMaY7UHS341ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 1669218000C X-Stat-Signature: 8b9p7e9myz14nuijwjxe46yo5xjbnt3t X-Rspam-User: X-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Jwa7kx0fDLfFRQfnUBuoFBY5LkNNpGX0pxzrPZy5o2Uw9pODHHt7PecNBlCnVBfunBqF9wy2x0cJHw5kYkEL0GCCaSx7JusXutambh4wUQCxJYM1KKgvcxZQOD6/8dOhDZtlCHxZDMlLvUiywuT3Q1D9BxI6ID5gRyPa5K7ZCFljZ/dvLiLTvDVoRtBTZIRn3m1G+fddNxWpYfYD00VdmEu9W6cSW6Xyr9AyvmK3Ljz/2aZFjHrqtHoic7acmhgQSd4muop1UY0NhQ/2dJuriye9zNsYZGjUNj5v2nxh36zeuIOn5WRn2cKidfBMSmvo8uBIw4n/pkL3JPfFc/8hNIGlMD1o/jPra81UdN20qSRSrFxyxKM9vhIcS3zp025fe3Y0QtyClboYR7PQKzsjOgJxJB/ayd4jCFri2QGqcLKUNfeMKjtfx1v/T0rbzkPUOnnXwpINuB3F3a/n/jtbcml3sGFFX18jjTmuaoiDRUu+/HIWm/Vbjx108AmaudOAgzkqzejss4Ro= 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 09.04.24 11:22, Barry Song wrote: > On Tue, Apr 9, 2024 at 8:51 PM Barry Song <21cnbao@gmail.com> wrote: >> >> On Tue, Apr 9, 2024 at 6:40 AM Ryan Roberts wrote: >>> >>> Now that we no longer have a convenient flag in the cluster to determine >>> if a folio is large, free_swap_and_cache() will take a reference and >>> lock a large folio much more often, which could lead to contention and >>> (e.g.) failure to split large folios, etc. >>> >>> Let's solve that problem by batch freeing swap and cache with a new >>> function, free_swap_and_cache_nr(), to free a contiguous range of swap >>> entries together. This allows us to first drop a reference to each swap >>> slot before we try to release the cache folio. This means we only try to >>> release the folio once, only taking the reference and lock once - much >>> better than the previous 512 times for the 2M THP case. >>> >>> Contiguous swap entries are gathered in zap_pte_range() and >>> madvise_free_pte_range() in a similar way to how present ptes are >>> already gathered in zap_pte_range(). >>> >>> While we are at it, let's simplify by converting the return type of both >>> functions to void. The return value was used only by zap_pte_range() to >>> print a bad pte, and was ignored by everyone else, so the extra >>> reporting wasn't exactly guaranteed. We will still get the warning with >>> most of the information from get_swap_device(). With the batch version, >>> we wouldn't know which pte was bad anyway so could print the wrong one. >>> >>> Signed-off-by: Ryan Roberts >>> --- >>> include/linux/pgtable.h | 29 ++++++++++++ >>> include/linux/swap.h | 12 +++-- >>> mm/internal.h | 63 ++++++++++++++++++++++++++ >>> mm/madvise.c | 12 +++-- >>> mm/memory.c | 13 +++--- >>> mm/swapfile.c | 97 +++++++++++++++++++++++++++++++++-------- >>> 6 files changed, 195 insertions(+), 31 deletions(-) >>> >>> diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h >>> index a3fc8150b047..75096025fe52 100644 >>> --- a/include/linux/pgtable.h >>> +++ b/include/linux/pgtable.h >>> @@ -708,6 +708,35 @@ static inline void pte_clear_not_present_full(struct mm_struct *mm, >>> } >>> #endif >>> >>> +#ifndef clear_not_present_full_ptes >>> +/** >>> + * clear_not_present_full_ptes - Clear multiple not present PTEs which are >>> + * consecutive in the pgtable. >>> + * @mm: Address space the ptes represent. >>> + * @addr: Address of the first pte. >>> + * @ptep: Page table pointer for the first entry. >>> + * @nr: Number of entries to clear. >>> + * @full: Whether we are clearing a full mm. >>> + * >>> + * May be overridden by the architecture; otherwise, implemented as a simple >>> + * loop over pte_clear_not_present_full(). >>> + * >>> + * Context: The caller holds the page table lock. The PTEs are all not present. >>> + * The PTEs are all in the same PMD. >>> + */ >>> +static inline void clear_not_present_full_ptes(struct mm_struct *mm, >>> + unsigned long addr, pte_t *ptep, unsigned int nr, int full) >>> +{ >>> + for (;;) { >>> + pte_clear_not_present_full(mm, addr, ptep, full); >>> + if (--nr == 0) >>> + break; >>> + ptep++; >>> + addr += PAGE_SIZE; >>> + } >>> +} >>> +#endif >>> + >>> #ifndef __HAVE_ARCH_PTEP_CLEAR_FLUSH >>> extern pte_t ptep_clear_flush(struct vm_area_struct *vma, >>> unsigned long address, >>> diff --git a/include/linux/swap.h b/include/linux/swap.h >>> index f6f78198f000..5737236dc3ce 100644 >>> --- a/include/linux/swap.h >>> +++ b/include/linux/swap.h >>> @@ -471,7 +471,7 @@ extern int swap_duplicate(swp_entry_t); >>> extern int swapcache_prepare(swp_entry_t); >>> extern void swap_free(swp_entry_t); >>> extern void swapcache_free_entries(swp_entry_t *entries, int n); >>> -extern int free_swap_and_cache(swp_entry_t); >>> +extern void free_swap_and_cache_nr(swp_entry_t entry, int nr); >>> int swap_type_of(dev_t device, sector_t offset); >>> int find_first_swap(dev_t *device); >>> extern unsigned int count_swap_pages(int, int); >>> @@ -520,8 +520,9 @@ static inline void put_swap_device(struct swap_info_struct *si) >>> #define free_pages_and_swap_cache(pages, nr) \ >>> release_pages((pages), (nr)); >>> >>> -/* used to sanity check ptes in zap_pte_range when CONFIG_SWAP=0 */ >>> -#define free_swap_and_cache(e) is_pfn_swap_entry(e) >>> +static inline void free_swap_and_cache_nr(swp_entry_t entry, int nr) >>> +{ >>> +} >>> >>> static inline void free_swap_cache(struct folio *folio) >>> { >>> @@ -589,6 +590,11 @@ static inline int add_swap_extent(struct swap_info_struct *sis, >>> } >>> #endif /* CONFIG_SWAP */ >>> >>> +static inline void free_swap_and_cache(swp_entry_t entry) >>> +{ >>> + free_swap_and_cache_nr(entry, 1); >>> +} >>> + >>> #ifdef CONFIG_MEMCG >>> static inline int mem_cgroup_swappiness(struct mem_cgroup *memcg) >>> { >>> diff --git a/mm/internal.h b/mm/internal.h >>> index 3bdc8693b54f..de68705624b0 100644 >>> --- a/mm/internal.h >>> +++ b/mm/internal.h >>> @@ -11,6 +11,8 @@ >>> #include >>> #include >>> #include >>> +#include >>> +#include >>> #include >>> >>> struct folio_batch; >>> @@ -189,6 +191,67 @@ static inline int folio_pte_batch(struct folio *folio, unsigned long addr, >>> >>> return min(ptep - start_ptep, max_nr); >>> } >>> + >>> +/** >>> + * pte_next_swp_offset - Increment the swap entry offset field of a swap pte. >>> + * @pte: The initial pte state; is_swap_pte(pte) must be true. >>> + * >>> + * Increments the swap offset, while maintaining all other fields, including >>> + * swap type, and any swp pte bits. The resulting pte is returned. >>> + */ >>> +static inline pte_t pte_next_swp_offset(pte_t pte) >>> +{ >>> + swp_entry_t entry = pte_to_swp_entry(pte); >>> + pte_t new = __swp_entry_to_pte(__swp_entry(swp_type(entry), >>> + swp_offset(entry) + 1)); >>> + >>> + if (pte_swp_soft_dirty(pte)) >>> + new = pte_swp_mksoft_dirty(new); >>> + if (pte_swp_exclusive(pte)) >>> + new = pte_swp_mkexclusive(new); >>> + if (pte_swp_uffd_wp(pte)) >>> + new = pte_swp_mkuffd_wp(new); >> >> I don't quite understand this. If this page table entry is exclusive, >> will its subsequent page table entry also be exclusive without >> question? >> in try_to_unmap_one, exclusive is per-subpage but not per-folio: >> >> anon_exclusive = folio_test_anon(folio) && >> PageAnonExclusive(subpage); >> >> same questions also for diry, wp etc. > > Sorry for the noise. you are right. based on your new version, I think I should > entirely drop: > > [PATCH v2 3/5] mm: swap_pte_batch: add an output argument to reture if > all swap entries are exclusive Yes. If we ever want to ignore some bits, we should likely add flags to change the behavior, like for folio_pte_batch(). For swapin, you really want the exclusive bits to match, though. softdirty and uffd-wp as well at least initially for simplicity. -- Cheers, David / dhildenb