Received: by 10.192.165.156 with SMTP id m28csp568265imm; Mon, 16 Apr 2018 05:20:57 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/CYQMgsYOwd5Yk481uS3h6y2QOk4X7uRH7B9YdNbEF5WiTS3kJnFP1SHOHF0NcCcFSXmYk X-Received: by 10.98.32.134 with SMTP id m6mr21537881pfj.27.1523881257364; Mon, 16 Apr 2018 05:20:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523881257; cv=none; d=google.com; s=arc-20160816; b=k5fyXmpqJ4ohMVMk3XlwHYDlWun2RwcszsYFJMggxiR/ALdnHSQkkcmDahMLof6KGA IV5Djyl7xuOfLg1JH3NoquTAf6fqrRA42zVmX+OtTzXbvy0vzLd9edhTx0r8CMkc3dXy c3QikXzjiDYrOZCzp5Wmi5DUKx3qgEdbMfMpsRsFAOnBFdhWw1GIxqPyCg7WQQ810F8G V60JiTZFNrjl16JPjHN3Rr2+SX0lXU/4vDOMbtCdeFe1mv2EzhLDnMLKsYbmDYMxcMru 3grq7l80TRQgn6if2NSntav9DISM+ORRN0OVuULjzEehj3d7pJPwYThLdyvTxIlSsRrr GsOQ== 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 :dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=KkXBWJThX9ekeXWT0DAPTrMQ71gzXyOpqnjltvdKIrw=; b=HOTb9qkJQFuhxA2QY22cRGns9DP6Nr//VFEhzyL8dwxD/UtWASFMRS/I5KCdrgO9Vn V0t0K4Oe029wvh2LSYfaLAlRf4CWL5L5+p75XAuQo2lUD9Q42JQZO/Rsug9oDoiq5S7A Xzpxk6fSPTuIUypc48nZO1Yce2kKB8m7ZKSy9d27MP3m72yWoaICRTxSoxdUYU+JOVrJ u6z44lOcF0pRGCksA5wV8JPHU8zaL6oodOmEbLLnImln52co/1eFxuth+ElAD9Lax4yr aDC8sCskEpEcDboMqGCskEoSWw2pHxORspmlhrEfUMblbnx+Nbdfq49b1zGIvR7ldabo WOyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=VoWYZnjF; dkim=pass header.i=@codeaurora.org header.s=default header.b=V/Ed97qn; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 196si7413206pfv.94.2018.04.16.05.20.43; Mon, 16 Apr 2018 05:20:57 -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; dkim=pass header.i=@codeaurora.org header.s=default header.b=VoWYZnjF; dkim=pass header.i=@codeaurora.org header.s=default header.b=V/Ed97qn; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754450AbeDPK7R (ORCPT + 99 others); Mon, 16 Apr 2018 06:59:17 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:60900 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753166AbeDPK7Q (ORCPT ); Mon, 16 Apr 2018 06:59:16 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 91D8160F94; Mon, 16 Apr 2018 10:59:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1523876355; bh=+jSHYt/2fBiRk66pNC5FU0r0Jh52WUbO6J8aDmPgTCo=; h=From:To:Cc:Subject:Date:From; b=VoWYZnjFx1FOfit5Kz8r00c9n/yQctNsOl1lDcsPsnzj8gPHKrfwsCIYhl+pLbXXB ozLXaTxPDkLpyJCzQmjbG6avB0/UYel/JjI49vGUObFtUZfSZ697qvrLFwRlRHkpcI N9xHMTVG60XhZDT6MpPCwnxoC3DFUkdr8CjYD/m0= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from cpandya-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: cpandya@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 0F752602B8; Mon, 16 Apr 2018 10:59:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1523876354; bh=+jSHYt/2fBiRk66pNC5FU0r0Jh52WUbO6J8aDmPgTCo=; h=From:To:Cc:Subject:Date:From; b=V/Ed97qnZfXvvbP1GPveI8d3HhVQZ63DSMX7ExSsVHmdYlPRqf1cxTVX2N4f89T9v LReQWE1f1W3T5CZ5rvvnBcsfLi4l8lylEg4nWfO/nqXDZkHDDxvpT0RPOeuIPYmmgU ncjevnAoWAX5j/pS9b6P34H6g0edEBgw/Otyk1eE= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 0F752602B8 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=cpandya@codeaurora.org From: Chintan Pandya To: vbabka@suse.cz, labbott@redhat.com, catalin.marinas@arm.com, hannes@cmpxchg.org, f.fainelli@gmail.com, xieyisheng1@huawei.com, ard.biesheuvel@linaro.org, richard.weiyang@gmail.com, byungchul.park@lge.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Chintan Pandya Subject: [PATCH v2] mm: vmalloc: Clean up vunmap to avoid pgtable ops twice Date: Mon, 16 Apr 2018 16:29:02 +0530 Message-Id: <1523876342-10545-1-git-send-email-cpandya@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org vunmap does page table clear operations twice in the case when DEBUG_PAGEALLOC_ENABLE_DEFAULT is enabled. So, clean up the code as that is unintended. As a perf gain, we save few us. Below ftrace data was obtained while doing 1 MB of vmalloc/vfree on ARM64 based SoC *without* this patch applied. After this patch, we can save ~3 us (on 1 extra vunmap_page_range). CPU DURATION FUNCTION CALLS | | | | | | | 6) | __vunmap() { 6) | vmap_debug_free_range() { 6) 3.281 us | vunmap_page_range(); 6) + 45.468 us | } 6) 2.760 us | vunmap_page_range(); 6) ! 505.105 us | } Signed-off-by: Chintan Pandya --- mm/vmalloc.c | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index ebff729..6729400 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -603,26 +603,6 @@ static void unmap_vmap_area(struct vmap_area *va) vunmap_page_range(va->va_start, va->va_end); } -static void vmap_debug_free_range(unsigned long start, unsigned long end) -{ - /* - * Unmap page tables and force a TLB flush immediately if pagealloc - * debugging is enabled. This catches use after free bugs similarly to - * those in linear kernel virtual address space after a page has been - * freed. - * - * All the lazy freeing logic is still retained, in order to minimise - * intrusiveness of this debugging feature. - * - * This is going to be *slow* (linear kernel virtual address debugging - * doesn't do a broadcast TLB flush so it is a lot faster). - */ - if (debug_pagealloc_enabled()) { - vunmap_page_range(start, end); - flush_tlb_kernel_range(start, end); - } -} - /* * lazy_max_pages is the maximum amount of virtual address space we gather up * before attempting to purge with a TLB flush. @@ -756,6 +736,9 @@ static void free_unmap_vmap_area(struct vmap_area *va) { flush_cache_vunmap(va->va_start, va->va_end); unmap_vmap_area(va); + if (debug_pagealloc_enabled()) + flush_tlb_kernel_range(va->va_start, va->va_end); + free_vmap_area_noflush(va); } @@ -1142,7 +1125,6 @@ void vm_unmap_ram(const void *mem, unsigned int count) BUG_ON(!PAGE_ALIGNED(addr)); debug_check_no_locks_freed(mem, size); - vmap_debug_free_range(addr, addr+size); if (likely(count <= VMAP_MAX_ALLOC)) { vb_free(mem, size); @@ -1499,7 +1481,6 @@ struct vm_struct *remove_vm_area(const void *addr) va->flags |= VM_LAZY_FREE; spin_unlock(&vmap_area_lock); - vmap_debug_free_range(va->va_start, va->va_end); kasan_free_shadow(vm); free_unmap_vmap_area(va); -- Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc., is a member of Code Aurora Forum, a Linux Foundation Collaborative Project