Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp104143lqc; Thu, 7 Mar 2024 11:32:42 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVblk8Vqez5byX1e1PuQrEvfjug/jRQh4smOHqRAuB87o4qXgb3P2XwG1udtpJZzTLD5h7z1uqeP4S7RaRIVtLFag1jmhx0ANHLNC/0PA== X-Google-Smtp-Source: AGHT+IGOQ3MdZy3TQwJ8p2J8f0maREn+IlbCmGwcErhp9x3hvvL5mFH6f5I7hnGNri+LpYiEZxOU X-Received: by 2002:a50:d614:0:b0:567:9ddd:65c3 with SMTP id x20-20020a50d614000000b005679ddd65c3mr477160edi.29.1709839962702; Thu, 07 Mar 2024 11:32:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709839962; cv=pass; d=google.com; s=arc-20160816; b=iT/JWB3P13tHlcT/t2KSjFP/oKDfUhdxp4g7tUKEquJIOe5FYRLSvdcQX4ixeTPb1q TM11klKvyq+bbf/E5jFb3+MC8aOI7GY/IWvFAp/BI4Jfi9vZgwUu+2vz1OV3ChUtW3ct x290T3MkEBbzVgiu3QMDzD90110b6jDwh43XVslSi2/mMj8wvM+s1bWHEa1UEMyPq0xP 0pRG6eZiWi1gtfjM/1JITlrK7yUHtlcEDkfel3JntORN3KrN9fhpFSRvaRegyQWWoYi1 S6ebf9zYETrD6DdjZZ4AIzSHuie9BzssnwEdDinYfCFl+e3Bq5hclShEmwRjGBmDrCiv iT3w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:date:from:dkim-signature; bh=JvAHrOWgvGZRpeE0nYshgsb1o+/iRGWu+GmckAg1TGw=; fh=xUne4OTZzmdmNRE0VWDKC8GXfO7SwD9gD1CqPhH+fk8=; b=iqipjW/LqBC6dz49FkgVhxteyWtgL2cXY9+Ba1KvuyAD1Mz5C8rPOaEqcseIjiN7In rpVKpK+31hgoFQLd4Y5USBn5Ur9DvbqsPkN9iRPBeVtQ35Q8wRUORp6rXbDE4U6AvGBF HFiHz+styg2xtN3qEcmGobCRBsJzbU61cGbNSzhPxllxbZQO9+1zI+HGh3UeTT2/9GpW qoL7IK9QpTbhWmBk4HYXLzC0l7GqzTeBIgc9eOTNe3iuWUclh7LqRpajfhEfrCWgZM8n E2eF0xJIVupQXLCsw7XX9vVBSXqRvdcnUxlzHVdrkH5JgySp/4aqsal9xAl5xbziSJCH JBuw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="BP9Vp/Sj"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-96101-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96101-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id n3-20020aa7db43000000b0056571ee608csi1606748edt.353.2024.03.07.11.32.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 11:32:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-96101-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="BP9Vp/Sj"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-96101-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96101-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 34C0A1F24F47 for ; Thu, 7 Mar 2024 19:26:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BA33413665C; Thu, 7 Mar 2024 19:26:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BP9Vp/Sj" Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD8432574B for ; Thu, 7 Mar 2024 19:26:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709839577; cv=none; b=SLojYgG1iFd6fNyYkrNKXLbTpooEZ6cb/2g3RcJT7R7uQ0JXLR1aDNwUnmJSo/ZdEzJNH20JiCnKAgY80P74X22pXvr8U0fLuKnXhNNkqknfE85HSJzbO6Bc2tK8R6bKgQAiieVFFjSgtM18IqoMi7flOYcBKRPSA0RB7e1ym9g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709839577; c=relaxed/simple; bh=vl/7CX10XaEjtfxjgYniZhszRKdGJJTOG6AODuVHJiM=; h=From:Date:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tFY4pkx1/PqjuWf4ZLPIS2PS22nQL1iklqvDGmYUamvQvv+rACd3kzEZaHnvbQXYMy0kDmxfCPhdKuEahDYWF8P8+WOnmtd/pQWPGOX7rOInPogKdaA3iq918H4nyioJElm2Pu3n0+PK4Pe25vCtRG/gxQ3KVPuobn4tvkyj3dw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BP9Vp/Sj; arc=none smtp.client-ip=209.85.167.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-5131c0691feso1710261e87.1 for ; Thu, 07 Mar 2024 11:26:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709839574; x=1710444374; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc:subject:date:message-id:reply-to; bh=JvAHrOWgvGZRpeE0nYshgsb1o+/iRGWu+GmckAg1TGw=; b=BP9Vp/SjqYDxDw3+pLRvEUPd1lxNQnF7Bn2F72LXtMvL0c/X4JrZb/j//dfFAGDekY jnAGGUJvyYTK61XiG2VzF4huHNcUpdZbr7fqS12uPkcO4uQufFCXIyEQ4R36JkK4/CbS tfFH5xMVaENybd8eRYzoJPD1BnH1xE0vfzKmvOtwEvBKxcuICS0jfBD9eOA0kpFTEncY FSkmXV8jV8vV3XV7HxVmv+glAnNH+lC5sY8NP2qLGo++V82snd06MS+61KI1C8H1FEpY zL1dtG+DP3kLsNHlSQp3mx86FEDxFbfr/stTJQBoGUTK7akP6r/8jp272VdVMwwNWgTM 6ntQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709839574; x=1710444374; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=JvAHrOWgvGZRpeE0nYshgsb1o+/iRGWu+GmckAg1TGw=; b=SXam2mTf7D+MAdnJ/oEFaprjWmBdyewBLVKwgtfDPRnrmsdeUvWfsZWg8E1HBIIfwg kZi7Be3EMRL+Ah9xL4pCFBAR52lqy8LcGfTvkZLJuOiAQiNACvIe6mvUw9DADdRHqj/a myeNZf3brFXNDkKim4HsQKgm8JdFUGL6/vy/7R1hD25LlaW8ay1cg/NXQgMheyyPOfUy /PoGiT9hximDG7Sz5+I7PTaB1fTbkmiiEAfWM12iLxpMpdCQpgX4BwmnpaA9jmiFBD4C 7kXycrVuG1jbirua3yD8YSGqfRp810S1oBHuB3dO84ol0Z2RlJ/0ta9O5BtDboaOU9+b D+kA== X-Forwarded-Encrypted: i=1; AJvYcCWWIeX55GS82CdMzy1oNe+KO7tqC4AhlwWbJVgGh7BBoo6iQUMcH8+WoG/2kpHqYZoV+vfbKE27NgFtqcUNVKIgc2IDNpxwHPvs5u1b X-Gm-Message-State: AOJu0YxKvckAwcXWNXpUHHTqWBx52GVdb9L6GTDVQmiPuHt5ZfUXRCWZ hTlTyg0HkIgeLpVJ+nZiWoHXYRYlbigLsRs2K8du0GUsYwyUgPXu X-Received: by 2002:a19:7717:0:b0:513:2b24:7599 with SMTP id s23-20020a197717000000b005132b247599mr2104689lfc.46.1709839573570; Thu, 07 Mar 2024 11:26:13 -0800 (PST) Received: from pc638.lan (host-185-121-47-193.sydskane.nu. [185.121.47.193]) by smtp.gmail.com with ESMTPSA id i12-20020ac2522c000000b0051321ac86bcsm3134641lfl.290.2024.03.07.11.26.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 11:26:13 -0800 (PST) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Thu, 7 Mar 2024 20:26:11 +0100 To: rulinhuang Cc: urezki@gmail.com, bhe@redhat.com, akpm@linux-foundation.org, colin.king@intel.com, hch@infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, lstoakes@gmail.com, tianyou.li@intel.com, tim.c.chen@intel.com, wangyang.guo@intel.com, zhiguo.zhou@intel.com Subject: Re: [PATCH v8] mm/vmalloc: Eliminated the lock contention from twice to once Message-ID: References: <20240307021440.64967-1-rulin.huang@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240307021440.64967-1-rulin.huang@intel.com> On Wed, Mar 06, 2024 at 09:14:40PM -0500, rulinhuang wrote: > When allocating a new memory area where the mapping address range is > known, it is observed that the vmap_node->busy.lock is acquired twice. > > The first acquisition occurs in the alloc_vmap_area() function when > inserting the vm area into the vm mapping red-black tree. The second > acquisition occurs in the setup_vmalloc_vm() function when updating the > properties of the vm, such as flags and address, etc. > > Combine these two operations together in alloc_vmap_area(), which > improves scalability when the vmap_node->busy.lock is contended. > By doing so, the need to acquire the lock twice can also be eliminated > to once. > > With the above change, tested on intel sapphire rapids > platform(224 vcpu), a 4% performance improvement is > gained on stress-ng/pthread(https://github.com/ColinIanKing/stress-ng), > which is the stress test of thread creations. > > Co-developed-by: "Chen, Tim C" > Signed-off-by: "Chen, Tim C" > Co-developed-by: "King, Colin" > Signed-off-by: "King, Colin" > Signed-off-by: rulinhuang > --- > V1 -> V2: Avoided the partial initialization issue of vm and > separated insert_vmap_area() from alloc_vmap_area() > V2 -> V3: Rebased on 6.8-rc5 > V3 -> V4: Rebased on mm-unstable branch > V4 -> V5: Canceled the split of alloc_vmap_area() > and keep insert_vmap_area() > V5 -> V6: Added bug_on > V6 -> V7: Adjusted the macros > V7 -> V8: Removed bugs_on and adjustion of macros > --- > mm/vmalloc.c | 50 ++++++++++++++++++++++---------------------------- > 1 file changed, 22 insertions(+), 28 deletions(-) > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index 25a8df497255..f933a62fef50 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -1841,15 +1841,26 @@ node_alloc(unsigned long size, unsigned long align, > return va; > } > > +static inline void setup_vmalloc_vm(struct vm_struct *vm, > + struct vmap_area *va, unsigned long flags, const void *caller) > +{ > + vm->flags = flags; > + vm->addr = (void *)va->va_start; > + vm->size = va->va_end - va->va_start; > + vm->caller = caller; > + va->vm = vm; > +} > + > /* > * Allocate a region of KVA of the specified size and alignment, within the > - * vstart and vend. > + * vstart and vend. If vm is passed in, the two will also be bound. > */ > static struct vmap_area *alloc_vmap_area(unsigned long size, > unsigned long align, > unsigned long vstart, unsigned long vend, > int node, gfp_t gfp_mask, > - unsigned long va_flags) > + unsigned long va_flags, struct vm_struct *vm, > + unsigned long flags, const void *caller) > { > struct vmap_node *vn; > struct vmap_area *va; > @@ -1912,6 +1923,9 @@ static struct vmap_area *alloc_vmap_area(unsigned long size, > va->vm = NULL; > va->flags = (va_flags | vn_id); > > + if (vm) > + setup_vmalloc_vm(vm, va, flags, caller); > + > vn = addr_to_node(va->va_start); > > spin_lock(&vn->busy.lock); > @@ -2486,7 +2500,8 @@ static void *new_vmap_block(unsigned int order, gfp_t gfp_mask) > va = alloc_vmap_area(VMAP_BLOCK_SIZE, VMAP_BLOCK_SIZE, > VMALLOC_START, VMALLOC_END, > node, gfp_mask, > - VMAP_RAM|VMAP_BLOCK); > + VMAP_RAM|VMAP_BLOCK, NULL, > + 0, NULL); > if (IS_ERR(va)) { > kfree(vb); > return ERR_CAST(va); > @@ -2843,7 +2858,8 @@ void *vm_map_ram(struct page **pages, unsigned int count, int node) > struct vmap_area *va; > va = alloc_vmap_area(size, PAGE_SIZE, > VMALLOC_START, VMALLOC_END, > - node, GFP_KERNEL, VMAP_RAM); > + node, GFP_KERNEL, VMAP_RAM, > + NULL, 0, NULL); > if (IS_ERR(va)) > return NULL; > > @@ -2946,26 +2962,6 @@ void __init vm_area_register_early(struct vm_struct *vm, size_t align) > kasan_populate_early_vm_area_shadow(vm->addr, vm->size); > } > > -static inline void setup_vmalloc_vm_locked(struct vm_struct *vm, > - struct vmap_area *va, unsigned long flags, const void *caller) > -{ > - vm->flags = flags; > - vm->addr = (void *)va->va_start; > - vm->size = va->va_end - va->va_start; > - vm->caller = caller; > - va->vm = vm; > -} > - > -static void setup_vmalloc_vm(struct vm_struct *vm, struct vmap_area *va, > - unsigned long flags, const void *caller) > -{ > - struct vmap_node *vn = addr_to_node(va->va_start); > - > - spin_lock(&vn->busy.lock); > - setup_vmalloc_vm_locked(vm, va, flags, caller); > - spin_unlock(&vn->busy.lock); > -} > - > static void clear_vm_uninitialized_flag(struct vm_struct *vm) > { > /* > @@ -3002,14 +2998,12 @@ static struct vm_struct *__get_vm_area_node(unsigned long size, > if (!(flags & VM_NO_GUARD)) > size += PAGE_SIZE; > > - va = alloc_vmap_area(size, align, start, end, node, gfp_mask, 0); > + va = alloc_vmap_area(size, align, start, end, node, gfp_mask, 0, area, flags, caller); > if (IS_ERR(va)) { > kfree(area); > return NULL; > } > > - setup_vmalloc_vm(area, va, flags, caller); > - > /* > * Mark pages for non-VM_ALLOC mappings as accessible. Do it now as a > * best-effort approach, as they can be mapped outside of vmalloc code. > @@ -4584,7 +4578,7 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets, > > spin_lock(&vn->busy.lock); > insert_vmap_area(vas[area], &vn->busy.root, &vn->busy.head); > - setup_vmalloc_vm_locked(vms[area], vas[area], VM_ALLOC, > + setup_vmalloc_vm(vms[area], vas[area], VM_ALLOC, > pcpu_get_vm_areas); > spin_unlock(&vn->busy.lock); > } > > base-commit: f4239a5d7acc1b5ff9bac4d5471000b952279ef0 > -- > 2.43.0 > Thank you to be patient and thank you for your work! Reviewed-by: Uladzislau Rezki (Sony) -- Uladzislau Rezki