Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp3016889rdb; Tue, 13 Feb 2024 04:39:35 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWpzEzRIZC9SNGbYcbbtz2RdzrzayZFLTN0UZ7uu4qWf+BRV0UCKBGPh3PMsqLa1N85nMHclRo4XWFIktzTb1Z0lB8tCAtTVafDnvijmg== X-Google-Smtp-Source: AGHT+IESzeJlqPH2W/HqAPJQzQ1L8fGLMxiBhHHxC6Ki7zn59wslS3JDguXW/Xo+cHzUKDh7xCt0 X-Received: by 2002:a05:6214:3a01:b0:68c:8218:30a2 with SMTP id nw1-20020a0562143a0100b0068c821830a2mr3623222qvb.0.1707827975572; Tue, 13 Feb 2024 04:39:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707827975; cv=pass; d=google.com; s=arc-20160816; b=NgijrK2dZxA9W5Vt+F8ilS2qXjM2xMIQdPJRdE4WEhFqFnuyvGMAe6oK1sPIDKMnVJ GOiSq6oEOPe1Y/Uk5Q4buJKKtqNGtr9H4gN2mLMhdIZMFNkpIBgTmpA7kidsqNAwOW8o vdO+3cN5BuchVJDrJ+lw9NbG1qqe/XPqCabsBaIVNGYyiXmRUoKB/5rN6dZ8VC4yZEEz u8ztRIPWEc87fbXjE3tm1BknBLFQS4FO8wYOzmSQf1BSnYOXQ0ayodwqk3ChLr4+Z6KI HiJEdsb5fr9MBC4X3yawZn5PMxamNUMNv+2aNfT8R2SYSFoE465+HFWiP/Zi5UYZT+Jp fyDQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature:dkim-signature:dkim-signature :dkim-signature; bh=unsCwvhy3hos4hRTOHPJFcc0LouOpI2E7yhqv0G6kRk=; fh=/LI2AyCMwjjOWIciQ/ws5sRtY6t7GI59jrgOgJVV9Qs=; b=Z2U1+ncwXQDJQgAkGet6nY3Lp+emgnt7ZyzA7BJcvkxwzmvIaIzOBmjkoL4UDxM8DB i6OO0LiuJV1hH2ld0rFjpHmbgMY2jXoij8Dk2FtU8sJ7FfnPtnA3CM+9JHTHuF88KihZ 1iTzZK+CPffDeDAQevxxvGA3ILACaQIJ/AK5U5DJrmefxOVcn71SnXv/lppLsfNpD77k WW6sSd2UcZuq5f+86kCnzuNj1s/nGVl6YnLdE0f4r0JtGlPfGcB6e6O29krhdwDc88Is zdnP0+NWxxKb2Jzq/aI80fDmv7hJpE3hFtDzy+RFb5mKM72N2Zboq55IJCTp5Ok33Uik BH3A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=m68folJe; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=IlwrjTqj; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=m68folJe; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-63516-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63516-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de X-Forwarded-Encrypted: i=2; AJvYcCVybICyWUwkAkxwC2WLMX05DnB3Frphp6zyz7OzjovJv2jFrTfaXhsXSgJhWpHBkKuwJQv1MjDR74eN2wgXed1dweRYk6dRCM3qBppagA== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id kd15-20020a056214400f00b0068c7439385fsi2677630qvb.387.2024.02.13.04.39.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 04:39:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-63516-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=m68folJe; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=IlwrjTqj; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=m68folJe; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-63516-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63516-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 29B271C262D7 for ; Tue, 13 Feb 2024 12:39:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A8958482DA; Tue, 13 Feb 2024 12:39:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="m68folJe"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="IlwrjTqj"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="m68folJe"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="IlwrjTqj" Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 0FF4B45BF1 for ; Tue, 13 Feb 2024 12:39:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707827956; cv=none; b=bChssiBX4/46FHyZleQNV4zUWx4x6PuEvYdaufZNW0cVQ+jGwaA8/tpqpyWsRfB/pyP67zFA6LuOhNOaOITYzGN2HDFDe/40/Bc0BdfURevbB1ycgjxB7VLxZPraewy7drItV/Fj8VkCVFpDFgKMaKpTJCWiyCgzTCshjAskdtI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707827956; c=relaxed/simple; bh=rwSA92KX87luSNNWjkBVYK299PueHIWqFuGDWLzlQMI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=V6fE3vvX109UgG1QC8mqu7d0tshWe+H0nSv6hOJDeL6LJFhAiUsbY7tqxuuP4VDKudw1Kv+lMJwMltOUemzGso5e8/czSzYprhvqciM2CcqSz57OktUEWRUaDt4e1lZDLKk4tR2WsnzAjZmXCE9QAcVIVnArbF2+M3KYBQFlUnc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=m68folJe; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=IlwrjTqj; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=m68folJe; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=IlwrjTqj; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 337AD1F79C; Tue, 13 Feb 2024 12:39:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707827953; h=from:from:reply-to: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=unsCwvhy3hos4hRTOHPJFcc0LouOpI2E7yhqv0G6kRk=; b=m68folJevTPvYOJh0BkqGgtbihRPtYlHAeCtxxEZ6ZTNSEhh/SU92XWYU07CoJqfcsLVvv WKo+FqYbfcD0PfDSkyl27H87k8GnMkssh06Arn9iadqcATVEZKmpscYKUY8Tpxf0GS/9oF vB8aYNdQVtaDq13LPDQQedW8BFw6XUQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707827953; h=from:from:reply-to: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=unsCwvhy3hos4hRTOHPJFcc0LouOpI2E7yhqv0G6kRk=; b=IlwrjTqjDE3CES/wBjTJIRbGfq3Qaq7tnCoOBCStZ8Hjpq0yG7ykJzxFepEtyy4BS+jct2 aBPu7hJLVWeNrBDg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707827953; h=from:from:reply-to: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=unsCwvhy3hos4hRTOHPJFcc0LouOpI2E7yhqv0G6kRk=; b=m68folJevTPvYOJh0BkqGgtbihRPtYlHAeCtxxEZ6ZTNSEhh/SU92XWYU07CoJqfcsLVvv WKo+FqYbfcD0PfDSkyl27H87k8GnMkssh06Arn9iadqcATVEZKmpscYKUY8Tpxf0GS/9oF vB8aYNdQVtaDq13LPDQQedW8BFw6XUQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707827953; h=from:from:reply-to: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=unsCwvhy3hos4hRTOHPJFcc0LouOpI2E7yhqv0G6kRk=; b=IlwrjTqjDE3CES/wBjTJIRbGfq3Qaq7tnCoOBCStZ8Hjpq0yG7ykJzxFepEtyy4BS+jct2 aBPu7hJLVWeNrBDg== Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id B02841329E; Tue, 13 Feb 2024 12:39:12 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id dr1CKPBiy2UoVAAAn2gu4w (envelope-from ); Tue, 13 Feb 2024 12:39:12 +0000 Date: Tue, 13 Feb 2024 13:40:22 +0100 From: Oscar Salvador To: Vlastimil Babka Cc: Marco Elver , Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Andrey Konovalov , Alexander Potapenko Subject: Re: [PATCH v8 2/5] mm,page_owner: Implement the tracking of the stacks count Message-ID: References: <20240212223029.30769-1-osalvador@suse.de> <20240212223029.30769-3-osalvador@suse.de> <11cb2ac2-102f-4acd-aded-bbfd29f7269a@suse.cz> 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: <11cb2ac2-102f-4acd-aded-bbfd29f7269a@suse.cz> Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [-0.48 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_SEVEN(0.00)[8]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.cz:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[google.com,linux-foundation.org,vger.kernel.org,kvack.org,suse.com,gmail.com]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.38)[77.26%] X-Spam-Level: X-Spam-Flag: NO X-Spam-Score: -0.48 On Tue, Feb 13, 2024 at 12:34:55PM +0100, Vlastimil Babka wrote: > On 2/13/24 10:21, Marco Elver wrote: > > On Tue, 13 Feb 2024 at 10:16, Vlastimil Babka wrote: > >> Isn't this racy? Shouldn't we use some atomic cmpxchg operation to change > >> from REFCOUNT_SATURATED to 1? > > > > If 2 threads race here, both will want to add it to the list as well > > and take the lock. So this could just be solved with double-checked > > locking: > > > > if (count == REFCOUNT_SATURATED) { > > spin_lock(...); > > Yeah probably stack_list_lock could be taken here already. But then the > kmalloc() of struct stack must happen also here, before taking the lock. I am thinking what would be a less expensive and safer option here. Of course, taking the spinlock is easier, but having the allocation inside is tricky, and having it outside could mean that we might free the struct once we checked __within__ the lock that the refcount is no longer REFCOUNT_SATURATED. No big deal, but a bit sub-optimal. On the other hand, IIUC, cmpxchg has some memory ordering, like store_and_release/load_acquire do, so would it be safe to use it instead of taking the lock? -- Oscar Salvador SUSE Labs