From patchwork Wed Feb 1 09:13:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13123984 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51A6EC38142 for ; Wed, 1 Feb 2023 09:13:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D32B26B0072; Wed, 1 Feb 2023 04:13:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CE37D6B0074; Wed, 1 Feb 2023 04:13:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BAB6C6B0075; Wed, 1 Feb 2023 04:13:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id ACEE46B0072 for ; Wed, 1 Feb 2023 04:13:55 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 736D0160373 for ; Wed, 1 Feb 2023 09:13:55 +0000 (UTC) X-FDA: 80418160830.22.014F014 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf02.hostedemail.com (Postfix) with ESMTP id BEEEC80009 for ; Wed, 1 Feb 2023 09:13:53 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="YVTz/GJl"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf02.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675242833; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ZnCrWWx4pp/03QuBJCB11gBYLXEsVuMTBc/8ULu0oDY=; b=YcJEdULxDfN+nWPOtq6wIizgXxhF2ajz5ek9a29bj4znhVwqhFgjWHuP9yv0OZUA42aDlX ST0WpL9WOjqNw3hAEl+cxiQO2WhBd215bVSQaoV9tOhc4T3FaPsDz40Ded5Xc8P5vE7rGE 5ai8Km8j9xZvNYiategopmlVUpO53hg= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="YVTz/GJl"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf02.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675242833; a=rsa-sha256; cv=none; b=SfOXrdttEzWgWYEva0YC4r6miUFL9DIFKlMKNrmtzhWIdA8ZWjT34bCxDs7FZ8I77HJtzq kXmOQshDypODbkWf5obFKU7FRzSDHc3Kt+1tJOPe42Gl/OSDAUg2nlCaDYN3LCjy0LT8AP WjC8ApSlz4cZexUp+86SOoZ8noOlOb8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675242833; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZnCrWWx4pp/03QuBJCB11gBYLXEsVuMTBc/8ULu0oDY=; b=YVTz/GJlsqNGgDDN+GW1TsmfbAumfvRVbc7hPz9hAyyo6ZoG6GlhXVdn+NzP/ovD+uavLr qyGggIaoOt9VXIUQKKr/gIN0N0Cthn4R8IUh5xRTCgl3EJw9HdvmnChde9hWcDaARP71mb /Ffxymtkn2HiRP7YWsNciaLnkjVlGRY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-637-Nc5wLedcPe-Xy7Ol7YXmwg-1; Wed, 01 Feb 2023 04:13:52 -0500 X-MC-Unique: Nc5wLedcPe-Xy7Ol7YXmwg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 53881855305; Wed, 1 Feb 2023 09:13:51 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-13-89.pek2.redhat.com [10.72.13.89]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24BCB492C3E; Wed, 1 Feb 2023 09:13:46 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, stephen.s.brennan@oracle.com, urezki@gmail.com, lstoakes@gmail.com, willy@infradead.org, hch@infradead.org, error27@gmail.com, Baoquan He Subject: [PATCH v4 1/7] mm/vmalloc.c: add used_map into vmap_block to track space of vmap_block Date: Wed, 1 Feb 2023 17:13:33 +0800 Message-Id: <20230201091339.61761-2-bhe@redhat.com> In-Reply-To: <20230201091339.61761-1-bhe@redhat.com> References: <20230201091339.61761-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Rspamd-Queue-Id: BEEEC80009 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: yyejghcsfzqfjki4o3mn1mkq7f9it8ni X-HE-Tag: 1675242833-967669 X-HE-Meta: U2FsdGVkX1+NEw6dXKnHcz/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kovWjXlWNyYhrAcJBimCXtHUev1/72043GrIjXdru6hlRdpMGAe5stLa3F17XiNFB3q8sQPqRfNsTqX8rIcxa2SshwL6Nqjfj2FRtihlJGzcR5m/ByE3745W4sfSeFkd/Wzim52TJJXypU1rSWEojZqIKgsTUoNMK 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: In one vmap_block area, there could be three types of regions: region being used which is allocated through vb_alloc(), dirty region which is freed via vb_free() and free region. Among them, only used region has available data. While there's no way to track those used regions currently. Here, add bitmap field used_map into vmap_block, and set/clear it during allocation or freeing regions of vmap_block area. This is a preparatoin for later use. Signed-off-by: Baoquan He Reviewed-by: Lorenzo Stoakes Reviewed-by: Uladzislau Rezki (Sony) --- mm/vmalloc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 428e0bee5c9c..d6ff058ef4d0 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -1922,6 +1922,7 @@ struct vmap_block { spinlock_t lock; struct vmap_area *va; unsigned long free, dirty; + DECLARE_BITMAP(used_map, VMAP_BBMAP_BITS); unsigned long dirty_min, dirty_max; /*< dirty range */ struct list_head free_list; struct rcu_head rcu_head; @@ -1998,10 +1999,12 @@ static void *new_vmap_block(unsigned int order, gfp_t gfp_mask) vb->va = va; /* At least something should be left free */ BUG_ON(VMAP_BBMAP_BITS <= (1UL << order)); + bitmap_zero(vb->used_map, VMAP_BBMAP_BITS); vb->free = VMAP_BBMAP_BITS - (1UL << order); vb->dirty = 0; vb->dirty_min = VMAP_BBMAP_BITS; vb->dirty_max = 0; + bitmap_set(vb->used_map, 0, (1UL << order)); INIT_LIST_HEAD(&vb->free_list); vb_idx = addr_to_vb_idx(va->va_start); @@ -2111,6 +2114,7 @@ static void *vb_alloc(unsigned long size, gfp_t gfp_mask) pages_off = VMAP_BBMAP_BITS - vb->free; vaddr = vmap_block_vaddr(vb->va->va_start, pages_off); vb->free -= 1UL << order; + bitmap_set(vb->used_map, pages_off, (1UL << order)); if (vb->free == 0) { spin_lock(&vbq->lock); list_del_rcu(&vb->free_list); @@ -2144,6 +2148,9 @@ static void vb_free(unsigned long addr, unsigned long size) order = get_order(size); offset = (addr & (VMAP_BLOCK_SIZE - 1)) >> PAGE_SHIFT; vb = xa_load(&vmap_blocks, addr_to_vb_idx(addr)); + spin_lock(&vb->lock); + bitmap_clear(vb->used_map, offset, (1UL << order)); + spin_unlock(&vb->lock); vunmap_range_noflush(addr, addr + size);