Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp916126lqs; Fri, 14 Jun 2024 09:09:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVBibLtfS2DDh+Y4wgijTfsbDXZwMPOZF8wo4N/xOqYhlXKlAvZsil7T+2HgIVQlhT1EH5sp6x6OUecCjB9+X5kiKRNSNumPYCkEvJdYQ== X-Google-Smtp-Source: AGHT+IF/jqfFYmPGSpX9BTcCqnMhL3G6h00uMiTUzo9+x0y8g7LSQd4moddg24xjZBH/1CMrYI7e X-Received: by 2002:a17:907:86a6:b0:a6e:4e0:8a56 with SMTP id a640c23a62f3a-a6f524740c7mr579088766b.32.1718381391865; Fri, 14 Jun 2024 09:09:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718381391; cv=pass; d=google.com; s=arc-20160816; b=SHRa9ehRtBUedA2C7XPflGKNwur286zxCeqXSMswEUH/2EvfubnWQCZZvUmirIHOIH 1Z5v8ZBM25AaHcFeuXs4OSfFB5FwHLGAtoEHlfcvzWZpHj16hkoMKD8Lr1rkY+xt5RmJ FVmBdtf9CxvU9YC8Xkz9d3ra8dck2s/TayvOdx+g9TJH1tCGIJ54ZdDUrefwzfbCLSTE to/QhBZM5VaCuZ0/MU2ogrqY+tXPC2cattssfUfGPNBEn5DyOCtWED7QDbaOakV+o8D1 sgg/hN9e/p20lzh7NJBTpqJ/AQ5BGXvpBqTe11o3I3m3aJA/KYDd1t1JG1AcdOJU69KC X/SQ== 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=0hAKD4tdrnYVynLpr5DvjQNcNA/jB+gYVWWIMn1vLoc=; fh=g8QqGHOWWm4utLeC66qTu1fvtAi2WK8UyNYLFnjVwKI=; b=rJJANSMQykKw9HdcQy73oecxqEqmKpSlcfNOplCbmEkU2qNvJOdF0tz+uyB0EiRBOL 1+wfdp7c6t2JoEBC8I4e8KC6QKEkD3RUEsKh1vG8pZIPZNwsZxy8gswDFt/kbrOp9VMS 0Px/fAK68cb0aVI0UEL6wXh2b0uQvAK2VrJLnqa9Q9QZrOI6mvKgPdXJPHll7Tb50FSk fH/LhTEDCLGzjrUto4sQyUV9MVPLjQGKUfzoYEMNz5SWJm2k0R1h7DEOjJioJfUuFx7e zfP5QGmjie4W2ftdSihwlXTRtuNoD9DuNJUaT2rDVH+VN70o+Tj1Gmt8vKe9J14VIHY4 bO2Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KJemTTI4; 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-215201-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215201-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f5d0a18e0si155631466b.471.2024.06.14.09.09.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 09:09:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-215201-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KJemTTI4; 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-215201-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215201-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 978C41F21A9D for ; Fri, 14 Jun 2024 16:09:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 034B519A29B; Fri, 14 Jun 2024 16:08:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="KJemTTI4" 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 76299181323; Fri, 14 Jun 2024 16:08:54 +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=1718381336; cv=none; b=FqCXoUSiBf9M+Q0wrEXYS2sfpG50GhDTa4W48DTurcBDPuyKcsURQMIG6Wo7czRw6//YebHkK/ycuN+J9LCzN6LGiHBFktep4B1eiVCSoju+hLgyuuvpGGI1nWUeGCf+ctLI0mANWawOA6Z75GluYu95BHEg986U0xfHLAS6www= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718381336; c=relaxed/simple; bh=PW1CwgwF4DEJPAtCw5E8u2zb9VKV5pgVkPiDLQwmwMg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kRDwojqr4km8qBGEjgG6gCgKqhQN/rgsgqGe3tnwaD/ISLh9XVZinIoQJfcosNyY9Tgj7ZVWW0bUYYMmmLwFS9/mKu/fgBvfiosl9bMorBQ0Kt2epL0qZFhD3BT4LntvVc1sVXKBuM6bvjw2kBjhwgSJasBtGIFB7QdNPW8o8Vo= 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=KJemTTI4; 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=1718381334; x=1749917334; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PW1CwgwF4DEJPAtCw5E8u2zb9VKV5pgVkPiDLQwmwMg=; b=KJemTTI48iVgiG+z1cqTsCyZOSKwMmF+owKz8g7Lp7FxJjfr7PUwsgYY Vs6gFTXhIjtjuPqRzgSZYldKayrG4d8KbX7dSTvp8a9xonaVqU1lyy+OC R1Oez9MMFLsVnLZOLNO+dkudMILQwfAsGV1NVuX1DArzuSqAPx3LCjvaM rGBQiE/P8Y+a6YXX7p1Et4cF0Hb7b/Ou51A15ADxlUnaqXdkkkwSmRgoG cN6FW+PTVgbUtRLx+15HT3GZuQhMu7SMZ241Wy21x5Ue/pXUIQFhV4+s5 J/hhxElhvjbVAAnhODvvvNYUBVU7ef9iQ+UeJfJOrJCxKYjvbu3IEewU9 w==; X-CSE-ConnectionGUID: ipZD0eH/RSCv9qktbPlTlQ== X-CSE-MsgGUID: uf3cEddyQHyZOPtJS2A3lg== X-IronPort-AV: E=McAfee;i="6700,10204,11103"; a="15399385" X-IronPort-AV: E=Sophos;i="6.08,238,1712646000"; d="scan'208";a="15399385" 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:08:54 -0700 X-CSE-ConnectionGUID: yBxsODLRSlK45G+x8PXgMA== X-CSE-MsgGUID: ygVkJ34WQKyUBeRivbolNg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,238,1712646000"; d="scan'208";a="71741074" 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:51 -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 1/3] fs/file.c: add fast path in alloc_fd() Date: Fri, 14 Jun 2024 12:34:14 -0400 Message-ID: <20240614163416.728752-2-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 There is available fd in the lower 64 bits of open_fds bitmap for most cases when we look for an available fd slot. Skip 2-levels searching via find_next_zero_bit() for this common fast path. Look directly for an open bit in the lower 64 bits of open_fds bitmap when a free slot is available there, as: (1) The fd allocation algorithm would always allocate fd from small to large. Lower bits in open_fds bitmap would be used much more frequently than higher bits. (2) After fdt is expanded (the bitmap size doubled for each time of expansion), it would never be shrunk. The search size increases but there are few open fds available here. (3) There is fast path inside of find_next_zero_bit() when size<=64 to speed up searching. With the fast path added in alloc_fd() through one-time bitmap searching, pts/blogbench-1.1.0 read is improved by 20% and write by 10% on Intel ICX 160 cores configuration with v6.8-rc6. Reviewed-by: Tim Chen Signed-off-by: Yu Ma --- fs/file.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/file.c b/fs/file.c index 3b683b9101d8..e8d2f9ef7fd1 100644 --- a/fs/file.c +++ b/fs/file.c @@ -510,8 +510,13 @@ static int alloc_fd(unsigned start, unsigned end, unsigned flags) if (fd < files->next_fd) fd = files->next_fd; - if (fd < fdt->max_fds) + if (fd < fdt->max_fds) { + if (~fdt->open_fds[0]) { + fd = find_next_zero_bit(fdt->open_fds, BITS_PER_LONG, fd); + goto success; + } fd = find_next_fd(fdt, fd); + } /* * N.B. For clone tasks sharing a files structure, this test @@ -531,7 +536,7 @@ static int alloc_fd(unsigned start, unsigned end, unsigned flags) */ if (error) goto repeat; - +success: if (start <= files->next_fd) files->next_fd = fd + 1; -- 2.43.0