From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 541E3C28D13 for ; Thu, 25 Aug 2022 11:24:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D8ED5940007; Thu, 25 Aug 2022 07:24:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D3EA26B0075; Thu, 25 Aug 2022 07:24:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB935940007; Thu, 25 Aug 2022 07:24:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A863D6B0074 for ; Thu, 25 Aug 2022 07:24:06 -0400 (EDT) Received: from smtpin31.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 789881C3DDE for ; Thu, 25 Aug 2022 11:24:06 +0000 (UTC) X-FDA: 79837880892.31.A86EDE3 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by imf20.hostedemail.com (Postfix) with ESMTP id ED49C1C0009 for ; Thu, 25 Aug 2022 11:24:05 +0000 (UTC) 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661426646; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=6A06woBR/q196VX7s2hmXjoHgljGUazOm+PtrpxMR58=; b=nShYfLbxPrF40uCHMP92HxPzT2Rp6k5EImEUCk4HNH9/e/eWdZq0mf2LC0NqGwg+CR9q+4 5E5dVYRoNafj8/ktr0TCbJFG/FQ8NdwIzMT4CNeZb063VALpyIk6QtZAWnutQdYAkkrF9A MbDqVsVEQL+GX3mNRxTP6mSjVq7hD3M= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b="Ih7X9n/8"; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf20.hostedemail.com: domain of quic_pkondeti@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_pkondeti@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661426646; a=rsa-sha256; cv=none; b=j+zZrQN7ANGNHUvlto37DdoM+wzavwnZi8VbAwg9EjP5TGNshLFfeGsr/5TNEwNFng7VAB MkYXj+y/Yyw0Zn8aQlyz2ZGkqKb9dCH1dzg3YkCecPRaCsxJoAMGkGYvBquUAqPralJZd0 tVTT4aAI7oDMCwIxBaRreoeFd7AZ0fE= Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b="Ih7X9n/8"; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf20.hostedemail.com: domain of quic_pkondeti@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_pkondeti@quicinc.com X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: ED49C1C0009 X-Stat-Signature: 45iddw9o45dpu5okft8q1qutfx1mx66h X-Rspam-User: X-HE-Tag: 1661426645-769071 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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/