From patchwork Sat Dec 17 01:54:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13075746 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 32DC1C4332F for ; Sat, 17 Dec 2022 01:54:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8A61D8E0003; Fri, 16 Dec 2022 20:54:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 856088E0001; Fri, 16 Dec 2022 20:54:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 71E5B8E0003; Fri, 16 Dec 2022 20:54:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 63F4B8E0001 for ; Fri, 16 Dec 2022 20:54:54 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 42324AB9BF for ; Sat, 17 Dec 2022 01:54:54 +0000 (UTC) X-FDA: 80250129708.19.AB372D8 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf04.hostedemail.com (Postfix) with ESMTP id A155340005 for ; Sat, 17 Dec 2022 01:54:52 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RhVoc49a; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.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=1671242092; 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=cIt3sYb4X2Dic9YdLpVEM6DfWLpP7LlIvSJefb8eTGQ=; b=Z2m3g8dq9wL4KhzU913286MMveUpt7c1d+nmho1JoQ3Z1xWSMNeNgxCNggd0rx5Jb1t1dW WtepnWn317//jUG6Woo73ErkYSU5asAOdT+ss140eQA54nWWKm5M0KI1t0pE2fedRVRQ+e 9JdBumtJJlQ3MAPjNajDlQXiQQ3kZOs= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RhVoc49a; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.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=1671242092; a=rsa-sha256; cv=none; b=wvFjP/22SAkpW1wRM8sq7wiFje6svE/Uaj2FYF3u81f7cTjq7VI63qCkXiwsnvuPdFwPsN qrOgCF2Gl6/fJwzvGHNvVOoyr1GDaYpilh4l6zMphzPKobPaunKrW47xt+2QBLOBnab56V rhyFs2uCYMDekRbMQ32jrTtDPMcOFQE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671242092; 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=cIt3sYb4X2Dic9YdLpVEM6DfWLpP7LlIvSJefb8eTGQ=; b=RhVoc49aik41IADQOMoMgQATOeNenz+SdYzq5HXAC6HUjFqDh9z5yLixSMQatUC9kP4N28 QLS+14V9zflJDeYPpLmZtrr7upwi+GA+Dw4NPu2BmzLK0+q3v/vTO7l83LhGm0MPX/mAjy lFgnh8zRLWmrQTfPZsXcV66TMJnfe80= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-497-eldor5REOyyUyGect5JAew-1; Fri, 16 Dec 2022 20:54:48 -0500 X-MC-Unique: eldor5REOyyUyGect5JAew-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 27A3338041E4; Sat, 17 Dec 2022 01:54:48 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-34.pek2.redhat.com [10.72.12.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 25B5F400F5E; Sat, 17 Dec 2022 01:54:43 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, urezki@gmail.com, stephen.s.brennan@oracle.com, willy@infradead.org, akpm@linux-foundation.org, hch@infradead.org, Baoquan He Subject: [PATCH v2 1/7] mm/vmalloc.c: add used_map into vmap_block to track space of vmap_block Date: Sat, 17 Dec 2022 09:54:29 +0800 Message-Id: <20221217015435.73889-2-bhe@redhat.com> In-Reply-To: <20221217015435.73889-1-bhe@redhat.com> References: <20221217015435.73889-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: A155340005 X-Stat-Signature: zieigx7oyjjodz55zxdj7b8fc7y5wbqd X-HE-Tag: 1671242092-802319 X-HE-Meta: U2FsdGVkX1+3dgcIMVv3TxZ4dyrc1T+H4S9DJ71EkrP0OGKUNZ/mqxKrfFXGl2dKTKvTtMYA7LXNJU/1UScsqr7XsX/jCzo7eEu3KdpzfnP7xjdSwVdUVvwcEOLeL5EDU7CBPNb3893rg3gRQN7LoYTCoeuTalSM2IeBVLzLIfP63vbljAhUa3PAsoV+XnRi9yHz2/cBNyukUAzeaGrvdqGW7b0qXSDSfQ6M/p3+k96raGlsnqfzEDJ9V/I+OShWAdCwsUHHVHlIu+th0G1Hx5Fwt0McGzsXjoR+IbgoOp+1WcdQqEHZ9C4anuZ6kl/efc5b1uAjvXZxPjfCOlQt0/J2nmJWNEiP9XTUOKz5DQrUEq2uDhNfe73OnZAtV2vhXBwrDLrtlrZ/zCElblqg0GcBRiREu2ty9b1jG9Mv7/u9FtAFGpC4dE2UG2nA+Iux2TATOfa6fa2kEB6lxQcYrCK/LaAWPGvDdU5HqmmiJQfSDUaNMoui9cqSPYtAc6OuSPwQXo8e/6iy1W6U3kf7bbP5fUXmIKFvLvHaSAIFZWaNZW+qwHsYXZMi0vTHu1fo3aB6qcYaayGwS+RIQMV1krFVFNA80rnVR+ro4dk9nOFH2UHFARR1bbT8Buk10DNBdpJT1+BxA7blqlN8cv5Z53iwVdpGvg9bOvXchf4Qj6w78C8vhFsxvoZbseRNh4nWeuv4ftAmlVNgb46GJtiljGFIYbct//QiVH6IHQ//UdYzkOqehwdgF4SlDrNquX6hLVnF6z2eYEPdS2Yfqh+fw09odPjYafk9Dzm0Yyy5bxmO967utLiARa8qI+drTFvEO1lAVc2ULx9u+4O0f1agAMqXl3Zqs5ntFreH8s4RlFxgmQ9uJC7gM3MTGth2CHhW/vibRpSu6rL6i3Yc64RowFAnczaEa7uRdo9Dm8jSVPICX4GnCMnVylMaPNzBAF+vaaPBACXK9vYH1+60htY hJA== 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 --- mm/vmalloc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index ccaa461998f3..5d3fd3e6fe09 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -1896,6 +1896,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; @@ -1972,10 +1973,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); @@ -2081,6 +2084,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); @@ -2114,6 +2118,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);