Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7019817rwd; Tue, 6 Jun 2023 05:28:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4lIyRysf9H1ueHBqtsd3XJffq86kteBOCRGAnkZ2QZSCOooe51S/IFoboE3AmCW5OfgaLD X-Received: by 2002:a05:6214:d8a:b0:621:64c7:235f with SMTP id e10-20020a0562140d8a00b0062164c7235fmr1497054qve.27.1686054491016; Tue, 06 Jun 2023 05:28:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686054490; cv=none; d=google.com; s=arc-20160816; b=SVwKCfjvHicyhfo8dHrYEhqN7V8ZW52JfKEjBWohxOOnDcRi634wweTpejVgH/D145 ZTEdLZ+3bfKZ4XvdNVd1d4NxeDv3r779MjlK0bRY2wYEsfuM1jentLMLOdUSgmDYsxlD zOz+7uYmGO7y2WMU0XSYqnQtbZTIMhGoE5nU2TPXvGAyIZRCuyXNHWIRmTyKbTAuHXHx p/pN6EVStX/wRONFO9LfF6/NllxnzWBnSSlpN75xwrdWXt5M6WPdx3SBLNko9B86fezJ a8QHrxGZR9XMPM68jHPp3YYMq6QEao+uNwfK17edujxOVTUWC08wnB5hIAYE84rP5OXh wOhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=C9UWxNSLczplRrlU8D85PXIfR9MjaZts2kqh1cwWtVQ=; b=yvaT7ZvZaZaPvzV3eXaxPRUJ2lsDt2MsW8yzncvzN8IldrV/B82EwRIIfN91dg1XUY hXBYMuDq5+GXflwC+AGGcYXAMgX5jN8yRz/WFh0u4PdSd1x/HTAcRIVjxsCil9bf6UXa Di2RS0ydcBp9s9RKQ/Xb5rmNpYjAIXOgcRWJpc9tALfnyoQqyj2uanF4fb96Nr+tZCdk dSuQzFWUc3SpZVGQWrv9cFEpp+DBHm5u//lJoJhutGS9QCXn719d4ygSTWh2fSAZRMXG GQ9Zyv3vTyW5H6LQI8vewSxXOn+fIW1QJI1ovPKMK9CQG2zyo9LmxJnqoGOgzuEPhZ0n N6fQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="O/hFqfes"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u15-20020ad45aaf000000b0061b69d0a7d5si6221517qvg.243.2023.06.06.05.27.50; Tue, 06 Jun 2023 05:28:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="O/hFqfes"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237526AbjFFMNS (ORCPT + 99 others); Tue, 6 Jun 2023 08:13:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236266AbjFFMNM (ORCPT ); Tue, 6 Jun 2023 08:13:12 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEB87199D for ; Tue, 6 Jun 2023 05:12:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686053475; 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=C9UWxNSLczplRrlU8D85PXIfR9MjaZts2kqh1cwWtVQ=; b=O/hFqfesUD8iA6RLTT/0Mj6sCJTv7rmZibBCb/IHvXs6BhOVGHQwdH3jY0iPgwdDxRHDGh GjpDzTCBjYk5mAIMzPGwoHUltdTSwkuQ2cm6vrdo4bAFLQp8znHpVG2zaBsj4A3X/1EfRY Em6yxJNsnhiJsvEeJ9a2iczKVkAEr/I= 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-639-qeLKYcDPMJqNh4S-gPwWtw-1; Tue, 06 Jun 2023 08:11:10 -0400 X-MC-Unique: qeLKYcDPMJqNh4S-gPwWtw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 72CDE858F1C; Tue, 6 Jun 2023 12:11:09 +0000 (UTC) Received: from localhost (ovpn-12-83.pek2.redhat.com [10.72.12.83]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9C01E492B00; Tue, 6 Jun 2023 12:11:08 +0000 (UTC) Date: Tue, 6 Jun 2023 20:11:04 +0800 From: Baoquan He To: Uladzislau Rezki 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 8/9] mm: vmalloc: Offload free_vmap_area_lock global lock Message-ID: References: <20230522110849.2921-1-urezki@gmail.com> <20230522110849.2921-9-urezki@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/06/23 at 11:01am, Uladzislau Rezki wrote: > On Mon, Jun 05, 2023 at 08:43:39AM +0800, Baoquan He wrote: > > On 05/22/23 at 01:08pm, Uladzislau Rezki (Sony) wrote: > > ...... > > > +static unsigned long > > > +this_cpu_zone_alloc_fill(struct cpu_vmap_zone *z, > > > + unsigned long size, unsigned long align, > > > + gfp_t gfp_mask, int node) > > > +{ > > > + unsigned long addr = VMALLOC_END; > > > + struct vmap_area *va; > > > + > > > + /* > > > + * It still can race. One task sets a progress to > > > + * 1 a second one gets preempted on entry, the first > > > + * zeroed the progress flag and second proceed with > > > + * an extra prefetch. > > > + */ > > > + if (atomic_xchg(&z->fill_in_progress, 1)) > > > + return addr; > > > + > > > + va = kmem_cache_alloc_node(vmap_area_cachep, gfp_mask, node); > > > + if (unlikely(!va)) > > > + goto out; > > > + > > > + spin_lock(&free_vmap_area_lock); > > > + addr = __alloc_vmap_area(&free_vmap_area_root, &free_vmap_area_list, > > > + cvz_size, 1, VMALLOC_START, VMALLOC_END); > > > + spin_unlock(&free_vmap_area_lock); > > > > The 'z' is passed in from this_cpu_zone_alloc(), and it's got with > > raw_cpu_ptr(&cpu_vmap_zone). Here when we try to get chunk of cvz_size > > from free_vmap_area_root/free_vmap_area_list, how can we guarantee it > > must belong to the 'z' zone? With my understanding, __alloc_vmap_area() > > will get efficient address range sequentially bottom up from > > free_vmap_area_root. Please correct me if I am wrong. > > > We do not guarantee that and it does not worth it. The most important is: > > If we search a zone that exactly match a CPU-id the usage of a global > vmap space becomes more wider, i.e. toward a high address space. This is > not good because we can affect other users which allocate within a specific > range. On a big system it might be a problem. Therefore a pre-fetch is done > sequentially on demand. > > Secondly, i do not see much difference in performance if we follow > exactly CPU-zone-id. Ah, I see, the allocated range will be put into appropriate zone's busy tree by calculating its zone via addr_to_cvz(va->va_start). The cvz->free tree is only a percpu pre-fetch cache. This is smart, thanks a lot for explanation. > > > static unsigned long > > this_cpu_zone_alloc(unsigned long size, unsigned long align, gfp_t gfp_mask, int node) > > { > > struct cpu_vmap_zone *z = raw_cpu_ptr(&cpu_vmap_zone); > > ...... > > if (addr == VMALLOC_END && left < 4 * PAGE_SIZE) > > addr = this_cpu_zone_alloc_fill(z, size, align, gfp_mask, node); > > } > > > > > + > > > + if (addr == VMALLOC_END) { > > > + kmem_cache_free(vmap_area_cachep, va); > > > + goto out; > > > + } > > > + > > > + va->va_start = addr; > > > + va->va_end = addr + cvz_size; > > > + > > > + fbl_lock(z, FREE); > > > + va = merge_or_add_vmap_area_augment(va, > > > + &fbl_root(z, FREE), &fbl_head(z, FREE)); > > > + addr = va_alloc(va, &fbl_root(z, FREE), &fbl_head(z, FREE), > > > + size, align, VMALLOC_START, VMALLOC_END); > > > + fbl_unlock(z, FREE); > > > + > > > +out: > > > + atomic_set(&z->fill_in_progress, 0); > > > + return addr; > > > +} > > > + > > > +static unsigned long > > > +this_cpu_zone_alloc(unsigned long size, unsigned long align, gfp_t gfp_mask, int node) > > > +{ > > > + struct cpu_vmap_zone *z = raw_cpu_ptr(&cpu_vmap_zone); > > > + unsigned long extra = align > PAGE_SIZE ? align : 0; > > > + unsigned long addr = VMALLOC_END, left = 0; > > > + > > > + /* > > > + * It is disabled, fallback to a global heap. > > > + */ > > > + if (cvz_size == ULONG_MAX) > > > + return addr; > > > + > > > + /* > > > + * Any allocation bigger/equal than one half of > > ~~~~~~typo~~~~~~ bigger than/equal to > I will rework it! > > -- > Uladzislau Rezki >