From patchwork Mon Aug 26 07:31:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 11114157 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D694C14DB for ; Mon, 26 Aug 2019 07:31:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ACE35206BA for ; Mon, 26 Aug 2019 07:31:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ACE35206BA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9D86E6B0537; Mon, 26 Aug 2019 03:31:46 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9AFD56B0539; Mon, 26 Aug 2019 03:31:46 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C52A6B053A; Mon, 26 Aug 2019 03:31:46 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0065.hostedemail.com [216.40.44.65]) by kanga.kvack.org (Postfix) with ESMTP id 680536B0537 for ; Mon, 26 Aug 2019 03:31:46 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 1217D181AC9AE for ; Mon, 26 Aug 2019 07:31:46 +0000 (UTC) X-FDA: 75863759412.22.iron02_66a9b6817143f X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,richardw.yang@linux.intel.com,:akpm@linux-foundation.org:vbabka@suse.cz:kirill.shutemov@linux.intel.com:yang.shi@linux.alibaba.com::linux-kernel@vger.kernel.org:richardw.yang@linux.intel.com,RULES_HIT:30054:30070:30075,0,RBL:192.55.52.136:@linux.intel.com:.lbl8.mailshell.net-62.18.0.100 64.95.201.95,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:1:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: iron02_66a9b6817143f X-Filterd-Recvd-Size: 3512 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Mon, 26 Aug 2019 07:31:45 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Aug 2019 00:31:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,431,1559545200"; d="scan'208";a="196992425" Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by fmsmga001.fm.intel.com with ESMTP; 26 Aug 2019 00:31:43 -0700 From: Wei Yang To: akpm@linux-foundation.org, vbabka@suse.cz, kirill.shutemov@linux.intel.com, yang.shi@linux.alibaba.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wei Yang Subject: [PATCH 1/2] mm/mmap.c: update *next* gap after itself Date: Mon, 26 Aug 2019 15:31:05 +0800 Message-Id: <20190826073106.29971-2-richardw.yang@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190826073106.29971-1-richardw.yang@linux.intel.com> References: <20190826073106.29971-1-richardw.yang@linux.intel.com> 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: Since we link a vma to the leaf of a rb_tree, *next* must be a parent of vma if *next* is not NULL. This means if we update *next* gap first, it will be re-update again if vma's gap is bigger. For example, we have a vma tree like this: a [0x9000, 0x10000] / \ b c [0x8000, 0x9000] [0x10000, 0x11000] The gap for each node is: a's gap = 0x8000 b's gap = 0x8000 c's gap = 0x0 Now we want to insert d [0x6000, 0x7000], then the tree look like this: a [0x9000, 0x10000] / \ b c [0x8000, 0x9000] [0x10000, 0x11000] / d [0x6000, 0x7000] b is the *next* of d. If we update b's gap first, it would be 0x1000 and propagate to a. And then when update d's gap, which is 0x6000 and propagate through b to a again. If we update d's gap first, the un-consistent gap 0x1000 will not be propagated. Signed-off-by: Wei Yang --- mm/mmap.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index aa66753b175e..672ad7dc6b3c 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -587,12 +587,6 @@ static unsigned long count_vma_pages_range(struct mm_struct *mm, void __vma_link_rb(struct mm_struct *mm, struct vm_area_struct *vma, struct rb_node **rb_link, struct rb_node *rb_parent) { - /* Update tracking information for the gap following the new vma. */ - if (vma->vm_next) - vma_gap_update(vma->vm_next); - else - mm->highest_vm_end = vm_end_gap(vma); - /* * vma->vm_prev wasn't known when we followed the rbtree to find the * correct insertion point for that vma. As a result, we could not @@ -605,6 +599,13 @@ void __vma_link_rb(struct mm_struct *mm, struct vm_area_struct *vma, rb_link_node(&vma->vm_rb, rb_parent, rb_link); vma->rb_subtree_gap = 0; vma_gap_update(vma); + + /* Update tracking information for the gap following the new vma. */ + if (vma->vm_next) + vma_gap_update(vma->vm_next); + else + mm->highest_vm_end = vm_end_gap(vma); + vma_rb_insert(vma, &mm->mm_rb); } From patchwork Mon Aug 26 07:31:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 11114159 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 520F61398 for ; Mon, 26 Aug 2019 07:31:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 27A2E206BA for ; Mon, 26 Aug 2019 07:31:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 27A2E206BA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BFD556B0539; Mon, 26 Aug 2019 03:31:47 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B356E6B053B; Mon, 26 Aug 2019 03:31:47 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A75636B053C; Mon, 26 Aug 2019 03:31:47 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0111.hostedemail.com [216.40.44.111]) by kanga.kvack.org (Postfix) with ESMTP id 7ADFC6B0539 for ; Mon, 26 Aug 2019 03:31:47 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id 13678180AD7C3 for ; Mon, 26 Aug 2019 07:31:47 +0000 (UTC) X-FDA: 75863759454.26.mist89_66d2154aafd43 X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,richardw.yang@linux.intel.com,:akpm@linux-foundation.org:vbabka@suse.cz:kirill.shutemov@linux.intel.com:yang.shi@linux.alibaba.com::linux-kernel@vger.kernel.org:richardw.yang@linux.intel.com,RULES_HIT:30054:30090,0,RBL:192.55.52.136:@linux.intel.com:.lbl8.mailshell.net-62.18.0.100 64.95.201.95,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:27,LUA_SUMMARY:none X-HE-Tag: mist89_66d2154aafd43 X-Filterd-Recvd-Size: 2766 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Mon, 26 Aug 2019 07:31:46 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Aug 2019 00:31:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,431,1559545200"; d="scan'208";a="196992431" Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by fmsmga001.fm.intel.com with ESMTP; 26 Aug 2019 00:31:44 -0700 From: Wei Yang To: akpm@linux-foundation.org, vbabka@suse.cz, kirill.shutemov@linux.intel.com, yang.shi@linux.alibaba.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wei Yang Subject: [PATCH 2/2] mm/mmap.c: unlink vma before rb_erase Date: Mon, 26 Aug 2019 15:31:06 +0800 Message-Id: <20190826073106.29971-3-richardw.yang@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190826073106.29971-1-richardw.yang@linux.intel.com> References: <20190826073106.29971-1-richardw.yang@linux.intel.com> 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: Current sequence to remove a vma is: vma_rb_erase_ignore() __vma_unlink_list() vma_gap_update() This may do some extra subtree_gap propagation due the vma is unlink from list after rb_erase. For example, we have a tree: a [0x9000, 0x10000] / \ b c [0x8000, 0x9000] [0x10000, 0x11000] / d [0x6000, 0x7000] The gap for each node is: a's gap = 0x6000 b's gap = 0x6000 c's gap = 0x0 d's gap = 0x6000 Now we want to remove node d. Since we don't unlink d from link when doing rb_erase, b's gap would still be computed to 0x1000. This leads to the vma_gap_update() after list unlink would recompute b and a's gap. For this case, by unlink the list before rb_erase, we would have one time less of vma_compute_subtree_gap. Signed-off-by: Wei Yang --- mm/mmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/mmap.c b/mm/mmap.c index 672ad7dc6b3c..907939690a30 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -678,8 +678,8 @@ static __always_inline void __vma_unlink_common(struct mm_struct *mm, struct vm_area_struct *vma, struct vm_area_struct *ignore) { - vma_rb_erase_ignore(vma, &mm->mm_rb, ignore); __vma_unlink_list(mm, vma); + vma_rb_erase_ignore(vma, &mm->mm_rb, ignore); /* Kill the cache */ vmacache_invalidate(mm); }