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 9C9C7C433EF for ; Fri, 24 Jun 2022 13:31:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 04ABA8E0223; Fri, 24 Jun 2022 09:31:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F16448E020E; Fri, 24 Jun 2022 09:31:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB6B18E0223; Fri, 24 Jun 2022 09:31:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C6E698E020E for ; Fri, 24 Jun 2022 09:31:42 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 9785761366 for ; Fri, 24 Jun 2022 13:31:42 +0000 (UTC) X-FDA: 79613216844.25.943F43E Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf10.hostedemail.com (Postfix) with ESMTP id 30906C009E for ; Fri, 24 Jun 2022 13:31:41 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 843F71F8EF; Fri, 24 Jun 2022 13:31:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1656077500; h=from:from:reply-to:reply-to:date:date:message-id:message-id:to:to: cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=RgjcjsWwgFCT51qzN2+gjNYaVNpGbaTRZxVXLNJmXbg=; b=VvgWBKdl1CvOhvyADG1uOBOtFL4EJM2iTP2RJqENtsxjEYxFI99ueud6cmoj+xODh0wwcW kMqP/2+9iWPT6AEnQqfytCLGO+D2y6T+8o8FSO3uf4PV21cMv2Cyo8bgWLj0jJBKaV558o OODUa0Kvif5Pec8YeSKL8+/Flq4R9Tc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1656077500; h=from:from:reply-to:reply-to:date:date:message-id:message-id:to:to: cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=RgjcjsWwgFCT51qzN2+gjNYaVNpGbaTRZxVXLNJmXbg=; b=rbv9OWQH8nhn7uiUClbt61DsOVh1zVoZ2ZxvEt5asVQO0+SUARI8H8X4igIt64k89EDwJw uzXtiGYjZlESk3DQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 3F69B13480; Fri, 24 Jun 2022 13:31:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id WYCFDry8tWJVBQAAMHmgww (envelope-from ); Fri, 24 Jun 2022 13:31:40 +0000 Date: Fri, 24 Jun 2022 15:27:01 +0200 From: David Sterba To: Qu Wenruo Cc: dsterba@suse.cz, Christoph Hellwig , clm@fb.com, josef@toxicpanda.com, dsterba@suse.com, linux-btrfs@vger.kernel.org, Linux Kernel Mailing List , Linux Memory Management List Subject: Re: [PATCH] btrfs: remove btrfs_writepage_cow_fixup Message-ID: <20220624132701.GT20633@twin.jikos.cz> Reply-To: dsterba@suse.cz Mail-Followup-To: dsterba@suse.cz, Qu Wenruo , Christoph Hellwig , clm@fb.com, josef@toxicpanda.com, dsterba@suse.com, linux-btrfs@vger.kernel.org, Linux Kernel Mailing List , Linux Memory Management List References: <20220624122334.80603-1-hch@lst.de> <20220624124913.GS20633@twin.jikos.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23.1-rc1 (2014-03-12) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656077502; a=rsa-sha256; cv=none; b=t7g+dw58j344m9rZ1t+pQkN2th7g8fCaAlJYBDZX4zJESPoy0dRa4xkpT7C4jYC1ktB9Rq eEAoygwo5Jf6xZEgirQZBpalk/Rb/TKg2r52/z7PZe0piI0OHXEb9PNdQ4e9wL+MLflRTw WGivd6EJSEeDozxtk2dygmIuk+Zq19M= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=VvgWBKdl; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=rbv9OWQH; dmarc=none; spf=pass (imf10.hostedemail.com: domain of dsterba@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=dsterba@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656077502; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=RgjcjsWwgFCT51qzN2+gjNYaVNpGbaTRZxVXLNJmXbg=; b=yxVCS7RFu71qTpA7EWxqSh1Sg2r9Yu6YRlF0ayjWjiYbKPsfZ0HANeFnrtf3strb5dpYgf QnUebfU40q56B3HxxnuEQVxzjxi0EydZic5CfhJeuFGqxgtGgF4O4Lc/GM3Hs+jjDsANik 09jTTHDfPzCs6k2GoFnP3tWOT0VXt2w= X-Rspam-User: X-Stat-Signature: q15f9w7yfwho6f8a3jz3yazqdb4gw88t X-Rspamd-Queue-Id: 30906C009E Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=VvgWBKdl; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=rbv9OWQH; dmarc=none; spf=pass (imf10.hostedemail.com: domain of dsterba@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=dsterba@suse.cz X-Rspamd-Server: rspam03 X-HE-Tag: 1656077501-920449 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: On Fri, Jun 24, 2022 at 09:12:44PM +0800, Qu Wenruo wrote: > On 2022/6/24 20:49, David Sterba wrote: > > On Fri, Jun 24, 2022 at 02:23:34PM +0200, Christoph Hellwig wrote: > >> Since the page_mkwrite address space operation was added, starting with > >> commit 9637a5efd4fb ("[PATCH] add page_mkwrite() vm_operations method") > >> in 2006, the kernel does not just dirty random pages without telling > >> the file system. > > > > It does and there's a history behind the fixup worker. tl;dr it can't be > > removed, though every now and then somebody comes and tries to. > > > > On s390 the page status is tracked in two places, hw and in memory and > > this needs to be synchronized manually. > > > > On x86_64 it's not a simple reason but it happens as well in some edge > > case where the mappings get removed and dirty page is set deep in the > > arch mm code. We've been chasing it long time ago, I don't recall exact > > details and it's been a painful experience. > > > > If there's been any change on the s390 side or in arch/x86/mm code I > > don't know but to be on the safe side, I strongly assume the fixup code > > is needed unless proven otherwise. > > I'd say, if this can be a problem to btrfs, then all fs supporting COW > should also be affected, and should have similar workaround. Probably yes. > Furthermore, this means we can get a page dirtied without us knowing. This should not happen because we do have the detection of the page and extent state mismatch and the fixup worker makes things right again. > This is a super big surprise to any fs, and should be properly > documented, not just leaving some seemly dead and special code in some > random fs. You seem to be a non-believer that the bug is real and calling the code dead. Each filesystem should validate the implementation agains the platform where it is and btrfs once found the hard way that there are some corner cases where structures get out of sync. > Furthermore, I'm not sure even if handling this in a fs level is correct. > This looks like more a MM problem to me then. > > > I totally understand it's a pain to debug such lowlevel bug, but > shouldn't we have a proper regression for it then? The regression test is generic/208 and it was not reliable at all, it fired randomly once a week or month, there used to be a BUG() in the fixup worker callback. > Instead of just keeping what we know works, I really want to handle this > old case/bug in a more modern way. As long as the guarantees stay the same, then fine. We need to be able to detect the unexpected dirty bit and have a way to react to it. f4b1363cae43 ("btrfs: do not do delalloc reservation under page lock") 25f3c5021985 ("Btrfs: keep pages dirty when using btrfs_writepage_fixup_worker") 1d53c9e67230 ("Btrfs: only associate the locked page with one async_chunk struct") And the commit that fixed it: 87826df0ec36 ("btrfs: delalloc for page dirtied out-of-band in fixup worker") You can find several reports in the mailing list archives (search term btrfs_writepage_fixup_worker): https://lore.kernel.org/linux-btrfs/1295053074.15265.6.camel@mercury.localdomain https://lore.kernel.org/linux-btrfs/20110701174436.GA8352@yahoo.fr https://lore.kernel.org/linux-btrfs/j0k65i$29a$1@dough.gmane.org https://lore.kernel.org/linux-btrfs/CAO47_--H0+6bu4qQ2QA9gZcHvGVWO4QUGCAb3+9a5Kg3+23UiQ@mail.gmail.com https://lore.kernel.org/linux-btrfs/vqfmv8-9ch.ln1@hurikhan.ath.cx