From patchwork Mon Jun 24 07:41:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Guzik X-Patchwork-Id: 13709118 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFA33C2BD05 for ; Mon, 24 Jun 2024 07:41:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 813106B043D; Mon, 24 Jun 2024 03:41:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7C4546B043E; Mon, 24 Jun 2024 03:41:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 68BCE6B0440; Mon, 24 Jun 2024 03:41:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 48B026B043D for ; Mon, 24 Jun 2024 03:41:48 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E8DB7160C45 for ; Mon, 24 Jun 2024 07:41:47 +0000 (UTC) X-FDA: 82264987854.14.83F6B51 Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) by imf18.hostedemail.com (Postfix) with ESMTP id 1DB541C0006 for ; Mon, 24 Jun 2024 07:41:45 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="Sb4/LNDd"; spf=pass (imf18.hostedemail.com: domain of mjguzik@gmail.com designates 209.85.208.175 as permitted sender) smtp.mailfrom=mjguzik@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719214900; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=oXBCIub9Fx6A3rK4w/i/XPN7m1LBrK8LUX9NK9s/egM=; b=Ypi8oykkLSJmZLUnWcYSgQjWkoVP1mkSYlp/HZ1k3kx6Vi2np2Hssm9I1SW1wGhL0ZlO6m d4lkr+CYsShkBlUuEQCKkcE/TSR3cz+QAwkAPMJvSPS7SlDIPZKuHCJVsPnm9WAMBRUDoQ uhWB4d6JV03CuQKqkqfsfrTFObWwyTw= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="Sb4/LNDd"; spf=pass (imf18.hostedemail.com: domain of mjguzik@gmail.com designates 209.85.208.175 as permitted sender) smtp.mailfrom=mjguzik@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719214900; a=rsa-sha256; cv=none; b=dG1jaKqElOAnQf5USB04Lw2hTA6QJSANt8CUjOMBqXYQAvao+olfvmh6IQe3inzMBhmS5C 1f2xKXGLTmSy1RQPrC1B384Oqe5vfXCvrjHa2xHXnfkraZg2dIWs9KQ5q0As3FASeOjLeq 6wjNedLaUzPxMDgEgv0ctUx0e8/kW0w= Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-2ec595d0acbso13465801fa.1 for ; Mon, 24 Jun 2024 00:41:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719214904; x=1719819704; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=oXBCIub9Fx6A3rK4w/i/XPN7m1LBrK8LUX9NK9s/egM=; b=Sb4/LNDdrJW6/xclOxB5Ki5xzvVGw7e4ShAfCVdO18DcJ0+p2gkUfPRZ0xyjse6Gvq G2NxJ3bgwu7Rze/lrXEMnsUIHRHF8//xhqZeBL8N5xGEArqTa3C3CtGnhv9cURDZ5e6J GBABCW0dTjH0VEGAHmYaiVVv09RD5QzyaM5JvSTwvpGAtB+G/mcvXyczX8GG9MeqG5GH K4UxMRhC31sdgs9dXQJeFXp9L0+bGIB4jv9oYMRmr7OdtksdlhcILMZ5lmpJ6B6c9i4A ncQuUaJy48oap44p/FJGphJDzC7tgCpVCUePBWN43f084q2qqSpwiun0kh/y/Vvwkd64 0zkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719214904; x=1719819704; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=oXBCIub9Fx6A3rK4w/i/XPN7m1LBrK8LUX9NK9s/egM=; b=vhUP7Qluq9+BW9yvNoJCll1ZZaIH0zobV7f4sGhUcGAj7WxKBEebKIxoPo6pcceZWx vbbIXxYDVNntazoN5LRWZDOwXZDq+k3/puT2v0PiFCzhmRrmzTGPUk9gak6u+Ccrg80e NMUWB9YK3hixnxfv+VMb2hxsnvpTdgLS4uGiBF1UxNpjOlul7i8cgmr6vHhvcoQhTIMv l7e3gEblQtfUjoCQU54NSfgVBK0GRhWb99w4Mi9nZ5aUSXyLcUomMiCbEsJ24Gb5DqWl XUkfYVptdmFK/DBiOvDZvG0FB+ge3/tn6VNeMVMxo2/6JgER/lH9NUFuI0cVGGjTCpy6 zoTw== X-Forwarded-Encrypted: i=1; AJvYcCU0fCDwHGXgyqntpcESUkMS3GzCfMmzRfWuFOPmY9ei1enSaBvpCZhDoN4uxO7OzzLmCE6Ue6nCoWnH+n9LaHphePU= X-Gm-Message-State: AOJu0YxyXdmJPDLel+xmYl844x5IaY6dZv8APL3zz0Y9+4RtO4vdqk9o swVHk4ypNVs/hceTOxfBh3dqW2cbwZDyKUSF7ZWEj0VGYRTXZiFM X-Google-Smtp-Source: AGHT+IG11fsxSsN23a0lExAwPS2/6Bzf3b+gb697LzAFSY2k3/HMvphibAWbFWauunANWEB252UUcA== X-Received: by 2002:a2e:720c:0:b0:2ec:4e79:b416 with SMTP id 38308e7fff4ca-2ec5b2fc299mr27368231fa.6.1719214904154; Mon, 24 Jun 2024 00:41:44 -0700 (PDT) Received: from f.. (cst-prg-87-23.cust.vodafone.cz. [46.135.87.23]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57d30535010sm4370063a12.59.2024.06.24.00.41.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jun 2024 00:41:43 -0700 (PDT) From: Mateusz Guzik To: cfijalkovich@google.com Cc: brauner@kernel.org, viro@zeniv.linux.org.uk, jack@suse.cz, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Mateusz Guzik Subject: [RFC PATCH] vfs: wrap CONFIG_READ_ONLY_THP_FOR_FS-related code with an ifdef Date: Mon, 24 Jun 2024 09:41:34 +0200 Message-ID: <20240624074135.486845-1-mjguzik@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 1DB541C0006 X-Stat-Signature: 59fqwmgrafz5oh9kw7wuba7cctypa5td X-HE-Tag: 1719214905-148090 X-HE-Meta: U2FsdGVkX19LTMs+KyfHhdSvHZuflBE5Fsf3JMQ3AgtyATQts8UC+n/1t79B05CGwqM9UgteJjhGV+ohJhOtDcSewwJ6L3AGZLM4lAE0G/Y3ocjTfxxqvAZ+ys2JqnukqG8VRnY2J9sM6DDo5f7jU9RLOenS7I+wHYQv454pESR7P0wICRw8n85eRg5OagjzNINAffkao7yLZ+YsIchgS1WvAtly5dwOWMlwjlGdxAoMg6OJGv18K1jypugzGy0R3uxKe6zudUlIV8ShN+ZPWaK6+5qyxplD560MRVzuJSEDeOGfTHT8CW7PVIz/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pseblA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000677, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On kernels compiled without this option (which is currently the default state) filemap_nr_thps expands to 0. do_dentry_open has a big chunk dependent on it, most of which gets optimized away, except for a branch and a full fence: if (f->f_mode & FMODE_WRITE) { [snip] smp_mb(); if (filemap_nr_thps(inode->i_mapping)) { [snip] } } While the branch is pretty minor the fence really does not need to be there. This is a bare-minimum patch which takes care of it until someone(tm) cleans this up. Notably it does not conditionally compile other spots which issue the matching fence. I did not bother benchmarking it, not issuing a spurious full fence in the fast path does not warrant justification from perf standpoint. Signed-off-by: Mateusz Guzik --- I am not particularly familiar with any of this, the smp_mb in the open for write path was sticking out like a sore thumb on code read so I figured there may be One Weird Trick to whack it. If the stock code is correct as is, then the ifdef as above is fine. The ifdefed chunk is big enough that it should probably be its own routine. I don't want to bikeshed so I did not go for it. For a moment I considered adding filemap_nr_thps_mb which would expand to 0 or issue the fence + do the read, but then I figured a routine claiming to post a fence and only conditionally do it is misleading at best. As per the commit message fences in collapse_file remain compiled in. It is unclear to me if the code following them is doing anything useful on kernels !CONFIG_READ_ONLY_THP_FOR_FS. All that said, if there is cosmetic touch ups you want done here, I can do them. However, a nice full patch would take care of all of the above and I have neither the information needed to do it nor the interest to get it, so should someone insinst on a full version I'm going to suggest they write it themselves. I repeat this is merely a damage control until someone sorts thigs out. fs/open.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/open.c b/fs/open.c index 28f2fcbebb1b..654c300b3c33 100644 --- a/fs/open.c +++ b/fs/open.c @@ -980,6 +980,7 @@ static int do_dentry_open(struct file *f, if ((f->f_flags & O_DIRECT) && !(f->f_mode & FMODE_CAN_ODIRECT)) return -EINVAL; +#ifdef CONFIG_READ_ONLY_THP_FOR_FS /* * XXX: Huge page cache doesn't support writing yet. Drop all page * cache for this file before processing writes. @@ -1007,6 +1008,7 @@ static int do_dentry_open(struct file *f, filemap_invalidate_unlock(inode->i_mapping); } } +#endif return 0;