From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 307851C5D77 for ; Sun, 23 Nov 2025 20:10:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763928610; cv=none; b=hut83OFW46vYAj9owpXjTebY8gcszS15avAtJ6r9cJzUVLzqn7agz+PcaAdKUrAXDS506llo94LTVTjE18w4oIsp8yEE5qIdQJCXjH91UeuS0gKpuFewPDn0UPNUFuC/fVEoaNW1oWnbWUuEQtFkmCwiGzQeJLPf9gDHDHHFCSM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763928610; c=relaxed/simple; bh=59pyrJX91YopO2QPU0o8tsYYx1CdzaF6cGD6X7OS3WI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GY24OO0O3LuLPU35fGUdexz74ARRmfQ/f/ncO/4uUv2nRK3Y2u9kdw9zaB/GMS/KLLjB5d5tXdI8R2C6wx3mYs6r38vD4dPSQqRDMqqCTHDuf3qdpd/tD6PPLiniqFupmLngsXn82JHhfFFn07c5a9txeUvw+r29+O8/+UNz/qg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Fr15hBVw; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Fr15hBVw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763928605; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=kCNBLrjOr1foGs26XOE6a2gSNdqIv5bHIjwCsegLTIA=; b=Fr15hBVw3wovuY8YXW48DIQNC/5d6E5HbLpHRKNWGopvFATQxmRGQ9U1R0/Dm7rB01/DTK 3z7fOvvoaQnheYsHCLcoNopS12+5mmedZDeodBCkBJRyFmMFdsLLgSWr29VyXncTAUlU0C dyVFsuOYOGMMmJxiXS+r5R3u2nyoaa4= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-88-hZe5QCUTOCOc5Rs5Q6zXug-1; Sun, 23 Nov 2025 15:10:00 -0500 X-MC-Unique: hZe5QCUTOCOc5Rs5Q6zXug-1 X-Mimecast-MFC-AGG-ID: hZe5QCUTOCOc5Rs5Q6zXug_1763928599 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CA10D195608A; Sun, 23 Nov 2025 20:09:58 +0000 (UTC) Received: from fedora (unknown [10.45.224.57]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id B7C091955F1B; Sun, 23 Nov 2025 20:09:56 +0000 (UTC) Received: by fedora (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Sun, 23 Nov 2025 21:09:58 +0100 (CET) Date: Sun, 23 Nov 2025 21:09:55 +0100 From: Oleg Nesterov To: Mateusz Guzik Cc: brauner@kernel.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org Subject: Re: [PATCH 3/3] pid: only take pidmap_lock once on alloc Message-ID: References: <20251123063054.3502938-1-mjguzik@gmail.com> <20251123063054.3502938-4-mjguzik@gmail.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: <20251123063054.3502938-4-mjguzik@gmail.com> X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 On 11/23, Mateusz Guzik wrote: > > This reduces contention on the lock during parallel clone/exit. > > It remains the primary bottleneck in such a case. > > While here tidy up the code. Not sure I can review... But FWIW this patch looks good to me after the very quick glance. I'll try to actually read it tomorrow. But please find a couple of minor "can't resist" nits below. > + for (tmp = ns, i = ns->level; i >= 0; i--) { > + int tid = set_tid[ns->level - i]; > > if (tid) { > nr = idr_alloc(&tmp->idr, NULL, tid, > @@ -235,10 +261,8 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid, > * a partially initialized PID (see below). > */ > nr = idr_alloc_cyclic(&tmp->idr, NULL, pid_min, > - pid_max, GFP_ATOMIC); > + pid_max[ns->level - i], GFP_ATOMIC); > } > - spin_unlock(&pidmap_lock); > - idr_preload_end(); > > if (nr < 0) { > retval = (nr == -ENOSPC) ? -EAGAIN : nr; So. With or without this patch we have if (tid) { nr = idr_alloc(...); if (nr == -ENOSPC) nr = -EEXIST; } else { nr = idr_alloc_cyclic(...); } if (nr < 0) { retval = (nr == -ENOSPC) ? -EAGAIN : nr; goto out_free; } and somehow this looks annoying to me... Perhaps it makes sense to make this code more symmetric (and imo more readable) ? if (tid) { nr = idr_alloc(...); if (nr == -ENOSPC) nr = -EEXIST; } else { nr = idr_alloc_cyclic(...); if (nr == -ENOSPC) nr = -EAGAIN; } if (nr < 0) retval = nr; goto out_free; } > - idr_preload(GFP_KERNEL); > - spin_lock(&pidmap_lock); > - if (!(ns->pid_allocated & PIDNS_ADDING)) > - goto out_unlock; > + if (unlikely(!(ns->pid_allocated & PIDNS_ADDING))) > + goto out_free; > pidfs_add_pid(pid); > - for ( ; upid >= pid->numbers; --upid) { > + for (upid = pid->numbers + ns->level; upid >= pid->numbers; --upid) { > /* Make the PID visible to find_pid_ns. */ > idr_replace(&upid->ns->idr, pid, upid->nr); > upid->ns->pid_allocated++; So.. unless I am totally confused the current code has another idr_preload + idr_preload_end around pidfs_add_pid(). AFAICS, this makes no sense, and your patch removes it. But perhaps this deserves a note in the changelog or even a separate patch? And another stupid question... I don't understand fs/pidfs.c, but it looks a bit strange to me that pidfs_add_pid() is called before the for (...) idr_replace(...); loop. I don't see any problem, but to me it would look a bit better to do pidfs_add_pid(pid) when this pid is fully initialized... Oleg.