From patchwork Fri Mar 4 04:25:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 12768443 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA741C433EF for ; Fri, 4 Mar 2022 04:25:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5007B8D0002; Thu, 3 Mar 2022 23:25:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 486A88D0001; Thu, 3 Mar 2022 23:25:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 327228D0002; Thu, 3 Mar 2022 23:25:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0183.hostedemail.com [216.40.44.183]) by kanga.kvack.org (Postfix) with ESMTP id 1FA5F8D0001 for ; Thu, 3 Mar 2022 23:25:56 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id D21248249980 for ; Fri, 4 Mar 2022 04:25:55 +0000 (UTC) X-FDA: 79205415870.30.380BB14 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) by imf18.hostedemail.com (Postfix) with ESMTP id 648DF1C000A for ; Fri, 4 Mar 2022 04:25:55 +0000 (UTC) Received: by mail-qk1-f180.google.com with SMTP id g24so5646007qkl.3 for ; Thu, 03 Mar 2022 20:25:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:mime-version; bh=Id7pgGOO69QmZf5bRtrRvNE114HKj31YJPHYLkWotfI=; b=Dc1GakVAq5QcDWMo9XcNXQhyxj1Lv7bV4IPMOboz54pcw3aO3cCUTl9n5x8tdDGSRj RILQi1WeKzyNaJ5kktQrMrJqSp3U8o9oVM7zTxtCUsrs6jQyjxlEYlr3aUo+YmAjIWOl iA3mWWLh2H9bOnouKiAReKFf22SS5+rsN+21qp9DAbfjbbiYLuSz7hl8iEAoEU6vYwwJ Riwj/JmoOyV6KUUKcUZuXrp9hdqwg4RkLrET8z1Av/z2jx+c/yrEUNtTJJ8x6+2kqMle XgLS/8zlGA4IgKcRq3te4B20sKEQjVuSiZ42SmteKS8CAWFbmLPZKqkb09CSrtEnOune lp6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version; bh=Id7pgGOO69QmZf5bRtrRvNE114HKj31YJPHYLkWotfI=; b=UOSA/yCA7VW5Q2v1JIENn/R0px0yN2wP5TI09wJ580e1gb9tyrRQQPHgAjNnbrhORq DoWVnLjYL94okCfwT2e+DPJo0SzRc48J4IX/+JwUp5lbg/arNnh8iEfC2Kt4ZhtYO6He gMDWFBvcNNo4OJRBZTisj52kqzfayzq7/b1rwi5N2LEKjMLMNpNevOX84Oaa6nn0A31o MwTyJarW+TiukXOrwKM6SWVU/GXQwsarMivGSNb0WJggXrRVYiUlnbmqFP+RiE5rUmsu YY7JrQSLhGDnOOUU8G0EwfUOSgHtbHQX2T1RDXb8oZHMGSzJUwF+Db9QhXPI6QUfALW1 nRkA== X-Gm-Message-State: AOAM530l4e1KuWZHGYzDMnIMXwrAFdm4SAEXbI6m+FDGAIcipKW8v52T fZ2Z3AkCg01Vg5aic9tGexuTfQ9s7yQ8Xg== X-Google-Smtp-Source: ABdhPJwWxulxlUIucVMWVbypFF9SWrVVSTvDuxJyPZr+pGZGBPM5dTO1DK0hFQM7uCbr/4r7p60MMg== X-Received: by 2002:a37:3c6:0:b0:5e9:57ac:a5be with SMTP id 189-20020a3703c6000000b005e957aca5bemr1451609qkd.756.1646367954057; Thu, 03 Mar 2022 20:25:54 -0800 (PST) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id b8-20020a05620a088800b00648bfd00a41sm1957965qka.80.2022.03.03.20.25.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Mar 2022 20:25:52 -0800 (PST) Date: Thu, 3 Mar 2022 20:25:50 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Andrew Morton cc: Matthew Wilcox , Jan Kara , Christoph Hellwig , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH mmotm] mm: warn on deleting redirtied only if accounted Message-ID: MIME-Version: 1.0 X-Rspamd-Queue-Id: 648DF1C000A X-Stat-Signature: jztyys7n7qcw1bqbew8c7yj6trt4w15m X-Rspam-User: Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Dc1GakVA; spf=pass (imf18.hostedemail.com: domain of hughd@google.com designates 209.85.222.180 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam07 X-HE-Tag: 1646367955-475045 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: filemap_unaccount_folio() has a WARN_ON_ONCE(folio_test_dirty(folio)). It is good to warn of late dirtying on a persistent filesystem, but late dirtying on tmpfs can only lose data which is expected to be thrown away; and it's a pity if that warning comes ONCE on tmpfs, then hides others which really matter. Make it conditional on mapping_cap_writeback(). Cleanup: then folio_account_cleaned() no longer needs to check that for itself, and so no longer needs to know the mapping. Signed-off-by: Hugh Dickins --- include/linux/pagemap.h | 3 +-- mm/filemap.c | 14 +++++++++----- mm/page-writeback.c | 18 ++++++++---------- 3 files changed, 18 insertions(+), 17 deletions(-) --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -991,8 +991,7 @@ static inline void __set_page_dirty(struct page *page, { __folio_mark_dirty(page_folio(page), mapping, warn); } -void folio_account_cleaned(struct folio *folio, struct address_space *mapping, - struct bdi_writeback *wb); +void folio_account_cleaned(struct folio *folio, struct bdi_writeback *wb); void __folio_cancel_dirty(struct folio *folio); static inline void folio_cancel_dirty(struct folio *folio) { --- a/mm/filemap.c +++ b/mm/filemap.c @@ -193,16 +193,20 @@ static void filemap_unaccount_folio(struct address_space *mapping, /* * At this point folio must be either written or cleaned by * truncate. Dirty folio here signals a bug and loss of - * unwritten data. + * unwritten data - on ordinary filesystems. * - * This fixes dirty accounting after removing the folio entirely + * But it's harmless on in-memory filesystems like tmpfs; and can + * occur when a driver which did get_user_pages() sets page dirty + * before putting it, while the inode is being finally evicted. + * + * Below fixes dirty accounting after removing the folio entirely * but leaves the dirty flag set: it has no effect for truncated * folio and anyway will be cleared before returning folio to * buddy allocator. */ - if (WARN_ON_ONCE(folio_test_dirty(folio))) - folio_account_cleaned(folio, mapping, - inode_to_wb(mapping->host)); + if (WARN_ON_ONCE(folio_test_dirty(folio) && + mapping_can_writeback(mapping))) + folio_account_cleaned(folio, inode_to_wb(mapping->host)); } /* --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2548,16 +2548,14 @@ static void folio_account_dirtied(struct folio *folio, * * Caller must hold lock_page_memcg(). */ -void folio_account_cleaned(struct folio *folio, struct address_space *mapping, - struct bdi_writeback *wb) +void folio_account_cleaned(struct folio *folio, struct bdi_writeback *wb) { - if (mapping_can_writeback(mapping)) { - long nr = folio_nr_pages(folio); - lruvec_stat_mod_folio(folio, NR_FILE_DIRTY, -nr); - zone_stat_mod_folio(folio, NR_ZONE_WRITE_PENDING, -nr); - wb_stat_mod(wb, WB_RECLAIMABLE, -nr); - task_io_account_cancelled_write(nr * PAGE_SIZE); - } + long nr = folio_nr_pages(folio); + + lruvec_stat_mod_folio(folio, NR_FILE_DIRTY, -nr); + zone_stat_mod_folio(folio, NR_ZONE_WRITE_PENDING, -nr); + wb_stat_mod(wb, WB_RECLAIMABLE, -nr); + task_io_account_cancelled_write(nr * PAGE_SIZE); } /* @@ -2768,7 +2766,7 @@ void __folio_cancel_dirty(struct folio *folio) wb = unlocked_inode_to_wb_begin(inode, &cookie); if (folio_test_clear_dirty(folio)) - folio_account_cleaned(folio, mapping, wb); + folio_account_cleaned(folio, wb); unlocked_inode_to_wb_end(inode, &cookie); folio_memcg_unlock(folio);