From: Ryan Roberts <ryan.roberts@arm.com>
To: Barry Song <21cnbao@gmail.com>,
akpm@linux-foundation.org, linux-mm@kvack.org
Cc: chrisl@kernel.org, david@redhat.com, hanchuanhua@oppo.com,
kasong@tencent.com, linux-kernel@vger.kernel.org,
v-songbaohua@oppo.com, ying.huang@intel.com
Subject: Re: [PATCH v2] mm: Extend 'usage' parameter so that cluster_swap_free_nr() can be reused
Date: Tue, 9 Jul 2024 09:06:07 +0100 [thread overview]
Message-ID: <5dcfd3e6-ce76-4243-8a37-ad83f8335eda@arm.com> (raw)
In-Reply-To: <20240709012122.16994-1-21cnbao@gmail.com>
On 09/07/2024 02:21, Barry Song wrote:
> From: Barry Song <v-songbaohua@oppo.com>
>
> Extend a usage parameter so that cluster_swap_free_nr() can be reused by
> both swapcache_clear() and swap_free().
> __swap_entry_free() is quite similar but more tricky as it requires the
> return value of __swap_entry_free_locked() which cluster_swap_free_nr()
> doesn't support.
>
> Cc: "Huang, Ying" <ying.huang@intel.com>
> Cc: Chris Li <chrisl@kernel.org>
> Cc: Ryan Roberts <ryan.roberts@arm.com>
> Cc: Kairui Song <kasong@tencent.com>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Chuanhua Han <hanchuanhua@oppo.com>
> Signed-off-by: Barry Song <v-songbaohua@oppo.com>
LGTM!
Reviewed-by: Ryan Roberts <ryan.roberts@arm.com>
> ---
> mm/swapfile.c | 15 +++++----------
> 1 file changed, 5 insertions(+), 10 deletions(-)
>
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index f7224bc1320c..c097c513db02 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -1352,7 +1352,8 @@ static void swap_entry_free(struct swap_info_struct *p, swp_entry_t entry)
> }
>
> static void cluster_swap_free_nr(struct swap_info_struct *sis,
> - unsigned long offset, int nr_pages)
> + unsigned long offset, int nr_pages,
> + unsigned char usage)
> {
> struct swap_cluster_info *ci;
> DECLARE_BITMAP(to_free, BITS_PER_LONG) = { 0 };
> @@ -1362,7 +1363,7 @@ static void cluster_swap_free_nr(struct swap_info_struct *sis,
> while (nr_pages) {
> nr = min(BITS_PER_LONG, nr_pages);
> for (i = 0; i < nr; i++) {
> - if (!__swap_entry_free_locked(sis, offset + i, 1))
> + if (!__swap_entry_free_locked(sis, offset + i, usage))
> bitmap_set(to_free, i, 1);
> }
> if (!bitmap_empty(to_free, BITS_PER_LONG)) {
> @@ -1396,7 +1397,7 @@ void swap_free_nr(swp_entry_t entry, int nr_pages)
>
> while (nr_pages) {
> nr = min_t(int, nr_pages, SWAPFILE_CLUSTER - offset % SWAPFILE_CLUSTER);
> - cluster_swap_free_nr(sis, offset, nr);
> + cluster_swap_free_nr(sis, offset, nr, 1);
> offset += nr;
> nr_pages -= nr;
> }
> @@ -3492,15 +3493,9 @@ int swapcache_prepare(swp_entry_t entry)
>
> void swapcache_clear(struct swap_info_struct *si, swp_entry_t entry)
> {
> - struct swap_cluster_info *ci;
> unsigned long offset = swp_offset(entry);
> - unsigned char usage;
>
> - ci = lock_cluster_or_swap_info(si, offset);
> - usage = __swap_entry_free_locked(si, offset, SWAP_HAS_CACHE);
> - unlock_cluster_or_swap_info(si, ci);
> - if (!usage)
> - free_swap_slot(entry);
> + cluster_swap_free_nr(si, offset, 1, SWAP_HAS_CACHE);
> }
>
> struct swap_info_struct *swp_swap_info(swp_entry_t entry)
prev parent reply other threads:[~2024-07-09 8:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-09 1:21 Barry Song
2024-07-09 8:06 ` Ryan Roberts [this message]
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=5dcfd3e6-ce76-4243-8a37-ad83f8335eda@arm.com \
--to=ryan.roberts@arm.com \
--cc=21cnbao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=chrisl@kernel.org \
--cc=david@redhat.com \
--cc=hanchuanhua@oppo.com \
--cc=kasong@tencent.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=v-songbaohua@oppo.com \
--cc=ying.huang@intel.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