Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp937567lqs; Fri, 14 Jun 2024 09:43:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVHPGdx7stYhaVqdjaEgNMkatjtFaBHL5GkWcdixRPSTGQKmV8dqR3OXEw0k5uCyKpM+h7pWnZPQYce9lUaU8AJDVyPlZ4F1aq9yZdiqA== X-Google-Smtp-Source: AGHT+IHn08AuK5/YCdBDCC6Ud4BKZrQhY7ctOuG8fhz/nqKS/PdfX87+hcVfbxvecezieczcU12W X-Received: by 2002:a05:6a20:9189:b0:1b7:bdb3:7bb7 with SMTP id adf61e73a8af0-1bae7f14565mr3936404637.35.1718383419879; Fri, 14 Jun 2024 09:43:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718383419; cv=pass; d=google.com; s=arc-20160816; b=sKK188LzJRr0yMjRd9HsKUSs2zuMC0Wie/MM0a6fxG0a8Aou46eNU3k2uAgPchogF4 IwcvRBlLwBsG5ofM+ETjsvxo/39gAM+u67nvsIcIGICV0zYdvmqG5X2HCgVpTlTxxBK0 LcD43rZqLeBfjJupMqW6yAB14nifBE5ep/DAPh+ujEWm7ucOAM5WcDQuxPp83tIgbHIR vI7h/F5404bBqz4GHOdQ+tloclC4UUcrnLf4GgxJgOK13qqlNFJX9r3EMjldd77VSr6L XYhTXC8CHAxdIUaRoqEFIxtcj6fq/NMjJ7IBAUjBhoJMuXl5Osb++WagNhbIWAT1A6Aj aHDg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=OkMAaD/1F3nx3NbNbMXDMTg/kcKLTKRI30nhhnR9lI4=; fh=g8QqGHOWWm4utLeC66qTu1fvtAi2WK8UyNYLFnjVwKI=; b=nghe7VBcT7URbwfZmUxB4PQfWu/dkUN/WoAvA4NJsH+OSVmdP5J7QLpQpRGMS6kIZQ BFNxHzxoRKODCWCvOYI306bMrVr7mRiwFI0N0NZ14+qmZcEPC+eJq9200DtP5ksv+DXd MCflkgH85d9EWPqUslHPf8K24HEdXnlLdm3RP3UThIj1yoSeMy1OCJYAzU5pCffvNlmf mckCpwxW7WaQplwVADJ5LzmImry19Gt+5Y5SZKjCsCYUQbhOfwWIoEFHPZYjH5kxsmlS gpY7Oaj2k/dUDNdKRri3PcXZgG070+Sydys7JVcVHnzF34sz/avlRNFeSkhR0kj3Xq47 PJag==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VB20f3hC; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-215204-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215204-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2c4a75f3c18si5966812a91.52.2024.06.14.09.43.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 09:43:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-215204-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VB20f3hC; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-215204-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215204-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id B2A39B253BF for ; Fri, 14 Jun 2024 16:10:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2C8E619E7F0; Fri, 14 Jun 2024 16:09:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="VB20f3hC" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8FC219D068; Fri, 14 Jun 2024 16:09:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.17 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718381342; cv=none; b=Db4qomzak/+95p8h0TK9JuZjJD9cMzLLZuX/qIF/sBoATsvSLH7SWND0/XT4E3jQA9/vSmnLmnkVNzjAYHGz/tLLL1FggCNiOT4UJZrhwu4tXn6kJdG79m6WJU1GCP/tOq/Yym/Khwu04QdjilquZmVa/vjBnGPY3xcEfeHhMdk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718381342; c=relaxed/simple; bh=7j/faoRXzWh8uYOzQ7IXFB9d5L6kjkr5xK99YDrC7To=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QF/pk05xc1Y9bgz27SK+yD9gSzQfrGjxGuFQQ+8MicztL7WoWuotsD7uryKBgSi3GHH14chE/3dXWPfM+fCs+3jne5TjmTPrOHDyziZQlerYODWsXbmz1Inw+XTXVUiGfyzkFcFEOKaKmELvu9vnPNnD/UOuIA5KhWMCbSFtt0c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=VB20f3hC; arc=none smtp.client-ip=198.175.65.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718381341; x=1749917341; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7j/faoRXzWh8uYOzQ7IXFB9d5L6kjkr5xK99YDrC7To=; b=VB20f3hCKJcgOMYIFt4PpDglZ4g2NbLrdeQ4Ok27fSkFjrq9Tno+dNx7 Twzvxth4nNgcUfBNu8J5z4Lp7ekB4PyNkDFKsRISSconfl40Xlm/uIreJ rx6n/h+iR5YEiNjVk0SRieRWW4FvGux98+AKqAKNJVpD7LauFaq58kN27 npclSeVZuSCFUkut7pR1vxX72eq3uJPZkiWcF8zqBmQ0Yl9Z86gojCoLc Bkc0gNFF1Fc23EWgODtAwPhXj4brmPnfNRM8mNPnTsy7fSvE4xk+71kBX uHcNAqsLFI3Cf/n+NBUJwVz6PprqvauBDrr9XPzHeXIr8+vXVrfXC4pJh w==; X-CSE-ConnectionGUID: rur5bjjARpSF1Z+kfpxQRA== X-CSE-MsgGUID: aiTmifgOSJSUm6/oEbx1Pg== X-IronPort-AV: E=McAfee;i="6700,10204,11103"; a="15399431" X-IronPort-AV: E=Sophos;i="6.08,238,1712646000"; d="scan'208";a="15399431" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jun 2024 09:09:00 -0700 X-CSE-ConnectionGUID: Y2zZfm5BTlukoOmsTXo3aA== X-CSE-MsgGUID: koUQl62rTAqdHC4GeeJaBA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,238,1712646000"; d="scan'208";a="71741096" Received: from linux-pnp-server-16.sh.intel.com ([10.239.177.152]) by fmviesa001.fm.intel.com with ESMTP; 14 Jun 2024 09:08:58 -0700 From: Yu Ma To: viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, tim.c.chen@linux.intel.com, tim.c.chen@intel.com, pan.deng@intel.com, tianyou.li@intel.com, yu.ma@intel.com Subject: [PATCH 3/3] fs/file.c: move sanity_check from alloc_fd() to put_unused_fd() Date: Fri, 14 Jun 2024 12:34:16 -0400 Message-ID: <20240614163416.728752-4-yu.ma@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240614163416.728752-1-yu.ma@intel.com> References: <20240614163416.728752-1-yu.ma@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit alloc_fd() has a sanity check inside to make sure the FILE object mapping to the allocated fd is NULL. Move the sanity check from performance critical alloc_fd() path to non performance critical put_unused_fd() path. As the initial NULL FILE object condition can be assured by zero initialization in init_file, we just need to make sure that it is NULL when recycling fd back. There are 3 functions call __put_unused_fd() to return fd, file_close_fd_locked(), do_close_on_exec() and put_unused_fd(). For file_close_fd_locked() and do_close_on_exec(), they have implemented NULL check already. Adds NULL check to put_unused_fd() to cover all release paths. Combined with patch 1 and 2 in series, pts/blogbench-1.1.0 read improved by 32%, write improved by 15% on Intel ICX 160 cores configuration with v6.8-rc6. Reviewed-by: Tim Chen Signed-off-by: Yu Ma --- fs/file.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/fs/file.c b/fs/file.c index a0e94a178c0b..59d62909e2e3 100644 --- a/fs/file.c +++ b/fs/file.c @@ -548,13 +548,6 @@ static int alloc_fd(unsigned start, unsigned end, unsigned flags) else __clear_close_on_exec(fd, fdt); error = fd; -#if 1 - /* Sanity check */ - if (rcu_access_pointer(fdt->fd[fd]) != NULL) { - printk(KERN_WARNING "alloc_fd: slot %d not NULL!\n", fd); - rcu_assign_pointer(fdt->fd[fd], NULL); - } -#endif out: spin_unlock(&files->file_lock); @@ -572,7 +565,7 @@ int get_unused_fd_flags(unsigned flags) } EXPORT_SYMBOL(get_unused_fd_flags); -static void __put_unused_fd(struct files_struct *files, unsigned int fd) +static inline void __put_unused_fd(struct files_struct *files, unsigned int fd) { struct fdtable *fdt = files_fdtable(files); __clear_open_fd(fd, fdt); @@ -583,7 +576,12 @@ static void __put_unused_fd(struct files_struct *files, unsigned int fd) void put_unused_fd(unsigned int fd) { struct files_struct *files = current->files; + struct fdtable *fdt = files_fdtable(files); spin_lock(&files->file_lock); + if (unlikely(rcu_access_pointer(fdt->fd[fd]))) { + printk(KERN_WARNING "put_unused_fd: slot %d not NULL!\n", fd); + rcu_assign_pointer(fdt->fd[fd], NULL); + } __put_unused_fd(files, fd); spin_unlock(&files->file_lock); } -- 2.43.0