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 2/4] mm/compaction: use "spinlock_t *" to record held lock in isolate_migratepages_block
Date: Wed, 19 Jul 2023 19:29:59 +0800 [thread overview]
Message-ID: <20230719113001.2023703-3-shikemeng@huaweicloud.com> (raw)
In-Reply-To: <20230719113001.2023703-1-shikemeng@huaweicloud.com>
Use "spinlock_t *" instead of "struct lruvec *" to record held lock in
isolate_migratepages_block.
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 | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/mm/compaction.c b/mm/compaction.c
index dfef14d3ef78..638146a49e89 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -840,7 +840,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
unsigned long nr_scanned = 0, nr_isolated = 0;
struct lruvec *lruvec;
unsigned long flags = 0;
- struct lruvec *locked = NULL;
+ spinlock_t *locked = NULL;
struct folio *folio = NULL;
struct page *page = NULL, *valid_page = NULL;
struct address_space *mapping;
@@ -911,7 +911,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
*/
if (!(low_pfn % COMPACT_CLUSTER_MAX)) {
if (locked) {
- unlock_page_lruvec_irqrestore(locked, flags);
+ spin_unlock_irqrestore(locked, flags);
locked = NULL;
}
@@ -946,7 +946,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
if (PageHuge(page) && cc->alloc_contig) {
if (locked) {
- unlock_page_lruvec_irqrestore(locked, flags);
+ spin_unlock_irqrestore(locked, flags);
locked = NULL;
}
@@ -1035,7 +1035,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
if (unlikely(__PageMovable(page)) &&
!PageIsolated(page)) {
if (locked) {
- unlock_page_lruvec_irqrestore(locked, flags);
+ spin_unlock_irqrestore(locked, flags);
locked = NULL;
}
@@ -1120,12 +1120,11 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
lruvec = folio_lruvec(folio);
/* If we already hold the lock, we can skip some rechecking */
- if (lruvec != locked) {
+ if (&lruvec->lru_lock != locked) {
if (locked)
- unlock_page_lruvec_irqrestore(locked, flags);
+ spin_unlock_irqrestore(locked, flags);
- compact_lock_irqsave(&lruvec->lru_lock, &flags, cc);
- locked = lruvec;
+ locked = compact_lock_irqsave(&lruvec->lru_lock, &flags, cc);
lruvec_memcg_debug(lruvec, folio);
@@ -1188,7 +1187,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) {
- unlock_page_lruvec_irqrestore(locked, flags);
+ spin_unlock_irqrestore(locked, flags);
locked = NULL;
}
folio_put(folio);
@@ -1204,7 +1203,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
*/
if (nr_isolated) {
if (locked) {
- unlock_page_lruvec_irqrestore(locked, flags);
+ spin_unlock_irqrestore(locked, flags);
locked = NULL;
}
putback_movable_pages(&cc->migratepages);
@@ -1236,7 +1235,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
isolate_abort:
if (locked)
- unlock_page_lruvec_irqrestore(locked, flags);
+ spin_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 ` Kemeng Shi [this message]
2023-07-19 11:30 ` [PATCH 4/4] mm/compaction: add compact_unlock_irqrestore to remove repeat code Kemeng Shi
[not found] <20230725180456.2146626-1-shikemeng@huaweicloud.com>
2023-07-25 18:04 ` [PATCH 2/4] mm/compaction: use "spinlock_t *" to record held lock in isolate_migratepages_block 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-3-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).