From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2FC40427A19 for ; Wed, 13 May 2026 13:11:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778677877; cv=none; b=TDUDXfMR03aaCtUFq3xIOCWvb75qmtsy2m6lTZ4/0UtttzbrVScuxqXEalpKy8UdAlktvwZUvMxMmv+xVkm3AFH0y97xj1xt8Xonu6JzJZQHokxqO3KtWO/aTBeN1K0kSElZP2V//uhqLFkfBrIxo9nH7/21FlbyiID99ihdHL0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778677877; c=relaxed/simple; bh=6FWAOdMRCGXRhuY+RZ6so9OqbtSfnT1i9cx1+5lpsns=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=aiCs9tQZHPsX6QgVdjvCJEgZnHGFg4R+27GTlfMvqFoUXeintQbSBI3F/ilQHVr0kRw02h06kGVeAdK9RbQB8De1kqU9YuKAFcX/RSl0cLxCmoDA+AENQ943ITqQMfkBj7rN4TGod/jfIVlx9TNoLRvh3zmMmv8jwPzTbSE/C5E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=WP2Pe2L6; arc=none smtp.client-ip=209.85.210.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WP2Pe2L6" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-82748257f5fso4847571b3a.1 for ; Wed, 13 May 2026 06:11:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778677874; x=1779282674; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:from:to:cc:subject:date:message-id :reply-to; bh=wsFk6Og0o1PC9DlqH7Rg3d6wr5WjV/2ny+ljIhyfStU=; b=WP2Pe2L6oXwYZAIqerHUY2jAuvBDziO4BcAF9i3Pb+emXcqwkTFABpVZOMH3Ko/pno CzJayj5iwz5yhwYAdJuOZNaG8eGb0p6NyEr0ucleIkaFGgXft3rVGOE/dfxa4KmLxFWl w6F/jdjKBOenI1XJBRtTe9K8mcEkd2H1/7l6uC2N2JiN/9vQRlBW3XASZPDFQTQ0MK6z Aoal/rmw8eZOb6jm7+OgVV/dg196Y9SfClipaL96R/wJpIZTMVDpjPt4WwTvWjFz2oXj D+2CFKWiAbzblOB6nBb4EmE/tfY81VDM36T90zllVXUpn0hJ8tycl89xIksTN+CuS3Hp t2VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778677874; x=1779282674; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=wsFk6Og0o1PC9DlqH7Rg3d6wr5WjV/2ny+ljIhyfStU=; b=M6a+a+A56JEu3We/iwyKVoXp+nZO5Tvuxt+UFU5MBa+GGaMBz709v4SMXADQz15juO 0meBgm3jwRh7f92MN7cVNZurrfgk8M71Da8drrpcqYzdmdTUnwZdj6NB25D5zjFTktFi KH6Tw9gKWev9BPROOpnJf9+MvqNIHzJb7N42CcaSyLjbU7wG5uakcFCCtssb7hgxhzsZ yyag437ssdZ3cqy7ckEexxjs8QLqIn80OxBeSDfxihU9SVYQEOrTqBUGVjILmpQNpd/F nbVJA7T5yaeH5l9SMe7xq1vlJzyRENWXcAPIiECNoA6guu5lR8pt/uNgu3BHzt5aMEX6 k+qA== X-Forwarded-Encrypted: i=1; AFNElJ/PLJGLda3EWSJrMs9q9TYRLpmS4QrAAeUzDDN9+dWoFH6HAdZ7u1uO3i7Wl/OGue/82Zvcv9KgZ8YuJPk=@vger.kernel.org X-Gm-Message-State: AOJu0YwwWcH3zKFYqBiUu4gZlSBXG6E9hpASM6ZMxq1WDbjnyoS+ln1Y HHO4Hve39qwnMn9HDQLNVlncAamYUcrI3R8Ny3EWKGm/LnotkH5au6FH X-Gm-Gg: Acq92OErSelqliejG4c20Y287NoeccXaMxJwZq8jPFWGtVvmRc2SLyGYcoz0x/xydJV R0SU/GYz6pu+skXt56M9KyrZrDx/pQ2uaRDcxHDtIE9M1h2leoTZRlSPSW8xtVzz17kF8CPLe1k 2BzYWiD9yuaIIBWpKgLDLdbwDQ1LMu2Jj9OG04LA7s+auosGuSAae/U0wuGgT6Fj0d8pOk3a/ka Z/M0JNHRjLC3UcAVXYcoxP1TbI957C/xq1X7UPfKE4AE7cYE23nvmLUMuv8KTh7fB+RudKthImJ ctkJEHAkKCuBTAt4xWFOI1RfY7AFMrR5b39QYJe5K1Ifwl3uNxDG53oIXms2NDy6Yjuu9VUbAOd GLErCMoyn1C1lx3GJuW6GnaDrACg5ldXboITzXeN6VelcEbjTJfclxreCe8+n0QP3VAD4xfZOlV AKE/pTLvmFOaSTCvilqvJTcEe/+c1N/gVnopx7mMc= X-Received: by 2002:a05:6a00:3692:b0:82f:7cb7:63c7 with SMTP id d2e1a72fcca58-83ee8321af5mr6868969b3a.11.1778677874347; Wed, 13 May 2026 06:11:14 -0700 (PDT) Received: from localhost ([49.207.149.142]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-839659487afsm26237472b3a.18.2026.05.13.06.11.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2026 06:11:13 -0700 (PDT) From: Piyush Sachdeva To: Jeff Layton , linux-fsdevel@vger.kernel.org, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org, netfs@lists.linux.dev Cc: sprasad@microsoft.com, linux-kernel@vger.kernel.org, sfrench@samba.org Subject: Re: [DISCUSSION] Preventing ENOSPC/EDQUOT writeback errors on network filesystems In-Reply-To: <9e48229614786e0c2e92bb6a2dd3269868f160d0.camel@kernel.org> References: <9e48229614786e0c2e92bb6a2dd3269868f160d0.camel@kernel.org> Date: Wed, 13 May 2026 18:41:10 +0530 Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Jeff Layton writes: > On Tue, 2026-05-05 at 11:41 +0530, Piyush Sachdeva wrote: >> Hi, >> There have been plenty of discussions on how to handle writeback errors = for >> network filesystems, but most have focused on error reporting after the = fact. >> I'd like to start a discussion around preventing writeback errors specif= ically >> ENOSPC and EDQUOT, before they cause silent data loss. >>=20 >> The problem: >> With buffered writes on network filesystems (cifs, nfs, etc.), the write= () >> syscall copies data into the page cache and returns success immediately.= The >> actual upload to the server happens later during writeback. If the serve= r is >> out of space at that point, the write fails with ENOSPC. The netfs/write= back >> layer records this error via mapping_set_error(), but critically the fol= io's >> writeback flag is cleared and the page is now clean. Under memory pressu= re, the >> VM can reclaim these clean pages, permanently losing data that the appli= cation >> believes was successfully written. Meanwhile, i_size has already been up= dated >> to reflect the new file size. So stat() shows a file size inclusive of t= he data >> that was never persisted. Another inconsistency here is that total free = space >> hasn't been modified for the file system on the server, leading to incor= rect >> values in statfs() output from the client's pov (assuming statfs() calls= go >> to the server). >> To illustrate with real-world scenarios: >>=20 >> - A user or application can keep issuing writes to an fd well beyond the >> available space, since buffered writes return success as soon as data = is >> copied to the page cache. A significant amount of data, exceeding the >> available quota can accumulate before fsync() is called, at which point >> critical data loss is nearly certain. >>=20 >> - A malicious user can exploit this to keep resources pinned and memory >> oversubscribed, impacting other applications. >>=20 >> The error is technically observable: fsync() will return it, and close() >> surfaces it through the flush callback. But in practice, many applicatio= ns >> check neither, and the POSIX "just call fsync()" answer isn't satisfying= for >> users who lose data silently. >>=20 > > Yet, it is the only real answer we have. > > This is just a fundamental issue with buffered writes and delayed > writeback. Either you flush the data to stable storage now, or you have > to do it later. If you do it later, then it can still fail for all > sorts of reasons. > >> Local filesystems largely avoid this because they can check available sp= ace >> synchronously in write_begin() and fail the write() syscall directly. Ne= twork >> filesystems can't do this cheaply =E2=80=94 a round-trip per write to ch= eck server >> space would negate the benefits of buffered I/O. >>=20 >> Through recent development, netfs is becoming a central layer for network >> filesystem I/O. It already has retry logic for transient failures (EAGAI= N, >> ECONNABORTED), but ENOSPC/EDQUOT remain hard failures. This affects every >> network filesystem using buffered writes. >>=20 >> I am curious to know if NFS has a solution to this and what the approach= is >> towards this specific problem by NFS community? >>=20 >> This problem is worth solving for all network filesystems. I have a few >> thoughts on approaches, combining cached statfs() output with >> fallocate()-style pre-allocation on the write path: >>=20 >> 1. Pre-allocate space on the server before writing to the page cache, >> analogous to fallocate() on the write path. This guarantees server-si= de >> space for page cache data. >>=20 >> 2. Since per-write fallocate() calls require a server round-trip, effect= ively >> negating the benefit of buffered I/O. Use cached statfs() output to g= ate >> when pre-allocation is triggered. For example, once free space drops = below >> 20% of total space, enable fallocate() on the write path. Otherwise, = let >> writes proceed as normal. >>=20 >> 3. Handle refresh and synchronization of the cached statfs() data separa= tely >> to avoid staleness. >>=20 >> I'd appreciate feedback from the community on viable approaches. > > NFSv4.2 does have an ALLOCATE operation: > > https://datatracker.ietf.org/doc/html/rfc7862#section-15.1 > > ...and such an operation could (in principle) precede WRITE in a > compound, but that doesn't really help you. By the time we're issuing > RPCs to the server, the client application has already finished its > writes and moved on. > > For applications that want to avoid ENOSPC/EDQUOT, the best thing they > could do is call fallocate() themselves to ensure that the space > exists. With a sufficiently recent NFS client and server, that should > DTRT. Hey Jeff, Thanks for your email and for sharing the NFS spec. I noticed that the ALLOCATE operation ends up checking for space during write-back as well, and the initial concern of loosing data still remain. But if we do the operation before writing to the page-cache, it would be a performance issue. I will try a few experiments and then post my findings here.=20 -- Regards, Piyush