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 F2479C30653 for ; Wed, 26 Jun 2024 10:51:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 833706B0092; Wed, 26 Jun 2024 06:51:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7E34A6B0093; Wed, 26 Jun 2024 06:51:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 65D006B0095; Wed, 26 Jun 2024 06:51:49 -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 44EB66B0092 for ; Wed, 26 Jun 2024 06:51:49 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id F294F40E2B for ; Wed, 26 Jun 2024 10:51:48 +0000 (UTC) X-FDA: 82272724296.24.0DCDE6D Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) by imf29.hostedemail.com (Postfix) with ESMTP id 0384012000F for ; Wed, 26 Jun 2024 10:51:46 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=SvoxMDas; spf=pass (imf29.hostedemail.com: domain of urezki@gmail.com designates 209.85.208.182 as permitted sender) smtp.mailfrom=urezki@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719399099; 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=sAF9vjjeL2YSSoAhozbISzvWAPohgaJ/Mqgbub7kNF0=; b=4wxbtWOBGz18xIWRXD1rwSgqtHX9RENAmRp5SJjPFLZNHMATWUuKm1vl7uwz/3tKqkgMa4 q1cfiQXxV+2Qz+j/DCCUa92wDlAbHy4+R1J69XHgl6TVu8xq9ApE76DSG+nnICpCAx2gph XS2TdKS1RYyjFbRAP5JdeagTAdTVG98= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=SvoxMDas; spf=pass (imf29.hostedemail.com: domain of urezki@gmail.com designates 209.85.208.182 as permitted sender) smtp.mailfrom=urezki@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719399099; a=rsa-sha256; cv=none; b=n7aJdskhkJo1+zQ9kJ8TiFeAzxnazb9Az6YCCDevAcUiTT4P0E+XG5PWtqe5fmUO+rf+Dm NPokZ5s8PzBE3c7bx9CUc5j7agXNA9zDXeeQJwvI13Lj1N4llmYQ96j1v2w7OA0xX34N6Q H5LKg2Z879CGLznqn+mAuskRV/PH+f4= Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-2ec52fbb50bso44301431fa.2 for ; Wed, 26 Jun 2024 03:51:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719399105; x=1720003905; darn=kvack.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=sAF9vjjeL2YSSoAhozbISzvWAPohgaJ/Mqgbub7kNF0=; b=SvoxMDas3LDn/dfzhdvJiDb/kkYWlKRhnumwOlMHVFs6BxTwtf6aKA0lbGAxnpaFqA 36mMuLrZ6ShjJa+wCrQ2OSh73ytcURWYOgaFbGFLXrZR9q6HCDBsrIl5UzIViQnUGky7 cO8Kic4/kclGfqck54TijLG6U0NxEQ0sOwSOteyS0Uek/QXxTGYhPtJxvrjcZqhG7zKa Oj0SCbpGU35ay9kHa5/N1ZxyJ5AMo57k88fJ4X+D5S9ym1h7vxIR3hQsthqRefCPDthc ZT1f3ljC2RoHkQ4gVTyYns3ZOY5qAKuNZS15c8dmw/mhepRUqT4QXJanoqUKQ+XatTHU SPNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719399105; x=1720003905; 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=sAF9vjjeL2YSSoAhozbISzvWAPohgaJ/Mqgbub7kNF0=; b=HBDBfCin9VNv+gkbmqhFr3fkXv0/bz0lpEB3kU4PVnMO24cB+kYgeImKOtKfI0EKkZ 02CPVlFCh6EtwB67t74LIJtnvgUxvgFn+0u4ppo01IUADt+vbEDP4K1fMlUE8COHTNDr v+uR02unZQhTkCm5AmAwns2VxqNhk9KiHRcXrE9Dsq3JRudq/ykqMtPx4zofT/+Is/bC QuJdKwqeIwSQlJFV20zX4kbCxJoCygOC/oleq7wOVCSJiSHoVYnkEIjLeK5yqoycx5Ss au4FoReMcJUABbZYrtc1stHHwOPmlsmNVxt9MtPiKhrOxerS68tE5c5IdklWcyESvkYs qrEA== X-Forwarded-Encrypted: i=1; AJvYcCXDiUI7IIllMjr5Ogsm5Dhtm7N0dyxRPc3VVwBBTso19tteAdxW1+iS3oSE03fOwlgXFwRZc4bGaitp91fUvl98+Qo= X-Gm-Message-State: AOJu0YxhUbqXIgNXg9Vyf1EU4hnM72YqzfV1BnUv30vjUfo9ecLJrb8t bgeb3dYC3Fd9fO7PAbwC5PyzF2+0qCQA9pevE/sfREYgyRaQLs6+ X-Google-Smtp-Source: AGHT+IFKZSVhxM5coOj5/CC3REPwevHkwWRCxIsgNzYe4QGbxv+o6yN+lc0AxHbPqS/w93Knm6WQlQ== X-Received: by 2002:a2e:9104:0:b0:2ec:57c7:c72c with SMTP id 38308e7fff4ca-2ec5b3d4979mr52834821fa.35.1719399104689; Wed, 26 Jun 2024 03:51:44 -0700 (PDT) Received: from pc636 (host-90-233-219-252.mobileonline.telia.com. [90.233.219.252]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ec54860756sm11434241fa.131.2024.06.26.03.51.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jun 2024 03:51:44 -0700 (PDT) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Wed, 26 Jun 2024 12:51:42 +0200 To: Hailong Liu Cc: Uladzislau Rezki , Baoquan He , Nick Bowler , linux-kernel@vger.kernel.org, Linux regressions mailing list , linux-mm@kvack.org, sparclinux@vger.kernel.org, Andrew Morton Subject: Re: PROBLEM: kernel crashes when running xfsdump since ~6.4 Message-ID: References: <20240626051206.mx2r4iy3wpexykay@oppo.com> <20240626100342.2dudj6fjjx6srban@oppo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240626100342.2dudj6fjjx6srban@oppo.com> X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 0384012000F X-Stat-Signature: 5x8o411o486iqb4eyoraqp4k5haujjm6 X-HE-Tag: 1719399106-31717 X-HE-Meta: U2FsdGVkX19THqfRvbvVl18he8vIVDJrbxW1nQpmoTyqEixuvKZTyYnkbdZTttDPZCIhCgdxWYnNGuzV1Vo9yffYusrIHaqZCebuIgOdZ/VcXV7BZacC2Pnt75Ycz3n0n6iEfbkk2O8fWS2Akk4O7uz9QxMc+xUpVBSfaenscyuofuG0qOJtVQTO3qVcJ5uFQvrAz5Gtk5dL3bgUgbtidGVHsX/8IhE+2F1ObMNIo3RJeIFAtwYQLAseq8qNIoIJ7eqwQ6LmBmRTo4FT/Vtoe96UkrYA5RsdX7u3MM9DwS45Y+o/H8j/A2eDkHN4m80sl88Yj7DS5BMkE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sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, Jun 26, 2024 at 06:03:42PM +0800, Hailong Liu wrote: > On Wed, 26. Jun 11:15, Uladzislau Rezki wrote: > > On Wed, Jun 26, 2024 at 01:12:06PM +0800, Hailong Liu wrote: > > > On Tue, 25. Jun 22:05, Uladzislau Rezki wrote: > > > > > > > > > /** > > > > > > > > > * cpumask_next - get the next cpu in a cpumask > > > > > > > > > * @n: the cpu prior to the place to search (i.e. return will be > @n) > > > > > > > > > * @srcp: the cpumask pointer > > > > > > > > > * > > > > > > > > > * Return: >= nr_cpu_ids if no further cpus set. > > > > > > > > > > > > > > > > Ah, I got what you mean. In the vbq case, it may not have chance to get > > > > > > > > a return number as nr_cpu_ids. Becuase the hashed index limits the > > > > > > > > range to [0, nr_cpu_ids-1], and cpu_possible(index) will guarantee it > > > > > > > > won't be the highest cpu number [nr_cpu_ids-1] since CPU[nr_cpu_ids-1] must > > > > > > > > be possible CPU. > > > > > > > > > > > > > > > > Do I miss some corner cases? > > > > > > > > > > > > > > > Right. We guarantee that a highest CPU is available by doing: % nr_cpu_ids. > > > > > > > So we do not need to use *next_wrap() variant. You do not miss anything :) > > > > > > > > > > > > > > Hailong Liu has proposed more simpler version: > > > > > > > > > > > > > > > > > > > > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > > > > > > > index 11fe5ea208aa..e1e63ffb9c57 100644 > > > > > > > --- a/mm/vmalloc.c > > > > > > > +++ b/mm/vmalloc.c > > > > > > > @@ -1994,8 +1994,9 @@ static struct xarray * > > > > > > > addr_to_vb_xa(unsigned long addr) > > > > > > > { > > > > > > > int index = (addr / VMAP_BLOCK_SIZE) % num_possible_cpus(); > > > > > > > + int cpu = cpumask_nth(index, cpu_possible_mask); > > > > > > > > > > > > > > - return &per_cpu(vmap_block_queue, index).vmap_blocks; > > > > > > > + return &per_cpu(vmap_block_queue, cpu).vmap_blocks; > > > > > > > > > > > > > > > > > > > > > which just takes a next CPU if an index is not set in the cpu_possible_mask. > > > > > > > > > > > > > > The only thing that can be updated in the patch is to replace num_possible_cpu() > > > > > > > by the nr_cpu_ids. > > > > > > > > > > > > > > Any thoughts? I think we need to fix it by a minor change so it is > > > > > > > easier to back-port on stable kernels. > > > > > > > > > > > > Yeah, sounds good since the regresson commit is merged in v6.3. > > > > > > Please feel free to post this and the hash array patch separately for > > > > > > formal reviewing. > > > > > > > > > > > Agreed! The patch about hash array i will post later. > > > > > > > > > > > By the way, when I am replying this mail, I check the cpumask_nth() > > > > > > again. I doubt it may take more checking then cpu_possible(), given most > > > > > > of systems don't have gaps in cpu_possible_mask. I could be dizzy at > > > > > > this moment. > > > > > > > > > > > > static inline unsigned int cpumask_nth(unsigned int cpu, const struct cpumask *srcp) > > > > > > { > > > > > > return find_nth_bit(cpumask_bits(srcp), small_cpumask_bits, cpumask_check(cpu)); > > > > > > } > > > > > > > > > > > Yep, i do not think it is a big problem based on your noted fact. > > > > > > > > > Checked. There is a difference: > > > > > > > > 1. Default > > > > > > > > > > > > ... > > > > + 15.95% 6.05% [kernel] [k] __vmap_pages_range_noflush > > > > + 15.91% 1.74% [kernel] [k] addr_to_vb_xa <--------------- > > > > + 15.13% 12.05% [kernel] [k] vunmap_p4d_range > > > > + 14.17% 13.38% [kernel] [k] __find_nth_bit <-------------- > > > > + 10.62% 0.00% [kernel] [k] ret_from_fork_asm > > > > + 10.62% 0.00% [kernel] [k] ret_from_fork > > > > + 10.62% 0.00% [kernel] [k] kthread > > > > ... > > > > > > > > > > > > 2. Check if cpu_possible() and then fallback to cpumask_nth() if not > > > > > > > > > > > > ... > > > > + 6.84% 0.29% [kernel] [k] alloc_vmap_area > > > > + 6.80% 6.70% [kernel] [k] native_queued_spin_lock_slowpath > > > > + 4.24% 0.09% [kernel] [k] free_vmap_block > > > > + 2.41% 2.38% [kernel] [k] addr_to_vb_xa <----------- > > > > + 1.94% 1.91% [kernel] [k] xas_start > > > > ... > > > > > > > > > > > > It is _worth_ to check if an index is in possible mask: > > > > > > > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > > > > index 45e1506d58c3..af20f78c2cbf 100644 > > > > --- a/mm/vmalloc.c > > > > +++ b/mm/vmalloc.c > > > > @@ -2542,7 +2542,10 @@ static DEFINE_PER_CPU(struct vmap_block_queue, vmap_block_queue); > > > > static struct xarray * > > > > addr_to_vb_xa(unsigned long addr) > > > > { > > > > - int index = (addr / VMAP_BLOCK_SIZE) % num_possible_cpus(); > > > > + int index = (addr / VMAP_BLOCK_SIZE) % nr_cpu_ids; > > > IIUC, use nr_cpu_ids here maybe incorrect. > > > > > > take b101 as example, nr_cpu_ids is 3. if index is 2 cpumask_nth(2, cpu_possible_mask); > > > might return 64. > > > > > But then a CPU2 becomes possible? Cutting by % nr_cpu_ids generates values < nr_cpu_ids. > > So, last CPU is always possible and we never do cpumask_nth() on a last possible CPU. > > > > What i miss here? > > > Sorry, I forget to reply to all :), I write a demo to test as follows: > > static int cpumask_init(void) > { > struct cpumask mask; > unsigned int cpu_id; > cpumask_clear(&mask); > > cpumask_set_cpu(1, &mask); > cpumask_set_cpu(3, &mask); > cpumask_set_cpu(5, &mask); > > cpu_id = find_last_bit(cpumask_bits(&mask), NR_CPUS) + 1; > pr_info("cpu_id:%d\n", cpu_id); > > for (; i < nr_cpu_ids; i++) { > pr_info("%d: cpu_%d\n", i, cpumask_nth(i, &mask)); > } > > return 0; > } > > [ 1.337020][ T1] cpu_id:6 > [ 1.337338][ T1] 0: cpu_1 > [ 1.337558][ T1] 1: cpu_3 > [ 1.337751][ T1] 2: cpu_5 > [ 1.337960][ T1] 3: cpu_64 > [ 1.338183][ T1] 4: cpu_64 > [ 1.338387][ T1] 5: cpu_64 > [ 1.338594][ T1] 6: cpu_64 > > In summary, the nr_cpu_ids = last_bit + 1, and cpumask_nth() return the nth cpu_id. > OK, i misread the cpumask_nth(). We should go with *_next() variant instead. Thank you for pointing this. Below is updated version with extra comment: diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 45e1506d58c3..03b82fb8ecd3 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2542,7 +2542,15 @@ static DEFINE_PER_CPU(struct vmap_block_queue, vmap_block_queue); static struct xarray * addr_to_vb_xa(unsigned long addr) { - int index = (addr / VMAP_BLOCK_SIZE) % num_possible_cpus(); + int index = (addr / VMAP_BLOCK_SIZE) % nr_cpu_ids; + + /* + * Please note, nr_cpu_ids points on a highest set + * possible bit, i.e. we never invoke cpumask_next() + * if an index points on it which is nr_cpu_ids - 1. + */ + if (!cpu_possible(index)) + index = cpumask_next(index, cpu_possible_mask); return &per_cpu(vmap_block_queue, index).vmap_blocks; } Thanks! -- Uladzislau Rezki