From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.54.127.74 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796143024; b=4a24Iqup+zXl9OjNxFliqL4UlcdnUbYPKfx4af9KlVA2602nbO36TpD46QxiHmyKDfuC kWg/Slm7BxuQj/JRgGFcwGUnliT7CHQnFf31p7QV6R31zjggYVu44qiuY0q/urW78cc6T sXcZDaIKZoMoF6FumCiW5Tvmh8RfyOY4RDD3MvBeZjXwKfh0UMwKQ1kO9LWehvehj6LpY 7H0sMV1gsl7AogmjJVG1UPsaBaVLi8PL1PlG63esnlhzFq53aZT2BMSstfKpZeXQctE3a cjbFx6seHSQNE7FSNxwTZQDGqh+PiFUSHcqiyhtV7ssOxrDFWStVs3Q223eWjlShfXw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796143024; h=DMARC-Filter:Received:DKIM-Signature:From:To:Cc:Subject:Date: Message-ID:X-Mailer:MIME-Version:Assisted-by: Content-Transfer-Encoding:X-Envelope-From; bh=1Q7GzFouniF7QJHCkO31zk1h9zxXpyODSb/imxcB6Sk=; b=EhWpnMtY4slHfI7SHB2HWSa9SjBdFmYVU4q6SaRkkWrs+JDnmPvOGoZZzcC9roxrAH3Q n0ad/NSeDixh86tvCnxNKonoEPVDO1uIuxpiu9fMZLWMqQe0Gv4prSZ9z3i7leSr7mEvA WqwkE+EPn03mFsm/ldfvr56lAj9gcWm7vC9V1NdYrRxb1ZgP+3NYSTUHNYSNlOFdHE07k IZKSfolRAjMw4G7wvqMZvoEvt/kTOD+Ao1g6o2+NxDFnpzfFsE3GsYw4g9nCmf43p22ys J+RPobRd98vUKIOvhL2CsNJ6MdxPfEjAP3TOD9auP0Z+fPdsrxiDPzocbjYUeaUy3mg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=tychen.cc; spf=pass smtp.mailfrom=tychen.cc; dkim=pass header.d=tychen.cc header.i=@tychen.cc header.a=rsa-sha256 header.s=spacemail header.b=SFWOJjYI; arc=none smtp.remote-ip=198.54.127.74 Received: from out-zbxj-a74.jellyfish.systems (out-zbxj-a74.jellyfish.systems [198.54.127.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BFBBD606A31A for ; Tue, 1 Dec 2026 16:37:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BFBBD606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=tychen.cc Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tychen.cc Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tychen.cc header.i=@tychen.cc header.a=rsa-sha256 header.s=spacemail header.b=SFWOJjYI Received: from fedora (unknown [151.145.76.168]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.spacemail.com (Postfix) with ESMTPSA id 4jf63f55FXz8sWP; Tue, 01 Dec 2026 16:36:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tychen.cc; s=spacemail; t=1796143010; bh=1Q7GzFouniF7QJHCkO31zk1h9zxXpyODSb/imxcB6Sk=; h=From:To:Cc:Subject:Date:From; b=SFWOJjYIDlKAKVPYR1StetKNqpOLmtC+ofiPg7a5bEdEtXXtD/WaJzL3ldx/mwxKa hNArFNSN7C8hvGkLGsMQ2vmEGpXi2h2JyjCEjgKuWVBjye5fE8sStqRn97UBawVCfP smXctNWri36H/5Zz7qKLFnMMw2nUQLVCCU1XfQ4imLnx2fioehdrusCtLbCmkrM/6z dThECqLyQsBUWDBlQG84Df81To1/AIKa2qwSCpqnWPJYOH2COhFgdeeP6beXNlU/+x cR0eixv0VIYX4uoP7EVWfiB2Pi0qPlvzBQdgzl2XPGqrFXNLkyzYIZbhikuRkO+YMP uF+33FSKK4Igg== From: Tianyi Chen To: Jeff Layton , Chuck Lever Cc: Alexander Aring , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Christian Brauner , Jan Kara , linux-fsdevel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, hi@tychen.cc Subject: [RFC PATCH] filelock: trace the conflicting lock when a request is refused or deferred Date: Wed, 2 Dec 2026 01:36:02 +0900 Message-ID: <20261201163611.467129-1-hi@tychen.cc> X-Mailer: git-send-email 2.56.1 X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Assisted-by: LLM Content-Transfer-Encoding: 8bit X-Envelope-From: hi@tychen.cc A SQLite writer retrying F_SETLK never joins the kernel wait queue. When a frozen process held the conflicting lock in my test, the writer got EAGAIN but /proc/locks showed no waiter. The new event identified the blocker on byte 120. A later F_GETLK can only describe a conflict at query time, not the one that caused the refusal. Trace the request and conflicting lock together while fs/locks.c still holds the file-lock context lock. This also records blocking requests that are deferred and POSIX deadlock refusals; it does not change lock or freezer policy. For OFD and flock locks, blocker_pid is the recorded PID, not the identity of every task that can release the lock. This patch was developed with coding-assistant help. Signed-off-by: Tianyi Chen --- Would you prefer to limit this event to non-blocking refusals? Built and tested on mainline 19cc08c1a6a6 in one KVM boot (no dmesg warnings): no event on uncontended acquisition and release; the expected conflicts appeared for POSIX, OFD and flock refusals, deferred POSIX and flock requests, a POSIX deadlock, and the frozen SQLite writer case. fs/locks.c | 16 +++++++--- include/trace/events/filelock.h | 55 +++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 5 deletions(-) diff --git a/fs/locks.c b/fs/locks.c index 6e4ff7fce..5c3ab48c3 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -1178,10 +1178,12 @@ static int flock_lock_inode(struct inode *inode, struct file_lock *request) if (!flock_locks_conflict(&request->c, &fl->c)) continue; error = -EAGAIN; - if (!(request->c.flc_flags & FL_SLEEP)) - goto out; - error = FILE_LOCK_DEFERRED; - locks_insert_block(&fl->c, &request->c, flock_locks_conflict); + if (request->c.flc_flags & FL_SLEEP) { + error = FILE_LOCK_DEFERRED; + locks_insert_block(&fl->c, &request->c, + flock_locks_conflict); + } + trace_filelock_conflict(inode, request, fl, error); goto out; } if (request->c.flc_flags & FL_ACCESS) @@ -1260,8 +1262,11 @@ static int posix_lock_inode(struct inode *inode, struct file_lock *request, if (conflock) locks_copy_conflock(conflock, fl); error = -EAGAIN; - if (!(request->c.flc_flags & FL_SLEEP)) + if (!(request->c.flc_flags & FL_SLEEP)) { + trace_filelock_conflict(inode, request, fl, + error); goto out; + } /* * Deadlock detection and insertion into the blocked * locks list must be done while holding the same lock! @@ -1279,6 +1284,7 @@ static int posix_lock_inode(struct inode *inode, struct file_lock *request, posix_locks_conflict); } spin_unlock(&blocked_lock_lock); + trace_filelock_conflict(inode, request, fl, error); goto out; } } diff --git a/include/trace/events/filelock.h b/include/trace/events/filelock.h index f11284be0..93a1f064b 100644 --- a/include/trace/events/filelock.h +++ b/include/trace/events/filelock.h @@ -120,6 +120,61 @@ DEFINE_EVENT(filelock_lock, flock_lock_inode, TP_PROTO(struct inode *inode, struct file_lock *fl, int ret), TP_ARGS(inode, fl, ret)); +TRACE_EVENT(filelock_conflict, + TP_PROTO(struct inode *inode, struct file_lock *req, + struct file_lock *blocker, int ret), + + TP_ARGS(inode, req, blocker, ret), + + TP_STRUCT__entry( + __field(u64, i_ino) + __field(loff_t, req_start) + __field(loff_t, req_end) + __field(loff_t, blocker_start) + __field(loff_t, blocker_end) + __field(fl_owner_t, req_owner) + __field(fl_owner_t, blocker_owner) + __field(dev_t, s_dev) + __field(pid_t, req_pid) + __field(pid_t, blocker_pid) + __field(unsigned int, req_flags) + __field(unsigned int, blocker_flags) + __field(int, ret) + __field(unsigned char, req_type) + __field(unsigned char, blocker_type) + ), + + TP_fast_assign( + __entry->s_dev = inode->i_sb->s_dev; + __entry->i_ino = inode->i_ino; + __entry->req_owner = req->c.flc_owner; + __entry->req_pid = req->c.flc_pid; + __entry->req_flags = req->c.flc_flags; + __entry->req_type = req->c.flc_type; + __entry->req_start = req->fl_start; + __entry->req_end = req->fl_end; + __entry->blocker_owner = blocker->c.flc_owner; + __entry->blocker_pid = blocker->c.flc_pid; + __entry->blocker_flags = blocker->c.flc_flags; + __entry->blocker_type = blocker->c.flc_type; + __entry->blocker_start = blocker->fl_start; + __entry->blocker_end = blocker->fl_end; + __entry->ret = ret; + ), + + TP_printk("dev=0x%x:0x%x ino=0x%llx req_owner=%p req_pid=%d req_flags=%s req_type=%s req_start=%lld req_end=%lld blocker_owner=%p blocker_pid=%d blocker_flags=%s blocker_type=%s blocker_start=%lld blocker_end=%lld ret=%d", + MAJOR(__entry->s_dev), MINOR(__entry->s_dev), __entry->i_ino, + __entry->req_owner, __entry->req_pid, + show_fl_flags(__entry->req_flags), + show_fl_type(__entry->req_type), + __entry->req_start, __entry->req_end, + __entry->blocker_owner, __entry->blocker_pid, + show_fl_flags(__entry->blocker_flags), + show_fl_type(__entry->blocker_type), + __entry->blocker_start, __entry->blocker_end, + __entry->ret) +); + #define show_lease_break_flags(val) \ __print_flags(val, "|", \ { LEASE_BREAK_LEASE, "LEASE" }, \ base-commit: 19cc08c1a6a650f8e54c0461ff198be6448f425d -- 2.56.1