From: Kemeng Shi <shikemeng@huaweicloud.com>
To: akpm@linux-foundation.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Cc: shikemeng@huaweicloud.com
Subject: [PATCH 4/4] mm/compaction: add compact_unlock_irqrestore to remove repeat code
Date: Wed, 19 Jul 2023 19:30:01 +0800 [thread overview]
Message-ID: <20230719113001.2023703-5-shikemeng@huaweicloud.com> (raw)
In-Reply-To: <20230719113001.2023703-1-shikemeng@huaweicloud.com>
Add compact_unlock_irqrestore to remove repeat code. This also make
compact lock functions sereis complete as we can call
compact_lock_irqsave/compact_unlock_irqrestore in pair.
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
mm/compaction.c | 43 ++++++++++++++++---------------------------
1 file changed, 16 insertions(+), 27 deletions(-)
diff --git a/mm/compaction.c b/mm/compaction.c
index c1dc821ac6e1..eb1d3d9a422c 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -541,6 +541,14 @@ static spinlock_t *compact_lock_irqsave(spinlock_t *lock, unsigned long *flags,
return lock;
}
+static inline void compact_unlock_irqrestore(spinlock_t **locked, unsigned long flags)
+{
+ if (*locked) {
+ spin_unlock_irqrestore(*locked, flags);
+ *locked = NULL;
+ }
+}
+
/*
* Compaction requires the taking of some coarse locks that are potentially
* very heavily contended. The lock should be periodically unlocked to avoid
@@ -556,10 +564,7 @@ static spinlock_t *compact_lock_irqsave(spinlock_t *lock, unsigned long *flags,
static bool compact_unlock_should_abort(spinlock_t **locked,
unsigned long flags, struct compact_control *cc)
{
- if (*locked) {
- spin_unlock_irqrestore(*locked, flags);
- *locked = NULL;
- }
+ compact_unlock_irqrestore(locked, flags);
if (fatal_signal_pending(current)) {
cc->contended = true;
@@ -671,8 +676,7 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
}
- if (locked)
- spin_unlock_irqrestore(locked, flags);
+ compact_unlock_irqrestore(&locked, flags);
/*
* There is a tiny chance that we have read bogus compound_order(),
@@ -935,10 +939,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
}
if (PageHuge(page) && cc->alloc_contig) {
- if (locked) {
- spin_unlock_irqrestore(locked, flags);
- locked = NULL;
- }
+ compact_unlock_irqrestore(&locked, flags);
ret = isolate_or_dissolve_huge_page(page, &cc->migratepages);
@@ -1024,10 +1025,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
*/
if (unlikely(__PageMovable(page)) &&
!PageIsolated(page)) {
- if (locked) {
- spin_unlock_irqrestore(locked, flags);
- locked = NULL;
- }
+ compact_unlock_irqrestore(&locked, flags);
if (isolate_movable_page(page, mode)) {
folio = page_folio(page);
@@ -1111,9 +1109,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
/* If we already hold the lock, we can skip some rechecking */
if (&lruvec->lru_lock != locked) {
- if (locked)
- spin_unlock_irqrestore(locked, flags);
-
+ compact_unlock_irqrestore(&locked, flags);
locked = compact_lock_irqsave(&lruvec->lru_lock, &flags, cc);
lruvec_memcg_debug(lruvec, folio);
@@ -1176,10 +1172,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
isolate_fail_put:
/* Avoid potential deadlock in freeing page under lru_lock */
- if (locked) {
- spin_unlock_irqrestore(locked, flags);
- locked = NULL;
- }
+ compact_unlock_irqrestore(&locked, flags);
folio_put(folio);
isolate_fail:
@@ -1192,10 +1185,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
* page anyway.
*/
if (nr_isolated) {
- if (locked) {
- spin_unlock_irqrestore(locked, flags);
- locked = NULL;
- }
+ compact_unlock_irqrestore(&locked, flags);
putback_movable_pages(&cc->migratepages);
cc->nr_migratepages = 0;
nr_isolated = 0;
@@ -1224,8 +1214,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
folio = NULL;
isolate_abort:
- if (locked)
- spin_unlock_irqrestore(locked, flags);
+ compact_unlock_irqrestore(&locked, flags);
if (folio) {
folio_set_lru(folio);
folio_put(folio);
--
2.30.0
next prev parent reply other threads:[~2023-07-19 3:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[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
2023-07-19 11:29 ` [PATCH 2/4] mm/compaction: use "spinlock_t *" to record held lock in isolate_migratepages_block Kemeng Shi
2023-07-19 11:30 ` Kemeng Shi [this message]
[not found] <20230725180456.2146626-1-shikemeng@huaweicloud.com>
2023-07-25 18:04 ` [PATCH 4/4] mm/compaction: add compact_unlock_irqrestore to remove repeat code 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=20230719113001.2023703-5-shikemeng@huaweicloud.com \
--to=shikemeng@huaweicloud.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.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;
as well as URLs for NNTP newsgroup(s).