Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3087462rwb; Mon, 15 Aug 2022 17:49:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR6No/nbH2cLavanjKTksuqjMNfTDvS5LbgoifNXSMW+25W+HYmDWcwqQXEWfEb+QgrU89NE X-Received: by 2002:a05:6402:2b98:b0:43e:107:183d with SMTP id fj24-20020a0564022b9800b0043e0107183dmr16811824edb.366.1660610967048; Mon, 15 Aug 2022 17:49:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660610967; cv=none; d=google.com; s=arc-20160816; b=XoWzWqmSB8KYbT6UrKpDgGxXxiVx8LGbkzi+Vhnzc9GQihuoxE5Bgzwk7UJkkz9sXv 9hiv6igVJgd10+m2PcZpzfib2c4/pEnB+weTCtPzIfOXZR1kP4eoaDe0IfYRBMZGPHhm 2kUQt9TPKojq9pEjKd1kkd4wQ9vwf0AXD5gvR0hmxg+QJPSplSk81vE+43XC98EOIPiB Tps6drDq3B9GrjfrbMeWQvOIU+tY0VEJ7WBIOA21nqX1OF/dFanmnq+34bHQzv84128C 9j0xELk93tB0aErcipe1Bn90RF6ZDWy91KdgcxKOD0naqmblM6FLazNrF58n04f6FqDJ kvJA== 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=PIybRIG9C03RlLzVlH63Je6yD5+6sp8fp6cdU9g9SDQ=; b=ph8jwlRCmqzPD7PVYXPuJa/q7xXSX+2kO6jQKf0of+5byLP+QRyTqzf+Pqxi+3cLqm j+Cht5MQSRhi9WiS3dYsf3YMdF9zdoi3r9+leAV8wdNRqaKrqdUQqlEY1/OmW+89RYco 77wNRWUEJdsPC6PaNx9C0BONku5Mwho6sdpoRsQv4ykTmwp4RacYZdLNfk8/B6d9t/kx ekwRpKPl7ZZL8LFPFkAtBdtofI6Q5bstftO57ivhAOGRuBxanSTmfdxkr17iPLApFlgG ZbXl052ZG/z4rTJ+EXXWg+MzPrRfsQ9wtFTOlfNEXt2izdSb2vt/JCLSklu58wCcP3Ek WQxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=srIrpDi+; 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 qw4-20020a170906fca400b006efe41f067asi7704580ejb.234.2022.08.15.17.49.02; Mon, 15 Aug 2022 17:49:27 -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=srIrpDi+; 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 S1355143AbiHOXrJ (ORCPT + 99 others); Mon, 15 Aug 2022 19:47:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354333AbiHOXly (ORCPT ); Mon, 15 Aug 2022 19:41:54 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38C982C67A; Mon, 15 Aug 2022 13:12:55 -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 DF537B80EAB; Mon, 15 Aug 2022 20:12:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D94AC433D6; Mon, 15 Aug 2022 20:12:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660594372; bh=D0Kv8H6XorGh+j/hqdaLEAmyfP1fBTiLguzZ5ZJ4gUA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=srIrpDi+fNk3G3FEavlW5RUAc0v7Y/U9YZzKQhGDdkCnnw1NSUMPE1+X/l9teeArk 79mgiS/ai7Mb9xjUFG+cAPQcy4UIz2Qk787bdnXRiluMoXf3RTkW8AnBBhnwWMogbU c3zJqagIjBCnpLJNQ5Lyp1SFMTav/EWmeSe6xebo= 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.19 0425/1157] mm: Account dirty folios properly during splits Date: Mon, 15 Aug 2022 19:56:21 +0200 Message-Id: <20220815180456.662665693@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@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 834f288b3769..15965084816d 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -2440,11 +2441,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