Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3705774ybv; Mon, 10 Feb 2020 05:03:42 -0800 (PST) X-Google-Smtp-Source: APXvYqyQhjApH8g728Zp1j5bJEULHWLOOkfdya5TFq/eELRdcKXxuCYVfId7fkP4+Gbgfa/p3tSS X-Received: by 2002:a9d:f26:: with SMTP id 35mr926896ott.31.1581339822150; Mon, 10 Feb 2020 05:03:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581339822; cv=none; d=google.com; s=arc-20160816; b=0K2VE8HPajZJqSavIJJ8EZlEQ/q7wx2nFNDqBIrceceUQvfWDXN03lCCBg4yJsArQX vNJ7jKmuToIWhiYyrhS85NjEnGHu80Fnm9YP+SwTAxmE6UF6DHeMUcNlypfB7ZUwujgA DvuqkvGGxYwk8dGFmnUjo4lRAVp3D0M9D3IQho/GqC/tPjAJmPLQrcr0G623D3h1nCKt iRiB0qzSQ/hyY2NLssMlcvfOF2KBvCPmFEbO8uilkvOQ0YILyHM1UJYgxs+z9zuxR0ut bPGUuBEr/cWR0xsuZgOknXQF3+BZs6QHOqpuKAyFLcr0BH+ply0CLqKPBuqD6nimDUVq YeWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=no1X2HNNm3WdkFXIOynHQGmLTrjwvbZ4aD9sWubrQsY=; b=oXqWfl85wDjn0VpzLFEU4dEetC+ds0vl9lcN7yMOR/3viQgz+mwGtx952KSHAu5k1D a/GOCzdlztYbHn960HTj2hqWY3E18me4vaiwQ26BiMe2FhjV8MMzGbssymJqx+AiQ2ji k+GyxDOpmdytQYVbwIzQX/nLl0xJcIc6p6vZl5KKvwtewMG+WGTyOTSuWJuUtscGMGY/ +yB92ZI1hAV5BjvGe2fucfVinStO6d8k3tMYoxqBCm62GgwcD4UL0dmj3u5IgT0xMZ68 PX9lzJisMhsFAaOMl8Lb+46ycgbrkL6JzT0EGQEE8xpP5HMHagQTW83cYsiJLadUTYeL GnzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LZzqqDJq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e26si152969oii.88.2020.02.10.05.03.27; Mon, 10 Feb 2020 05:03:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LZzqqDJq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730059AbgBJNCq (ORCPT + 99 others); Mon, 10 Feb 2020 08:02:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:40726 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729747AbgBJMka (ORCPT ); Mon, 10 Feb 2020 07:40:30 -0500 Received: from localhost (unknown [209.37.97.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 28C3D20842; Mon, 10 Feb 2020 12:40:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338430; bh=/L09c4D6tvDhtBvettooq6PMqTLwWh1zJo9L3kooNdI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LZzqqDJq0eG3kRU8erkocQDdVLlD8x1tCbxUaNSzZXbjviptwGVJHEm5fpdd5KmbN 9kBPslQln8rNIQrvNCqiGIlspvfS6rG16ilBtYClKMyy2QAVm0JvlH4nIRCIJwKVM2 lxrbyToRzycylTX4oskK4YEauL5/AGx6PEtOp9uc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , David Sterba Subject: [PATCH 5.5 155/367] btrfs: fix improper setting of scanned for range cyclic write cache pages Date: Mon, 10 Feb 2020 04:31:08 -0800 Message-Id: <20200210122439.130689063@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200210122423.695146547@linuxfoundation.org> References: <20200210122423.695146547@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Josef Bacik commit 556755a8a99be8ca3cd9fbe36aaf9b3b0339a00d upstream. We noticed that we were having regular CG OOM kills in cases where there was still enough dirty pages to avoid OOM'ing. It turned out there's this corner case in btrfs's handling of range_cyclic where files that were being redirtied were not getting fully written out because of how we do range_cyclic writeback. We unconditionally were setting scanned = 1; the first time we found any pages in the inode. This isn't actually what we want, we want it to be set if we've scanned the entire file. For range_cyclic we could be starting in the middle or towards the end of the file, so we could write one page and then not write any of the other dirty pages in the file because we set scanned = 1. Fix this by not setting scanned = 1 if we find pages. The rules for setting scanned should be 1) !range_cyclic. In this case we have a specified range to write out. 2) range_cyclic && index == 0. In this case we've started at the beginning and there is no need to loop around a second time. 3) range_cyclic && we started at index > 0 and we've reached the end of the file without satisfying our nr_to_write. This patch fixes both of our writepages implementations to make sure these rules hold true. This fixed our over zealous CG OOMs in production. Fixes: d1310b2e0cd9 ("Btrfs: Split the extent_map code into two parts") Signed-off-by: Josef Bacik Reviewed-by: David Sterba [ add comment ] Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/extent_io.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -3941,6 +3941,11 @@ int btree_write_cache_pages(struct addre if (wbc->range_cyclic) { index = mapping->writeback_index; /* Start from prev offset */ end = -1; + /* + * Start from the beginning does not need to cycle over the + * range, mark it as scanned. + */ + scanned = (index == 0); } else { index = wbc->range_start >> PAGE_SHIFT; end = wbc->range_end >> PAGE_SHIFT; @@ -3958,7 +3963,6 @@ retry: tag))) { unsigned i; - scanned = 1; for (i = 0; i < nr_pages; i++) { struct page *page = pvec.pages[i]; @@ -4087,6 +4091,11 @@ static int extent_write_cache_pages(stru if (wbc->range_cyclic) { index = mapping->writeback_index; /* Start from prev offset */ end = -1; + /* + * Start from the beginning does not need to cycle over the + * range, mark it as scanned. + */ + scanned = (index == 0); } else { index = wbc->range_start >> PAGE_SHIFT; end = wbc->range_end >> PAGE_SHIFT; @@ -4120,7 +4129,6 @@ retry: &index, end, tag))) { unsigned i; - scanned = 1; for (i = 0; i < nr_pages; i++) { struct page *page = pvec.pages[i];