Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp830650lqj; Mon, 3 Jun 2024 01:59:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUCgvr9SvtXwyJmhtR/+LLechJH9OVF07hlqgiekkkpTfdThsnOFTv0ht/x3mrEmZHJKMHjsGtHeWM0J3QSwWZfjs4h24A1F/I0vaAJbw== X-Google-Smtp-Source: AGHT+IG+IxPT3PMhTkZufAjK9u5k/jvxvKf+5/dq1bNH7Njm7SuJ3JuLIE/yTrr/o9Mu/j/AijgG X-Received: by 2002:ac2:521b:0:b0:52b:5140:f548 with SMTP id 2adb3069b0e04-52b896bde6dmr6210994e87.46.1717405158915; Mon, 03 Jun 2024 01:59:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717405158; cv=pass; d=google.com; s=arc-20160816; b=oYT0wsXlClNkLzJg+SIVA5ukeD434CNxeG1KnrUyu5Ogy5Cbtf8TpZWA5QpfU658TC xzvqGQbk+QY40NFS/YNskmWXpTqdNQ+UwThDPLujbDrZB8mm6GO1K0Ypm9jX7wPIiJd4 SFNn61JAf/KhGB5dTIQAgwQ2J+0HGXXTYwviCH1jOBs/VwgBSvVnbgv+IQILrh+ocMDj iDQnedtqeoROtP5AjM67AwWNsVc0aOfoMVGDww35X3WEw/bOuUK6SFNw4ZeRe+PDeVO2 8jlmnMnCWCO7HPWA1QaoYqc5zU0dgMlVs9eXX6rbpNhpeGanhpRJCoHAm7hu4N5OfZ3q f8JQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id:dkim-signature; bh=TzPdstqt9IZKp/sl6m9OBFjYtVVR9pYii9OkkWcJFLc=; fh=j32nLY4DA4ZtryQcePSG/YeCut3cJXf2yGbTnrhm03Q=; b=ab2Clqn4Pc8CL93aN1PFzHgljuwVhTdoDemS/cKOPQ3sKMEQDnNI573IMHerFGy1fR ulKgneGLkrAu4q6WBWUpH8K4iocsBPgNd83mAJ5Oh1tPrh6uJ8K3hSRPOC47jco/AUM9 Ppi4qRiKl4aR3ScuEr+orzb8fXrPTkgUaSp/I1Nh5mdKPXLm57wnNRcsos6P+XGvo23R JY8BdUb9gU20Lwcs/jbi0Fti0mn4TCrGgQ3CezRlWlaxFL2A0KYfzprYdxRDzWR2nWHk lqWrqoAHN9vzCHBPPgkKOzveJRqh/+I0OgcxwHOZ3NWoYkCWyPws5pCR1Aln3vQGVaAc ALUw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=nCkImw7m; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-198823-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198823-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.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 4fb4d7f45d1cf-57a31b80e87si3908726a12.36.2024.06.03.01.59.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 01:59:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-198823-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=@linux.alibaba.com header.s=default header.b=nCkImw7m; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-198823-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198823-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.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 9DA841F21147 for ; Mon, 3 Jun 2024 08:59:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0E94876F17; Mon, 3 Jun 2024 08:59:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="nCkImw7m" Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) (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 13A0C7604F for ; Mon, 3 Jun 2024 08:59:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.97 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717405151; cv=none; b=pKbFdP0THdBtZmh2/Iim1pa/bLd6wZM4enTf73qKi1UBxPwjzrDFbkxJ9OBmApdQZ0DdKfTj9TAwzSHTAEbVcftQ6g/HPO4Gw8PWlDswkqhiH/kVmqhSWTLrqg/HArPFpD/vJuTCmaO1AT64Woc0uDAgJC4Y8i1EJnXce7TAkvs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717405151; c=relaxed/simple; bh=W3fg5nl6HNyYLjlSngUjxtPZxz3YW1afDlPZUYbTL5E=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Q4hE9RMifqz4EKqoBs+8yv9OgY13o33Ikj+9fdZZ9LQ2GLC8Ll+pJvy+BkJFt1gjqw9nxSYafWjFiQS0qZIXw0vP8/Nue5fTr4hqBimkohNMul6hzfOwmy5GdoREZkKp5A7PmUivRYH4LZd5DAly9q1Pohy63+fVPf7u3XPeU+o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=nCkImw7m; arc=none smtp.client-ip=115.124.30.97 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1717405140; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=TzPdstqt9IZKp/sl6m9OBFjYtVVR9pYii9OkkWcJFLc=; b=nCkImw7mEpRAE+qiSbcFM68Z0cW3cCsPAaCRAAQViiWUdNxgsg9wcUun/LcSydWs2MlQTEsMMiSrRVWmvGsk9FjBfdJOFHe8JA1WSoiS45U7M6ZNUcYM+jHAtiRGdKwx5KKnH2bahSgRlXJv7XBbvyQ3im6NaHwqE9PKt0ioRVI= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R751e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037067113;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0W7lDG5c_1717405138; Received: from 30.97.56.74(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W7lDG5c_1717405138) by smtp.aliyun-inc.com; Mon, 03 Jun 2024 16:58:59 +0800 Message-ID: Date: Mon, 3 Jun 2024 16:58:58 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/1] mm/mlock: implement folio_mlock_step() using folio_pte_batch() To: Barry Song <21cnbao@gmail.com>, Lance Yang Cc: akpm@linux-foundation.org, ryan.roberts@arm.com, david@redhat.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 References: <20240603033118.76457-1-ioworker0@gmail.com> From: Baolin Wang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2024/6/3 12:14, Barry Song wrote: > On Mon, Jun 3, 2024 at 3:31 PM Lance Yang wrote: >> >> 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 = folio_nr_pages(folio); >> - unsigned long pfn = folio_pfn(folio); >> - pte_t ptent = ptep_get(pte); >> - >> - if (!folio_test_large(folio)) >> + if (likely(!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; >> - } >> + const fpb_t fpb_flags = FPB_IGNORE_DIRTY | FPB_IGNORE_SOFT_DIRTY; >> + int max_nr = (end - addr) / PAGE_SIZE; >> + pte_t ptent = ptep_get(pte); >> >> - return i; >> + return folio_pte_batch(folio, addr, pte, ptent, max_nr, fpb_flags, NULL, >> + NULL, NULL); >> } > > what about a minimum change as below? > 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 = folio_nr_pages(folio); > - unsigned long pfn = folio_pfn(folio); > + unsigned int count = (end - addr) >> PAGE_SHIFT; > pte_t ptent = ptep_get(pte); > + const fpb_t fpb_flags = FPB_IGNORE_DIRTY | FPB_IGNORE_SOFT_DIRTY; > > 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); > } LGTM. Reviewed-by: Baolin Wang