Received: by 10.223.185.116 with SMTP id b49csp762928wrg; Sat, 10 Feb 2018 19:22:53 -0800 (PST) X-Google-Smtp-Source: AH8x226ZgwWOaLuu65csCiyiuUHpfWkVlS4nEGu8msEGS1eh1rG1kNpnY04RTAueTy/1pF2Q5ncb X-Received: by 10.99.188.2 with SMTP id q2mr6156642pge.67.1518319373122; Sat, 10 Feb 2018 19:22:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518319373; cv=none; d=google.com; s=arc-20160816; b=OTBfwRHDDABDjnYlOg4+Ugir7OjF/f7JB0Q1HdhB6NqQ8eO9DjGAccQiAa30wlIsOZ qXgyWqhoBiiIDYjstkj22NZuXPOOrdXY5tFhea91xpe64TmGTE2GsTQAwV1tRab06tYN vCNoKc9gha/zeuZX/2hb4/qDyUetj1qUvDwW2EQYGiro4zFMxsFiI5VkpH5hZWxN4Run DyU7jGtFCsEnjw/1qmha2GTObsIOdsoBrM8PshFPLQkmdvcMviIgJwMY+Xqkr/cIB7fJ vtDf2iwbOarpBqrA+8CU1Bga+q2VVZ6o7snUIS/xZ30LIFrZ6mEoW9VP7vnr/1hPmBxs cAZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=MQdgs6ujP7LWDZGNv/WHuQlAySLcoOwNL8AuKWrbq/c=; b=f8SQ4DSfg6xPFr5iE1quUEZbY0cNMvCda8py+1VDOYkczHA486DmRaAFDMVo/dKsFC XcjUdY30YiQYZF/RCKYjTCg9/gdNPepGKlwSEjJ9TKa6nYp60R/xR/3JBgz6HAJHPPdE l6bjvvfYDzOMOAKazovDar5OgCr05M3dqBn0uoTZodwGpxLSUEpGfQQ/kMhk+XdjcP5u np53+M16XxqRHd1SLTt8tpDp4f75jzoMZlEKRAy33Er/ItphuS0Z7E9v+iRXvclltX0n wb0R0joSBnYTSEasvvUTnP2gHcGHQ4Ph3TPD26dA9oRPREg1aEINadclsFmP/ltgu1PX vmRg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b18si760089pgu.8.2018.02.10.19.22.39; Sat, 10 Feb 2018 19:22:53 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752465AbeBKDVa (ORCPT + 99 others); Sat, 10 Feb 2018 22:21:30 -0500 Received: from lhrrgout.huawei.com ([194.213.3.17]:26064 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752285AbeBKDV2 (ORCPT ); Sat, 10 Feb 2018 22:21:28 -0500 Received: from LHREML712-CAH.china.huawei.com (unknown [172.18.7.106]) by Forcepoint Email with ESMTP id C4E27A179BBFB; Sun, 11 Feb 2018 03:21:25 +0000 (GMT) Received: from localhost.localdomain (10.122.225.51) by smtpsuk.huawei.com (10.201.108.35) with Microsoft SMTP Server (TLS) id 14.3.361.1; Sun, 11 Feb 2018 03:21:20 +0000 From: Igor Stoppa To: , , , , , , , CC: , , , , , Igor Stoppa Subject: [PATCH 3/6] struct page: add field for vm_struct Date: Sun, 11 Feb 2018 05:19:17 +0200 Message-ID: <20180211031920.3424-4-igor.stoppa@huawei.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180211031920.3424-1-igor.stoppa@huawei.com> References: <20180211031920.3424-1-igor.stoppa@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.122.225.51] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When a page is used for virtual memory, it is often necessary to obtian a handler to the corresponding vm_struct, which refers to the virtually continuous area generated when invoking vmalloc. The struct page has a "mapping" field, which can be re-used, to store a pointer to the parent area. This will avoid more expensive searches. As example, the function find_vm_area is reimplemented, to take advantage of the newly introduced field. Signed-off-by: Igor Stoppa --- include/linux/mm_types.h | 1 + mm/vmalloc.c | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index fd1af6b9591d..c3a4825e10c0 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -84,6 +84,7 @@ struct page { void *s_mem; /* slab first object */ atomic_t compound_mapcount; /* first tail page */ /* page_deferred_list().next -- second tail page */ + struct vm_struct *area; }; /* Second double word */ diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 673942094328..9404ffd0ee98 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -1466,13 +1466,16 @@ struct vm_struct *get_vm_area_caller(unsigned long size, unsigned long flags, */ struct vm_struct *find_vm_area(const void *addr) { - struct vmap_area *va; + struct page *page; - va = find_vmap_area((unsigned long)addr); - if (va && va->flags & VM_VM_AREA) - return va->vm; + if (unlikely(!is_vmalloc_addr(addr))) + return NULL; - return NULL; + page = vmalloc_to_page(addr); + if (unlikely(!page)) + return NULL; + + return page->area; } /** @@ -1536,6 +1539,7 @@ static void __vunmap(const void *addr, int deallocate_pages) struct page *page = area->pages[i]; BUG_ON(!page); + page->area = NULL; __free_pages(page, 0); } @@ -1744,6 +1748,7 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align, const void *caller) { struct vm_struct *area; + unsigned int i; void *addr; unsigned long real_size = size; @@ -1769,6 +1774,9 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align, kmemleak_vmalloc(area, size, gfp_mask); + for (i = 0; i < area->nr_pages; i++) + area->pages[i]->area = area; + return addr; fail: -- 2.14.1