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 63172C54EBE for ; Mon, 16 Jan 2023 17:54:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B67C16B0071; Mon, 16 Jan 2023 12:54:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AEF716B0072; Mon, 16 Jan 2023 12:54:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 94BBF6B0073; Mon, 16 Jan 2023 12:54:41 -0500 (EST) 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 7D60F6B0071 for ; Mon, 16 Jan 2023 12:54:41 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 454FE80658 for ; Mon, 16 Jan 2023 17:54:41 +0000 (UTC) X-FDA: 80361412362.17.105D601 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) by imf12.hostedemail.com (Postfix) with ESMTP id 6715B40011 for ; Mon, 16 Jan 2023 17:54:39 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=BnfVX22P; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.45 as permitted sender) smtp.mailfrom=urezki@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673891679; 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=1jdt3zqp8+vihNO8d83ajsiCC9GXXQBkXGpmuLk4Zs4=; b=TO3M25847agPY/w0tB/O5wNEYkoHbvaRnOYODuOxULq6LacDAwlDTc5FL9jjUPVs26csdm pmmzxYTLG2kMszq70ss2F77LT/JwTX93TiYgGRmqJTbLdpMogF/g/f6UmIykiMdlGJXlS7 MVKedRPEPnLuGpaNPJx7Ci2v6btzuRY= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=BnfVX22P; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.45 as permitted sender) smtp.mailfrom=urezki@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673891679; a=rsa-sha256; cv=none; b=rYvpA4KVXPvuDOp6Bu/KoT9szThlLBGESs88gopaF2rjzTcMTxGCUgEYWMxrROrN1pEPTN 4X2I+dpRhLMF4vX4O033/rOAXiifq8QcieJNXToFq9s+OHxM+uQKDJ9q/eUZYRRPNl9lBX cp8QL5z1VvongAoEZ/6nNn2UyuT1G3c= Received: by mail-lf1-f45.google.com with SMTP id x40so9661757lfu.12 for ; Mon, 16 Jan 2023 09:54:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:date:from:from:to :cc:subject:date:message-id:reply-to; bh=1jdt3zqp8+vihNO8d83ajsiCC9GXXQBkXGpmuLk4Zs4=; b=BnfVX22PJyTU2rnUz4ScLrN5Xta5JGIECsQySefTlhElXrgfPgQhCGw6rQCAmXyTPA f8tYMnEgM1mUQGLejD/7si8pxGnGTczlNGjQhQT+aMLN3alhdMPAYtQEEH+GebZaebe7 W80xnODpbRvmTD0EJHojm3dXOqsbMVzkGRmOwjw4CiI1xBfJOqMBifr+eVKUqQ/UMKzg I228f0UHNB8+XzvF63AP1bm7pPkDK0WMChKPAMsz4y7aCVMN10JM+pslFu7SSacMtymI H3wHWTLc3OZVh15Ac/thDDtD12uHW0wQ/ZFR8Xavx3xq6D2Mx3pPtNTh1NlOKKaKyRMD yYMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding: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=1jdt3zqp8+vihNO8d83ajsiCC9GXXQBkXGpmuLk4Zs4=; b=NHOjvyKPvl9CLpljmUsSUR3bTLtnEFy6ILC4fzvSESe3qM1mgPACWdxmzAvductiCP EGNlG2PKz7sZ/7/QVN3f+yzuSvmu9LEGASlIvSDDdEwEjvaExnFB8m5XlJpScpAZK1Re EhXnc2wdft7rYbMTPYcgcByxlS1R8TQUNLyiDPIoRaEZ+hhWe8YchUn7ZbWac0HkKTOM Vbci7TWCusoNOd1OWCtZaliuzCPT38wA8fOJL96Coa+ci189xhqRGIcYt2BEPguqbaSJ CDB7B2j5JdMKpg/WL57ge8dL0dJ87t8dMN6gRvCuymlETqUN9bbJsdQk5EQ4CJZA42MS gtog== X-Gm-Message-State: AFqh2krs8ybV9bljz/8x3y5VruQQ5alE0Fkrr52Bxd3+xMsyhHZdg8QX /RIEiCgNEZtO6NidT6jkHCg= X-Google-Smtp-Source: AMrXdXs6k2eZUQ2G3TgxS7FwNXHILZ/IkSJDqimGBmu65SYdVuiLs+NUp0U1G5Mp+TbOj/wm6GgOfg== X-Received: by 2002:a05:6512:3410:b0:4a4:68b8:f4db with SMTP id i16-20020a056512341000b004a468b8f4dbmr24974979lfr.33.1673891677491; Mon, 16 Jan 2023 09:54:37 -0800 (PST) Received: from pc636 (host-90-235-24-7.mobileonline.telia.com. [90.235.24.7]) by smtp.gmail.com with ESMTPSA id k14-20020a05651239ce00b004d4ead86cb2sm1034761lfu.20.2023.01.16.09.54.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jan 2023 09:54:37 -0800 (PST) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Mon, 16 Jan 2023 18:54:34 +0100 To: Baoquan He Cc: Uladzislau Rezki , linux-kernel@vger.kernel.org, linux-mm@kvack.org, stephen.s.brennan@oracle.com, willy@infradead.org, akpm@linux-foundation.org, hch@infradead.org Subject: Re: [PATCH v2 2/7] mm/vmalloc.c: add flags to mark vm_map_ram area Message-ID: References: <20221217015435.73889-1-bhe@redhat.com> <20221217015435.73889-3-bhe@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspamd-Queue-Id: 6715B40011 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: 4iqgy4ay66qrtjorjbfmidf93ashngso X-HE-Tag: 1673891679-499083 X-HE-Meta: U2FsdGVkX1+0XgSKnR9IYmwHbTGCXpLwZlC1YsjIIDzAtSkQKEeJ0jA6/DxL1mBMBgdgl9D/UNrEALtVy7ZQxipjTaeSwuZ2yrskTtQq2YHWsv+VbKjNxRUEbXnRpSxJ52pRauP+C47bLOkreM4V9koOOr6qTM6hVm3ZeQckGiDp7/7JFlfVDSYg93B9Bs77g6U4oPkKlDLgWup0P5uszs+GiUt2C3U9v8CamjPn6aExoaLqpnk2dRvTo4AOg66EUG48vk+iUlOK9reROf7cK1Y+8gvSmKSD33N88hIISfExsz1LsZ6Lbjp30DZNbLzCaSOE5tT00RLjMXd4KQ1cdcER/r5ukvoMLK1hMaUFtIToQGcNFJdsulGSaOQepO+86Pp0roTSZOLW68c1Ob7UimIJtuj6K3i9i3RyNin6zEXxP1Wk5Jz+hPHQkQLLnacc9ffKhEKghrKh3t++0d36xdPVEfNM2C/RM4gUlEg8klk9soYsykPYVbjtCBdyayk1Bm7txgpULvSqeKVkwtFJYZSOti2Cp341OUHIOkuPMHeUrcoakr6++lfovDrAx8+2ACkWpSu5bFmL+O7Zkr7VecvKAyBZUTYBGJqifndJpr+LrKnPlvbpzVHKtI68SHWM29kDR4XOVHPwrN5xTc63BDt8CHW0R4lzxXi+C/zgXD5kSGfVvNaRl4A/NE44y2erI6ZDlOyi2WQB429k4l0jYgphEUUsQRSzhr6oj04bjJEHKoRruIGWBmK3FDvQ/Ue+zFg2DudpsKHbPstZqkA0x5LE0CPm6hQlBbibdelFXqiXSzzkG+yEt8fBNVKxrsZhnkFZ8ZDK2X0yUydAyDAabecRHe8kcvdgJtnP68/CGhywRnDGbaamHK2GKjW2sJBCMObSm/XZOdzPXAQpZVXg6pV6PxMcO7dpOc27TQxZY+B3CimliW26IHA3TpdPfGJyMr1+uJrmu4mE6slIEjk VeHPeZaP styh/dEGFpHU4rylH5CXKFeu18YjoJNdeAfXBT7WS9Ch7yWlX1fQZxKpbv4yGI0Hka52cWVbyExX7WgGrhpa+M1ceLvv4xeg2lfTHxhSVrHybusDqEc6bN+nk948jXElK//0SPhi1EY/pbio= 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 Fri, Jan 13, 2023 at 11:55:07AM +0800, Baoquan He wrote: > Hi Uladzislau Rezki, > > On 12/23/22 at 12:14pm, Baoquan He wrote: > > On 12/20/22 at 05:55pm, Uladzislau Rezki wrote: > ...... > > > spin_lock(&vmap_area_lock); > > > > insert_vmap_area(va, &vmap_area_root, &vmap_area_list); > > > > @@ -1887,6 +1889,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 > > > > > > > Maybe to rename a VMAP_BLOCK to something like VMAP_BLOCK_RESERVED or > > > VMAP_PER_CPU_BLOCK? > > > > Both VMAP_BLOCK or VMAP_PER_CPU_BLOCK look good to me, please see my > > explanation at below. > > > > > > > > > struct vmap_block_queue { > > > > spinlock_t lock; > > > > struct list_head free; > > > > @@ -1962,7 +1968,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); > > > > + node, gfp_mask, > > > > + VMAP_RAM|VMAP_BLOCK); > > > > > > > A new_vmap_block() is for a per-cpu path. As far as i see the VMAP_BLOCK > > > flag is used to mark a VA that corresponds to a reserved per-cpu free area. > > > > > > Whereas a VMAP_RAM is for VA that was obtained over per-cpu path but > > > over alloc_vmap_area() thus a VA should be read out over "busy" tree > > > directly. > > Rethinking about the vmap->flags and the bit0->VMAP_RAM, > bit1->VMAP_BLOCK correspondence, it looks better to use bit0->VMAP_RAM > to indicate the vm_map_ram area, no matter how it's handled inside > vm_map_ram() interface; and use bit1->VMAP_BLOCK to mark out the special > vm_map_ram area which is further subdivided and managed by struct > vmap_block. With these, you can see that we can identify vm_map_ram area > and treat it as one type of vmalloc area, e.g in vread(), s_show(). > > Means when we are talking about vm_map_ram areas, we use > (vmap->flags & VMAP_RAM) to recognize them; when we need to > differentiate and handle vm_map_ram areas respectively, we use > (vmap->flags & VMAP_BLOCK) to pick out the area which is further managed > by vmap_block. Please help check if this is OK to you. > > > > > > > Why do you need to set here both VMAP_RAM and VMAP_BLOCK? > > > > My understanding is that the vm_map_ram area has two types, one is > > the vb percpu area via vb_alloc(), the other is allocated via > > alloc_vmap_area(). While both of them is got from vm_map_ram() > > interface, this is the main point that distinguishes the vm_map_ram area > > than the normal vmalloc area, and this makes vm_map_ram area not owning > > va->vm pointer. So here, I use flag VMAP_RAM to mark the vm_map_ram > > area, including the two types; meanwhile, I add VMAP_BLOCK to mark out > > the vb percpu area. > > > > I understand people could have different view about them, e.g as you > > said, use VMAP_RAM to mark the type of vm_map_ram area allocated through > > alloc_vmap_area(), while use VMAP_PER_CPU_BLOCK to mark vb percpu area > > from vb_alloc. In this way, we may need to rename VMAP_RAM to reflect > > the area allocated from alloc_vmap_area() only. Both is fine to me. > > > > > > > > > if (IS_ERR(va)) { > > > > kfree(vb); > > > > return ERR_CAST(va); > > > > @@ -2229,8 +2236,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, > > > > > > > Agree with Lorenzo. BUG_ON() should be out of spinlock(). Furthermore > > > i think it makes sense to go with WARN_ON_ONCE() and do not kill a system. > > > Instead emit a warning and bailout. > > > > > > What do you think? Maybe separate patch for it? > > > > Agree, your patch looks great to me. Thanks. > > > > > > > > > (va->va_end - va->va_start)); > > > > free_unmap_vmap_area(va); > > > > @@ -2265,7 +2276,8 @@ void *vm_map_ram(struct page **pages, unsigned int count, int node) > > > > } else { > > > > struct vmap_area *va; > > > > va = alloc_vmap_area(size, PAGE_SIZE, > > > > - VMALLOC_START, VMALLOC_END, node, GFP_KERNEL); > > > > + VMALLOC_START, VMALLOC_END, > > > > + node, GFP_KERNEL, VMAP_RAM); > > > > if (IS_ERR(va)) > > > > return NULL; > > > > > > > > @@ -2505,7 +2517,7 @@ 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); > > > > + va = alloc_vmap_area(size, align, start, end, node, gfp_mask, 0); > > > > if (IS_ERR(va)) { > > > > kfree(area); > > > > return NULL; > > > > > > > I know we have already discussed the new parameter. But what if we just > > > use atomic_set operation to mark VA as either vmap-ram or vmap-block? > > As I replied at above, I take the vm_map_ram as one kind of vmalloc > area, and mark out the percpu vmap block handling of vm_map_ram area. > Seems the passing in the flags through function parameter is better. Not > sure if I got your suggestion correctly, and my code change is > appropriate. I have sent v3 according to your and Lorenzo's comments and > suggestion, and my rethinking after reading your words. I make some > adjustment to try to remove misundersanding or confusion when reading > patch and code. Please help check if it's OK. > OK, if we decided to go with a parameter it is OK, it is not a big deal and complexity. If needed it can be adjusted later on if there is a need. Thanks! -- Uladzislau Rezki