Received: by 10.223.185.116 with SMTP id b49csp658522wrg; Sat, 3 Mar 2018 04:51:58 -0800 (PST) X-Google-Smtp-Source: AG47ELsbp/9VGtstHABpzQ0wF3Y1DxZETXkwNE0Skpw0C1drC3cwOhoO1NhO0oWHjfspPl2MEsa7 X-Received: by 10.101.97.139 with SMTP id c11mr7176185pgv.435.1520081518447; Sat, 03 Mar 2018 04:51:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520081518; cv=none; d=google.com; s=arc-20160816; b=atumIuoSe5PEWHCT2TXHWhzLPB/0XxpoNZGHtH8hXCSgBXJpnHyOSnALMSJEjmD71g 1qWX+fYiWCuKSpESEjJMyWeHakxCHhAKF8KE2WNng4e7+QpGC06nE/Jt23gVX4fodijR wM3JjCeFsYzH2qD/kFiCjvgk7oxpSHB4ytY4ZrOEuN0HSbn08ZpYdGAjwwAk+xXwdZVp cK4b0cRsOekQEa/WRzrMkZvVjUNnAHpcxVHjqZPFTJlbp6VlfLb3/MMKyE/k9Q9fyQVO 4iBlgqKx9zjGUv375+vogq0X9g1aDzrB/pFReysI031xbHIPhFkc+VnHfisoi45H47q9 /X6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=IlL9xKZfACcy8d1a9JuRERa9gA3DLuYMKtCmtacDRno=; b=VsaclDFWv4GsqwsYmOWAFW6RvXSJ8hIFFcQa7baR3YJuGZznVoEK85Svec/6/1/VHn nGqIhcFYnc3dxx/poQWhZYdd5BKKXB17KWX3guIWtmsybcdrhcmDLH5T4JUQgFxP7t2C CGu+ANUfko6AVFJJFlXBxIOpl1BJA2WYt34bxXF+J4WCkv73P3Ol8NJxmRik9zAVGmUi lnarqKZ+Q2HkStOFGeH0Uu+i6ZRZlJ9GQ4feqJxZeDyxXXSOLAZPVJ77PBxPIywmPUNC VpcLlfYvDxVUo3arkBv1EPDLxnlSyDom9RV8X5dFKYgrICOrX/ir+ZKnN7XL1jJUnyns uRWg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k14si5442123pgp.812.2018.03.03.04.51.42; Sat, 03 Mar 2018 04:51:58 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751994AbeCCMvC (ORCPT + 99 others); Sat, 3 Mar 2018 07:51:02 -0500 Received: from mga18.intel.com ([134.134.136.126]:7688 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751811AbeCCMvB (ORCPT ); Sat, 3 Mar 2018 07:51:01 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Mar 2018 04:50:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,417,1515484800"; d="scan'208";a="208538720" Received: from bee.sh.intel.com (HELO inn.lkp.intel.com) ([10.239.97.14]) by fmsmga005.fm.intel.com with ESMTP; 03 Mar 2018 04:50:56 -0800 From: Li Zhijian To: 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, Li Zhijian , Mike Kravetz Subject: [PATCH v2] selftests/vm/run_vmtests: adjust hugetlb size accroding to nr_cpus Date: Sat, 3 Mar 2018 20:50:27 +0800 Message-Id: <20180303125027.81638-1-zhijianx.li@intel.com> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Fix userfaultfd_hugetlb on hosts which have more than 64 cpus. --------------------------- running userfaultfd_hugetlb --------------------------- invalid MiB Usage: [FAIL] Via userfaultfd.c we can know, hugetlb_size needs to meet hugetlb_size >= nr_cpus * hugepage_size. hugepage_size is often 2M, so when host cpus > 64, it requires more than 128M. Changes since v1: - update changelog/comments and variable name to make code more easier to read/understand(stolen from Mike Kravetz) Link: http://lkml.kernel.org/r/20180302024356.83359-1-zhijianx.li@intel.com Signed-off-by: Li Zhijian Cc: Shuah Khan Cc: SeongJae Park Cc: Philippe Ombredanne Cc: Aneesh Kumar K.V Cc: Mike Kravetz Signed-off-by: Andrew Morton --- 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 d2561895a021a..22d5646738302 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.11.0