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 1C68DC4829A for ; Tue, 13 Feb 2024 12:39:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7F2956B0088; Tue, 13 Feb 2024 07:39:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 77A896B0089; Tue, 13 Feb 2024 07:39:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F3406B008A; Tue, 13 Feb 2024 07:39:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 49F716B0088 for ; Tue, 13 Feb 2024 07:39:17 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 1498E160C0A for ; Tue, 13 Feb 2024 12:39:17 +0000 (UTC) X-FDA: 81786735954.20.A75177B Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf14.hostedemail.com (Postfix) with ESMTP id E774210000D for ; Tue, 13 Feb 2024 12:39:14 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=m68folJe; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=IlwrjTqj; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=m68folJe; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=IlwrjTqj; spf=pass (imf14.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707827955; 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=unsCwvhy3hos4hRTOHPJFcc0LouOpI2E7yhqv0G6kRk=; b=SH2xgldlvdTN2tMimA2XrJPRE3Duu01+xNkuQ9lQffJqvuTOWh2U5nv8w8kT5rQSWnicnV 8aB1BcsojJIgtKYPykIX6/wHJ4AmOQukr8yD/4brC+yWDTSZKoXDdWYWCS58CB217Wy6tC RdgyIeR0ewE0v1AkXvjsnt0Ap5nQ46c= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=m68folJe; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=IlwrjTqj; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=m68folJe; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=IlwrjTqj; spf=pass (imf14.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707827955; a=rsa-sha256; cv=none; b=pV9aLj3j0eZHF6hM6b8O7btO7HhZJVpGYXXeH/GR0ufP3OUdgudB1azPGvIlt49rSrj9nV /OlnWYvNjVHvsQZHRzFP83+V0l8d/j2YV2cIUJOVer2Y/yCGpJNT/tNL61DneMRt3VTV9d bXHaOgseVfyU0ZojFgVlfU855+aAqCM= 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <11cb2ac2-102f-4acd-aded-bbfd29f7269a@suse.cz> X-Rspamd-Queue-Id: E774210000D X-Rspam-User: X-Stat-Signature: x4mdd6b45x47bnsx635tqpmgiamgc6up X-Rspamd-Server: rspam01 X-HE-Tag: 1707827954-915469 X-HE-Meta: U2FsdGVkX1/1Bft50jpE2d6zzEl+53fR3YDt/jTN0nH//Fq/92DZkDnqcEu5Ww3k7jbXciQyQLLKkFpTMETrsVLcOxZykRo24ECMMwn0yef8w5AjDWLLl/AUmChBK7uEkuuTdM5+cMqShnJBMsxzQ/WwcaEfup5H7PtHzuzPX2l168Y+vr4FlscKGWu3C140znSFoI9eWUsw+if+xUs/C//KgIeqosgYQ/mMT92n1ppyUIMqm+tUXtuP3sNSz0/n9OOmn+0sEGxpBG95A/It98zinptQeJolRyQ8f0NNT27AUrotwax/oFBuKl1FiUGBZub9NdCJeCDVbVNfvAfrBflPAx2cDO02DrQf/KN5q1CdQiXHP7lnTQQd+PtvVvciHZ50Dd9cSzfBJ6/kUG8yHrorQmcmqj8yge6Mg3DBIPc7oQR0lzsoJZjX6Q5jySw1k1jY3UKF4dPFA+KH9uMbJOyAynQRA1KVr1Z3hY4a/YN4Op8F4ONVwZpKOnxccb78j5b5COxf0PAuDwkOXEW5NQygIwjK+ZzGDlcmAy+PqHHVBOYFqZBpsmvi/iILHgGWOdHLrJqf0wVzMql0ca9MKxQ88UtBfFB+jBAM0HQumYxg9QDJ6CAqGbV9vTOsgLU/ABnDHPlqPS8ULB5eeQZIL3w0Tpxt3Osoi4Mrcjs1YGBxj/xxDJ0mYkWV7En/jBYlB5yTfOBUlsrJXC0CcC05vfMYTbw71VjLDl24XuaFJzxM8a19fKI6jvMPja0s+Jo5PM/lTbyFa68C+i5muwxHWxZakkfF984eNjCjnSOYfOFVbRVvlihg1bp3BYIhzuAPoQUdj5XRImWs0FtvpLiIahRSpI3oqWG2pLewcsRwX8uepeGXMQLC6UllGXZ2hT+SLEL9UttDf58ed/Q67pvteYrtsQgA8F5tL3aZ2b/NTJU= 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: List-Subscribe: List-Unsubscribe: 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