From patchwork Sun May 12 12:35:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Taotao X-Patchwork-Id: 13662722 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 E15ACC10F1A for ; Sun, 12 May 2024 12:36:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 21A746B0184; Sun, 12 May 2024 08:36:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1C7B16B0185; Sun, 12 May 2024 08:36:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 08F516B0186; Sun, 12 May 2024 08:36:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id DF9ED6B0184 for ; Sun, 12 May 2024 08:36:23 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B77C7140BE6 for ; Sun, 12 May 2024 12:36:22 +0000 (UTC) X-FDA: 82109691804.01.62D591E Received: from chinatelecom.cn (smtpnm6-07.21cn.com [182.42.151.156]) by imf16.hostedemail.com (Postfix) with ESMTP id 8F10B180017 for ; Sun, 12 May 2024 12:36:19 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf16.hostedemail.com: domain of chentt10@chinatelecom.cn designates 182.42.151.156 as permitted sender) smtp.mailfrom=chentt10@chinatelecom.cn ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715517380; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=U6iyJ2KmlZEcZpzlk5XDComs+UelHn1f6mfkW4lNR90=; b=Hd+2CTiS7VhKjKb6TSjO3NQWnizTlshIxQ84kXLk3/kgNdSS4Zf6p7TgtFSD99mIwOHBjp vXL6L4w/ApSeG2X5F4EXBTiHLSIknCV8t1fgwmEisqQd4ORaE0P5+DiYVbQQBl5uSGVeb/ RPAnB60FM0Aa2pc2MW+vtHczeK3yBSI= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf16.hostedemail.com: domain of chentt10@chinatelecom.cn designates 182.42.151.156 as permitted sender) smtp.mailfrom=chentt10@chinatelecom.cn ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715517380; a=rsa-sha256; cv=none; b=7w6/r88RBBIab9FP6PNtAlfWKcN5VCUIaTJzHQbnE2mhbAkoqjijGqiEsouVxoT1uIwyFP t3hshnfis+4PpcE5XMP/Kw3ztPQBqA+KrbFcXvWQ9el0Qzh1tMFmLFjaZ5v10UjF6tbXcA ZquXkVRwvmVoT497EHKku3e0H6AwCD4= HMM_SOURCE_IP: 192.168.137.232:14399.1573931882 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-36.111.64.84 (unknown [192.168.137.232]) by chinatelecom.cn (HERMES) with SMTP id F35339BCE7; Sun, 12 May 2024 20:36:06 +0800 (CST) X-189-SAVE-TO-SEND: chentt10@chinatelecom.cn Received: from ([36.111.64.84]) by gateway-ssl-dep-7f596d7dc-5nwtg with ESMTP id d7e17b3c31254085a3111d9a6febed44 for akpm@linux-foundation.org; Sun, 12 May 2024 20:36:12 CST X-Transaction-ID: d7e17b3c31254085a3111d9a6febed44 X-Real-From: chentt10@chinatelecom.cn X-Receive-IP: 36.111.64.84 X-MEDUSA-Status: 0 From: Chen Taotao To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm/rmap: optimize folio_move_anon_rmap() Date: Sun, 12 May 2024 20:35:55 +0800 Message-Id: <20240512123555.8358-1-chentt10@chinatelecom.cn> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 8F10B180017 X-Stat-Signature: sb3coyofns7od64oezar463kxioh4ijx X-HE-Tag: 1715517379-451545 X-HE-Meta: U2FsdGVkX19EtzZQu1vgCZ9TlfSLzUHuUcKEag8QsQt665/bA7pmvFkwL7ES5jjOTGDBxsZQasAgWLl05U4KPr1XEhglH57QBcrt6fBkYNH3DvzNwgyWqwa2TkpckD1DDvaVPAT3pLmwqZ+LjLpcTL+3c70AN7gRYMMlPxq2nmCSbTTmCqlixDgUMQ/daEbsp0j+tKXiwHs/yV9Gl//kaTNMW/mZt44QnQWleXPCUESx5/YYsfF7Um6ni5P2Df5ghDDauBOQWNj+hJIL/4BJWd1zdYApxghYY7oID9Es3gLTGYgdzddVzzEpgl66KlSS3a9kVZXpMvSKFYhhstyJgERLmNPVy0CT53BdTlQOHocodrGwd7+/p+OS/keBGZWoypIsZrzdiFRj+RBOxQJVv/LOrkVHVv7sgjPYKjviclB1Z68fApSQoSjF0PxBrbEMPAqBXvUtmzfZzLmtnjuew2AvMKKhw+/yKKfa7eE/P4yOwSq/0pWhef6M5HnVgPKTBPCrSUC4Zyo8nKXekk3QuergkdFdYIqaorzlquoJUfgTAVHxbrmpThdzuemT+JI/J2OB0TNtGj0Y2Fou6L3S1zM5GLAKwhPrUAL3Sf/qcIK6aCdAgn+HU/FbeA+PPUCcXMtmUiY8vLmU4rjR/6LcpK4pQrN7PH1MWWwOGqZ/ldunFkkDEWGUOy6CUH3+FemAWh4U1RXVNs0l7pHISdSs8Y58He8y5pEEjahDQyfZRyAxHFWeDj9bJrYcWgpLAa/ifohkEqkIzRm+t43KGamK86a0uX9NL5099BylANWaMFE+oF6qA31gUA2qliZSRBfEtwk/bCgBg5fv+Oli62CUbaVQMPPVbFp4j9sg2WMfqg+xLInx49XrpiPM3uZ82DmnzNgIPILCemeFkbVXu7mx6BPaQeqevwmthGUwRWSGvN4A3cqyy2SmL0bbukjJf3tYXVDBdPPji2eCDGd/oQo hU724kAn Dnnc/qHnx74vXpfAwsTMKAWtxBK+W3ET//l6bg5n6PDUUdsa/IhP6PNowD62JbWHmIHZXA1olhyMbuiYYzjXdkBWT74v2DyW9KmoZGNjeqeBsiypJpFesppP/Um0cRV35nPP7drVV3p6beG3fioLkekS4kw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.357119, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: When a folio belongs exclusively to one process after a COW event, folio_move_anon_rmap() always moves the folio into the anon_vma belongs only to this process. However, if the folio already belongs to the anon_vma of the this process, we don't need to move it again. In this case, we first check if the folio already belongs to the anna_vma of the this process, and only move it if it does not. The above changes may improve the performance of vm faults in some scenarios, because the performance loss caused by WRITE_ONCE() is much more than the performance loss caused by add a judgment. Signed-off-by: Chen Taotao --- mm/rmap.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index 3746a5531018..5720cb78162d 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1216,12 +1216,15 @@ void folio_move_anon_rmap(struct folio *folio, struct vm_area_struct *vma) VM_BUG_ON_VMA(!anon_vma, vma); anon_vma += PAGE_MAPPING_ANON; + /* - * Ensure that anon_vma and the PAGE_MAPPING_ANON bit are written - * simultaneously, so a concurrent reader (eg folio_referenced()'s - * folio_test_anon()) will not see one without the other. + * If anon_vma != folio->mapping ensure that anon_vma and the + * PAGE_MAPPING_ANON bit are writtensimultaneously, so a concurrent + * reader (eg folio_referenced()'s folio_test_anon()) will not see + * one without the other. */ - WRITE_ONCE(folio->mapping, anon_vma); + if (anon_vma != folio->mapping) + WRITE_ONCE(folio->mapping, anon_vma); } /**