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 B4F50CE8D58 for ; Thu, 19 Sep 2024 07:10:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D84206B0082; Thu, 19 Sep 2024 03:10:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D0C8D6B0083; Thu, 19 Sep 2024 03:10:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5F9E6B0085; Thu, 19 Sep 2024 03:10:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 91BA16B0082 for ; Thu, 19 Sep 2024 03:10:46 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 299D6140286 for ; Thu, 19 Sep 2024 07:10:46 +0000 (UTC) X-FDA: 82580615292.04.A19C3B8 Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) by imf10.hostedemail.com (Postfix) with ESMTP id E383BC0007 for ; Thu, 19 Sep 2024 07:10:43 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=KTnTpCbT; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of boqun.feng@gmail.com designates 209.85.160.175 as permitted sender) smtp.mailfrom=boqun.feng@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726729718; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7QO2c7/I67RlCRDcr/Y3qX9Q299kYfHctBt13qLUVFY=; b=mmvvw5B4mtBkJEagsbdiZCj1LmVDcfGBJc/SEqFzQMqPdO6S5LaedQ9I/Oqwz5LIhegUnk oyfm7KQ1eLgYIxeUX2+rB9UgtTrCMQp+2mCgcFfVqs+r69Bsz71rVPlwbFDMtMqZbDvmRR ICh9owpK/CoYhciF/DTXLJz9HFebaJo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726729718; a=rsa-sha256; cv=none; b=VqIXAjAdmNLZBiB8tABtp/fCGkw4CyLBjf2rbPQzn6GD7C3J38ObyknTlHzNZ1SuFE20Jf l2H/ANBDCJZK9wF+jY23AX38nHn5O6foT8b6vd8+AOMFY/2F2GnfpB5FvHRQx1h5bM7tAU dnYbJtkTK2ZENjFA5djbgBbXzPepIuI= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=KTnTpCbT; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of boqun.feng@gmail.com designates 209.85.160.175 as permitted sender) smtp.mailfrom=boqun.feng@gmail.com Received: by mail-qt1-f175.google.com with SMTP id d75a77b69052e-4582c4aa2c2so3082581cf.0 for ; Thu, 19 Sep 2024 00:10:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726729843; x=1727334643; darn=kvack.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :feedback-id:from:to:cc:subject:date:message-id:reply-to; bh=7QO2c7/I67RlCRDcr/Y3qX9Q299kYfHctBt13qLUVFY=; b=KTnTpCbTJJrKTCGa80w8ShRjDd7Fx1BMwtiVjyuPosOVVHt52c2ysciXl9xUqYez0Y FWHnMMOWriNiIBcEvvq08zQczsbehWPs2MnWvIwZjUGBahLVi6Hl2U1sRV88Gd7rCYd6 mNQX37sIviJSaMiJrvdS1j+v5yOYkurNr6GibExxpo3YCKicxc6Akuj8WnXRclM409E5 jCxio3RG+gRzPKMUy3dav3T3q+noYLUTT4V+OizyxoKBVs8fDH5fZkvnI9M0Yl3MNBzH 44ZYqNR4fjTuiXmkAmTVQ3C67/yw468+KsUCUEvOu0X+HB91plngevJzLSq+xdqqXc6T CypA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726729843; x=1727334643; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :feedback-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7QO2c7/I67RlCRDcr/Y3qX9Q299kYfHctBt13qLUVFY=; b=VbLhDHaUtxi0mwxB9GeV4fFVecuMxnol24SNsvv5DfTeM9cKNLUSNMHy+dej7gDB6P DbSgNQfsZJixx3KnPPmaFgJpHPcsImV2MMAJrPgM/IaGQ3obJCxft8EVPsUP2ho+gQ8Q jOU4nOUurw0c5OsBSIwSpKPbviRzSaAuZDUo05SqNyDaImagqWv9qm0eUJ7pCKaRJinI TtFaii2stxLZNNK15R/zwWnL5sl2yqqgE97WlFgy2ZIEp6lrrQBKlWPPn3F2vS/wMH3i UiMcjR4S2INliUo6580y6sLYiZ3pqxwTzriJEY+ooUoBh5ikFsI0UoAi5QwavSJYymlU qhOw== X-Forwarded-Encrypted: i=1; AJvYcCUC66YzbrU4hwhKxHk/6kcOxeBt5eyQnrgL9fXiNRlyH88ecDyh/kRUSJmIOxyGpM7Hq1Kth4sGYA==@kvack.org X-Gm-Message-State: AOJu0YwVSnDRjg4NDIo5eUP6m6EVV3rMdXyXFFPa8wDV2BdQ3u1NDItN zYom/lbe4UCTP+7ZAnz3pnrWCbuKCOWRlx3435CPaOdeaasPCaPl X-Google-Smtp-Source: AGHT+IEKX3hg+/XrCUs3vNj5lGyvUgv9sa2s1gAeDJdkuaQ80BEsYKQrkSosZ6GkHLs9lV7qEOSmyg== X-Received: by 2002:ac8:7d02:0:b0:458:52f0:9bd8 with SMTP id d75a77b69052e-45860422a45mr368514221cf.53.1726729842653; Thu, 19 Sep 2024 00:10:42 -0700 (PDT) Received: from fauth2-smtp.messagingengine.com (fauth2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-45b1788c181sm4461881cf.52.2024.09.19.00.10.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 00:10:42 -0700 (PDT) Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfauth.phl.internal (Postfix) with ESMTP id 785DF120006E; Thu, 19 Sep 2024 03:10:41 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Thu, 19 Sep 2024 03:10:41 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudeltddguddulecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtugfgjgesthekredttddt jeenucfhrhhomhepuehoqhhunhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrih hlrdgtohhmqeenucggtffrrghtthgvrhhnpeevgffhueevkedutefgveduuedujeefledt hffgheegkeekiefgudekhffggeelfeenucevlhhushhtvghrufhiiigvpedtnecurfgrrh grmhepmhgrihhlfhhrohhmpegsohhquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgr lhhithihqdeiledvgeehtdeigedqudejjeekheehhedvqdgsohhquhhnrdhfvghngheppe hgmhgrihhlrdgtohhmsehfihigmhgvrdhnrghmvgdpnhgspghrtghpthhtohepvdeipdhm ohguvgepshhmthhpohhuthdprhgtphhtthhopehjihgrnhhgshhhrghnlhgrihesghhmrg hilhdrtghomhdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghr nhgvlhdrohhrghdprhgtphhtthhopehrtghusehvghgvrhdrkhgvrhhnvghlrdhorhhgpd hrtghpthhtoheplhhinhhugidqmhhmsehkvhgrtghkrdhorhhgpdhrtghpthhtoheplhhk mhhmsehlihhsthhsrdhlihhnuhigrdguvghvpdhrtghpthhtohepphgruhhlmhgtkheskh gvrhhnvghlrdhorhhgpdhrtghpthhtohepfhhrvgguvghrihgtsehkvghrnhgvlhdrohhr ghdprhgtphhtthhopehnvggvrhgrjhdruhhprgguhhihrgihsehkvghrnhgvlhdrohhrgh dprhgtphhtthhopehjohgvlhesjhhovghlfhgvrhhnrghnuggvshdrohhrgh X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 19 Sep 2024 03:10:40 -0400 (EDT) Date: Thu, 19 Sep 2024 00:10:16 -0700 From: Boqun Feng To: Lai Jiangshan Cc: linux-kernel@vger.kernel.org, rcu@vger.kernel.org, linux-mm@kvack.org, lkmm@lists.linux.dev, "Paul E. McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Zqiang , Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Mark Rutland , Thomas Gleixner , Kent Overstreet , Linus Torvalds , Vlastimil Babka , maged.michael@gmail.com, Neeraj Upadhyay Subject: Re: [RFC PATCH 1/4] hazptr: Add initial implementation of hazard pointers Message-ID: References: <20240917143402.930114-1-boqun.feng@gmail.com> <20240917143402.930114-2-boqun.feng@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: E383BC0007 X-Stat-Signature: xawm1fniargao8neybdrdi95feom5c5a X-Rspam-User: X-HE-Tag: 1726729843-530345 X-HE-Meta: U2FsdGVkX1/GZfb59H3eojy5kioPh8tdumHsGpv1ZiuYF/THt+fHmJOKsY8bvJv0DgAEek7Zwuyyasy7IROJLM4TG0jUWS5uU8CDIe2jL7PyCcGT92xNnhkXOoqjV3OUPZL1w2BYGtYcAfn/6qV2EFIxLlsHvAt6lPaDYQkKDQwCcqyMS350eZl1KGk2O+IMepGfm2ukBYOA6Y2coovCIHhtYcQfx1DWBkLNw4Ckr43Zpfz1KsdZAiCuAsfWu5/keF3VJBfTlbHlXGXBnb6Qf62MpfpDl1IuvNlTJWERKuIpKCuQX7gY/GSZf32vWEwgtl6l96uZS8DqspqkjN5wK2FV0QXnsDHx911svo1aN1w2NCo258Qp3qjqffFd9aA87dcMIGu56wpXy0y7Vl9bMAU8kDa1lnuXdluPzcuW1ou30prO9oxlWCE8moX2ubBvskHpSMPGiWC9CutJn1HajJHSaeC752LGxINsgE8gYtOIZY09X7wUQPX1Pe8vpB8DUHSd92q2LwCHcN8uDiuJI/Ga9yN+H7kQbtu01gsXbplb8Xu9Bci0LeWQ284x29B8i0rUHHrUQ5IeH7iVuhnOtFW8ujA4V58gY7se1ZMRTwTWZulUgDvZYRa9f8505PrIKEp9aO04aHYhK3PQHr2VD+h73+OKjp1Q36LmoRp4F8QyUVB8vBE5QMM/tbKq1ZdHCuaLmE4qj5mY4kAaGI95UpknDb7WIm9mzT6uBLof+/r47fUplUcRczZR5soiglvaHa/O7d//eLxhFz8hXMUL7Kc1BKqyLdRna46WPxn+NEa5whzLsepecCfyCrKaO5rzfaBnCjvxD+ekvGV7H1daHVT4lBJL2RykTRac+PNEPw3iH7UVKkZtQv7ul1/q51VjxBFP7yCUWKgwo9elmK8DUHyWJgml2IoQbOQUFAn0l86tJd8/WIcKYTIueu7FWRaduSYQrNh5QRwAHTVaEzG GKutzriO Es+NeS/K/4m/ztiBZDNm+psSYEwaHj88AOJB631X9//Y5ETp2mXas60Jx8l5Fz90CHN5s98Rm4CA+gZd4Iu5SnEP3cZYfguEV13iXWlSFK9ABwzEW5qnOWBb/vUPXSg+0gmJ1SS1XTcjVfd3LEpRsOUbNIy2zC806HeHbCjDyd8F4b3lZkI2RgjgeZjlvQoh+rPbUtDBo3Zy+BYSmtrf97JyrfAYtktWBjFdGgeUcX0sj50Km3HRXmeYw2ewUhnGnNa802ovcFR/qlXR9gpup1o59wedkJ6SB5CItPO60Qy/Qr+FMVW5e39z31GjRILkLdeN+J/FVSOafC6bPqyBmHr99WTW7sz6Jh8rgeQlhqO/PWP7sPRxlrnVqowiBh5IK0VVosMQNhcSNzMFo7WE1x7ZxofppSTz9rJhxGoqCYTPxaponNuVxFdijyhEWpYufbPEwnod580LBixVe+QvL04QQcaeT/1YoC+0MpLGPRrsUM3k5B98fX85x+3M8V00hi4Wik3j6ppNbMOZKQvkHbYuqZg== 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 Thu, Sep 19, 2024 at 02:39:13PM +0800, Lai Jiangshan wrote: > On Tue, Sep 17, 2024 at 10:34 PM Boqun Feng wrote: > > > +static void hazptr_context_snap_readers_locked(struct hazptr_reader_tree *tree, > > + struct hazptr_context *hzcp) > > +{ > > + lockdep_assert_held(hzcp->lock); > > + > > + for (int i = 0; i < HAZPTR_SLOT_PER_CTX; i++) { > > + /* > > + * Pairs with smp_store_release() in hazptr_{clear,free}(). > > + * > > + * Ensure > > + * > > + * > > + * > > + * [access protected pointers] > > + * hazptr_clear(); > > + * smp_store_release() > > + * // in reader scan. > > + * smp_load_acquire(); // is null or unused. > > + * [run callbacks] // all accesses from > > + * // reader must be > > + * // observed. > > + */ > > + hazptr_t val = smp_load_acquire(&hzcp->slots[i]); > > + > > + if (!is_null_or_unused(val)) { > > + struct hazptr_slot_snap *snap = &hzcp->snaps[i]; > > + > > + // Already in the tree, need to remove first. > > + if (!is_null_or_unused(snap->slot)) { > > + reader_del(tree, snap); > > + } > > + snap->slot = val; > > + reader_add(tree, snap); > > + } > > + } > > +} > > Hello > > I'm curious about whether there are any possible memory leaks here. > > It seems that call_hazptr() never frees the memory until the slot is > set to another valid value. > > In the code here, the snap is not deleted when hzcp->snaps[i] is null/unused > and snap->slot is not which I think it should be. > > And it can cause unneeded deletion and addition of the snap if the slot > value is unchanged. > I think you're right. (Although the node will be eventually deleted at cleanup_hazptr_context(), however there could be a long-live hazptr_context). It should be: hazptr_t val = smp_load_acquire(&hzcp->slots[i]); struct hazptr_slot_snap *snap = &hzcp->snaps[i]; if (val != snap->slot) { // val changed, need to update the tree node. // Already in the tree, need to remove first. if (!is_null_or_unused(snap->slot)) { reader_del(tree, snap); } // use the latest snapshot. snap->slot = val; // Add it into tree if there is a reader if (!is_null_or_unused(val)) reader_add(tree, snap); } Regards, Boqun > I'm not so sure... > > Thanks > Lai