Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1225209rwb; Fri, 13 Jan 2023 09:23:29 -0800 (PST) X-Google-Smtp-Source: AMrXdXsmhwsbL0psfTxQJ9TfU1Suo5A2Te7r+udHo8WEfq+vkfqd/75WJkdGLY4yolveyWpXJj/V X-Received: by 2002:a17:907:cbc9:b0:7ad:b6d8:c9d0 with SMTP id vk9-20020a170907cbc900b007adb6d8c9d0mr76330869ejc.53.1673630609478; Fri, 13 Jan 2023 09:23:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673630609; cv=none; d=google.com; s=arc-20160816; b=iOi7ftFYrku9sKvAT9myYLXf9t3Z0NYQ91WOslhPyDtGabJVZzWQ52/a7E02/xE7x4 DeV0fuZj/QrFk/ApSQY92ez7gI2+cSgaDjDRGXBNkWs7avhGxyyDiDllhka5OuZrZJdy DXxtJpiajDeAumhyNfd+oUVewyo6/Abd94xHAKkieytftRFNploogzot98i7YrnAvcme AgDfC6ldSkCl/9EjSyDwuo7sJFYYoU2n95HTfW0XfZOeUCAXhXA+umbRqMuqjCsvTZFT NmX+xZHNhwvielsCBsnJ5rby1nD2VVG1WFEBlQICpOwXhZpODdXE7P9qQxXJY0wadh7d LpEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ZrIktPWt6uDyBFSnP2WU+2Nh/aWfw7kkDySc2ve2K0M=; b=whQRfEbfTKIiHBT8fQBNaxFJaFruaziLSpNzMDO1NuVMSzD16RBY6XcrNR40nscFXC xCYxsdwNqOSJHMD5yIXmzXMnscu5ok5vpH8a1Efe7LFFPOMbIlqI2GfnreygGBwPXLJF /mH8DR7/D3NYbhO9EhrCCUHqFrlI6OC3eD4ykpOd97FTKZU7GYfZlB+YcjJLpDcamTaQ tO6ZL48PzBeGc7wEKEOR6RSUkqiovNksqiOT3CisNTzJFSyKnWoo7DYUJ5ftrAIloO/o WKkqxDiT7ClLe2RGGS7D6tx1wzJEeIu3L/nz72mcjJY+TGUfB4E2KWRzHojeL4ZqbEm6 zeFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=FRpCw8xx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ho6-20020a1709070e8600b0085feab41d0asi9974422ejc.270.2023.01.13.09.23.16; Fri, 13 Jan 2023 09:23:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=FRpCw8xx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229567AbjAMRES (ORCPT + 53 others); Fri, 13 Jan 2023 12:04:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229537AbjAMREN (ORCPT ); Fri, 13 Jan 2023 12:04:13 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB0F75FF6; Fri, 13 Jan 2023 09:04:11 -0800 (PST) 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-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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