Received: by 10.223.185.116 with SMTP id b49csp303933wrg; Fri, 2 Mar 2018 19:48:16 -0800 (PST) X-Google-Smtp-Source: AG47ELv3yNsATTO8608aWb4PdNWCX2BRy4gXUI5VSRav+zPZxIB4D7XVDZsTzu+2qvK9hpJ9sPVk X-Received: by 10.101.70.133 with SMTP id h5mr6381838pgr.166.1520048895978; Fri, 02 Mar 2018 19:48:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520048895; cv=none; d=google.com; s=arc-20160816; b=aUE7srW0c1DuawF2BAm1u2Dvl0y8ZMIfWdF0qsYai4b0bDnZAlCb5VSvUJPdpR06vR MVPGDvIfIfXmInaNujhcW9KzkPdiVBKIXKVH/krqJWzh3kNxId81XnhOy2kPnNCFpsQL y2SFEwwYQvVNRQc4jdFNFYAiXaVSBnq7NLNF12Oz4u9bgKEkrF5j1Ya+/0zwPkjwI7x3 lyssBWJspmX2Yl0b3SwUKj5nFFZUvtVcuBy00U67MyPmUX5rZTzh9crEP1YIm3HAlr/C pDH1dR0DS9apTL0js2I89+uBkIOT57m/3LHbhiruMUip8TLPOsW2JtYzpWTKH6PwZbrC aTqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=HAO9OAx/jQMMnagXnzEdRTqyTqEyOYC6fxyd8nKuFPM=; b=qzmYAwXMJIhFm4AGMu1k3unmf+uypVzfRRO6oynVDQkHHFbPyjCTSZeBpdaaApgI+3 yoRDs8qFLiUi13DWGBPIkdwvRox8My9UvTcfdOfYV9/QFVV/jIluv/ZFKRgFYNEAdVQq U/2mMzjmY/J1fT7EqlZHM8wULMBiWrkcwO226jj7mvFtu0RxwKdPSKY6UCpJP7HjfF3A 50k3x9l2sI0IwenDbI/jbF7Stsi06dUIicnLmlv04twt7UrjJMqye8fhtQ/lgY9D6ps4 AP3Raq12nnROtFftpLQmrzfZoQpGi3HMTWIhnHeCBhUGP6jufFA1iiuGuLExReRuoj8i kU4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=pLJjfhaQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h6-v6si5901346pln.198.2018.03.02.19.48.01; Fri, 02 Mar 2018 19:48:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=pLJjfhaQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934582AbeCBX06 (ORCPT + 99 others); Fri, 2 Mar 2018 18:26:58 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:34136 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934230AbeCBX05 (ORCPT ); Fri, 2 Mar 2018 18:26:57 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w22NQmIZ181046; Fri, 2 Mar 2018 23:26:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=corp-2017-10-26; bh=HAO9OAx/jQMMnagXnzEdRTqyTqEyOYC6fxyd8nKuFPM=; b=pLJjfhaQKHsFvkTuFTD17hCZgUa2T3hdB7I9uCXYAHOFtLLzOjEbKCaVxf7oTt3kL6Ko sD0QOTjK3a5s39KYCzykBY2GnpBxHVcm2LdzZTE5RylFJTvCplMkkJMyP+b22OLeLXdB 3yfYdEz9e5/1Y8sGS3aCugnuSJwFxIiNSczuQxngCl3twGHBxBqhISvzPI06cukTDwx9 /D7/ZuvosTwDg2k7kbQxcD8n5dRifx6vVS1FxtkWsMTJxUGJiZ2ZKRyWGJqQqkxZvVYr +x2SdbCjvoRbp3o4a25CWHH/OziXbvpuxMHD9z4u5o5kUI+Y13u/3p/YtTii596Sfw6L Kg== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2130.oracle.com with ESMTP id 2gf4g1u525-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 02 Mar 2018 23:26:47 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w22NQglb032436 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 2 Mar 2018 23:26:42 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w22NQfap008391; Fri, 2 Mar 2018 23:26:41 GMT Received: from [192.168.1.164] (/98.246.252.205) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 02 Mar 2018 15:26:41 -0800 Subject: Re: [PATCH] selftests/vm/run_vmtests: adjust hugetlb size accroding to nr_cpus To: Li Zhijian , shuah@kernel.org, akpm@linux-foundation.org, sj38.park@gmail.com, pombredanne@nexb.com, aneesh.kumar@linux.vnet.ibm.com, linux-kselftest@vger.kernel.org Cc: linux-kernel@vger.kernel.org, lizhijian@cn.fujitsu.com References: <20180302024356.83359-1-zhijianx.li@intel.com> From: Mike Kravetz Message-ID: <27de0b4e-d75b-a71d-c45c-1d84bc7e6e9e@oracle.com> Date: Fri, 2 Mar 2018 15:26:40 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <20180302024356.83359-1-zhijianx.li@intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8820 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1803020271 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/01/2018 06:43 PM, Li Zhijian wrote: > this patch is to fix running userfaultfd_hugetlb failed on the host which has > more than 64 cpus > --------------------------- > running userfaultfd_hugetlb > --------------------------- > invalid MiB > Usage: > [FAIL] > > From userfaultfd.c we can know, hugetlb_size need to meet hugetlb_size >= nr_cpus * hugepage_size > hugepage_size is often 2M, so when host cpus > 64, it requires more than 128M. > > Signed-off-by: Li Zhijian Thanks for fixing this. > --- > tools/testing/selftests/vm/run_vmtests | 13 +++++++++---- > 1 file changed, 9 insertions(+), 4 deletions(-) > > diff --git a/tools/testing/selftests/vm/run_vmtests b/tools/testing/selftests/vm/run_vmtests > index d2561895a021a..c440fb972afe9 100755 > --- a/tools/testing/selftests/vm/run_vmtests > +++ b/tools/testing/selftests/vm/run_vmtests > @@ -2,8 +2,6 @@ > # SPDX-License-Identifier: GPL-2.0 > #please run as root > > -#we need 256M, below is the size in kB > -needmem=262144 > mnt=./huge > exitcode=0 > > @@ -17,6 +15,13 @@ while read name size unit; do > fi > done < /proc/meminfo > > +nr_cpus=$(nproc) > +pgsize_MB=$((pgsize/1024)) > +# rule: nr_cpus * pgsize_MB <= hugetlb_size(round to 128M for testing) > +hugetlb_size=$((((nr_cpus*pgsize_MB+127)/128)*128)) > +# needmem depends on the nr_cpus, below is the size in kB > +needmem=$((hugetlb_size*2*1024)) > + > #set proper nr_hugepages > if [ -n "$freepgs" ] && [ -n "$pgsize" ]; then > nr_hugepgs=`cat /proc/sys/vm/nr_hugepages` > @@ -107,8 +112,8 @@ fi > echo "---------------------------" > echo "running userfaultfd_hugetlb" > echo "---------------------------" > -# 256MB total huge pages == 128MB src and 128MB dst > -./userfaultfd hugetlb 128 32 $mnt/ufd_test_file > +# 256MB total huge pages == 128MB src and 128MB dst when nr_cpus <= 64 > +./userfaultfd hugetlb $hugetlb_size 32 $mnt/ufd_test_file > if [ $? -ne 0 ]; then > echo "[FAIL]" > exitcode=1 The above changes are functionally OK. But, I think something like the following may be easier to read/understand. Feel free to use as much or little as you would like. -- Mike Kravetz Signed-off-by: Mike Kravetz --- tools/testing/selftests/vm/run_vmtests | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/vm/run_vmtests b/tools/testing/selftests/vm/run_vmtests index d2561895a021..40671f6739a9 100755 --- a/tools/testing/selftests/vm/run_vmtests +++ b/tools/testing/selftests/vm/run_vmtests @@ -2,25 +2,33 @@ # SPDX-License-Identifier: GPL-2.0 #please run as root -#we need 256M, below is the size in kB -needmem=262144 mnt=./huge exitcode=0 -#get pagesize and freepages from /proc/meminfo +#get huge pagesize and freepages from /proc/meminfo while read name size unit; do if [ "$name" = "HugePages_Free:" ]; then freepgs=$size fi if [ "$name" = "Hugepagesize:" ]; then - pgsize=$size + hpgsize_KB=$size fi done < /proc/meminfo +# Simple hugetlbfs tests have a hardcoded minimum requirement of +# huge pages totaling 256MB (262144KB) in size. The userfaultfd +# hugetlb test requires a minimum of 2 * nr_cpus huge pages. Take +# both of these requirements into account and attempt to increase +* number of huge pages available. +nr_cpus=$(nproc) +hpgsize_MB=$((hpgsize_KB / 1024)) +half_ufd_size_MB=$((((nr_cpus * hpgsize_MB + 127) / 128) * 128)) +needmem_KB=$((half_ufd_size_MB * 2 * 1024)) + #set proper nr_hugepages -if [ -n "$freepgs" ] && [ -n "$pgsize" ]; then +if [ -n "$freepgs" ] && [ -n "$hpgsize_KB" ]; then nr_hugepgs=`cat /proc/sys/vm/nr_hugepages` - needpgs=`expr $needmem / $pgsize` + needpgs=$((needmem_KB / hpgsize_KB)) tries=2 while [ $tries -gt 0 ] && [ $freepgs -lt $needpgs ]; do lackpgs=$(( $needpgs - $freepgs )) @@ -107,8 +115,9 @@ fi echo "---------------------------" echo "running userfaultfd_hugetlb" echo "---------------------------" -# 256MB total huge pages == 128MB src and 128MB dst -./userfaultfd hugetlb 128 32 $mnt/ufd_test_file +# Test requires source and destination huge pages. Size of source +# (half_ufd_size_MB) is passed as argument to test. +./userfaultfd hugetlb $half_ufd_size_MB 32 $mnt/ufd_test_file if [ $? -ne 0 ]; then echo "[FAIL]" exitcode=1 -- 2.13.6