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: 86507 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1371639vqo; Fri, 21 Apr 2023 15:18:22 -0700 (PDT) X-Google-Smtp-Source: AKy350Z2HGSpIPReY4GzpHaKAvgRTqUdp+xCIdKHPv90fzRfEhJK7vWzpzeIGW/Czut4i0kjwkeP X-Received: by 2002:a05:6a00:1582:b0:63f:539:3fb with SMTP id u2-20020a056a00158200b0063f053903fbmr8305407pfk.11.1682115501751; Fri, 21 Apr 2023 15:18:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682115501; cv=none; d=google.com; s=arc-20160816; b=qEJ4PCqlte+dfH7w64+EiIylGvCDg2tuMEyLDOwJCYmP73WNWX2+8120L2dwn2HCGV orjU/we2FDFl4Qh0ncPZ9mwqCwoUaRWNUtBTYkgoSphr5V7aSwNq7x4Xmhnqfk3pPqlS Od9JB6Xsr8dr2Lp2kEvGquFQHpW5deIUSdKPZzz/wvAT7GreKWD19HPHMt0VQdkeHunt 3iT2e0NXNTM4t12hjfFqL4qNQW0fnchk+vXdq1Qb3TtNV0tZnU0HcPBqsHJzh+vtXJ9q STMO2oh5e0ccTJjHIenG5qDhhqO+z7I+q2yoMyp5VjZfcNclZ6RC4jC3+CDSFCXHJcXH g1og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Dc5jbER8wEc7OW3/IotC+kA2A3o7OZfeQaN33ZlBlP4=; b=LbH+PYOeDyBiL4E6l6hH8f7/zm+OoJIyaT2kY4U2S6zuiY9D1BX9tKpLogSiVpKWjy csAkXRf0KlXtUx9QFC5GAEw7sRxX443SXvhoTdBVxrL7R3fQXOFXOi4V6uGCQznvHvFg r64fRnsCyqIwtQaKC4m6/R9sdgCxubxNan7mSQ2xK8feEQb9UrWNdcOP1NbJPy+ZjiXc ARPpidQQAO3X/H55YL8JoOB4mvT8QWzYTsBZ9n6OIoHO4XZFin94x4S1qPy9FQeqLoDf HU2gKmoqg2aTvaZvLu9Le6qrU1pM7eHriGg1NGozTxTtRoohiTOGOC8de5FodPmbhEGK z0eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Bj7hb2g1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y9-20020aa79ae9000000b0062d9eed7d25si5252650pfp.57.2023.04.21.15.18.08; Fri, 21 Apr 2023 15:18:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Bj7hb2g1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233724AbjDUWNt (ORCPT + 99 others); Fri, 21 Apr 2023 18:13:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233770AbjDUWNb (ORCPT ); Fri, 21 Apr 2023 18:13:31 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EBBA2D52 for ; Fri, 21 Apr 2023 15:13:30 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-63b62d2f729so2293385b3a.1 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=RoSt24tej8oDzoSVoTbST6U8qNRvgTNTF1zdg/0P5FTZI/nIj1x759PaxXp4fOhpyH lp7ESlKbz4wCqLDN531LwsHRqP5witMe7tW/SjGYKGaVSkd/DrP6UI39fBroj/mXKpwK WE+Sjs9egFwBNngdrRM8BJcrZnJgvCOxENfYtmTO66POo8Es2hRYCifgVuWPZHipu6NJ DfMA3csEKc2/Ud06H3/fchlZq/bK/mIUdov/PglKtme/Py8ahhoX7/l7dWDHyoxKhWlX PH2Rgq+1niyaVIZL3uPMxFaZiRcJDs1uJaFzuWhzXq6azM+LBEgKvxRo27i8k9UqxStT uVvQ== X-Gm-Message-State: AAQBX9f7oOtTOuVxR0zyF5GGSIipCNinqBQprHNBhrv3YFDMcNwSKYSg cE8tbgBD8kKsvhIILVLQw3+Pow== 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763825944367822644?= X-GMAIL-MSGID: =?utf-8?q?1763825944367822644?= 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) {