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 A2EC3C54EBD for ; Fri, 13 Jan 2023 17:04:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CEE7A8E0002; Fri, 13 Jan 2023 12:04:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C781F8E0001; Fri, 13 Jan 2023 12:04:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B190D8E0002; Fri, 13 Jan 2023 12:04:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id A21178E0001 for ; Fri, 13 Jan 2023 12:04:15 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 5CCD3A0BDC for ; Fri, 13 Jan 2023 17:04:15 +0000 (UTC) X-FDA: 80350398870.10.D7CC882 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf14.hostedemail.com (Postfix) with ESMTP id 085C810000F for ; Fri, 13 Jan 2023 17:04:11 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=FRpCw8xx; spf=pass (imf14.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.29 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673629452; 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=ZrIktPWt6uDyBFSnP2WU+2Nh/aWfw7kkDySc2ve2K0M=; b=iTN8FUy+9uEbSvFfkC0bA/VAQCbFPx41ii/7yRadIi35/LIHlSNmJAR8fduDA/9tB69eDe plN+Kln/4GK1RegtS6w8NnHvghFgTNoNFf9i+o99uI7ZmZ5qvhjE2vVQPUgwvk3uoBh8/K zbQybBYUC9AYtwZlIQ1j3uR00OVdpn0= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=FRpCw8xx; spf=pass (imf14.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.29 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673629452; a=rsa-sha256; cv=none; b=oPB/S/BFI9N+xvgE58JT78twqo3R2U1c9ya1zEUaqVJ56VGgfMs4PZRptqJE8hJGmuAG/E /ttb63Qj7gu2rgm5Z8AH5APKHM0X8dKjnNfJO4MqlAMdMDlRrwmYzkUWwIWn53IAV7GUQl TN3noUKWb4hOcqLcT9VCUkdukCDp50M= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 5843020036; Fri, 13 Jan 2023 17:04:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673629450; 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=ZrIktPWt6uDyBFSnP2WU+2Nh/aWfw7kkDySc2ve2K0M=; b=FRpCw8xxBRP2i2AbveMiI9ohchbggYYiIX2zvghZQKS2RVujRdZMtv0nMEyqJT2ACsvomf yrJUepySV7UBaa/TxMa9plHdgHzpAjUeIegkpWWud2xe7cw9XwTtZGPoiCPYX03dW+pULi WF81SfDhkJDJ43+llmF6gZJU8BOwav0= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 38D4A13913; Fri, 13 Jan 2023 17:04:10 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id CjXKCwqPwWPpZwAAMHmgww (envelope-from ); Fri, 13 Jan 2023 17:04:10 +0000 Date: Fri, 13 Jan 2023 18:04:09 +0100 From: Michal Hocko To: Zhongkun He Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, wuyun.abel@bytedance.com Subject: Re: [PATCH 0/3] mm: replace atomic_t with percpu_ref in mempolicy. Message-ID: References: <20221204161432.2149375-1-hezhongkun.hzk@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221204161432.2149375-1-hezhongkun.hzk@bytedance.com> X-Rspamd-Queue-Id: 085C810000F X-Stat-Signature: 3kemwkf3yx1oeyqtbi6a3zu5dwoxzkio X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1673629451-196396 X-HE-Meta: U2FsdGVkX1+BQ3/Tl5efhOYPBT0iAUYioOcyiIMZMOfodwxzWZggFT9BuKbAfM388buozvlyqUyqT6qw8TCZtjApb2GdlnmRO1UIR59qH5Id3nKAZzXrgRnbKreoNW8pv0PBvp3PZJAe55l3arKuaMv5IpbOubBtdh5dV5s/s3HSITbe7usUl6SYLT744wPtrBbWMF7v7kAkbCyxOciY7m8NE7du0vCPTLFVcXYxJ7ih1x7HmRi93zqE85LwpXlSAlbBQY0v9MLwxWDSiJtqJA+4ezSbxUJ/99u6mMaVunSieBUjEOoQHal8PFQMX0v7bwaYI0VXaLv/uUy2kKYGD1QQTG3ShIw3npkus/33udQ78kz1wtNwwpnHqSHTo0u1Fbolcnz6TZFfS8BpvA42kV2GnPhSsX8IiMVCXBCWwZr7PNovtcIuzdX2lIXjZPasekwO+FvdMVTLEBl4jhO4XaCCMzdML20WZFbw8I6/7sACUhaybPOzkQvSAdMLud5IwkFHvJ9vkKH8T52a4wvAkm+mT+KQ5XzX6dQvslA2mGEwAvQM6W3Rr94h+mc03AcOBPOspOz9GlH7fGZJ2O3PfanLxHQy4hPgcy3MqixT5chqPEAOrk4CkhYpJydoPK+OkAlaE65qxs7XGv41ip0aThdkRcAzx7NZi6H25nfFV0aGW/B1jFvG2wVu8UI06iVHlFpGVtqXXLuniBHpXlbB/SdFya96TrusboKd5thUiD99pdNbkyYA3H91OdA2GLFnl7aWa1RKJB7LaIHoS/jVzYeVr01VtKXw1lw+cXSNrEsMrJINbFWvA7pEf8LEsCNn8PIUu2LBrbkiQidCp5A/65aQkIfIA0UnXGnjeYvpQNY32IJOyt9inF08PCZVDmSV/P3X8RM0DdCb444EKUuOHT00WqWEK23X 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: On Mon 05-12-22 00:14:29, Zhongkun He wrote: [...] > +/* Obtain a reference on the specified mpol */ > static inline void mpol_get(struct mempolicy *pol) > { > if (pol) Shouldn't this be mpol_needs_cond_ref? > - atomic_inc(&pol->refcnt); > + percpu_ref_get(&pol->refcnt); > +} > + > +static inline bool mpol_tryget(struct mempolicy *pol) > +{ > + return pol && percpu_ref_tryget(&pol->refcnt); > } > > +/* > + * This function initiates destruction of mempolicy. This is not a useful comment. It would be much more helpful to say when this should be called. > + */ > +static inline void mpol_kill(struct mempolicy *pol) > +{ > + if (pol) > + percpu_ref_kill(&pol->refcnt); > +} > + > + > extern bool __mpol_equal(struct mempolicy *a, struct mempolicy *b); > static inline bool mpol_equal(struct mempolicy *a, struct mempolicy *b) > { > @@ -197,11 +210,15 @@ static inline void mpol_put(struct mempolicy *p) > { > } > > -static inline void mpol_cond_put(struct mempolicy *pol) > +static inline void mpol_get(struct mempolicy *pol) > { > } > > -static inline void mpol_get(struct mempolicy *pol) > +static inline bool mpol_tryget(struct mempolicy *pol) > +{ > +} This should return false, right? [...] > +/* Obtain a reference on the specified task mempolicy */ Again, this is pretty much clear from the name. It would be more useful to explain how the pointer can be used - e.g. needs to call mpol_put or mpol_kill depending on the calling context. > +static mempolicy *get_task_mpol(struct task_struct *p) > +{ > + struct mempolicy *pol; > + > + rcu_read_lock(); > + pol = rcu_dereference(p->mempolicy); > + > + if (!pol || mpol_tryget(pol)) Shouldn't be !mpol_tryget? > + pol = NULL; > + rcu_read_unlock(); > + > + return pol; > +} > + I do not see any rcu_assign_pointer for the newly created policy so this seems incomplete. Ditto no mpol_kill calls. I am unlikely to get into follow up patches now. Please split up the work so that it is reviewable more easily and then I can have a further look. Thanks! -- Michal Hocko SUSE Labs