From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.15 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796221524; b=tqCGmT8xbxLZhGnCET2QoVhrl6g8CFcZ3ZJKpn7Qg8afIHYUAB6KLKBo5QtoHT4/ug3b ISdGnxqtrtAbTOMliZornWSIYeRvyPGNQVnCe72Q3jf/JVvXVbwFXvP8gM6vIj167UkuG zDuMmDBxcPMrkMPn9wF2Oyl50FKIobyrzDxVO8Bi1FCZ2G18jMikiwymv07Q2v9FSketn AdQOCaOJLt/tUQhGOLtzzVMVzqJWn2FBGxxSIR2o2ZbWZpn0B3i2+HuDmnlZmSjpObbkM L5zm+oVcNNiKpFhMobVHofV8HcdrG3JEYCoKPGpV7C5Q4cmU8XIhQnQOaVaFMGF5xlw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796221524; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=YH1GTgYrowMgZTpSHZZYiSUqVfU/O8T6a/X5jB8OFos=; b=kkr3WeP0rMlTw0eIbJPf3ykN1ELPS+xpVtkV/JiekkNytBag168v2n68B5Ds/0IIh1+Q eSxm6lFbq3sx51COQuIe1Kr9RIV7gYJ1sV5jw/KgkKqLd2jltNOGYjadMZyqiEIHAyuhW KVqSWZRVBuJ3St1xSHx96kTeaXUos6zHEfUBVo2Pr4iaEjCaGkPHEKzw4FFXEIYgVK5Uj T96dRj54Ei7DcHOENF71SQafFpgyqPwZyV3M8LkJniG1sLIeF0Bfk9S9oesjGDufNxD4r B8gl0ETclP9PAnHLw7WsChahYb454hC4yOOiONJEMdIXBc3eIOOfzLPU+4m63E1kelA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=sJLCgBHq; arc=none smtp.remote-ip=91.218.175.15 Received: from mta0.migadu.com (out-15.mta0.migadu.com [91.218.175.15]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 48644606A327 for ; Wed, 2 Dec 2026 14:25:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 48644606A327 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=sJLCgBHq X-Envelope-To: linux-rt-devel@lists.linux.dev DKIM-Signature: a=rsa-sha256; bh=762WJ5Js1QXCBon0iuRt6A27ZJKdp8J/riKNL+eUx+8=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796221521; v=1; x=1796826321; b=sJLCgBHq0iO0bZV7SUj9z/jCBZL7UgVVJ/7ACYUGYmHAUHG0PRLP2ITx0Xer214DtkJL/3q2 XeYYFdw5Uy0BHZWJdEccdcJxLdDGOD6/xqQjdPe2D0dt9qVVtyPgU3/x1Q3wocj/MIsTdsgwgL5 B/3oWDtN0oNqYWg3ATGncGtU= X-Envelope-To: linux-rt-devel@lists.linux.dev Received: by mta12.migadu.com with ESMTPS id f0d41061f7862f98; Wed, 02 Dec 2026 14:25:15 +0000 X-Mizu-Trace-ID: f0d41061f7862f98 X-Migadu-Flow: FLOW_OUT From: Usama Arif To: Andrew Morton , willy@infradead.org, jack@suse.cz, david@kernel.org, axboe@kernel.dk, Christoph Hellwig , hannes@cmpxchg.org, jlayton@kernel.org, brauner@kernel.org, tz2294@columbia.edu, ritesh.list@gmail.com, chentaotao@didiglobal.com, ziy@nvidia.com, bigeasy@linutronix.de, liam@infradead.org, vbabka@kernel.org, rppt@kernel.org, mhocko@suse.com, apopple@nvidia.com, byungchul@sk.com, gourry@gourry.net, joshua.hahnjy@gmail.com, matthew.brost@intel.com, ying.huang@linux.alibaba.com, clrkwllms@kernel.org, rostedt@goodmis.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-rt-devel@lists.linux.dev, kas@kernel.org, riel@surriel.com, shakeel.butt@linux.dev, kernel-team@meta.com Cc: Usama Arif Subject: [PATCH 0/4] mm: drop folios under writeback on POSIX_FADV_DONTNEED Date: Wed, 2 Dec 2026 06:24:35 -0800 Message-ID: <20261202142513.2951661-1-usama.arif@linux.dev> X-Mailer: git-send-email 2.53.1 X-Mailing-List: linux-rt-devel@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit POSIX_FADV_DONTNEED starts writeback on the dirty folios in the range without waiting for it, then invalidates what it can and skips folios under writeback. With small folios most bios complete while DONTNEED is still invalidating. With large folios on XFS a single bio can carry hundreds of megabytes, none of which leaves writeback until all of it completes, so DONTNEED right after writing a new 256 MiB file leaves all of it cached. This is affecting production workloads after a kernel upgrade that started using large folios on XFS: an application that writes files through a shared mapping, unmaps them and calls DONTNEED without syncing now fills its memory limit with page cache that DONTNEED used to drop. Patch 4 marks the unmapped dirty folios in the range dropbehind before starting writeback, and the unmapped folios still under writeback after it, so that writeback completion drops them as it does for RWF_DONTCACHE writes. Only regular files on filesystems that support RWF_DONTCACHE are marked, and not the folio extending past EOF, which an appender calling DONTNEED after each write would have to read back. Patches 1-3 fix dropbehind bugs that patch 4 makes easier to hit: 1. Migration does not copy PG_dropbehind, so WB_DONTCACHE_DIRTY leaks. 2. Lookups clear PG_dropbehind without the folio lock, racing with dirtying and cleaning, so WB_DONTCACHE_DIRTY drifts. 3. folio_end_dropbehind() can invalidate with interrupts disabled in a forced-threaded handler, as ext4 RWF_DONTCACHE overwrites did with threadirqs from v6.17 until commit 7d7c9c83c822. Patches 1-3 are stable candidates. With the series, new files and overwrites on XFS and ext4 were dropped within a second of DONTNEED apart from the folio at EOF; without the series most of them stayed cached. Alternatives considered: - fdatasync() before DONTNEED works, but blocks the caller and needs every application changed. - Restoring the PG_reclaim that DONTNEED set on these folios until commit 5c211ba29deb ("mm: add and use find_lock_entries") only moves them to the tail of the inactive list, still cached and charged. - Calling bio_complete_in_task() for every bio with a dropbehind folio would also catch folios marked after submission, but needs a pass over every write bio's folios before completing it. Limitations: - Folios already under writeback that complete in interrupt context stay cached. base-commit: 872ceec1e3caf227655a58f7407a9c8493dcf56f Usama Arif (4): mm/migrate: preserve PG_dropbehind across folio migration mm/filemap: clear PG_dropbehind on lookup under the folio lock mm/filemap: don't drop dropbehind folios with interrupts disabled mm/fadvise: drop folios under writeback on POSIX_FADV_DONTNEED mm/fadvise.c | 60 +++++++++++++++++++++++++++++++++++++++++---- mm/filemap.c | 30 +++++++++++++++++------ mm/internal.h | 1 + mm/migrate.c | 3 +++ mm/page-writeback.c | 23 +++++++++++++++++ 5 files changed, 104 insertions(+), 13 deletions(-) -- 2.53.1-Meta