Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp510058rwe; Thu, 25 Aug 2022 04:38:23 -0700 (PDT) X-Google-Smtp-Source: AA6agR76uWLqtLNe22DT2j4lQtmEp53r4OxpabHSP6IPGzdLMBWx8gmX7H4NlXiPGbIfdhucePo3 X-Received: by 2002:a17:90a:19d:b0:1f7:2b1a:947a with SMTP id 29-20020a17090a019d00b001f72b1a947amr4403303pjc.118.1661427502829; Thu, 25 Aug 2022 04:38:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661427502; cv=none; d=google.com; s=arc-20160816; b=yp2uR4dj5wETyG1GICeITIFTEYq1M3hVKe3qNM9ogYf2obfrtdoAyvBqUDBfMGnkPq dO/WCmir+nbffPRuRmq1HW7nRgyFrdes6u7vcRcUoA8SgOH3SBBNeRPJrmdNmeVbtKlE pEAlYEy/SIxnUJrKuxsNsamVmqQJmT5PxU8szk42t3BBifxMdxHzFQ42HXZVOphmyvBn q7LR2W/HIVErWcME7GX5B8LkfhtKYLt/Q8bnqJimDQJmElIO3aXZaFRSCnelpfmmjFsl XgRs78LOLh5kfmVOWWjQfVFgpoSFuF5j3mPZeMICiyZMOTbBx/nbzidvE/Y+eXXEtOl1 BnUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=6A06woBR/q196VX7s2hmXjoHgljGUazOm+PtrpxMR58=; b=mLx3TUwod7UluwC7FldvLwvauZAAfCjpIJgY/uSZfpzSIV9Md1CTL1Mq2U9DSHyFIu nxNycrirzS7sHYTM4nRS01LV4K2UJRCh6lkh6r6yDJBU4lzfsj4VuecyWjSp7k9bLa9p OHx1cM9P93HI0GT/yyYOexO60PRs6nDyFAZT/myKSundCPC9qZQreeMDTByutt08XZGg D70xNUVI9fstgFnsZtnUvx/x4BMKOmyxsD73srZl01tFUMCeoSHTWiHQmEO1y0iPUyuV KlyBMk8e6oVqjIduEO45lNxzNPDcLy0xUQESuZnx1vBCN6Wd9RnA1Nj5NKGs37Zz/bFa WJ8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="Ih7X9n/8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 8-20020a630b08000000b00420bdc28d4asi15189970pgl.355.2022.08.25.04.38.11; Thu, 25 Aug 2022 04:38:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="Ih7X9n/8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241559AbiHYL0k (ORCPT + 99 others); Thu, 25 Aug 2022 07:26:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241592AbiHYL0c (ORCPT ); Thu, 25 Aug 2022 07:26:32 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CFAF832EE for ; Thu, 25 Aug 2022 04:26:31 -0700 (PDT) Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27PBLogZ026452; Thu, 25 Aug 2022 11:23:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=qcppdkim1; bh=6A06woBR/q196VX7s2hmXjoHgljGUazOm+PtrpxMR58=; b=Ih7X9n/87MDRVVk1ffJFb2VFrvyf/Ejpqy9M8gRRLcyuMJyHc6dmjlkumtoVLPYo+ND3 VOStNsZWa6jKP1onFuHGmtmEaxOiiGgJVN3uhUpq6rOxoW5mTc2lMKYAMyTv419fy5X3 871gfKRjVJp4L+2FrykGMLhEBFSQlS8qmWqRQzP2WPBfIo9ADncMJWUZKrHZw5Eo4U0A +LCf71MGX3YhXNc6KbTEvauHyoUBMS9yyKTvv1K1BFDESp9nTv/45wvpz9FsTwZroCmb f7/q4ISEi0B7bYwuiv/sMaR5f2te3qWKkT4/RBhjnJwxsHMznfJkxKJWDq5pXHnp2yvR 0Q== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3j64h7gq4c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Aug 2022 11:23:45 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 27PBNjd4015588 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Aug 2022 11:23:45 GMT Received: from hu-pkondeti-hyd.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.29; Thu, 25 Aug 2022 04:23:38 -0700 Date: Thu, 25 Aug 2022 16:53:34 +0530 From: Pavan Kondeti To: Michel Lespinasse CC: Linux-MM , , Andrew Morton , , Laurent Dufour , Jerome Glisse , Peter Zijlstra , Michal Hocko , Vlastimil Babka , Davidlohr Bueso , Matthew Wilcox , Liam Howlett , Rik van Riel , Paul McKenney , Song Liu , Suren Baghdasaryan , Minchan Kim , Joel Fernandes , David Rientjes , Axel Rasmussen , Andy Lutomirski Subject: Re: [PATCH v2 10/35] mm: add per-mm mmap sequence counter for speculative page fault handling. Message-ID: <20220825112334.GA23298@hu-pkondeti-hyd.qualcomm.com> References: <20220128131006.67712-1-michel@lespinasse.org> <20220128131006.67712-11-michel@lespinasse.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20220128131006.67712-11-michel@lespinasse.org> User-Agent: Mutt/1.5.24 (2015-08-30) X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: HHldoLC9XfyxZbpoue1XcmoLSQENsrDK X-Proofpoint-GUID: HHldoLC9XfyxZbpoue1XcmoLSQENsrDK X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-25_05,2022-08-25_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 clxscore=1011 priorityscore=1501 lowpriorityscore=0 malwarescore=0 phishscore=0 mlxscore=0 bulkscore=0 adultscore=0 mlxlogscore=999 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208250044 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 28, 2022 at 05:09:41AM -0800, Michel Lespinasse wrote: > The counter's write side is hooked into the existing mmap locking API: > mmap_write_lock() increments the counter to the next (odd) value, and > mmap_write_unlock() increments it again to the next (even) value. > > The counter's speculative read side is supposed to be used as follows: > > seq = mmap_seq_read_start(mm); > if (seq & 1) > goto fail; > .... speculative handling here .... > if (!mmap_seq_read_check(mm, seq) > goto fail; > > This API guarantees that, if none of the "fail" tests abort > speculative execution, the speculative code section did not run > concurrently with any mmap writer. > > This is very similar to a seqlock, but both the writer and speculative > readers are allowed to block. In the fail case, the speculative reader > does not spin on the sequence counter; instead it should fall back to > a different mechanism such as grabbing the mmap lock read side. > > Signed-off-by: Michel Lespinasse > --- > include/linux/mm_types.h | 4 +++ > include/linux/mmap_lock.h | 58 +++++++++++++++++++++++++++++++++++++-- > 2 files changed, 60 insertions(+), 2 deletions(-) > > diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h > index 0ae3bf854aad..e4965a6f34f2 100644 > --- a/include/linux/mm_types.h > +++ b/include/linux/mm_types.h > @@ -523,6 +523,10 @@ struct mm_struct { > * cacheline. > */ > struct rw_semaphore mmap_lock; > +#ifdef CONFIG_SPECULATIVE_PAGE_FAULT > + unsigned long mmap_seq; > +#endif > + > The previous version of patches [1] had maintained this sequence counter per-vma which is more granualar. Can you please share the rationale behind this? I guess, this is more maintainable as we did not scatter the write side changes but nicely hooked into the mmap write lock API. I have tested ebizzy test with per-mm and per-vma sequence counter on x86 QEMU and aarch64 platforms. The results indicate that we are taking classic page fault route 5% more with per-mm sequence counter but it did not showed up in the end results (how much time it takes to do fixed number of operations). So I am asking this only to understand the reasoning behind this change. [1] https://lore.kernel.org/lkml/1523975611-15978-9-git-send-email-ldufour@linux.vnet.ibm.com/