Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3016338rwb; Mon, 15 Aug 2022 16:12:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR4D2L/i/ttnQi7OW2Slmm0ehJ5Ahjhvuj6gpRjlq5RH4rFt2M/NryR4Y12odPBKQV4QNdnQ X-Received: by 2002:a17:907:2bcf:b0:738:7bce:a94e with SMTP id gv15-20020a1709072bcf00b007387bcea94emr899183ejc.501.1660605162975; Mon, 15 Aug 2022 16:12:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605162; cv=none; d=google.com; s=arc-20160816; b=O8AGftkfWsWjruDVQjxvze3HfVG2zZ1K7aTX2LYZ6AeulLGQKPjN4MoEtTSnN74r+7 M1aHdkKn4/yzmyAXMgU8sO7EWZM1bfP87gmj5O4fma2GpZ6OSq7kRxG9HWkSu+06HdUD ydx9lmxTpm330gLHWh3Kv0YuJ9sVts4g1f/+bjIc9DgE38eAoJ3zVG/HPVOYJkNOX7dC TKu1wjsDZC1efRnWoZwNP++BGVR5IYPIUOgbdnodZYVcQGPwWqjIZsI86lDkLNkWcrMK CklTuTm45qk1q+SzYiy24O0Xixb4SNJ05NkbPKCG/GpCMtSPWyHbVZvc9pUSslEo66VQ 2YbQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CIdAxKSzv9dN5AXMsTaGKUUmsMQQdlhE8ke2nRkw5xE=; b=1CHbaCTHKQt9enbEV15WkHzlr1aLXFCrqMQQBI+eJCSQNPURMXZzEwCU1piKCC/oE8 iXKoP8Uiq9PwUdt714ai07kvA1jbBtDc2nCf3kwqjx4gvdDoQPgqRJLiqRhusT0bHhJW /qHGJYbusg5gEqX7WotfP/2QsmrOcEc2HW821Y1aMUhjXKl7gibKLCgjJltqHdhuG3fu n8F3Ag5UmSuFVzSYRgJvDVtSACnQmuDe0f/6qV3qgbdAPs9/SSs0NnH7GjET8noFukGB WPQ2KOa3aBFCJS4js6c147q45oXKZq7owndrNYULFEEOovN63BNrp/viFN4B8GsIL1Ym hoeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=or5MVeNa; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b3-20020a170906728300b007303db545e6si8497100ejl.786.2022.08.15.16.12.17; Mon, 15 Aug 2022 16:12:42 -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=@linuxfoundation.org header.s=korg header.b=or5MVeNa; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233234AbiHOVM0 (ORCPT + 99 others); Mon, 15 Aug 2022 17:12:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347877AbiHOVHm (ORCPT ); Mon, 15 Aug 2022 17:07:42 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16EE052DC5; Mon, 15 Aug 2022 12:16:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id BD0F7B810A3; Mon, 15 Aug 2022 19:16:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06969C433C1; Mon, 15 Aug 2022 19:16:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660590977; bh=FSlNSLhvpoyiw9eFcM5g7ayib14ZGARLfiKQGyQtPDc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=or5MVeNaDHLyvahTYk8jm3RKn0dOmZQelv7FqKEFWutWN8u9f6dWlu8MqM54L0NWZ 33gSvLUil5nQnQLiaFJwzaM1FyQkRfxjVHqoHKq79T4QMYe/MmwDraOnk0MtcqFuby RpjxVS5skLWAjh1PcySzkhB7VQFVDIv+O3bHe2Uk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dave Chinner , "Darrick J. Wong" , "Matthew Wilcox (Oracle)" , Sasha Levin Subject: [PATCH 5.18 0401/1095] mm: Account dirty folios properly during splits Date: Mon, 15 Aug 2022 19:56:40 +0200 Message-Id: <20220815180446.282386990@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Matthew Wilcox (Oracle) [ Upstream commit fb5c2029f8221e904e604938171c4a8ef169aadb ] If the last folio in a file is split as a result of truncation, we simply clear the dirty bits for the pages we're discarding. That causes NR_FILE_DIRTY (among other counters) to be thrown off and eventually Linux will hang in balance_dirty_pages_ratelimited() Reported-by: Dave Chinner Tested-by: Dave Chinner Tested-by: Darrick J. Wong Fixes: d68eccad3706 ("mm/filemap: Allow large folios to be added to the page cache") Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Sasha Levin --- mm/huge_memory.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index b7d0697b1f26..e0c1cf3168d7 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -2389,11 +2390,15 @@ static void __split_huge_page(struct page *page, struct list_head *list, __split_huge_page_tail(head, i, lruvec, list); /* Some pages can be beyond EOF: drop them from page cache */ if (head[i].index >= end) { - ClearPageDirty(head + i); - __delete_from_page_cache(head + i, NULL); + struct folio *tail = page_folio(head + i); + if (shmem_mapping(head->mapping)) shmem_uncharge(head->mapping->host, 1); - put_page(head + i); + else if (folio_test_clear_dirty(tail)) + folio_account_cleaned(tail, + inode_to_wb(folio->mapping->host)); + __filemap_remove_folio(tail, NULL); + folio_put(tail); } else if (!PageAnon(page)) { __xa_store(&head->mapping->i_pages, head[i].index, head + i, 0); -- 2.35.1