Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp741042lqj; Sun, 2 Jun 2024 21:27:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVcrKISLUvCAZSa1IEa4KZ8n174KwU2uGwZYgu7FpSkxkm5Xs4RON0GayMhpBeKEdBNWmnUrGg5tKxDfO80CVSy7/XleI+DszbLSbFtxg== X-Google-Smtp-Source: AGHT+IGm1U/sWpK6QNpMywPQDKquP7KErJVKVro4124YtRicgW++k9PrqjgmaTJTFnd8Naj2Yo3E X-Received: by 2002:a05:651c:c1:b0:2e9:841d:dacb with SMTP id 38308e7fff4ca-2ea951ab2d4mr53671021fa.40.1717388855015; Sun, 02 Jun 2024 21:27:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717388854; cv=pass; d=google.com; s=arc-20160816; b=f/tjpdrRc9yIXvpmmvqssz9JUN+7gVfkiXoaKiIizdY/iF47VSdp4X21wT1dJGanX3 KnPjAGTY6O57rVl2/O1iUv590fJf9lkeyCewsLWVNglyyS6NWXfuhPqIwzlFDDJ5v7nv KVGpTB9Tfv2KWqpL20/uT77/h5UD0jLufZZ1SxH0x1+EBsFT0gTEiIgF6O7xoRwkl25o r53veLIPcrtKHQpL/5fa6NPXdSLtEr91R+i2MZpIwGHaTpg5eJY6hvQqvY3scJYLfcaE xI2OLzkcSnJW/nZrmRT8v5K+GkDFG5QQ3+B3EdQ05qzGj4QlaUs/glQmbl1R76pTTyV2 TZ+g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=h9qPC6w1NV4TD2a+FwRxTwDP6kMv2SLCKMCaWmtBFqU=; fh=ckelGvoPJpjctH95QAFO8JJxVFd+BDzTW/mh9Yf81bc=; b=r1hBuXrlX1gTUOLF1UktyUp7lYvpA0ZCvprTFtdJpLgnVwWgjSvI5MCFwI9g1HP5e+ xR7KA9l777Uh+QUbVRVibz7mWJjJT6a4j/7eD+0E/SPpi6Bw086TvbG62SOukTj5WlbM Gdl066ScL//hjURgNcdpFJxJTBrJ3ed6plxNUUw/h/JSorc+RPbbmNCx9JVVQQOBIVQh riOctXOOokIPaXEBpI2gxTEb2+HD8csu2hcl9LE3CnsTVS31XeAFeKV3CKrpVIC+QFbw Fc8mxor193WHoaGj0pxkpo+B2chN+nJO6vVCxoSgeKYMIC5zx+2eWZ4/M4v4PYpFgeWH 1sYQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="Ufc/Fcf3"; 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-198592-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198592-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-57a31c62fe6si3780361a12.271.2024.06.02.21.27.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jun 2024 21:27:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-198592-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="Ufc/Fcf3"; 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-198592-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198592-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 8E9091F2232B for ; Mon, 3 Jun 2024 04:27:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2999217C77; Mon, 3 Jun 2024 04:27:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ufc/Fcf3" Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (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 95A5910F1 for ; Mon, 3 Jun 2024 04:27:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717388847; cv=none; b=DKXYTqTbTcJcfhMlLxGW0QglBZLb6IxvdnC42+8W/MRqur25kv2ElmfNq+20rCIeak8RVm3WH/t2NHkv83y2P9JL1UT2zu8Zoo6O9AZbZ3LivMWypX605xuau7IxxWhz766+YPyAGaRfLUpWCN2nc0TZ2XYAPRQ3p0Vc91AVO2s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717388847; c=relaxed/simple; bh=t9uHrRS4KFkljpjCuYI2/7oYBr0iY+/XkHCfMqpyTYs=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=U4wJH7olKGz3gnn6d1CNP1yMCt9/dAG9O0UjFXBa6GyNuz0r+uyUwZFrGn93ttK1TPK17oB+75vYxS3883LgvWVkFEB2DnDgc33swNLldtT1PdBcLQhUyx5FoDnD/SPam6zdCKI4TRgqQkbQZROXQjBYPUPogiyPPPA0aUDrGt8= 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=Ufc/Fcf3; arc=none smtp.client-ip=209.85.167.45 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-lf1-f45.google.com with SMTP id 2adb3069b0e04-52965199234so4377782e87.2 for ; Sun, 02 Jun 2024 21:27:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717388843; x=1717993643; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=h9qPC6w1NV4TD2a+FwRxTwDP6kMv2SLCKMCaWmtBFqU=; b=Ufc/Fcf3SDj8SQm6ijscxK5sbGhXKdd5keBMVbPPG36r2mQW1ug5upJxEsgEi2Cg1k BiJbcThvmlCvLJQ/Mh+LfbEBxY8djDJFodJqjlFwOomk0UrTDMOTkV0jC42ofEX5cMH6 ZW0/3euc8/hCxu4TV+Cm1NNt5W8F3+6TtfqjbMSQeQzILRFIduWAwHbqksS9Q9JlDeBh tg6pQDfxYQffII2BpH3lNqjWQk6K6T4M74rxYaOWtwQ7rkHhSy63SKYJT3AHJ6tcAGwH hBqjvKcMhHnIvZMEO/HSiAxVo7s3HHdSc91CfrlmuxX1PtMUZzJ7wZiq/evQpVFSUkqr T5JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717388843; x=1717993643; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=h9qPC6w1NV4TD2a+FwRxTwDP6kMv2SLCKMCaWmtBFqU=; b=jF5BJYMfR5U3DWSIhu6IyaEzVgjMtOpBTz+2SPgDqz2n/R7McF3G0aWePZdLfxGKQN WGyDMlGUNdyy1VES9Ocqbx9lEv8Lh+Q8wLx1cAlkebgH3VWHsGZW162f3atOGoLrs6Gj 2V3pvuYsCnIVItmuG+ruy9r44LI0XzXtZnjmWFhTv8vfpVVTZBAyFjMrGugTMNrH4oql /ZWrIJE6QBZtE7GuVYzj2tU1iATtqbqmife23g7MHSDEeksqmzvEUyEYmxtt8Jg12yg4 dBTU1dOccFKxBPktwzDWZ+WYFfyXSWldC1kekDp7xoicS+rgsFVretIAzb+KkxJKLWtu hVkw== X-Forwarded-Encrypted: i=1; AJvYcCUWVwVDVfKjDCi7QnTKp1IkZKFtoTp8uOfghw2mBBlfWIIlht1zYpv/kpE3Xfoszy1fU2GxOcqPdTOSzPWPiu7wmx+xDzkXo75I2CEA X-Gm-Message-State: AOJu0YwiRBWk+tCqnu7ewR13/W8+WNXcxqEWvIzcTDdxcWX/ZJXmUAMZ QRHXJzxDhkhPx8+77w6NeICDQ6ncxtOt3LmDxWBO+mBm5Zwnt1r069LdnWpLmuDK1El0lGXPTar h2GmvAwO9gvezAecttzLP2Wz34ig= X-Received: by 2002:ac2:544c:0:b0:51c:a0e1:2a44 with SMTP id 2adb3069b0e04-52b8957f627mr4896967e87.26.1717388843141; Sun, 02 Jun 2024 21:27:23 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240603033118.76457-1-ioworker0@gmail.com> In-Reply-To: From: Lance Yang Date: Mon, 3 Jun 2024 12:27:09 +0800 Message-ID: Subject: Re: [PATCH 1/1] mm/mlock: implement folio_mlock_step() using folio_pte_batch() To: Barry Song <21cnbao@gmail.com> Cc: akpm@linux-foundation.org, ryan.roberts@arm.com, david@redhat.com, baolin.wang@linux.alibaba.com, ziy@nvidia.com, fengwei.yin@intel.com, ying.huang@intel.com, libang.li@antgroup.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Barry, Thanks for taking time to review! On Mon, Jun 3, 2024 at 12:14=E2=80=AFPM Barry Song <21cnbao@gmail.com> wrot= e: > > On Mon, Jun 3, 2024 at 3:31=E2=80=AFPM Lance Yang w= rote: > > > > 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. > > > > Signed-off-by: Lance Yang > > --- > > mm/mlock.c | 23 ++++++----------------- > > 1 file changed, 6 insertions(+), 17 deletions(-) > > > > diff --git a/mm/mlock.c b/mm/mlock.c > > index 30b51cdea89d..1ae6232d38cf 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 =3D folio_nr_pages(folio); > > - unsigned long pfn =3D folio_pfn(folio); > > - pte_t ptent =3D ptep_get(pte); > > - > > - if (!folio_test_large(folio)) > > + if (likely(!folio_test_large(folio))) > > return 1; > > > > - count =3D pfn + nr - pte_pfn(ptent); > > - count =3D min_t(unsigned int, count, (end - addr) >> PAGE_SHIFT= ); > > - > > - for (i =3D 0; i < count; i++, pte++) { > > - pte_t entry =3D ptep_get(pte); > > - > > - if (!pte_present(entry)) > > - break; > > - if (pte_pfn(entry) - pfn >=3D nr) > > - break; > > - } > > + const fpb_t fpb_flags =3D FPB_IGNORE_DIRTY | FPB_IGNORE_SOFT_DI= RTY; > > + int max_nr =3D (end - addr) / PAGE_SIZE; > > + pte_t ptent =3D ptep_get(pte); > > > > - return i; > > + return folio_pte_batch(folio, addr, pte, ptent, max_nr, fpb_fla= gs, NULL, > > + NULL, NULL); > > } > > what about a minimum change as below? Nice, that makes sense to me ;) I'll adjust as you suggested. Thanks again for your time! Lance > index 30b51cdea89d..e8b98f84fbd2 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 =3D folio_nr_pages(folio); > - unsigned long pfn =3D folio_pfn(folio); > + unsigned int count =3D (end - addr) >> PAGE_SHIFT; > pte_t ptent =3D ptep_get(pte); > + const fpb_t fpb_flags =3D FPB_IGNORE_DIRTY | FPB_IGNORE_SOFT_DIRT= Y; > > if (!folio_test_large(folio)) > return 1; > > - count =3D pfn + nr - pte_pfn(ptent); > - count =3D min_t(unsigned int, count, (end - addr) >> PAGE_SHIFT); > - > - for (i =3D 0; i < count; i++, pte++) { > - pte_t entry =3D ptep_get(pte); > - > - if (!pte_present(entry)) > - break; > - if (pte_pfn(entry) - pfn >=3D 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 > >