From patchwork Sun Dec 1 01:50:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 11268237 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 11E49921 for ; Sun, 1 Dec 2019 01:50:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C7273208E4 for ; Sun, 1 Dec 2019 01:50:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="A6d9++za" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C7273208E4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B79616B0292; Sat, 30 Nov 2019 20:50:45 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B28EE6B0294; Sat, 30 Nov 2019 20:50:45 -0500 (EST) 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 A668E6B0295; Sat, 30 Nov 2019 20:50:45 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0056.hostedemail.com [216.40.44.56]) by kanga.kvack.org (Postfix) with ESMTP id 8E3DB6B0292 for ; Sat, 30 Nov 2019 20:50:45 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id 4D20D180AD817 for ; Sun, 1 Dec 2019 01:50:45 +0000 (UTC) X-FDA: 76214893650.13.spoon18_68f064652928 X-Spam-Summary: 2,0,0,6b296b6472f42619,d41d8cd98f00b204,akpm@linux-foundation.org,:akpm@linux-foundation.org:hch@infradead.org::mgorman@techsingularity.net:mm-commits@vger.kernel.org:osalvador@suse.de:richardw.yang@linux.intel.com:torvalds@linux-foundation.org:vbabka@suse.cz:willy@infradead.org,RULES_HIT:41:69:355:379:800:960:967:968:973:988:989:1260:1263:1345:1381:1431:1437:1534:1542:1711:1730:1747:1777:1792:2198:2199:2393:2525:2559:2563:2682:2685:2859:2901:2902:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3872:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:5007:6119:6261:6653:7576:8599:9010:9025:9121:9545:10004:10913:11026:11658:11914:12043:12048:12296:12297:12438:12517:12519:12555:12679:12783:12986:13161:13172:13229:14096:14181:14721:14849:21080:21451:21627:21790:21939:30054,0,RBL:error,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0 ,LFtime: X-HE-Tag: spoon18_68f064652928 X-Filterd-Recvd-Size: 3895 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Sun, 1 Dec 2019 01:50:44 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E28E72086A; Sun, 1 Dec 2019 01:50:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575165044; bh=tRkNnM4/yqTlTEfqmxUfUHlryVaKPkSHBrI726c/yAE=; h=Date:From:To:Subject:From; b=A6d9++zauhm51fcmUa0IELIy88+CDL4lyR8+TYfjTwf5Tn6xxCF2u5OA7UFK8Qsje LaulgDTAXKh4CY5WYAZdEeJQ6KVmI1mJ0mCVvS8J0eUMXUOKjhUT91MyisdeqwZ967 94/s5hD0VptGeK3Tljq/CTF7CvVqGQn0l4LGD/LE= Date: Sat, 30 Nov 2019 17:50:43 -0800 From: akpm@linux-foundation.org To: akpm@linux-foundation.org, hch@infradead.org, linux-mm@kvack.org, mgorman@techsingularity.net, mm-commits@vger.kernel.org, osalvador@suse.de, richardw.yang@linux.intel.com, torvalds@linux-foundation.org, vbabka@suse.cz, willy@infradead.org Subject: [patch 030/158] mm/mmap.c: prev could be retrieved from vma->vm_prev Message-ID: <20191201015043.vxwibc4lm%akpm@linux-foundation.org> User-Agent: s-nail v14.8.16 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: From: Wei Yang Subject: mm/mmap.c: prev could be retrieved from vma->vm_prev Currently __vma_unlink_common handles two cases: * has_prev * or not When has_prev is false, it is obvious prev is calculated from vma->vm_prev in __vma_unlink_common. When has_prev is true, the prev is passed through from __vma_unlink_prev in __vma_adjust for non-case 8. And at the beginning next is calculated from vma->vm_next, which implies vma is next->vm_prev. The above statement sounds a little complicated, while to think in another point of view, no matter whether vma and next is swapped, the mmap link list still preserves its property. It is proper to access vma->vm_prev. Link: http://lkml.kernel.org/r/20191006012636.31521-1-richardw.yang@linux.intel.com Signed-off-by: Wei Yang Cc: Mel Gorman Cc: Vlastimil Babka Cc: Oscar Salvador Cc: Christoph Hellwig Cc: Matthew Wilcox (Oracle) Signed-off-by: Andrew Morton --- mm/mmap.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) --- a/mm/mmap.c~mm-mmapc-prev-could-be-retrieved-from-vma-vm_prev +++ a/mm/mmap.c @@ -684,23 +684,17 @@ static void __insert_vm_struct(struct mm static __always_inline void __vma_unlink_common(struct mm_struct *mm, struct vm_area_struct *vma, - struct vm_area_struct *prev, - bool has_prev, struct vm_area_struct *ignore) { - struct vm_area_struct *next; + struct vm_area_struct *prev, *next; vma_rb_erase_ignore(vma, &mm->mm_rb, ignore); next = vma->vm_next; - if (has_prev) + prev = vma->vm_prev; + if (prev) prev->vm_next = next; - else { - prev = vma->vm_prev; - if (prev) - prev->vm_next = next; - else - mm->mmap = next; - } + else + mm->mmap = next; if (next) next->vm_prev = prev; @@ -712,7 +706,7 @@ static inline void __vma_unlink_prev(str struct vm_area_struct *vma, struct vm_area_struct *prev) { - __vma_unlink_common(mm, vma, prev, true, vma); + __vma_unlink_common(mm, vma, vma); } /* @@ -898,7 +892,7 @@ again: * "next" (which is stored in post-swap() * "vma"). */ - __vma_unlink_common(mm, next, NULL, false, vma); + __vma_unlink_common(mm, next, vma); if (file) __remove_shared_vm_struct(next, file, mapping); } else if (insert) {