Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp847758pxb; Wed, 13 Jan 2021 18:12:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJxeu7EuGqhTdMQNZFWZ+MDz5MKo7qTY118WZF5Ojbt9ffyi0j7aqSnDs9blT350EcB7adPb X-Received: by 2002:a17:906:1d0f:: with SMTP id n15mr3446756ejh.26.1610590346658; Wed, 13 Jan 2021 18:12:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610590346; cv=none; d=google.com; s=arc-20160816; b=AYwB+nUct3j0Cktd1Od/ljjDH/BlLDENK3wjtoaA56Mveuhlf8JgLZ3pY/0e2jNTVD o2dPmMIr2frGws4r0FZX0XV28UYqTC+M58kkfm+ZAe0v5LGIt9pzEZyshlcrghBjd/F3 /cIMINcGWtb7ZCD52XD5dYQn/Nn9eYSv2CnbiJA35p+5ca7PsahTQrBXPIm8/Jak+6wB fB1L5xAd/zNAzKIu+obMtewKedvxZsiyUIZq4OSzLUnHwTBHxUH+t6EBCQgVcaH2MLTx S5KsUr+IJWWD+Ofiem9c67bO4PeQvOAfxmlXg31Yv9/Z7y0A+mD6FyfeuPU/lAWjhIAL l53Q== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=f44459R0W1AGwcc9BWILd7jja1t8A+AdL8/2x0Rd+pc=; b=nVtKFmrYbjzuHqcMalJdhKtiurCQrIc4IJCMlPlbr7YnEJlppEUG2Z5ahm92sLnu28 rIObiFEZrNxqb22vf6ouNL0/KXGBg7XlEGjFw+//2h5Tzzy0FaagvPMoks7fEvmumZeq ReYgOLGPuHlPmkigMAgEDC1DKN6oab7p+dAEVvV8JCzrHOmyRU7MRuCY6nrJYUV6l7P5 yEq5ww0GjMdiW5IYULkbBFucy4Imk6ulhxpoqKle/h9dobeAj7IxNU8BcVPwHiZptOh9 ucCh8+CS28qnlz+OFO0Jt1zwf31h6D5ZVAFJNgIzeR5gC+uUO03zqRQgaOGjliViV3qr 0/bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pseKpRNR; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v3si1723414ejx.433.2021.01.13.18.12.02; Wed, 13 Jan 2021 18:12:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pseKpRNR; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729251AbhANCLj (ORCPT + 99 others); Wed, 13 Jan 2021 21:11:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729231AbhAMWO5 (ORCPT ); Wed, 13 Jan 2021 17:14:57 -0500 Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23209C061575 for ; Wed, 13 Jan 2021 14:14:17 -0800 (PST) Received: by mail-qk1-x72a.google.com with SMTP id 186so4412511qkj.3 for ; Wed, 13 Jan 2021 14:14:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=f44459R0W1AGwcc9BWILd7jja1t8A+AdL8/2x0Rd+pc=; b=pseKpRNRPbD5k9pfBGNJb1S01KhurYi+vqr4EQfW6fV1qQ8Vs1Q8N9IqRU7p2NO220 6/a9lsBT3V9ZNv3+k+lrYnAaiIgVv+b+SSmamC+Qs7HTl4FhpweJ9XHIK28rBzx4ZUeX FtFAguSa+uwBRyYL9Co7FGyH4rYO2PfmGRU/pXdr9b2fm1fa3BFQ214DZWCSXNdP7BZP tNw1d8u30aKWQSXx099YrI2BpmXkvKuNcazIE4IPo4JChwrb3npU+VrebHoDIH+b2QP+ wcGILaHHdtitESK/C2O5UAxbLiQGcLDOn7ZVZRgNl2S2tGxEfVH5d3QYckvYmgL4XkOd nM9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=f44459R0W1AGwcc9BWILd7jja1t8A+AdL8/2x0Rd+pc=; b=pz1CYwZ7iTK020Xsj8nvoMB0ydowGj6RTCexPGdaG3bR5Cb9UEc55mKa+dfzFHUlnH 90091zoxlxLPYz2rD+u/JwhzvFacA2QO4dYbnKzduAmM6y0hbgefr+0BpV/z8FppGTOf uwc/OxV8fm6yAOtzBb/6fdYctN4QqAq5ig4cHL29Scwr2lBPgelDzDcOc2p8VcZ8ihwr +fb52977+WB7nI7VMM+C8n3f9EdM4eTssCYo3hBrEBJTERBAzziaNC/oSB99JJq4cJAs 5mkF1PjgdPQKpUkjtoH0rZ1qNDy716rKLBl5ULNazKGz/ymBg5HEgP0SuBvGHhNiUtkp awYg== X-Gm-Message-State: AOAM5333Fpno50mHnC+RDxMbGS+0FFD8Wo6OaDZwgv2EonxBjpzH75QG ljUtGHoyJ9v19VN0n7FQNDb9L0ocWKQ= X-Received: by 2002:a37:d2c7:: with SMTP id f190mr4336166qkj.95.1610576054602; Wed, 13 Jan 2021 14:14:14 -0800 (PST) Received: from localhost.localdomain (c-73-60-226-25.hsd1.nh.comcast.net. [73.60.226.25]) by smtp.gmail.com with ESMTPSA id f134sm1906641qke.23.2021.01.13.14.14.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jan 2021 14:14:14 -0800 (PST) From: Eric Whitney To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, Eric Whitney Subject: [PATCH] ext4: reset retry counter when ext4_alloc_file_blocks() makes progress Date: Wed, 13 Jan 2021 17:14:03 -0500 Message-Id: <20210113221403.18258-1-enwlinux@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Change the retry policy in ext4_alloc_file_blocks() to allow for a full retry cycle whenever a portion of an allocation request has been fulfilled. A large allocation request often results in multiple calls to ext4_map_blocks(), each of which is potentially subject to a temporary ENOSPC condition and retry cycle. The current code only allows for a single retry cycle. This patch does not address a known bug or reported complaint. However, it should make block allocation for fallocate and zero range more robust. In addition, simplify the conditional controlling the allocation while loop, where testing len alone is sufficient. Remove the assignment to ret2 in the error path after the call to ext4_map_blocks() since its value isn't subsequently used. Signed-off-by: Eric Whitney --- fs/ext4/extents.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 3960b7ec3ab7..77c7c8a54da7 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -4382,8 +4382,7 @@ static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset, { struct inode *inode = file_inode(file); handle_t *handle; - int ret = 0; - int ret2 = 0, ret3 = 0; + int ret, ret2 = 0, ret3 = 0; int retries = 0; int depth = 0; struct ext4_map_blocks map; @@ -4408,7 +4407,7 @@ static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset, depth = ext_depth(inode); retry: - while (ret >= 0 && len) { + while (len) { /* * Recalculate credits when extent tree depth changes. */ @@ -4430,9 +4429,13 @@ static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset, inode->i_ino, map.m_lblk, map.m_len, ret); ext4_mark_inode_dirty(handle, inode); - ret2 = ext4_journal_stop(handle); + ext4_journal_stop(handle); break; } + /* + * allow a full retry cycle for any remaining allocations + */ + retries = 0; map.m_lblk += ret; map.m_len = len = len - ret; epos = (loff_t)map.m_lblk << inode->i_blkbits; @@ -4450,11 +4453,8 @@ static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset, if (unlikely(ret2)) break; } - if (ret == -ENOSPC && - ext4_should_retry_alloc(inode->i_sb, &retries)) { - ret = 0; + if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) goto retry; - } return ret > 0 ? ret2 : ret; } -- 2.20.1