Received: by 10.192.165.148 with SMTP id m20csp4860155imm; Tue, 1 May 2018 05:17:03 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrltvMUbjL9vn4ybZfYEiAqp+JLZ0Ko0PNJVGDFsXn62gvtfHov7k2uQZjM4rE2+C6uTCXV X-Received: by 2002:a17:902:9a49:: with SMTP id x9-v6mr15588804plv.94.1525177022965; Tue, 01 May 2018 05:17:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525177022; cv=none; d=google.com; s=arc-20160816; b=QqCzGlLt2yeInETuIdLDbtE1hTeLLLzT8a0eeahMI9qalSTJW4iHVa9yM963IgHioV lqfv8I6lhy40Hf/EQVtzzzY4kqxKOgGdWuJS9roMjRcZc6XBE+adlpxxOyGL+rtGvfTJ S+cX6m/VX7HJa1a2Bkdf1PYx0q9OAlNcfuLpVJphiSdLdGB+fcNeTi+imxHcySl1MTV1 TpwmYDdDT5eSAneoD6YzLzDdSQQlx9vYYWmmE7ZyoFj9uyNxZColBlj1ol2NKYphn1WR ujE6faiT4D2zz+nP3SBQuzfzF9CJ03+E/HWyFE23I2xIw9Lq/T8cyF5ImPYHUDH3vVyv oEWg== 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=+7KNr5hrgNALuPPlaDp5is9gvAD0+L8iLmwfOz1H6nk=; b=hV7N7LxC6DzerObiBaVdZhIkG8Trf/VpY0Z84gGBn1shm3JiJYOkGGgjJrRAXFf6hp UhC5guXn8Fcpn7v5kq9R/sZXLHminj8rhQgZAV/cvtNu8Y7xDiDExMhVaBYN7moOQVTS 0zr19TCvLKLanECO/nzg5FFRx43xDeBmCIDw/tNaZVle7PwuvZGMJMKP0UAlgvFIUrH1 tsOAkovDlUmvaRKQiuLPs0WjJhcYgxRI/AtScJvctTSkE761S3hSkU0PIieu7ml3j6DS 05WCyhlz+vAUm47DvHGbbkLEKczWgITlt+nKsCsbbJWDat+UehtZn9aWtlf2VxBpTlU/ J1ZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=KoZl7tzD; dkim=pass header.i=@codeaurora.org header.s=default header.b=kVSuaNeL; 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 f35-v6si9250737plh.193.2018.05.01.05.16.48; Tue, 01 May 2018 05:17:02 -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=KoZl7tzD; dkim=pass header.i=@codeaurora.org header.s=default header.b=kVSuaNeL; 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 S1755448AbeEAMQT (ORCPT + 99 others); Tue, 1 May 2018 08:16:19 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:39982 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755089AbeEAMQP (ORCPT ); Tue, 1 May 2018 08:16:15 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id AD08B601A0; Tue, 1 May 2018 12:16:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1525176974; bh=ALKPZ6s3z9ESHbNllCoeRe26/qj5zH9ASLLrUWUbP5Y=; h=From:To:Cc:Subject:Date:From; b=KoZl7tzDN9+uAFWypdpKWPFgh9u0zwiLfbWL9o6uNjqcMB2kcsCBQgXGiwA00SpGo XbVHDVxWt/wj/R1ZVpjwYp0Sqbpwv+GOYygmr4R5g2X+ZTEFRcJiBlMeflOtWNvlKh h26n79HwnnYLb7FTgqhG1Yi3rGX1ZsjV8LLKOfdg= 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 86CD7601A0; Tue, 1 May 2018 12:16:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1525176973; bh=ALKPZ6s3z9ESHbNllCoeRe26/qj5zH9ASLLrUWUbP5Y=; h=From:To:Cc:Subject:Date:From; b=kVSuaNeLxBm9CYskVmwJkeWJsI18Rl/l/Aj5lOt8hfXldPVWXNCv+Qcfo9VkLFHNU tjjzRhzQZjAv0JOaXEoDa2jW0urgeX4d5bixCcYw4fkOvYKn268khM4oCs6uIIU8vr b5rRgg+cyTj2MssVAfWsxraPzoj97imcL6CxKiu8= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 86CD7601A0 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: Andrew Morton , Michal Hocko , Vlastimil Babka Cc: Catalin Marinas , Laura Abbott , Florian Fainelli , Ard Biesheuvel , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Chintan Pandya Subject: [PATCH v3] mm: vmalloc: Clean up vunmap to avoid pgtable ops twice Date: Tue, 1 May 2018 17:46:00 +0530 Message-Id: <1525176960-18408-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 | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index ebff729..781ce02 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); } @@ -1053,6 +1036,10 @@ static void vb_free(const void *addr, unsigned long size) vunmap_page_range((unsigned long)addr, (unsigned long)addr + size); + if (debug_pagealloc_enabled()) + flush_tlb_kernel_range((unsigned long)addr, + (unsigned long)addr + size); + spin_lock(&vb->lock); /* Expand dirty range */ @@ -1142,7 +1129,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 +1485,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