Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5900815rwb; Mon, 5 Dec 2022 05:43:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf6KVCJR9K0z2S6o69SxoJfLqwgtwmLwz+SUB4m5HZtCljSvv6G8lsCsk/51Djtj/KtGiGTb X-Received: by 2002:a17:906:745:b0:7bd:f50f:a51c with SMTP id z5-20020a170906074500b007bdf50fa51cmr36059608ejb.285.1670247780022; Mon, 05 Dec 2022 05:43:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670247780; cv=none; d=google.com; s=arc-20160816; b=QdtHitNDOfkKORDVNQL/QKkoDdYbvSEX9ekjDPPigVqR1eGBmYjlcYI6wjU/Ob8akR yuZrwO6E6FLqIK1F6ToGsjPjcxbXYSZ5LmPvqNNqa2FhD5ubacWUMLc7vT26NVglqJbF SrfR4qr+uiyfGM5iJalP/Ysgk83VHt6FAJQLu7BHtZ9eLRefBbdxm9L+xFc35QWFpSXe hjLr7gG0qFOWJpA8vNpxT5xH9e57mSVhpTPoQMxNBU218hHpCzDNfktnn1GjIVCraJpw R3DR2VY12zEhP00Nf9L6IOAg/ny3Y8f6cr598DOxbZM4Yow4TTxrXjPvqpUblDTcSV8H ym8A== 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:date:from:dkim-signature; bh=MNizMxTAJQcCerVNPojMjVYQUThcKeI/6F+iAZVM61E=; b=R926+qfRS27jOeUi7mwCyE7rBKwuD4TyhmYWVwul/xegaJqQk+9S1qNOW5ma4o9yrW uTMDC5lJBVePolI7W0M5jvon6kcsG1b+eGoenXnDfytFiO/utKpTR1kuWawXK1WjYRWO Xo6yz+5f/Pxa0J85iOuIZwbnSJPA3fJ2VAU3iISbNS7Ly0clKVTkyPgKHDZ86EEWhnCJ W21p07ykOaWxudkShIy5+1TERjFDyy2kKpM0jPFmJg1x8uSfKcwQc6EMiTtJQ+rAdpSV Kux8xpRCGzifFKRrWvNudWNm4Q5qnRMKe9nDx/jFTO5BCAnUVNKjKP65936jBneJwnRZ 7S6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=LoM4ZvQs; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xh8-20020a170906da8800b007b9944592c5si11539704ejb.935.2022.12.05.05.42.38; Mon, 05 Dec 2022 05:43:00 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=LoM4ZvQs; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231981AbiLEM4h (ORCPT + 83 others); Mon, 5 Dec 2022 07:56:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229917AbiLEM4f (ORCPT ); Mon, 5 Dec 2022 07:56:35 -0500 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF1951A3BF for ; Mon, 5 Dec 2022 04:56:34 -0800 (PST) Received: by mail-lj1-x22b.google.com with SMTP id z4so13418601ljq.6 for ; Mon, 05 Dec 2022 04:56:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=MNizMxTAJQcCerVNPojMjVYQUThcKeI/6F+iAZVM61E=; b=LoM4ZvQsmSIuu2v5/WOVXLHUPhjPjZKvAvKw7ppYq7FOFTyo8eFQ40euk6uUal8ca/ f4FcDS2k74EaENuC8SKrdfkO4r4zI94k6AANBExnMb/NGNbUc5Q/g3SmrZBM++rc2fRi Mvq/FgyW20b7S/QDS2u9mkIjfZhvwLX+GDHXtW1Dc/fDx/H/gJMe/qWedSoBDajI6OCa Iy1zXCVFUpz+u3JlTe5WYx5fjg8jDEg6jL7RBK/aZ8tfso/juT1/lWrf3m3F1uA/XWUD iUANfPIFLzASlDjKPtKEr/AwYdzMIBsl3l1xebHJfWzcKYdcxjqU5/8dmSHEGLXG/LI2 Bckw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=MNizMxTAJQcCerVNPojMjVYQUThcKeI/6F+iAZVM61E=; b=n0g9dvWkrEfByXMkhJNqpiTQNWvTeHVZIssTn6NeTFixO3/9iWW70BOGhWEbg6DokT yARg1Z2ikIQA3n0hZBMKuh+UHDZQDB5mSsNe6YfpOqWcttFUjJZtaY/xPR3Ydf67y3na qJZDaVzh+ljdrgawhEcGQApF9s4Y1U+J9tXESf01q0BK4Dqi9dw52t1kFe0nlzh2QICq fWtivoXBej9/kjPLRJ08p/5iprKsT5COAH1oO6GAZg/2ypijPQUQxEhhApuQrQoHtne1 Exe1CLaiqIzafO5N1OBoVLf18qTXwkdJOlY3fYnXQENQ8phOmsh5WApSfR6FYMMoY3c5 lkng== X-Gm-Message-State: ANoB5plOEciXg0YakKQX8PZgK2mIBH+5IOVJoHB+ot4QSOh0KgySbzZm WCvSYcZDRpgTODptCKmRPZk= X-Received: by 2002:a2e:a9a7:0:b0:26e:2de:49ad with SMTP id x39-20020a2ea9a7000000b0026e02de49admr21169013ljq.511.1670244992807; Mon, 05 Dec 2022 04:56:32 -0800 (PST) Received: from pc636 (host-90-235-25-230.mobileonline.telia.com. [90.235.25.230]) by smtp.gmail.com with ESMTPSA id s9-20020ac24649000000b004b5634f9b9dsm878455lfo.115.2022.12.05.04.56.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Dec 2022 04:56:32 -0800 (PST) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Mon, 5 Dec 2022 13:56:29 +0100 To: Baoquan He Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, stephen.s.brennan@oracle.com, urezki@gmail.com, willy@infradead.org, akpm@linux-foundation.org, hch@infradead.org Subject: Re: [PATCH v1 2/7] mm/vmalloc.c: add flags to mark vm_map_ram area Message-ID: References: <20221204013046.154960-1-bhe@redhat.com> <20221204013046.154960-3-bhe@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221204013046.154960-3-bhe@redhat.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 > Through vmalloc API, a virtual kernel area is reserved for physical > address mapping. And vmap_area is used to track them, while vm_struct > is allocated to associate with the vmap_area to store more information > and passed out. > > However, area reserved via vm_map_ram() is an exception. It doesn't have > vm_struct to associate with vmap_area. And we can't recognize the > vmap_area with '->vm == NULL' as a vm_map_ram() area because the normal > freeing path will set va->vm = NULL before unmapping, please see > function remove_vm_area(). > > Meanwhile, there are two types of vm_map_ram area. One is the whole > vmap_area being reserved and mapped at one time; the other is the > whole vmap_area with VMAP_BLOCK_SIZE size being reserved, while mapped > into split regions with smaller size several times via vb_alloc(). > > To mark the area reserved through vm_map_ram(), add flags field into > struct vmap_area. Bit 0 indicates whether it's a vm_map_ram area, > while bit 1 indicates whether it's a vmap_block type of vm_map_ram > area. > > This is a preparatoin for later use. > > Signed-off-by: Baoquan He > --- > include/linux/vmalloc.h | 1 + > mm/vmalloc.c | 18 +++++++++++++++++- > 2 files changed, 18 insertions(+), 1 deletion(-) > > diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h > index 096d48aa3437..69250efa03d1 100644 > --- a/include/linux/vmalloc.h > +++ b/include/linux/vmalloc.h > @@ -76,6 +76,7 @@ struct vmap_area { > unsigned long subtree_max_size; /* in "free" tree */ > struct vm_struct *vm; /* in "busy" tree */ > }; > + unsigned long flags; /* mark type of vm_map_ram area */ > }; > > /* archs that select HAVE_ARCH_HUGE_VMAP should override one or more of these */ > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index 5d3fd3e6fe09..d6f376060d83 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -1815,6 +1815,7 @@ static void free_vmap_area_noflush(struct vmap_area *va) > > spin_lock(&vmap_area_lock); > unlink_va(va, &vmap_area_root); > + va->flags = 0; > spin_unlock(&vmap_area_lock); > This is not a good place to set flags to zero. It looks to me like corner and kind of specific. > nr_lazy = atomic_long_add_return((va->va_end - va->va_start) >> > @@ -1887,6 +1888,10 @@ struct vmap_area *find_vmap_area(unsigned long addr) > > #define VMAP_BLOCK_SIZE (VMAP_BBMAP_BITS * PAGE_SIZE) > > +#define VMAP_RAM 0x1 > +#define VMAP_BLOCK 0x2 > +#define VMAP_FLAGS_MASK 0x3 > + > struct vmap_block_queue { > spinlock_t lock; > struct list_head free; > @@ -1967,6 +1972,9 @@ static void *new_vmap_block(unsigned int order, gfp_t gfp_mask) > kfree(vb); > return ERR_CAST(va); > } > + spin_lock(&vmap_area_lock); > + va->flags = VMAP_RAM|VMAP_BLOCK; > + spin_unlock(&vmap_area_lock); > The per-cpu code was created as a fast per-cpu allocator because of high vmalloc lock contention. If possible we should avoid of locking of the vmap_area_lock. Because it has a high contention. > > vaddr = vmap_block_vaddr(va->va_start, 0); > spin_lock_init(&vb->lock); > @@ -2229,8 +2237,12 @@ void vm_unmap_ram(const void *mem, unsigned int count) > return; > } > > - va = find_vmap_area(addr); > + spin_lock(&vmap_area_lock); > + va = __find_vmap_area((unsigned long)addr, &vmap_area_root); > BUG_ON(!va); > + if (va) > + va->flags &= ~VMAP_RAM; > + spin_unlock(&vmap_area_lock); > debug_check_no_locks_freed((void *)va->va_start, > (va->va_end - va->va_start)); > free_unmap_vmap_area(va); > @@ -2269,6 +2281,10 @@ void *vm_map_ram(struct page **pages, unsigned int count, int node) > if (IS_ERR(va)) > return NULL; > > + spin_lock(&vmap_area_lock); > + va->flags = VMAP_RAM; > + spin_unlock(&vmap_area_lock); > + > Same here. -- Uladzislau Rezki