From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 7D09C3DDDB8 for ; Tue, 31 Mar 2026 16:09:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774973346; cv=none; b=pbxfMP23Lk6vVkBP2p8PHYqxDcku/G5G82Q3QAeNSTSi8cmpMp2l/i8GYwjA2LRzOJlWl4jTTU2KR5RtuVGJvpd9NswTNfwJpv2dDVqctChpdMGnqT2YqYJsHrNSHXYv3ePe9u2mmblK6ygt80RF0hm58UQNizupyjepo2PfhCI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774973346; c=relaxed/simple; bh=8NiHJoWnyGoLZ8HlXI8Q5nWgT65wTTBn8F+eVynsvFQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ryqSy3eHySPkUCgOubobZ25SIjgxpCGDjrTGRXGF0pKXpwhgnXRDuh3rrfisStUfZmgAK7gjjTkDiQml3Z9jbPjfi6mcDUIq0kvPm9VagBMFdS0lqKxvoY0yHnHEbQv7/Abhcmm19/z0R+Wgf+FdRT6sdJV783+1XJ6t1FmCdhI= 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=iwE+ZFkd; arc=none smtp.client-ip=209.85.221.44 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="iwE+ZFkd" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-43b41b545d9so6385310f8f.2 for ; Tue, 31 Mar 2026 09:09:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774973344; x=1775578144; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=z6nIkg+M4Ho56ulVSYXGONPVGSrDDqFsxVsA34jDwtk=; b=iwE+ZFkdOR4VYxDL8E50EcZJNNvyiV9mcApXuaOc5IeWOkPiZr3BL5oqsSHqEoinS+ 9rsFThrKKJs0KMgdVadxT+6IGhcaq8b2Z/YSUgtMId2vodDhLtqc3jAlsKGALCaV9XFk ifZOHeOriMVIcs/pUK57zSmLDl3CBKcteS06Y6VT3zhEuD6gNZ+hDmVeQJ5zWbVDrIhs HgPRVlM3QHTHQHC/7kKyQLnebvn6hTFiUjhctHHzOHVRTdn9whOso5ovs8Ybj85zHZSY jKeS1w3NBb0kPIWR7U6fQK1Yqj4n5pmTWOUZSnj4SJpRbrUqRzTZ6XAkZYhTXdYP5o/q RDHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774973344; x=1775578144; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=z6nIkg+M4Ho56ulVSYXGONPVGSrDDqFsxVsA34jDwtk=; b=SeZf0512U+qNggG2UElSgO4vZhcCe57kLKLjjg3sGrx+vbzmEzInhELDVTiPeLXb0j ccQxubDC+PzbLf2Z4+w/BWyy7wbgiLszZ+EC0tgZ+27yn2hcqTpvnkXyTWlH7JtYT6BR me9GFKWpF/yQuq6spXP5+3/yHqc0cibQFT1sMbq4DDWVuD1MiGm6+uwOBCzTettUFiA0 aSXMnCXpaA6FxGXX/+MUswqHQG1zM0lBVYTwZg0Mjg6+n4DJsdOX13gkug0OCqw97C4q UlPY174DrfdTktbkPfa64hQeDH7xYhoNnQXHgXRQbN5+LYuJUckDpr70cxRl9atSHBvb YHqw== X-Forwarded-Encrypted: i=1; AJvYcCXl6fXagqPf0JGPncB+Uoee9KDkisLfDl6zeJbzGnOFeaatxJt2sz1qbQsgm3L8/7z6+YQhoM7O0q5TXmE=@vger.kernel.org X-Gm-Message-State: AOJu0YxYdViwLOv8p+aA84XcOLDl+egD5H7EuPMGy0/t2ILrzO2kITv/ S3BRRRcKomYhbDdx5R79TJeFMS4Pm+wKXdEwWXetR2sJlgG/qKA1Qr06 X-Gm-Gg: ATEYQzwlAvlsmMAEcb6RbOiwhcYyHB+uJGbsGgVFKc4GZvtQu02qIEJu+YMfsNOMQjn ALNtbOdK27jLBY2Xc50LjYnLTVT0nCeghIA09ylP/FIvG02pUinH9sikXkk9xgOIv7UJ+dxOwwn LxvdP+xCUnF9VGjpDUKNt1Y4Lg+bj73cMDGk1VlOaniJ7Ge+lha4vUWIoWMpK+XqD5gysI9uGHy e1g+Q6ajJdYJxEyzXN17t8mImUUp0JAsEIpN0MaflO2+RqxCVWVDzo3YfuAgrtRpKTSzkAfSXGs rIq7VPnpHbkB6xkvBkGie25qoUQqN6kH7q5H8YRQ85rqiC/zpNgxnZ5KXUs32wpX1MGAxOGAaAf KHXNS7e72vG4+ALWMwvv3mVq5BHWhU5W3irj6MEc5Fqp0Ab4QYwt+d8KVpN5lJKaeVDqjZTcAHM cbnYIyBtSd8Nua9PladNuO1r5bfbL3Jt2ixBBe9kNQXNo3r5n13pa2J12AqIGR9EKg4mKNJ5Pwm Q== X-Received: by 2002:a05:6000:1a89:b0:43c:fbde:3101 with SMTP id ffacd0b85a97d-43d150e0f1cmr394102f8f.41.1774973343541; Tue, 31 Mar 2026 09:09:03 -0700 (PDT) Received: from f.. (cst-prg-89-171.cust.vodafone.cz. [46.135.89.171]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43cf21e3602sm28792632f8f.4.2026.03.31.09.09.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2026 09:09:02 -0700 (PDT) From: Mateusz Guzik To: brauner@kernel.org Cc: viro@zeniv.linux.org.uk, jack@suse.cz, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Mateusz Guzik Subject: [PATCH v5 0/4] assorted ->i_count changes + extension of lockless handling Date: Tue, 31 Mar 2026 18:08:47 +0200 Message-ID: <20260331160851.3854954-1-mjguzik@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The stock kernel support partial lockless in handling in that iput() can decrement any value > 1. Any ref acquire however requires the spinlock. With this patchset ref acquires when the value was already at least 1 also become lockless. That is, only transitions 0->1 and 1->0 take the lock. I verified when nfs calls into the hash taking the lock is typically avoided. Similarly, btrfs likes to igrab() and avoids the lock. However, I have to fully admit I did not perform any benchmarks. While cleaning stuff up I noticed lockless operation is almost readily available so I went for it. Clean-up wise, the icount_read_once() stuff lines up with inode_state_read_once(). The prefix is different but I opted to not change it due to igrab(), ihold() et al. There is a future-proofing change in iput_final(). I am not going to strongly insist on it, but at the very least the problem it sorts out needs to be noted in a comment. v5: - reword some commentary - add unlikely to the new icount check in iput_final() v4: - squash icount_read patches - use icount_read_once in the new ihold assert, reported by syzbot - squash lockless ref acquire patches, rewrite new comments v3: - tidy up ihold - add lockless handling to the hash Mateusz Guzik (4): fs: add icount_read_once() and stop open-coding ->i_count loads fs: relocate and tidy up ihold() fs: handle potential filesystems which use I_DONTCACHE and drop the lock in ->drop_inode fs: allow lockless ->i_count bumps as long as it does not transition 0->1 arch/powerpc/platforms/cell/spufs/file.c | 2 +- fs/btrfs/inode.c | 2 +- fs/ceph/mds_client.c | 2 +- fs/dcache.c | 4 + fs/ext4/ialloc.c | 4 +- fs/hpfs/inode.c | 2 +- fs/inode.c | 122 ++++++++++++++++++----- fs/nfs/inode.c | 4 +- fs/smb/client/inode.c | 2 +- fs/ubifs/super.c | 2 +- fs/xfs/xfs_inode.c | 2 +- fs/xfs/xfs_trace.h | 2 +- include/linux/fs.h | 13 +++ include/trace/events/filelock.h | 2 +- security/landlock/fs.c | 2 +- 15 files changed, 130 insertions(+), 37 deletions(-) -- 2.48.1