From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, david@redhat.com, linux-mm@kvack.org, ryan.roberts@arm.com, chrisl@kernel.org Cc: 21cnbao@gmail.com, linux-kernel@vger.kernel.org, mhocko@suse.com, shy828301@gmail.com, steven.price@arm.com, surenb@google.com, wangkefeng.wang@huawei.com, willy@infradead.org, xiang@kernel.org, ying.huang@intel.com, yuzhao@google.com, kasong@tencent.com, yosryahmed@google.com, nphamcs@gmail.com, chengming.zhou@linux.dev, hannes@cmpxchg.org, linux-arm-kernel@lists.infradead.org, Chuanhua Han <hanchuanhua@oppo.com>, Barry Song <v-songbaohua@oppo.com> Subject: [PATCH RFC v2 2/5] mm: swap: introduce swap_nr_free() for batched swap_free() Date: Thu, 29 Feb 2024 13:37:50 +1300 [thread overview] Message-ID: <20240229003753.134193-3-21cnbao@gmail.com> (raw) In-Reply-To: <20240229003753.134193-1-21cnbao@gmail.com> From: Chuanhua Han <hanchuanhua@oppo.com> While swapping in a large folio, we need to free swaps related to the whole folio. To avoid frequently acquiring and releasing swap locks, it is better to introduce an API for batched free. Signed-off-by: Chuanhua Han <hanchuanhua@oppo.com> Co-developed-by: Barry Song <v-songbaohua@oppo.com> Signed-off-by: Barry Song <v-songbaohua@oppo.com> --- include/linux/swap.h | 6 ++++++ mm/swapfile.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/linux/swap.h b/include/linux/swap.h index 25f6368be078..b3581c976e5f 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -481,6 +481,7 @@ extern void swap_shmem_alloc(swp_entry_t); extern int swap_duplicate(swp_entry_t); extern int swapcache_prepare(swp_entry_t); extern void swap_free(swp_entry_t); +extern void swap_nr_free(swp_entry_t entry, int nr_pages); extern void swapcache_free_entries(swp_entry_t *entries, int n); extern int free_swap_and_cache(swp_entry_t); int swap_type_of(dev_t device, sector_t offset); @@ -561,6 +562,11 @@ static inline void swap_free(swp_entry_t swp) { } +void swap_nr_free(swp_entry_t entry, int nr_pages) +{ + +} + static inline void put_swap_folio(struct folio *folio, swp_entry_t swp) { } diff --git a/mm/swapfile.c b/mm/swapfile.c index 2b3a2d85e350..c0c058ee7b69 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1340,6 +1340,41 @@ void swap_free(swp_entry_t entry) __swap_entry_free(p, entry); } +/* + * Called after swapping in a large folio, batched free swap entries + * for this large folio, entry should be for the first subpage and + * its offset is aligned with nr_pages + */ +void swap_nr_free(swp_entry_t entry, int nr_pages) +{ + int i; + struct swap_cluster_info *ci; + struct swap_info_struct *p; + unsigned type = swp_type(entry); + unsigned long offset = swp_offset(entry); + DECLARE_BITMAP(usage, SWAPFILE_CLUSTER) = { 0 }; + + /* all swap entries are within a cluster for mTHP */ + VM_BUG_ON(offset % SWAPFILE_CLUSTER + nr_pages > SWAPFILE_CLUSTER); + + if (nr_pages == 1) { + swap_free(entry); + return; + } + + p = _swap_info_get(entry); + + ci = lock_cluster(p, offset); + for (i = 0; i < nr_pages; i++) { + if (__swap_entry_free_locked(p, offset + i, 1)) + __bitmap_set(usage, i, 1); + } + unlock_cluster(ci); + + for_each_clear_bit(i, usage, nr_pages) + free_swap_slot(swp_entry(type, offset + i)); +} + /* * Called after dropping swapcache to decrease refcnt to swap entries. */ -- 2.34.1
WARNING: multiple messages have this Message-ID (diff)
From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, david@redhat.com, linux-mm@kvack.org, ryan.roberts@arm.com, chrisl@kernel.org Cc: 21cnbao@gmail.com, linux-kernel@vger.kernel.org, mhocko@suse.com, shy828301@gmail.com, steven.price@arm.com, surenb@google.com, wangkefeng.wang@huawei.com, willy@infradead.org, xiang@kernel.org, ying.huang@intel.com, yuzhao@google.com, kasong@tencent.com, yosryahmed@google.com, nphamcs@gmail.com, chengming.zhou@linux.dev, hannes@cmpxchg.org, linux-arm-kernel@lists.infradead.org, Chuanhua Han <hanchuanhua@oppo.com>, Barry Song <v-songbaohua@oppo.com> Subject: [PATCH RFC v2 2/5] mm: swap: introduce swap_nr_free() for batched swap_free() Date: Thu, 29 Feb 2024 13:37:50 +1300 [thread overview] Message-ID: <20240229003753.134193-3-21cnbao@gmail.com> (raw) In-Reply-To: <20240229003753.134193-1-21cnbao@gmail.com> From: Chuanhua Han <hanchuanhua@oppo.com> While swapping in a large folio, we need to free swaps related to the whole folio. To avoid frequently acquiring and releasing swap locks, it is better to introduce an API for batched free. Signed-off-by: Chuanhua Han <hanchuanhua@oppo.com> Co-developed-by: Barry Song <v-songbaohua@oppo.com> Signed-off-by: Barry Song <v-songbaohua@oppo.com> --- include/linux/swap.h | 6 ++++++ mm/swapfile.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/linux/swap.h b/include/linux/swap.h index 25f6368be078..b3581c976e5f 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -481,6 +481,7 @@ extern void swap_shmem_alloc(swp_entry_t); extern int swap_duplicate(swp_entry_t); extern int swapcache_prepare(swp_entry_t); extern void swap_free(swp_entry_t); +extern void swap_nr_free(swp_entry_t entry, int nr_pages); extern void swapcache_free_entries(swp_entry_t *entries, int n); extern int free_swap_and_cache(swp_entry_t); int swap_type_of(dev_t device, sector_t offset); @@ -561,6 +562,11 @@ static inline void swap_free(swp_entry_t swp) { } +void swap_nr_free(swp_entry_t entry, int nr_pages) +{ + +} + static inline void put_swap_folio(struct folio *folio, swp_entry_t swp) { } diff --git a/mm/swapfile.c b/mm/swapfile.c index 2b3a2d85e350..c0c058ee7b69 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1340,6 +1340,41 @@ void swap_free(swp_entry_t entry) __swap_entry_free(p, entry); } +/* + * Called after swapping in a large folio, batched free swap entries + * for this large folio, entry should be for the first subpage and + * its offset is aligned with nr_pages + */ +void swap_nr_free(swp_entry_t entry, int nr_pages) +{ + int i; + struct swap_cluster_info *ci; + struct swap_info_struct *p; + unsigned type = swp_type(entry); + unsigned long offset = swp_offset(entry); + DECLARE_BITMAP(usage, SWAPFILE_CLUSTER) = { 0 }; + + /* all swap entries are within a cluster for mTHP */ + VM_BUG_ON(offset % SWAPFILE_CLUSTER + nr_pages > SWAPFILE_CLUSTER); + + if (nr_pages == 1) { + swap_free(entry); + return; + } + + p = _swap_info_get(entry); + + ci = lock_cluster(p, offset); + for (i = 0; i < nr_pages; i++) { + if (__swap_entry_free_locked(p, offset + i, 1)) + __bitmap_set(usage, i, 1); + } + unlock_cluster(ci); + + for_each_clear_bit(i, usage, nr_pages) + free_swap_slot(swp_entry(type, offset + i)); +} + /* * Called after dropping swapcache to decrease refcnt to swap entries. */ -- 2.34.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2024-02-29 0:38 UTC|newest] Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-02-29 0:37 [PATCH RFC v2 0/5] mm: support large folios swap-in Barry Song 2024-02-29 0:37 ` Barry Song 2024-02-29 0:37 ` [PATCH RFC v2 1/5] arm64: mm: swap: support THP_SWAP on hardware with MTE Barry Song 2024-02-29 0:37 ` Barry Song 2024-02-29 0:37 ` Barry Song [this message] 2024-02-29 0:37 ` [PATCH RFC v2 2/5] mm: swap: introduce swap_nr_free() for batched swap_free() Barry Song 2024-02-29 0:37 ` [PATCH RFC v2 3/5] mm: swap: make should_try_to_free_swap() support large-folio Barry Song 2024-02-29 0:37 ` Barry Song 2024-02-29 0:37 ` [PATCH RFC v2 4/5] mm: swap: introduce swapcache_prepare_nr and swapcache_clear_nr for large folios swap-in Barry Song 2024-02-29 0:37 ` Barry Song 2024-02-29 0:51 ` Yosry Ahmed 2024-02-29 0:51 ` Yosry Ahmed 2024-02-29 0:58 ` Barry Song 2024-02-29 0:58 ` Barry Song 2024-02-29 1:11 ` Yosry Ahmed 2024-02-29 1:11 ` Yosry Ahmed 2024-02-29 1:33 ` Barry Song 2024-02-29 1:33 ` Barry Song 2024-02-29 0:37 ` [PATCH RFC v2 5/5] mm: support large folios swapin as a whole Barry Song 2024-02-29 0:37 ` Barry Song 2024-03-04 1:34 ` Barry Song 2024-03-04 1:34 ` Barry Song
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=20240229003753.134193-3-21cnbao@gmail.com \ --to=21cnbao@gmail.com \ --cc=akpm@linux-foundation.org \ --cc=chengming.zhou@linux.dev \ --cc=chrisl@kernel.org \ --cc=david@redhat.com \ --cc=hanchuanhua@oppo.com \ --cc=hannes@cmpxchg.org \ --cc=kasong@tencent.com \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=mhocko@suse.com \ --cc=nphamcs@gmail.com \ --cc=ryan.roberts@arm.com \ --cc=shy828301@gmail.com \ --cc=steven.price@arm.com \ --cc=surenb@google.com \ --cc=v-songbaohua@oppo.com \ --cc=wangkefeng.wang@huawei.com \ --cc=willy@infradead.org \ --cc=xiang@kernel.org \ --cc=ying.huang@intel.com \ --cc=yosryahmed@google.com \ --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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.