From: Kemeng Shi <shikemeng@huaweicloud.com>
To: akpm@linux-foundation.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Cc: willy@infradead.org, baolin.wang@linux.alibaba.com,
david@redhat.com, shikemeng@huaweicloud.com
Subject: [PATCH 1/4] mm/compaction: use "spinlock_t *" to record held lock in compact [un]lock functions
Date: Wed, 26 Jul 2023 02:04:53 +0800 [thread overview]
Message-ID: <20230725180456.2146626-2-shikemeng@huaweicloud.com> (raw)
In-Reply-To: <20230725180456.2146626-1-shikemeng@huaweicloud.com>
Make compact_lock_irqsave and compact_unlock_should_abort use
"spinlock_t *" to record held lock.
This is a preparation to use compact_unlock_should_abort in
isolate_migratepages_block to remove repeat code.
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
mm/compaction.c | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/mm/compaction.c b/mm/compaction.c
index 9641e2131901..dfef14d3ef78 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -523,22 +523,22 @@ static bool test_and_set_skip(struct compact_control *cc, struct page *page)
* abort when the current block is finished regardless of success rate.
* Sync compaction acquires the lock.
*
- * Always returns true which makes it easier to track lock state in callers.
+ * Always returns lock which makes it easier to track lock state in callers.
*/
-static bool compact_lock_irqsave(spinlock_t *lock, unsigned long *flags,
+static spinlock_t *compact_lock_irqsave(spinlock_t *lock, unsigned long *flags,
struct compact_control *cc)
__acquires(lock)
{
/* Track if the lock is contended in async mode */
if (cc->mode == MIGRATE_ASYNC && !cc->contended) {
if (spin_trylock_irqsave(lock, *flags))
- return true;
+ return lock;
cc->contended = true;
}
spin_lock_irqsave(lock, *flags);
- return true;
+ return lock;
}
/*
@@ -553,12 +553,12 @@ static bool compact_lock_irqsave(spinlock_t *lock, unsigned long *flags,
* Returns true if compaction should abort due to fatal signal pending.
* Returns false when compaction can continue.
*/
-static bool compact_unlock_should_abort(spinlock_t *lock,
- unsigned long flags, bool *locked, struct compact_control *cc)
+static bool compact_unlock_should_abort(spinlock_t **locked,
+ unsigned long flags, struct compact_control *cc)
{
if (*locked) {
- spin_unlock_irqrestore(lock, flags);
- *locked = false;
+ spin_unlock_irqrestore(*locked, flags);
+ *locked = NULL;
}
if (fatal_signal_pending(current)) {
@@ -586,7 +586,7 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
int nr_scanned = 0, total_isolated = 0;
struct page *cursor;
unsigned long flags = 0;
- bool locked = false;
+ spinlock_t *locked = NULL;
unsigned long blockpfn = *start_pfn;
unsigned int order;
@@ -607,8 +607,7 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
* pending.
*/
if (!(blockpfn % COMPACT_CLUSTER_MAX)
- && compact_unlock_should_abort(&cc->zone->lock, flags,
- &locked, cc))
+ && compact_unlock_should_abort(&locked, flags, cc))
break;
nr_scanned++;
@@ -673,7 +672,7 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
}
if (locked)
- spin_unlock_irqrestore(&cc->zone->lock, flags);
+ spin_unlock_irqrestore(locked, flags);
/*
* There is a tiny chance that we have read bogus compound_order(),
--
2.30.0
next parent reply other threads:[~2023-07-25 10:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20230725180456.2146626-1-shikemeng@huaweicloud.com>
2023-07-25 18:04 ` Kemeng Shi [this message]
2023-07-25 18:04 ` [PATCH 2/4] mm/compaction: use "spinlock_t *" to record held lock in isolate_migratepages_block Kemeng Shi
2023-07-25 18:04 ` [PATCH 4/4] mm/compaction: add compact_unlock_irqrestore to remove repeat code Kemeng Shi
[not found] <20230719113001.2023703-1-shikemeng@huaweicloud.com>
2023-07-19 11:29 ` [PATCH 1/4] mm/compaction: use "spinlock_t *" to record held lock in compact [un]lock functions Kemeng Shi
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=20230725180456.2146626-2-shikemeng@huaweicloud.com \
--to=shikemeng@huaweicloud.com \
--cc=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=willy@infradead.org \
/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