From patchwork Fri Apr 21 22:12:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 13220745 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0DDBC77B76 for ; Fri, 21 Apr 2023 22:13:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 35FCB6B007B; Fri, 21 Apr 2023 18:13:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 30E9E6B007D; Fri, 21 Apr 2023 18:13:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 13A646B007E; Fri, 21 Apr 2023 18:13:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id ED13F6B007B for ; Fri, 21 Apr 2023 18:13:32 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B785D1C68A9 for ; Fri, 21 Apr 2023 22:13:32 +0000 (UTC) X-FDA: 80706800664.10.02A76EA Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf06.hostedemail.com (Postfix) with ESMTP id F2703180011 for ; Fri, 21 Apr 2023 22:13:30 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Bj7hb2g1; spf=pass (imf06.hostedemail.com: domain of dianders@chromium.org designates 209.85.210.175 as permitted sender) smtp.mailfrom=dianders@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682115211; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Dc5jbER8wEc7OW3/IotC+kA2A3o7OZfeQaN33ZlBlP4=; b=QxkIpUBZ5ocxcK3I2F3/jRo4PWRnQOE5jz9canlUEPkSAl3ueBPysDu/LeKqHb8qGt8mi9 BVBjQHAHw3phR9lZ82PDkNPaSkmfP8HKABmcsSXfi6m0z7gQig9o/g5EdpCBNyYqcua8bg AmlHZCQn9MbSYDbRnQiKfr8bZnK87SI= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Bj7hb2g1; spf=pass (imf06.hostedemail.com: domain of dianders@chromium.org designates 209.85.210.175 as permitted sender) smtp.mailfrom=dianders@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682115211; a=rsa-sha256; cv=none; b=zf9/t3WLqYf/po/X3m96lJnv7Si+yfhhpWcRwE0V1AIdYv0sf3r8YtO5xVMD8MzZJoruUj CQvpF5+APVJcPRn3yVlpoO8pqoVtkuws10cGOesDXIelHMgpWjqNqyjRYFZlSK8mfx+JhH RRKbDPaE1Yo4umFNs4BwSptC8go0ABU= Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-63b733fd00bso2308965b3a.0 for ; Fri, 21 Apr 2023 15:13:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1682115210; x=1684707210; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Dc5jbER8wEc7OW3/IotC+kA2A3o7OZfeQaN33ZlBlP4=; b=Bj7hb2g1Ygk+uI1Xxfx+Lf8COV76humjsOT5sJKw8qFdCUzNXODMPPSgSmVEXfumLP gUzdVnED6ugNaAcG2SKbDhlEqm5/AA1x3lyiaYtvzKe1z+7yY9FeeWZjZ4j8ZGNYMvpT nSEalWU0KsSv7vdtph2qjlryw/U/r62x/nUxA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682115210; x=1684707210; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Dc5jbER8wEc7OW3/IotC+kA2A3o7OZfeQaN33ZlBlP4=; b=jE+K3uanOtII22lOtGqVTTBOq+VdTAJ3P8eAe296NThPEj42QbCHjeA1q5PAlYRNJz GFMOhPfE32GP6iZysKNSKRjthz8ofkZSBxIx3RgK3dsqZMYkmZzfQsSb/U63OiQZE/Iy mJfyjFghmrNJcrVklypaJ7XJnZHpxtFb7qktKFy80qNR7QbS4OlmKLcusCKH7h0JiCh+ VykcEp+KMS6+yf72kacsdtrTA37kegNreTEl7iCttQ58p5mTs45zsdZttfRrjqMpEIq2 bz9vUOqcBQ40IGHaxJL2bwo9xT/JiVcI+mZuEVlq2jP6hTTK5jbp3QjEVXqnUJpDf3in aY0w== X-Gm-Message-State: AAQBX9df2ykAjdeEgGG8HD7RHYLQSHypUtRy3w7kXjdV969JRaxErSZY niFtPzOTKKMSSkqVRPOTh+cGwg== X-Google-Smtp-Source: AKy350aBr9TvmZeKHCBJSqIpG2B/nWcBgQOHXkcvQWceE4r02qrPTXFu3nXc3bs+0O5+8kUMfAUyog== X-Received: by 2002:a05:6a00:1a56:b0:63d:3789:733f with SMTP id h22-20020a056a001a5600b0063d3789733fmr8752575pfv.15.1682115209980; Fri, 21 Apr 2023 15:13:29 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:87cc:9018:e569:4a27]) by smtp.gmail.com with ESMTPSA id y72-20020a62644b000000b006372791d708sm3424715pfb.104.2023.04.21.15.13.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Apr 2023 15:13:29 -0700 (PDT) From: Douglas Anderson To: Andrew Morton , Mel Gorman , Vlastimil Babka , Ying , Alexander Viro , Christian Brauner Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Yu Zhao , linux-fsdevel@vger.kernel.org, Matthew Wilcox , Douglas Anderson 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 Message-ID: <20230421151135.v2.4.Ic39f0b16516acf4af1ce5d923150f93ee85a9398@changeid> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog In-Reply-To: <20230421221249.1616168-1-dianders@chromium.org> References: <20230421221249.1616168-1-dianders@chromium.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: F2703180011 X-Stat-Signature: qe7zczxujbjja8r8n7uqmi85b4uyhtnd X-HE-Tag: 1682115210-655388 X-HE-Meta: U2FsdGVkX19SCwposeMsHNqFmtOBs8zTmvm4CuKmfNqUT6z/oggV/IZWuwal0L4bUMVMXs50lksNQ9c65z2wHnGtDAIIoDvEMk0/Z10xlq9f9VvLib47RqgHK762X6eLKFIRZcNQ1E+5Eo0nxsr3FQRTO61ccqiIRNe30yNC9wvG8pgVRhFnFHt1OihRZ8R4fjS2qWgOp/nJeAM9ECPJAM3P6K2HFjAnP7eQWi5FCA4jIaamgyUpViOkX6fYphetnBZ2XdL9fJnMhwuTuLPm2pUnKlrUWr9tCgL7dr7rvFB3NpsNTPfsLuTghbsdqVkn7o5Maf+z9dL5wbuGaWiw20ljaCpv82piQtV9KOqD86SD8XbX9WAB3GBOUWx0onUWQd2CUOymXPEgMnHU11MzzPAmSWkIKBopz7U1gMuSwvseYN5HH+N5rfTQT5ZGjrUmnuafVJk5koeeCdyrdV23+N4H3I1YZTQnZUcnBE9D8ZjJrs44LepyS65Oc/QtTnsPJc7Trm/VRiLpsraLLeWZkq+z/r9p/h4L7TZhywVEJG+rpYblzjk7290R0iQyFf7m5nsBcmV2P7pnIs0tEkAyEMxIvvY4eOZs2pF9FOA64/fjom3mNsWG5tHXQtsT5mm2+yz5sHL+eYrMhbyh/VQmcG3kpx8FPE72fqsWqRoYZ31oKoxrqn1uh4abNG2LiDU5eMWKOuyUIy41qBn1Ws7rlHPwZ0aYk+MvZtgC3dGyfsCgjJSlpZES+ly0VWDRzg3w7DDuIHMRyOSnwTQZ6dGXbEqJGIXuEFPZamNTHIQ88ehSO9wnz+g84kJzpSGq64KVfFRL5tN0YHDRPhbg1UbPgV59MAA0u57tWDM+9WnIFxLt4qGfZUZRQ5t3ACT+4M4jSWNBmLJl1fxqUzqbSwrW/1HbMnl4ZupBIlWe84dw6GyckUJzN7oNNaq7hcmqfeoZFdDg9GxtNGu5v1UdMHg /dDnGW2y +8fE2Cm7hrFzNmuu28MmsYNwBBsC1mfLnmeulqD6zcA60njHG0+ziqNWKdxLmiNW//FIyHKKH6snivoZZChidBQ1fzPCij42UrwJF4uDcMx+JDWgIDrRiMrrZ4ArGj8AdrwWgpzYHo24iaR9lhJ9W2it8BCHmoI+QBhXRbRC3GoF8qA6N0fGV7OZz312Ivniz+JEo9ecv57KDuenYyhPEZHFo14ofIB+u1p1h0hPAWphqwiniZY2wXJcYgCtp34mH6EuwHXIC3hjLTM+XhshzMNtKjjyB40L+TlT/Zb0ScryqeTFbc/uUtmCqK3Wm/nYsp3KoRJBKgjTyw/F47M2aKwsGCvWXrnvP9q2GdT+HACdvwRpIRab+MDK3dVN0AFkDP4QVe+rBrh6+1leJkB8CMAJSBObQXl9jgmZhDFws26ylFPvGqq6XSubkWqLbjUql3ukA8RDj5JStr+U= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 --- 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) {