From mboxrd@z Thu Jan 1 00:00:00 1970 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 D00BEEE49A4 for ; Mon, 11 Sep 2023 02:38:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 429AC6B015B; Sun, 10 Sep 2023 22:38:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3D9D96B015C; Sun, 10 Sep 2023 22:38:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A1876B015D; Sun, 10 Sep 2023 22:38:40 -0400 (EDT) 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 18A2F6B015B for ; Sun, 10 Sep 2023 22:38:40 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E19571C9CE2 for ; Mon, 11 Sep 2023 02:38:39 +0000 (UTC) X-FDA: 81222758358.19.4362281 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf02.hostedemail.com (Postfix) with ESMTP id 0DF3180005 for ; Mon, 11 Sep 2023 02:38:37 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="I+/6r19N"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf02.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.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=1694399918; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=OA5FPhJGtcfrrgJQr2PSRC3PhbMxdwfUXAA3Q6/Xk48=; b=Cdp2z123IUf4hT2x3Gxpic87ypsgn60smLdkGsOB5GQVeSN4dBQAlVuYuLJdqPxEjYSgFA Ek2vmmx2LYIKIRFUenpN5WauJ8AYSe21ByhUTyNH9xkBrGoo3gK8aZG70q7Ej/NWBYx6mp lG/s8uzFBvJmBUx9bEDUGmCsWfNWSBo= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="I+/6r19N"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf02.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694399918; a=rsa-sha256; cv=none; b=A2zAPTaMal1+jmo2iVVJjg7CqFWYLodrp1jn6FSt4jj74afm9XExPIOmzkWF3p+KWCfw+p XCf0vU+nLEbAkmvEDZY4HjaJg+zIEejSFysSg1mHFb7pgip8HPsMcLjP8kmW/pDfixrJHY zRN7+4wS/ZcbLJ+RoI9sLVnGWKRaBd4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694399917; 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: in-reply-to:in-reply-to:references:references; bh=OA5FPhJGtcfrrgJQr2PSRC3PhbMxdwfUXAA3Q6/Xk48=; b=I+/6r19NCtj0NfxtxdciIAdhSRimE09KaZFRIx0O1sYJ4mkeFhle8R405VbHVx/J+0rT6j HqxbwP9m5468G9a0cKgbcWrWA5WgEjqNvwAZ0d54gjuD/KSgglBDUA7emrpTMJM92nqFyp siGwC6mkqrUuoBR/z9xdAuATdwxSWWg= Received: from mimecast-mx02.redhat.com (mx-ext.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-350-dKsYZfzTM7mxtbvPQVYjCw-1; Sun, 10 Sep 2023 22:38:33 -0400 X-MC-Unique: dKsYZfzTM7mxtbvPQVYjCw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 26C801C0514C; Mon, 11 Sep 2023 02:38:33 +0000 (UTC) Received: from localhost (unknown [10.72.112.35]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5EC35200B401; Mon, 11 Sep 2023 02:38:32 +0000 (UTC) Date: Mon, 11 Sep 2023 10:38:29 +0800 From: Baoquan He To: "Uladzislau Rezki (Sony)" Cc: linux-mm@kvack.org, Andrew Morton , LKML , Lorenzo Stoakes , Christoph Hellwig , Matthew Wilcox , "Liam R . Howlett" , Dave Chinner , "Paul E . McKenney" , Joel Fernandes , Oleksiy Avramchenko Subject: Re: [PATCH v2 4/9] mm: vmalloc: Remove global vmap_area_root rb-tree Message-ID: References: <20230829081142.3619-1-urezki@gmail.com> <20230829081142.3619-5-urezki@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230829081142.3619-5-urezki@gmail.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspamd-Queue-Id: 0DF3180005 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: xwrhu5j3k8xru7hx43xjdu4b7sbj4z8h X-HE-Tag: 1694399917-736290 X-HE-Meta: U2FsdGVkX1+Ba/D/g8mB02h3Nc+n6S8AYaJ6rlxfh2uBZTxtzGaDLJmQcTwZuep6+5iV4Qp8CLfYvisxxF0bb/fbE4XzTeZstoFzzm1Xdu4cI3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Nw8OWWjJm+GHyhgX/G471aIO0G1EpTSMOl959UX8Pf2hQLoobsoNWnHgjWMyO/fctqudCpwV425aVi9jGsCecoUA== 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: On 08/29/23 at 10:11am, Uladzislau Rezki (Sony) wrote: > Store allocated objects in a separate nodes. A va->va_start > address is converted into a correct node where it should > be placed and resided. An addr_to_node() function is used > to do a proper address conversion to determine a node that > contains a VA. > > Such approach balances VAs across nodes as a result an access > becomes scalable. Number of nodes in a system depends on number > of CPUs divided by two. The density factor in this case is 1/2. > > Please note: > > 1. As of now allocated VAs are bound to a node-0. It means the > patch does not give any difference comparing with a current > behavior; > > 2. The global vmap_area_lock, vmap_area_root are removed as there > is no need in it anymore. The vmap_area_list is still kept and > is _empty_. It is exported for a kexec only; > > 3. The vmallocinfo and vread() have to be reworked to be able to > handle multiple nodes. > > Signed-off-by: Uladzislau Rezki (Sony) > --- > mm/vmalloc.c | 209 +++++++++++++++++++++++++++++++++++++++------------ > 1 file changed, 161 insertions(+), 48 deletions(-) > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index b7deacca1483..ae0368c314ff 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -728,11 +728,9 @@ EXPORT_SYMBOL(vmalloc_to_pfn); > #define DEBUG_AUGMENT_LOWEST_MATCH_CHECK 0 > > > -static DEFINE_SPINLOCK(vmap_area_lock); > static DEFINE_SPINLOCK(free_vmap_area_lock); > /* Export for kexec only */ > LIST_HEAD(vmap_area_list); > -static struct rb_root vmap_area_root = RB_ROOT; > static bool vmap_initialized __read_mostly; > > static struct rb_root purge_vmap_area_root = RB_ROOT; > @@ -772,6 +770,38 @@ static struct rb_root free_vmap_area_root = RB_ROOT; > */ > static DEFINE_PER_CPU(struct vmap_area *, ne_fit_preload_node); > > +/* > + * An effective vmap-node logic. Users make use of nodes instead > + * of a global heap. It allows to balance an access and mitigate > + * contention. > + */ > +struct rb_list { > + struct rb_root root; > + struct list_head head; > + spinlock_t lock; > +}; > + > +struct vmap_node { > + /* Bookkeeping data of this node. */ > + struct rb_list busy; > +}; > + > +static struct vmap_node *nodes, snode; > +static __read_mostly unsigned int nr_nodes = 1; > +static __read_mostly unsigned int node_size = 1; It could be better if calling these global variables a meaningful name, e.g vmap_nodes, static_vmap_nodes, nr_vmap_nodes. When I use vim+cscope to reference them, it gives me a super long list. Aside from that, a simple name often makes me mistake it as a local virable. A weak opinion. > + > +static inline unsigned int > +addr_to_node_id(unsigned long addr) > +{ > + return (addr / node_size) % nr_nodes; > +} > + > +static inline struct vmap_node * > +addr_to_node(unsigned long addr) > +{ > + return &nodes[addr_to_node_id(addr)]; > +} > + > static __always_inline unsigned long > va_size(struct vmap_area *va) > {