mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ryan Roberts <ryan.roberts@arm.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	Chris Li <chrisl@kernel.org>, Kairui Song <kasong@tencent.com>,
	"Huang, Ying" <ying.huang@intel.com>,
	Kalesh Singh <kaleshsingh@google.com>,
	Barry Song <baohua@kernel.org>, Hugh Dickins <hughd@google.com>,
	David Hildenbrand <david@redhat.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: [RFC PATCH v1 1/5] mm: swap: Simplify end-of-cluster calculation
Date: Wed, 19 Jun 2024 00:26:41 +0100	[thread overview]
Message-ID: <20240618232648.4090299-2-ryan.roberts@arm.com> (raw)
In-Reply-To: <20240618232648.4090299-1-ryan.roberts@arm.com>

Its possible that a swap file will have a partial cluster at the end, if
the swap size is not a multiple of the cluster size. But this partial
cluster will never be marked free and so scan_swap_map_try_ssd_cluster()
will never see it. Therefore it can always consider that a cluster ends
at the next cluster boundary.

This leads to a simplification of the endpoint calculation and removal
of an unnecessary conditional.

This change has the useful side effect of making lock_cluster()
unconditional, which will be used in a later commit.

Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
---
 mm/swapfile.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/mm/swapfile.c b/mm/swapfile.c
index b3e5e384e330..30e79739dfdc 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -677,16 +677,14 @@ static bool scan_swap_map_try_ssd_cluster(struct swap_info_struct *si,
 	 * check if there is still free entry in the cluster, maintaining
 	 * natural alignment.
 	 */
-	max = min_t(unsigned long, si->max, ALIGN(tmp + 1, SWAPFILE_CLUSTER));
-	if (tmp < max) {
-		ci = lock_cluster(si, tmp);
-		while (tmp < max) {
-			if (swap_range_empty(si->swap_map, tmp, nr_pages))
-				break;
-			tmp += nr_pages;
-		}
-		unlock_cluster(ci);
+	max = ALIGN(tmp + 1, SWAPFILE_CLUSTER);
+	ci = lock_cluster(si, tmp);
+	while (tmp < max) {
+		if (swap_range_empty(si->swap_map, tmp, nr_pages))
+			break;
+		tmp += nr_pages;
 	}
+	unlock_cluster(ci);
 	if (tmp >= max) {
 		cluster->next[order] = SWAP_NEXT_INVALID;
 		goto new_cluster;
--
2.43.0


  reply	other threads:[~2024-06-18 23:27 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-18 23:26 [RFC PATCH v1 0/5] Alternative mTHP swap allocator improvements Ryan Roberts
2024-06-18 23:26 ` Ryan Roberts [this message]
2024-06-18 23:26 ` [RFC PATCH v1 2/5] mm: swap: Change SWAP_NEXT_INVALID to highest value Ryan Roberts
2024-06-18 23:26 ` [RFC PATCH v1 3/5] mm: swap: Track allocation order for clusters Ryan Roberts
2024-06-18 23:26 ` [RFC PATCH v1 4/5] mm: swap: Scan for free swap entries in allocated clusters Ryan Roberts
2024-06-18 23:26 ` [RFC PATCH v1 5/5] mm: swap: Optimize per-order cluster scanning Ryan Roberts
2024-06-19  7:19 ` [RFC PATCH v1 0/5] Alternative mTHP swap allocator improvements Huang, Ying
2024-06-19  9:17   ` Ryan Roberts
2024-06-20  1:34     ` Huang, Ying
2024-06-19  9:11 ` Barry Song
2024-06-19  9:17   ` Ryan Roberts
2024-06-21  8:48     ` Barry Song
2024-06-25  8:02 ` Ryan Roberts
2024-06-25 16:06   ` Chris Li
2024-06-25 16:36     ` Ryan Roberts

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=20240618232648.4090299-2-ryan.roberts@arm.com \
    --to=ryan.roberts@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=chrisl@kernel.org \
    --cc=david@redhat.com \
    --cc=hughd@google.com \
    --cc=kaleshsingh@google.com \
    --cc=kasong@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --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

all inboxes | Powered by JetHome®