From: Douglas Anderson <dianders@chromium.org>
To: Andrew Morton <akpm@linux-foundation.org>,
Mel Gorman <mgorman@techsingularity.net>,
Vlastimil Babka <vbabka@suse.cz>, Ying <ying.huang@intel.com>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Yu Zhao <yuzhao@google.com>,
linux-fsdevel@vger.kernel.org,
Matthew Wilcox <willy@infradead.org>,
Douglas Anderson <dianders@chromium.org>
Subject: [PATCH v2 4/4] migrate_pages: Don't wait forever locking buffers in MIGRATE_SYNC_LIGHT
Date: Fri, 21 Apr 2023 15:12:48 -0700 [thread overview]
Message-ID: <20230421151135.v2.4.Ic39f0b16516acf4af1ce5d923150f93ee85a9398@changeid> (raw)
In-Reply-To: <20230421221249.1616168-1-dianders@chromium.org>
Just as talked about in the patch ("migrate_pages: Don't wait forever
locking pages in MIGRATE_SYNC_LIGHT"), we don't really want unbounded
waits when we're running in MIGRATE_SYNC_LIGHT mode. Waiting on the
buffer lock is a second such unbounded wait. Let's put a timeout on
it.
While measurement didn't show this wait to be quite as bad as the one
waiting for the folio lock, it could still be measured to be over a
second in some cases.
Signed-off-by: Douglas Anderson <dianders@chromium.org>
---
Changes in v2:
- "Don't wait forever locking buffers in MIGRATE_SYNC_LIGHT" new for v2.
mm/migrate.c | 25 ++++++++-----------------
1 file changed, 8 insertions(+), 17 deletions(-)
diff --git a/mm/migrate.c b/mm/migrate.c
index 60982df71a93..97c93604eb4c 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -715,25 +715,16 @@ static bool buffer_migrate_lock_buffers(struct buffer_head *head,
enum migrate_mode mode)
{
struct buffer_head *bh = head;
+ bool locked;
- /* Simple case, sync compaction */
- if (mode != MIGRATE_ASYNC) {
- do {
- lock_buffer(bh);
- bh = bh->b_this_page;
-
- } while (bh != head);
-
- return true;
- }
-
- /* async case, we cannot block on lock_buffer so use trylock_buffer */
do {
- if (!trylock_buffer(bh)) {
- /*
- * We failed to lock the buffer and cannot stall in
- * async migration. Release the taken locks
- */
+ if (mode == MIGRATE_ASYNC)
+ locked = trylock_buffer(bh);
+ else
+ locked = !lock_buffer_timeout(bh, timeout_for_mode(mode));
+
+ if (!locked) {
+ /* We failed to lock the buffer. Release the taken locks. */
struct buffer_head *failed_bh = bh;
bh = head;
while (bh != failed_bh) {
--
2.40.0.634.g4ca3ef3211-goog
prev parent reply other threads:[~2023-04-21 22:13 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-21 22:12 [PATCH v2 0/4] migrate: Avoid unbounded blocks in MIGRATE_SYNC_LIGHT Douglas Anderson
2023-04-21 22:12 ` [PATCH v2 1/4] mm/filemap: Add folio_lock_timeout() Douglas Anderson
2023-04-22 5:18 ` Hillf Danton
[not found] ` <20230423081203.1812-1-hdanton@sina.com>
2023-04-23 8:35 ` Gao Xiang
2023-04-23 9:49 ` Hillf Danton
2023-04-23 10:45 ` Gao Xiang
2023-04-24 16:56 ` Doug Anderson
2023-04-25 1:09 ` Hillf Danton
2023-04-25 14:19 ` Doug Anderson
2023-04-26 4:42 ` Hillf Danton
2023-04-26 4:55 ` Doug Anderson
2023-04-26 10:09 ` Mel Gorman
2023-04-26 15:14 ` Matthew Wilcox
2023-04-26 20:46 ` Doug Anderson
2023-04-26 21:26 ` Matthew Wilcox
2023-04-26 21:39 ` Doug Anderson
2023-04-27 2:16 ` Matthew Wilcox
2023-04-27 9:48 ` Mel Gorman
2023-04-28 8:17 ` Hillf Danton
2023-04-26 15:24 ` Linus Torvalds
2023-04-23 7:50 ` Huang, Ying
2023-04-24 8:22 ` Mel Gorman
2023-04-24 16:22 ` Doug Anderson
2023-04-25 8:00 ` Mel Gorman
2023-04-21 22:12 ` [PATCH v2 2/4] buffer: Add lock_buffer_timeout() Douglas Anderson
2023-04-23 8:47 ` Huang, Ying
2023-04-21 22:12 ` [PATCH v2 3/4] migrate_pages: Don't wait forever locking pages in MIGRATE_SYNC_LIGHT Douglas Anderson
2023-04-23 7:59 ` Huang, Ying
2023-04-24 9:38 ` Mel Gorman
2023-04-21 22:12 ` Douglas Anderson [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=20230421151135.v2.4.Ic39f0b16516acf4af1ce5d923150f93ee85a9398@changeid \
--to=dianders@chromium.org \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@techsingularity.net \
--cc=vbabka@suse.cz \
--cc=viro@zeniv.linux.org.uk \
--cc=willy@infradead.org \
--cc=ying.huang@intel.com \
--cc=yuzhao@google.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;
as well as URLs for NNTP newsgroup(s).