Received: by 2002:ab2:69cc:0:b0:1fd:c486:4f03 with SMTP id n12csp54056lqp; Mon, 10 Jun 2024 18:13:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXgNNst9iaKzI649hrahU3qfK1LpnSWPiqx7Vp10YILdfbZQ9KvpqTSn7OBvI3tDAQIkjevY01GoFsNDahXb1IHjNhKmHwd51WqEafr0A== X-Google-Smtp-Source: AGHT+IGuPOmxjsd7V9twpUv/Tc0FhiySlx7BQAALw6B4BrxYSQyXI58kRH3m/SYxZHoOHxK764Cl X-Received: by 2002:a2e:80cf:0:b0:2eb:e5e9:b09e with SMTP id 38308e7fff4ca-2ebe5e9b1bbmr28643881fa.52.1718068407899; Mon, 10 Jun 2024 18:13:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718068407; cv=pass; d=google.com; s=arc-20160816; b=u4eu5HGN1eUDTN/LrrWcZUwUYPChv3MZXrfWKrQ0c7Ovff1Jly1a9slg8xF3TKd+wj ovxqo4rb/FTn98bsbQd/QggThXPu81gdsDBZnMSEHlx9JjAaqKKsXBwMYgXafRn5P+P3 S8xss//1N6PnHy/m+jyzAXFXtPLVIZZZJu3U1QaMlaPN2iyhjR0C6oVDje4pDd+IunGF ab89vH+cfGrSN+ViKGugml49cuyBxtsMzxiOngoZnNv42QetIBX4J7bC1GczPTp5YaBZ MicS56T/rKG7Hxjom1Bh5X9BxryxNiHxPzKIkFsZRQV5t89v37vEJr9TLDVS0cnn31Hk r1qw== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=o/e1voOxQLnVD8oRgm9L6T4MRE4ZONIiEombO/Pd7l0=; fh=jgHwfgIsskHGIbFpA2z+oYX7Mv95Dvmb6bTQaS33jjs=; b=pXT7Mp6yO26LfvFQpupkm1/b0mRPRFdYpMdzZeXbwlpcR6PVlScD5T6jHVhc20iBUN XqKXlD6tf9PGjJn8OaL54Uvsn/CIi8X8ZfmR0MDrRV60GgBRjWA+fuG6NcTz6Y6Cs/R0 A1gKAvujvi5OT8YMp7wMW8595uLYxftpTeBwFaFiau9gpALAWrFc2Wmg/8yPHmeNxuMB x16tpov/5Xn/HC6ZNnONmkuFI3ilHB/h0LpgBXwRjwYpftgzMQj7GWhO+WCXE6fYKJnH 1G3M7yY63tgM8gR3pnw7c32P4lSG03zSIkVs6GN4VE+XJti/5a34WLKWuWYbRQHE6pQw hIVw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Beb2hWCG; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-209144-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209144-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57c7417b46csi2471500a12.247.2024.06.10.18.13.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 18:13:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-209144-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Beb2hWCG; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-209144-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209144-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 28F691F23E39 for ; Tue, 11 Jun 2024 01:04:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E79338493; Tue, 11 Jun 2024 01:04:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Beb2hWCG" Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (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 BD4D4BA46 for ; Tue, 11 Jun 2024 01:04:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718067876; cv=none; b=kWKm8Nshy9tO0+sAcMy+DbAnSn/dMLon0ZzaCOC+PcmGfBra9oP7bivxHx7UtCC1mas0dsoIeBt/vsa5Pil8XVg01dsJ7M8uAvMMmZQvwpa7ktTbBpnVQAmR7VZTv9dnJPqADcbEY6eeK8qJ0BqQZ15j3etvmkNWzsBcFbMDy6Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718067876; c=relaxed/simple; bh=Kqs5bNdhSUR7SBKGPV75Vb3VNzhoHyhtP1ZoY9wzsWI=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=USkz4twcitSSYD02rLJAI7zYTDRnZyRh3qfI5dm9ZEWsqbdvgPQ5gqp+Qwx2ihE7jRRdHrT00ix4JXZiryIpEl+pijvkx5jK9Ly4NhsrhA0kdxNARs4DPa71ehtEtyRRErA+0qBg7OsUuxEZ9yvBVi4QqDSrlCyZQ1iVeWb3wgo= 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=Beb2hWCG; arc=none smtp.client-ip=209.85.210.180 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 Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-70436048c25so1676036b3a.0 for ; Mon, 10 Jun 2024 18:04:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718067874; x=1718672674; 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=o/e1voOxQLnVD8oRgm9L6T4MRE4ZONIiEombO/Pd7l0=; b=Beb2hWCGaWEJcsT6NkwiEHipQ3GZMMwlG5P920P+lk+9b4+9ViE7tzP2s3HKA8/P+M /yZ40I54dVpKGKOs4T63C7RFDEPynkLmexZoBjDe+e2hS2tDHFXA8yhyPJDEzCYVXI0M DnPMhYlY540Pvgv4Cgfx3PUJUZKZhk5nqne9q789CPydwNJ8w8ii0wNzPNHLR2JFveKr 0mB1dPd7QJoiV9ppEx9gUbcDPJbPRHeEKasZC051Ca7ZY1fGZWmezW3WQr6HTOQm9mFK 8MfnaNDdt2xUBv2TV3vMwIQWyZ2rUPd+je0kdF3NdWVe5/oeFZgPLHUPsi+1xr37Whvq fRPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718067874; x=1718672674; 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=o/e1voOxQLnVD8oRgm9L6T4MRE4ZONIiEombO/Pd7l0=; b=VKTsRqbJu+F9Cc3Vqio9Xkchngtyq3YYyxhMXl1Be/hQsiDDGuwhiNzsZVZfrk9XLh JueZGOZu5FUgtiZT26UYbUKjOtRNfI8olKoreOZtTsTIHj2LFJnm+sRdhyOwtzccMttB B90ANJzAUy6dJFDyBlpM1a68n/wZ0lkTu63Zvq9R6dzpBrexRAHBwgZ+pp2gsGLQjaOU hymaJLyuWphFb3oqNuoNcsPMAhZOrtBSSU64i4jtPxATH59Dqk1fZDUItyRZdnZhfX9q JSLq+KLza9A2IvStgsDFWfng86vaLDRyN3Oo70bMWTfigG4Lw6KQAGyvJAdPkPOodyYL 9vgg== X-Forwarded-Encrypted: i=1; AJvYcCXBpOo6nsPYkJhEvn4WIHYgWFoV+QSeDDlpGRk2crq2X0UqRxATQjlYQo89o/8faaiurDT3gNo2ncHiQyYs5SXArQC2/OuItCxCbzhF X-Gm-Message-State: AOJu0Yy75kd/F3zP5ImArXeXjJoL5ZCmAeQG5Ki1Dt5qzMclsHti6csA CAiiYJ6j/JxoEKqT8NA13cXwi8wtFrRX3U93DlrsN253KrOr+jyS X-Received: by 2002:a05:6a20:6a20:b0:1b5:cf26:ecfd with SMTP id adf61e73a8af0-1b5cf2704e2mr7248815637.24.1718067873837; Mon, 10 Jun 2024 18:04:33 -0700 (PDT) Received: from LancedeMBP.lan.lan ([2403:2c80:6::304c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70410b976a9sm6153772b3a.147.2024.06.10.18.04.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 18:04:33 -0700 (PDT) From: Lance Yang To: akpm@linux-foundation.org Cc: ryan.roberts@arm.com, david@redhat.com, 21cnbao@gmail.com, baolin.wang@linux.alibaba.com, ziy@nvidia.com, fengwei.yin@intel.com, ying.huang@intel.com, libang.li@antgroup.com, willy@infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Lance Yang Subject: [PATCH v3 1/1] mm/mlock: implement folio_mlock_step() using folio_pte_batch() Date: Tue, 11 Jun 2024 09:04:18 +0800 Message-Id: <20240611010418.70797-1-ioworker0@gmail.com> X-Mailer: git-send-email 2.33.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Let's make folio_mlock_step() simply a wrapper around folio_pte_batch(), which will greatly reduce the cost of ptep_get() when scanning a range of contptes. Acked-by: David Hildenbrand Reviewed-by: Baolin Wang Suggested-by: Barry Song <21cnbao@gmail.com> Suggested-by: Matthew Wilcox Signed-off-by: Lance Yang --- v2 -> v3: - Rebased to mm/mm-unstable - https://lore.kernel.org/linux-mm/20240603140745.83880-1-ioworker0@gmail.com/ v1 -> v2: - Remove the likely() hint (per Matthew) - Keep type declarations at the beginning of the function (per Matthew) - Make a minimum change (per Barry) - Pick RB from Baolin - thanks! - Pick AB from David - thanks! - https://lore.kernel.org/linux-mm/20240603033118.76457-1-ioworker0@gmail.com/ mm/mlock.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/mm/mlock.c b/mm/mlock.c index 30b51cdea89d..52d6e401ad67 100644 --- a/mm/mlock.c +++ b/mm/mlock.c @@ -307,26 +307,15 @@ void munlock_folio(struct folio *folio) static inline unsigned int folio_mlock_step(struct folio *folio, pte_t *pte, unsigned long addr, unsigned long end) { - unsigned int count, i, nr = folio_nr_pages(folio); - unsigned long pfn = folio_pfn(folio); + const fpb_t fpb_flags = FPB_IGNORE_DIRTY | FPB_IGNORE_SOFT_DIRTY; + unsigned int count = (end - addr) >> PAGE_SHIFT; pte_t ptent = ptep_get(pte); if (!folio_test_large(folio)) return 1; - count = pfn + nr - pte_pfn(ptent); - count = min_t(unsigned int, count, (end - addr) >> PAGE_SHIFT); - - for (i = 0; i < count; i++, pte++) { - pte_t entry = ptep_get(pte); - - if (!pte_present(entry)) - break; - if (pte_pfn(entry) - pfn >= nr) - break; - } - - return i; + return folio_pte_batch(folio, addr, pte, ptent, count, fpb_flags, NULL, + NULL, NULL); } static inline bool allow_mlock_munlock(struct folio *folio, -- 2.33.1