Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp2346228ybj; Mon, 23 Sep 2019 02:08:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqyso5zO7Kec7GJlU9ob1JTN9hfWC6Tr/gcfn+0+ZP6zfA6LBLyAAKnRN5randqTEFYoRVIR X-Received: by 2002:a05:6402:184d:: with SMTP id v13mr36586757edy.56.1569229724281; Mon, 23 Sep 2019 02:08:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569229724; cv=none; d=google.com; s=arc-20160816; b=X07DOTxhFEI/6AsfdGZCQmrr6/wuRkf2dL2QhTQeAWvMEA3DtNJWbYiT5R1LAu+R/C 2EVncX1OV5acG4FkwK0xBIToXJEE4aY6A8HHHx1rVOZRpWRxEcclxCX/K3rtJFDjDY3l V8FG/2fRVOuq5Zlz6f7h9uiJPBjSsWvbcqMO5mqOXEZ54QmL7fhVYCwd4mCcAwnRguv6 izKDlPFXWKgYxhpN+f8UfTt/SLNb7Vmu7eVQi7jieyiuviA6lu4i3cMjTASsHUGRg9tQ X+iNd1gHi74Ng/bicCJCtwLUC/bzMv3BSBHkmFtz/qVMP4J/q2Xp5eBaDVYcLBHjJgkm cLFA== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=wa8pv3ZUv4EkVSoPGuJD74o2JMvVJ9l6kJeBiXVB3lw=; b=feXJ1DKzVbcLD+vlVFEIzTbWM1n9YSm6FStf4WKqW+Z2x/tjW8b2OCRccwzF/RA4T3 GtcNNUvb1LaBCqjIgAfM/2HjSWd2ipjCYo9Ck4W7tRnYsk55U8MY5FCKdY6mJ4hWzT8L mMcDCqOPFQ+y2JdNSNtkHXEL8Gx3dElfpeuDdqGM9Ik4KaaQxUR8LyS+j5avlGY9GR23 wczHZxXtQRYyX7LzWrQGH1sREd/bdf/Ob0RBaT16eZAcl0w/TyCVvwX8vy1/wUh6Msd5 UwZpB/q7NFAXD3FEX7ll293trOH+bGrCux2+X2XbzJOccJ/7VTiOj7VJIduBmbXNYBBd orSw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l21si6322484edc.112.2019.09.23.02.08.20; Mon, 23 Sep 2019 02:08:44 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729778AbfITTvx (ORCPT + 99 others); Fri, 20 Sep 2019 15:51:53 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:34424 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726794AbfITTvx (ORCPT ); Fri, 20 Sep 2019 15:51:53 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x8KJm141039068; Fri, 20 Sep 2019 15:51:22 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 2v50uetuk4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Sep 2019 15:51:22 -0400 Received: from m0098396.ppops.net (m0098396.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.27/8.16.0.27) with SMTP id x8KJnH6A042230; Fri, 20 Sep 2019 15:51:22 -0400 Received: from ppma05wdc.us.ibm.com (1b.90.2fa9.ip4.static.sl-reverse.com [169.47.144.27]) by mx0a-001b2d01.pphosted.com with ESMTP id 2v50uetujg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Sep 2019 15:51:21 -0400 Received: from pps.filterd (ppma05wdc.us.ibm.com [127.0.0.1]) by ppma05wdc.us.ibm.com (8.16.0.27/8.16.0.27) with SMTP id x8KJoHqe015546; Fri, 20 Sep 2019 19:51:20 GMT Received: from b03cxnp08027.gho.boulder.ibm.com (b03cxnp08027.gho.boulder.ibm.com [9.17.130.19]) by ppma05wdc.us.ibm.com with ESMTP id 2v3vbu8p2f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Sep 2019 19:51:20 +0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x8KJpJPZ54788488 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Sep 2019 19:51:19 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2EE4278060; Fri, 20 Sep 2019 19:51:19 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 931697805E; Fri, 20 Sep 2019 19:51:14 +0000 (GMT) Received: from LeoBras.aus.stglabs.ibm.com (unknown [9.18.235.184]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Fri, 20 Sep 2019 19:51:14 +0000 (GMT) From: Leonardo Bras To: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Cc: Leonardo Bras , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Arnd Bergmann , "Aneesh Kumar K.V" , Christophe Leroy , Andrew Morton , Dan Williams , Nicholas Piggin , Mahesh Salgaonkar , Thomas Gleixner , Richard Fontana , Ganesh Goudar , Allison Randal , Greg Kroah-Hartman , Mike Rapoport , YueHaibing , Ira Weiny , Jason Gunthorpe , John Hubbard , Keith Busch Subject: [PATCH v2 01/11] powerpc/mm: Adds counting method to monitor lockless pgtable walks Date: Fri, 20 Sep 2019 16:50:37 -0300 Message-Id: <20190920195047.7703-2-leonardo@linux.ibm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190920195047.7703-1-leonardo@linux.ibm.com> References: <20190920195047.7703-1-leonardo@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-09-20_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1909200161 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It's necessary to monitor lockless pagetable walks, in order to avoid doing THP splitting/collapsing during them. Some methods rely on local_irq_{save,restore}, but that can be slow on cases with a lot of cpus are used for the process. In order to speedup some cases, I propose a refcount-based approach, that counts the number of lockless pagetable walks happening on the process. This method does not exclude the current irq-oriented method. It works as a complement to skip unnecessary waiting. start_lockless_pgtbl_walk(mm) Insert before starting any lockless pgtable walk end_lockless_pgtbl_walk(mm) Insert after the end of any lockless pgtable walk (Mostly after the ptep is last used) running_lockless_pgtbl_walk(mm) Returns the number of lockless pgtable walks running Signed-off-by: Leonardo Bras --- arch/powerpc/include/asm/book3s/64/mmu.h | 3 +++ arch/powerpc/mm/book3s64/mmu_context.c | 1 + arch/powerpc/mm/book3s64/pgtable.c | 17 +++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/arch/powerpc/include/asm/book3s/64/mmu.h b/arch/powerpc/include/asm/book3s/64/mmu.h index 23b83d3593e2..13b006e7dde4 100644 --- a/arch/powerpc/include/asm/book3s/64/mmu.h +++ b/arch/powerpc/include/asm/book3s/64/mmu.h @@ -116,6 +116,9 @@ typedef struct { /* Number of users of the external (Nest) MMU */ atomic_t copros; + /* Number of running instances of lockless pagetable walk*/ + atomic_t lockless_pgtbl_walk_count; + struct hash_mm_context *hash_context; unsigned long vdso_base; diff --git a/arch/powerpc/mm/book3s64/mmu_context.c b/arch/powerpc/mm/book3s64/mmu_context.c index 2d0cb5ba9a47..3dd01c0ca5be 100644 --- a/arch/powerpc/mm/book3s64/mmu_context.c +++ b/arch/powerpc/mm/book3s64/mmu_context.c @@ -200,6 +200,7 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm) #endif atomic_set(&mm->context.active_cpus, 0); atomic_set(&mm->context.copros, 0); + atomic_set(&mm->context.lockless_pgtbl_walk_count, 0); return 0; } diff --git a/arch/powerpc/mm/book3s64/pgtable.c b/arch/powerpc/mm/book3s64/pgtable.c index 7d0e0d0d22c4..13239b17a22c 100644 --- a/arch/powerpc/mm/book3s64/pgtable.c +++ b/arch/powerpc/mm/book3s64/pgtable.c @@ -98,6 +98,23 @@ void serialize_against_pte_lookup(struct mm_struct *mm) smp_call_function_many(mm_cpumask(mm), do_nothing, NULL, 1); } +void start_lockless_pgtbl_walk(struct mm_struct *mm) +{ + atomic_inc(&mm->context.lockless_pgtbl_walk_count); +} +EXPORT_SYMBOL(start_lockless_pgtbl_walk); + +void end_lockless_pgtbl_walk(struct mm_struct *mm) +{ + atomic_dec(&mm->context.lockless_pgtbl_walk_count); +} +EXPORT_SYMBOL(end_lockless_pgtbl_walk); + +int running_lockless_pgtbl_walk(struct mm_struct *mm) +{ + return atomic_read(&mm->context.lockless_pgtbl_walk_count); +} + /* * We use this to invalidate a pmdp entry before switching from a * hugepte to regular pmd entry. -- 2.20.1