From patchwork Mon Feb 6 08:40:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13129477 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 73765C61DA4 for ; Mon, 6 Feb 2023 08:40:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DB6746B0073; Mon, 6 Feb 2023 03:40:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D665E6B0074; Mon, 6 Feb 2023 03:40:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C2E3E6B0075; Mon, 6 Feb 2023 03:40:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B90746B0073 for ; Mon, 6 Feb 2023 03:40:39 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 88F51160C21 for ; Mon, 6 Feb 2023 08:40:39 +0000 (UTC) X-FDA: 80436220998.14.D27500A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id B923F40006 for ; Mon, 6 Feb 2023 08:40:36 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gi76awTw; spf=pass (imf07.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675672836; 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=6LdqnyIPCp2yEE1uaFad/YuuXwDh1xy+h2CTd6w04ss9Dfkwp/mrq7qf+mxsbRFgjOic3C o9IKFUG2f9KnY1yT1GvXluIQzY6EbOMaTYtDHWEAbjXeydx1coLaBlkMTUFaACjW9u5NHB iPHA8jCcCRH7q/ULmcLJ0DgqkdYyku4= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gi76awTw; spf=pass (imf07.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675672836; a=rsa-sha256; cv=none; b=fRxAEnoehz+DkpiIgyNYpNYIDIE4TRr1AezKSiQT3ah4vUdM6yB/L/o+Lwkxpn6SGvEZ+K eeWvCFv/8Bl//pRFrFsGTOTS1CeBXnxlRQI3Y/wPDJBGh52oipDV0/3xmYf1T5x8D9H6xp 8MKv8KNeGrhCzkcVzInzAwUIuZCrcOM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675672836; 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=gi76awTwhHCVj+5BH4F5H6c+T2LQIenU9dYbZyulWvqRf/wixmWjOyYawftBrwIMD6dBYR OFRND0BPF6t3XUPLJOtBQ44AAqgMEGMg03bHdEEE3ivE5OQw57Yh95c2nPvnADYiCHYt5A dCLKiK85xQXVRSgMaUYokoVNcWXvhQ4= 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-244-qNwJhTElN9GeQaPmcH1H-w-1; Mon, 06 Feb 2023 03:40:32 -0500 X-MC-Unique: qNwJhTElN9GeQaPmcH1H-w-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 74CF187B2A0; Mon, 6 Feb 2023 08:40:32 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-71.pek2.redhat.com [10.72.12.71]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5FC332166B2B; Mon, 6 Feb 2023 08:40:28 +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, error27@gmail.com, Baoquan He Subject: [PATCH v5 1/7] mm/vmalloc.c: add used_map into vmap_block to track space of vmap_block Date: Mon, 6 Feb 2023 16:40:14 +0800 Message-Id: <20230206084020.174506-2-bhe@redhat.com> In-Reply-To: <20230206084020.174506-1-bhe@redhat.com> References: <20230206084020.174506-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: B923F40006 X-Rspam-User: X-Stat-Signature: yeg4iuh784h5spga4pzx5w8nrn7jbdin X-HE-Tag: 1675672836-758906 X-HE-Meta: U2FsdGVkX19Ge1wlKiNI1iQzfaB481yJZ5eDJXvE8bYrWFiNC7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YkTQJLoOShzOepXNhXjwnexXk9Jz3vjEDJzvhswfXxOMgYREHIJ5Md3quA8eah7+b2W1zYF/eQ9J/2Nti+9FkMTzzHpqfv 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);