Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp6519687rwb; Tue, 9 Aug 2022 17:33:05 -0700 (PDT) X-Google-Smtp-Source: AA6agR6W/movzYnS5W3yUDrX3mzdvHoB/mCYacOolkL8G/khj1rwk2AmL377RRsw9JPlSmMvdVBZ X-Received: by 2002:a17:90b:514:b0:1f5:59b2:fceb with SMTP id r20-20020a17090b051400b001f559b2fcebmr1037796pjz.82.1660091584933; Tue, 09 Aug 2022 17:33:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660091584; cv=none; d=google.com; s=arc-20160816; b=XaF0BQe2+ZTWdCRI4kmri1cvZ9IyDYRGal8/rWFt/ceK4ErSzA+dMx5Hy7HIx0PEqx C4OqGO+d8P1z9UYjXCVvc9RDxCo1s4M7dfcnwfJvS9mccN42g/64MUY/6AtH92LLlg7+ Qz9NlgINZwIa/+kaUh7Qn5e96yc7H4kh/HCTzMiNFnaigzRvyvtAUxstp7Nv4Xk2eav+ SgXnmQzmYrAJpSFOf5yD7UfR8mPp8nH2j02VdMK+fLCBw+/oiADLz1EfK2TXaiPAG7xK JrGtow2Ir2ZnTX5263jaaMsYfRkr2zEz8EokAGv8FwYgBYU0kERLFPfBw6lJZcYjYs4U ee1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=Q80Fzd5Pmw8ZTfW5dsvJdOkN6SQJYu9Wu2kKg7cJAiw=; b=OBkCBq/jM2vHF2TrrCgbauRx9+y1ijelHPifsIRqjx6vx4tPsQTZ+C63RNTBtvvpb7 i4mK4+mTG0Q7qDV/El/8nkUj7j9aBuEbmzgmIULXRlIgBAbFhNh63u4vVAa0LTpeoUje 3Qdsp9qBBj9YCyQtvRU3ZTngiK2VrBzKUmhll7ykpSjwfO+LnWNGg5K1IbySdCSwhN8Q h5V7qs/Ta6YAG0b46ETg+vPjOKtpQO47GZDFVQWEhEtsgJosguVyjDBuxRqj5hNfTgvN ZHZko6q/X9BEZB71IpzaQvkh3EE918znMtgBYhPs+qG+XryKKu1iwhfZTId/+OmBjiFU xzWg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k11-20020a170902d58b00b0017086b1c40dsi11337112plh.400.2022.08.09.17.32.39; Tue, 09 Aug 2022 17:33:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229534AbiHJA3t (ORCPT + 99 others); Tue, 9 Aug 2022 20:29:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229475AbiHJA3s (ORCPT ); Tue, 9 Aug 2022 20:29:48 -0400 Received: from mail104.syd.optusnet.com.au (mail104.syd.optusnet.com.au [211.29.132.246]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A5EF41AD81 for ; Tue, 9 Aug 2022 17:29:47 -0700 (PDT) Received: from dread.disaster.area (pa49-181-193-158.pa.nsw.optusnet.com.au [49.181.193.158]) by mail104.syd.optusnet.com.au (Postfix) with ESMTPS id 7EE1E62D628; Wed, 10 Aug 2022 10:29:46 +1000 (AEST) Received: from dave by dread.disaster.area with local (Exim 4.92.3) (envelope-from ) id 1oLZbV-00BEms-F3; Wed, 10 Aug 2022 10:29:45 +1000 Date: Wed, 10 Aug 2022 10:29:45 +1000 From: Dave Chinner To: bugzilla-daemon@kernel.org Cc: linux-ext4@vger.kernel.org Subject: Re: [Bug 216322] Freezing of tasks failed after 60.004 seconds (1 tasks refusing to freeze... task:fstrim ext4_trim_fs - Dell XPS 13 9310 Message-ID: <20220810002945.GK3861211@dread.disaster.area> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.4 cv=VuxAv86n c=1 sm=1 tr=0 ts=62f2fbfa a=SeswVvpAPK2RnNNwqI8AaA==:117 a=SeswVvpAPK2RnNNwqI8AaA==:17 a=ZCXp25Omcg5n1RXD:21 a=kj9zAlcOel0A:10 a=biHskzXt2R4A:10 a=VwQbUJbxAAAA:8 a=20KFwNOVAAAA:8 a=7-415B0cAAAA:8 a=Qzhb2gN4u6QXIkT9oDwA:9 a=CjuIK1q_8ugA:10 a=hP7KuYlNnP_hzIlKH_V0:22 a=AjGcO6oz07-iQ99wixmX:22 a=biEYGPWJfzWAr4FL6Ov7:22 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE,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-ext4@vger.kernel.org On Thu, Aug 04, 2022 at 11:47:47AM +0000, bugzilla-daemon@kernel.org wrote: > https://bugzilla.kernel.org/show_bug.cgi?id=216322 > > --- Comment #4 from Lukas Czerner (lczerner@redhat.com) --- > On Thu, Aug 04, 2022 at 12:44:45AM +0000, bugzilla-daemon@kernel.org wrote: > > https://bugzilla.kernel.org/show_bug.cgi?id=216322 > > > > Theodore Tso (tytso@mit.edu) changed: > > > > What |Removed |Added > > ---------------------------------------------------------------------------- > > CC| |tytso@mit.edu > > > > --- Comment #2 from Theodore Tso (tytso@mit.edu) --- > > So the problem is that the FITRIM ioctl does not check if a signal is > > pending, > > and so if the fstrim program requests that the entire SSD (len=ULLONG_MAX), > > like the broomstick set off by Mickey Mouse in Fantasia's "Sorcerer's > > Apprentive", it will mindlessly send discard requests for any blocks not in > > use > > by the file system until it is done. Or to put it another way, "Neither > > rain, > > nor snow, or a request to freeze the OS, shall stop the FITRIM ioctl from its > > appointed task." :-) > > > > The question is how to fix things. The problem is that the FITRIM ioctl > > interface is pretty horrible. The fstrim_range.len variable is an IN/OUT > > field where on the input it is the number of bytes that should be trimmed > > (from > > start to start+len) and when the ioctl returns fstrm_range.len is the number > > of > > bytes that were actually trimmed. So this is not really amenable for > > -ERESTARTSYS. > > > > Worse, the fstrim program in util-linux doesn't handle an EAGAIN error return > > code, so if it gets the EAGAIN after try_to_freeze_tasks send the fake signal > > to the process, fstrim will print to stderr "fstrim: FITRIM ioctl failed" and > > the rest of the file system trim operation will be aborted. > > > > It might be that the only way we can fix this is to have FITRIM return > > EAGAIN, > > which will stop the fstrim in its tracks. This is... not great, but > > typically > > fstrim is run out of crontab or a systemd timer once a month, so if the user > > tries to suspend right as the fstrim is running, hopefully we'll get lucky > > next > > month. We can then try teach fstrim to do the right thing, and so this > > lossage mode would only happen in the combination of a new kernel and an > > older > > version of util-linux. > > > > I'm not happy with that solution, but the alternative of creating a new > > FITRIM2 > > ioctl that has a sane interface means that you need an new kernel and a new > > util-linux package, and if you don't, the user will have to deal with a hot > > laptop bag and a drained battery. And not changing FITRIM's behaviour will > > have the same potential end result, if the user gets unlucky and tries to > > suspend the laptop when there is more than 60 seconds left before FITRIM to > > complete. :-/ > > > > The other thing I'll note is that every file system has its own FITRIM > > implementation, and I suspect they all have this issue, because the FITRIM > > interface is fundamentally flawed. > > I agree that the FITRIM interface is flawed in this way. But > ext4_try_to_trim_range() actually does have fatal_signal_pending() and > will return -ERESTARTSYS if that's true. Or did you have something else in > mind? Why not just do: if (freezing(current)) break; After the call to fatal_signal_pending()? Remember: FITRIM is an -advisory- API. It does not provide any guarantees that the free space in the filesystem has any specific operation done on it, nor does the backing store guarantee that it performs GC on ranges the filesystem discards because discards are advisory as well! Hence the FITRIM API isn't a problem here at all - it's purely an advosiry interface and does not guarantee storage level garbage collection. Hence if filesystems skip the remaining requested range because the system is being suspended, then it isn't the end of the world. Userspace already has to expect that FITRIM will *do nothing*, and if userspace is doing FITRIM often enough that suspend is an issue, the next scheduled userspace FITRIM pass will clean up what this one skipped... Hence I don't see any problem with just stopping FITRIM and returning "no error" if it detects a suspend operation in progress. Simple logic, easy to retrofit to all filesystems, and doesn't require any userspace awareness of the issue at all... Cheers, Dave. -- Dave Chinner david@fromorbit.com