Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp218302ybl; Tue, 13 Aug 2019 19:20:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqwIJ1lH9gasdLuqo0bpBeKlCpeVdHllAj2rTzMFHH5hwfpt0kKKMYqQltBSmMAp+4Rh6EUp X-Received: by 2002:a17:902:8f93:: with SMTP id z19mr38987874plo.97.1565749204118; Tue, 13 Aug 2019 19:20:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565749204; cv=none; d=google.com; s=arc-20160816; b=zXOfP0t1cqnH9gZT7j82dNagZaQ8t/Tm7Xnvb+NOCSivKIS75mp5vJNhoZ4YMU1tbU 72dfA1oL7MlHWT14DtOaqwegUzLnLtJM5pzMUv7m52EIzxQM1wQ7G7O5+87GCqm5Fm1J Fn8hs6mRXsJARNBQhiWf2hhFe1/8CC1lCmsbiF9EPGn1wQcN4uzo6Azaur7lf4FZAddh WEsP8tD7xLI2uK5/Q+PuEBoFtm/cM3claa9TKvlxuHqwCRIbcTiAesOWAwxq3Kl5UhxO P40gzWc7M4pGGkENZVWvcFaQhplMmVfMbfvgADpjmjAkYjgtD68MvTtD5ttQJrhmAd2O u3Xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=9Y+srqrFDFgnMr0vwhpTBNzGCgpOcF4tNB1lCauRJF4=; b=z4PiqPVrl8exlDYYxnv51TlA8SecxDurRJnnlLnXoOtnm1R/UkLspnfsCamcoUiPbH 8Q/OIY5Mw1fH73aMK8Dbjp45HEEM+nh0dzAOaYcDtaPD7M8EVTIMgGpFe96ZxIWdqIRF FKinr8pg9hjlDJDWRXeWoAY5Ux1LzSu4uJo21ny1ymrPkNExrCS4sSaKqn1ojmRk+SG2 u2hbqzw3FOgwvTKJQcS/W8KEzi2spHiJJa0FUcfSJmFA0f/Iw9IjXFBxHfK8hC+qhcV2 zrbqOVnRkW8RUPiv6qYnm8jcwcHCkAc/F1pmZnbfnb/B0Bm+vfCaa7aPzNIk+ZlwmSJ7 c2Lw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j4si53939533pfa.141.2019.08.13.19.19.48; Tue, 13 Aug 2019 19:20:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728288AbfHNCSX (ORCPT + 99 others); Tue, 13 Aug 2019 22:18:23 -0400 Received: from mga09.intel.com ([134.134.136.24]:54536 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727877AbfHNCSV (ORCPT ); Tue, 13 Aug 2019 22:18:21 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Aug 2019 19:18:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,382,1559545200"; d="scan'208";a="205293131" Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by fmsmga002.fm.intel.com with ESMTP; 13 Aug 2019 19:18:19 -0700 From: Wei Yang To: akpm@linux-foundation.org, mgorman@techsingularity.net, vbabka@suse.cz, osalvador@suse.de Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wei Yang Subject: [PATCH 1/3] mm/mmap.c: prev could be retrieved from vma->vm_prev Date: Wed, 14 Aug 2019 10:17:53 +0800 Message-Id: <20190814021755.1977-1-richardw.yang@linux.intel.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Wei Yang --- mm/mmap.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index b8072630766f..3d56340fea36 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -675,23 +675,17 @@ static void __insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma) 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; @@ -703,7 +697,7 @@ static inline void __vma_unlink_prev(struct mm_struct *mm, struct vm_area_struct *vma, struct vm_area_struct *prev) { - __vma_unlink_common(mm, vma, prev, true, vma); + __vma_unlink_common(mm, vma, vma); } /* @@ -891,7 +885,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start, * "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) { -- 2.17.1