From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 C9B80233149 for ; Tue, 25 Aug 2026 16:47:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787676430; cv=none; b=D6OopI5tllMcc44mGoJzKi4E/JMyKFBvGkyUHimd7Jno9CFKumW2AGq5a4rD+eYpe4yvVk5LrCbTILHTQftk/J5B7raCia+lfH+NUuIQWGgFbIhf7efKVDRMcd2UtmUQJ9ZzH/e7ykOsAxltC7sPNgDKShiuexDXhGRGDl3f+qE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787676430; c=relaxed/simple; bh=rW1JjzQdWGonYI/ecwWMscBZgkGK3L+yGjq03166Gcg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=owG+p4aUr/yhScuYYGat83/fvOGgeMOmwv+h6exHWrzy8jYcYa6Ozela1a1PkEIr1ZIIhUq/WDDvI3vDC1MAOfL3q/++BPIUFPzs1icqKlWBHRVOXAZODekoF35GjQUTh1TwsmkPBiErSz0JLQ0HeuIKQB972FOXYRBTz5VOhwM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=purestorage.com; spf=pass smtp.mailfrom=purestorage.com; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b=L3wgFVKt; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=purestorage.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=purestorage.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b="L3wgFVKt" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2d6fe26ef1cso711545ad.2 for ; Tue, 25 Aug 2026 09:47:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1787676428; x=1788281228; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to:content-type; bh=+G+f6/zjd8uOjlOFFFuS9kFtoy+MaAtVcFc3NRBELBU=; b=L3wgFVKtHu3eg11K5yZLsr0kRZwKAgbOsFCnx3tVDSH2KeK95p90pfqGC0jmT4y3zX vH3dNZlgkyxnYsBVG2YKxk17kJ0KKKbdMoPd5vX2Uke/JiDd7OElDLSlUyygJjSsOJfw hmWBL3ZZ6MGKlpqqo2YUXs2byiUZ/YbGYe/DmkqUQgnColj4dKVlh35sAn38HF/DXnew ivrVjK7L92RECpWJ6D9rXQbC50aRICvqeKHV2ffjXtvWplN9xxEeqNnXLIindyS1kWLA 5LRVHoQzqoLaj9/Ohcd9xEQAScK3749OGlzSeVkrt+Lspe0C22AotwFlWjLr+TjcmPUg ykDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787676428; x=1788281228; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=+G+f6/zjd8uOjlOFFFuS9kFtoy+MaAtVcFc3NRBELBU=; b=pHFws172XkRucA2h+SXZywJbRVwGWyRwi7+YJBj+4c9uQ2yeP390a7h1Llakoqf2kU xxZqSNEuzah2PGiWO6l6kOFVReJCu/PLje16I8gMEygMUh0EpVyzC9+fjCyfyuunJvTg cKWkqjJfW/C1iEr5H90FD+mMhJOqkdnL836fkwqod9qDUtBTLq33oP5V19uzB/aHjbn6 XKpXNEegHyWvc1a3vMermh6pc8a1Idlk37gLsUi+/k5blOI7ZN8+kDmPrG95/bByduQl 2p5Ll2tDzVx4jq66PyaPsC7dbl5Uc58QIVq36y0Op6Deq9gqH288tVWePoPsBfw/KAA5 hVsQ== X-Forwarded-Encrypted: i=1; AHgh+RpjyAKh10h5GpYmQREgJsWA3Xu8w5KZrUY7XT/alZDP12YgwLiMyNcmB+Kzv8wLYRRJpai/uUtWev31lWk=@vger.kernel.org X-Gm-Message-State: AFuF++lxbokAdnstswPFdrAtWG+3zgdgZv6WmsKgjKpmn/nX0oLStqI0 tXZjHrv8OZ9pwf0e0X9EPJyutFfoKJiH/VSA0lNnlAxr4kgOhX/iYCuplJNURNq6yIby19Scvwt 8orCL3Ug= X-Gm-Gg: AR+sD12LEkNqvnYQMwNLg1bTl4RVAh5VApyAnjAFkKLBYIy5bXrOyozDPU+LEdee1vr yyIkJoG9mlPYCI0+txL6wSTaWQAoopoOTPLCgZ3j3v/sHIOwJIx+CyqAz/lvUyfrGAbTjwyFcOb s4sjmoliGRdIYYQcjdMfjQl1x6A2EH9mSDtlqDK+CDzcfw/3tgI7aLalMvRgQxWmfbOUkqrmG2o c7krFULOD/FfGpePk2N2FbmMXYWWVCn2bns1HoIMhKipbQJXyvds3NSpzZbTjsuoXN9zfaMXTse wUTavjovhLldEm56KfE5SVkkwhqcjmA83CoCKzHSyAE/aXr2OBOwWGhdPCt93m02AKA7N+fp0Z4 1+i368tgmHrZwcNkEiVY7QsUC/ZZL5HP6EyKY4dXZh1xF8+EwbDL/l9OsGK5kdM7cwhZwi6B3yo AKEZZupzkvD37nnEIq66m5YZUegc3us81oUbd3kEVD8/jvnQ5GOl8Ep5hzoqoxwbEVzJjoVReV2 jkPELkJ3A== X-Received: by 2002:a17:903:38cd:b0:2d6:e074:9cad with SMTP id d9443c01a7336-2d6e0749efbmr166931885ad.6.1787676426753; Tue, 25 Aug 2026 09:47:06 -0700 (PDT) Received: from medusa.lab.kspace.sh ([208.88.152.253]) by smtp.googlemail.com with ESMTPSA id 5a478bee46e88-3283d60c291sm313431eec.6.2026.08.25.09.46.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 09:47:00 -0700 (PDT) Date: Tue, 25 Aug 2026 09:46:56 -0700 From: Mohamed Khalfella To: Randy Jennings Cc: Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] nvme: remove stale namespaces by NSID range during scan Message-ID: <20260825164656.GF323015-mkhalfella@purestorage.com> References: <20260823004641.1369895-1-mkhalfella@purestorage.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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Mon 2026-08-24 17:21:26 -0700, Randy Jennings wrote: > On Sat, Aug 22, 2026 at 5:47 PM Mohamed Khalfella > wrote: > > > > nvme_scan_ns_list() drops the stale namespaces in each gap in the > > reported NSID list one NSID at a time. Every iteration calls > > nvme_find_get_ns() to look the namespace up and removes it if it is > > present. The loop runs once per NSID in the gap rather than once per > > namespace actually present. > > > > NSIDs are 32-bit, so a target with a sparse NSID space can make a > > single gap spin the loop billions of times with nothing to remove. > > > > watchdog: BUG: soft lockup - CPU#4 stuck for 26s! > > Workqueue: nvme-wq nvme_scan_work [nvme_core] > > RIP: 0010:__srcu_read_unlock+0xb/0x20 > > Call Trace: > > nvme_find_get_ns+0x7d/0xb0 [nvme_core] > > nvme_scan_ns_list+0xe8/0x280 [nvme_core] > > nvme_scan_work+0x18a/0x280 [nvme_core] > > process_one_work+0x197/0x380 > > worker_thread+0x2fe/0x410 > > kthread+0xe0/0x100 > > > > Rename nvme_remove_invalid_namespaces() to nvme_remove_nsid_range() > > and give it an open (start, end) NSID range. ctrl->namespaces is > > sorted by NSID, so the whole gap is dropped in a single walk that > > stops once end is reached. This bounds the work by the namespaces > > that are present instead of by the size of the gap. > > > > Fixes: 540c801c65eb ("NVMe: Implement namespace list scanning") > > Signed-off-by: Mohamed Khalfella > > Reviewed-by: Sagi Grimberg > Reviewed-by: Randy Jennings > > > --- > > drivers/nvme/host/core.c | 18 +++++++++--------- > > > -static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl, > > - unsigned nsid) > > +static void nvme_remove_nsid_range(struct nvme_ctrl *ctrl, u32 start, u32 end) > It is not intuitive to me that start is non-inclusive. May we add > a comment to that effect? Yes, it is not intuitive. [start, end) makes more sense IMO. That is said, this is how nvme_remove_invalid_namespaces() worked and I decided not to change that because it is not part of the fix. I do not think a comment will make a big difference here. The next person who works on this code will read the nvme_remove_nsid_range(), it is a short function, and figure out how it works. > > > { > > struct nvme_ns *ns, *next; > > LIST_HEAD(rm_list); > > > > mutex_lock(&ctrl->namespaces_lock); > > list_for_each_entry_safe(ns, next, &ctrl->namespaces, list) { > > - if (ns->head->ns_id > nsid) { > > + if (ns->head->ns_id >= end) > > + break; > > + if (ns->head->ns_id > start) { > > list_del_rcu(&ns->list);