Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp2483405rwi; Tue, 11 Oct 2022 09:16:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6/ihS0zKcKkSvrYLIYm3LbiSFYCqj9JfJh0v7/6PZvOpZ0NcTUF0CFg2uqm6laE54mCLdy X-Received: by 2002:a05:6402:2547:b0:459:1752:2a97 with SMTP id l7-20020a056402254700b0045917522a97mr23620439edb.323.1665505007419; Tue, 11 Oct 2022 09:16:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665505007; cv=none; d=google.com; s=arc-20160816; b=N2gUqDbiRnTnGmOzcnTpxEiq4AJSplnIk430Kj5fZr5L+Qfp9A+sQu4WrB9Aubm8tQ kthp/dmZaMxRTHaCylwpJWdbg4mabxRhUHpFbQIUQ1bNw3lUeHx/Mtecq221pZtihP2U 5WkIPrb39Zh85/WQrMqjsNf7wm1i5ftp922/ys5Wlgj732MSZVmQhQdtLX6mn18cnlcK XvzHsU2zbu3tqnt4szr+9abZlJ1q/NfZ/092tyWtAzOTJRJVxwl3uCXaYNNywQDEG7tc DnljR2Th/LQSxyPzHLd8IhdhmYXvcYQ61au+H8k7V+6SXD7T/h9jJhD8i3/0ddXSikHd UH/A== 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=uq2eyzBPhkHR87loB7Swe6vfT9JewwGCA0YfCXRfsuI=; b=zgPy5h2p7iXRwdmo+drL9t4vzrwoVU2vhzCIKd3+ojhltACzSC5xYqqh+jiLl0YYup LqXFQhFVpcyt5kA5aDPqe3GieuvomDt2H5nlo/7nx3VjOwbBkw4uI7QF45CBTLc0IQqJ nOM8705irknPb3Y+MMdAYKt7MwSOALcIOdK4MBAZS4XTXJICZazCXFw5iNBEvGk7xsg2 QJ3mI7psA1h5TsWMHsyJqj1Ozvva6A8PdBh7C8YzGz1oTk6wKUAdnT8QOBQE8HpeknlE mK0GG5BCmgsowaExxwFrV+xkTmI2bt2B6E22hOuDXh1jZ9se4bM1gz7jV7FlkCTYbNda s7Gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=jMVi+AsL; 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 z17-20020a05640235d100b0045957575facsi14916510edc.19.2022.10.11.09.16.09; Tue, 11 Oct 2022 09:16:47 -0700 (PDT) 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=jMVi+AsL; 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 S230302AbiJKPnd (ORCPT + 99 others); Tue, 11 Oct 2022 11:43:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229780AbiJKPnK (ORCPT ); Tue, 11 Oct 2022 11:43:10 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E9EFC4DBF; Tue, 11 Oct 2022 08:32:45 -0700 (PDT) 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-out1.suse.de (Postfix) with ESMTPS id 5636B33D70; Tue, 11 Oct 2022 14:57:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1665500269; 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=uq2eyzBPhkHR87loB7Swe6vfT9JewwGCA0YfCXRfsuI=; b=jMVi+AsLr/wUxc5+USNsrnM9R6R2/FnU9ZHuL0emC3HbOW/FolepsIBMqNV7lHo+DPP0rx 0ZphIu82iivF9WLhRY+M4s78H1w/vbYz+QXIu3/LiN13KzNw9B7rWlOmQkFE/mkPfMKEbN bT9o4QyIPXLovgr3RSu/+prVPmLWu6k= 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 2F56A139ED; Tue, 11 Oct 2022 14:57:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id hBE9Cm2ERWNOSAAAMHmgww (envelope-from ); Tue, 11 Oct 2022 14:57:49 +0000 Date: Tue, 11 Oct 2022 16:57:48 +0200 From: Michal Hocko To: Zhongkun He Cc: corbet@lwn.net, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, wuyun.abel@bytedance.com Subject: Re: [RFC] mm: add new syscall pidfd_set_mempolicy() Message-ID: References: <20221010094842.4123037-1-hezhongkun.hzk@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221010094842.4123037-1-hezhongkun.hzk@bytedance.com> X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,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 10-10-22 17:48:42, Zhongkun He wrote: > There is usecase that System Management Software(SMS) want to give a > memory policy to other processes to make better use of memory. > > The information about how to use memory is not known to the app. > Instead, it is known to the userspace daemon(SMS), and that daemon > will decide the memory usage policy based on different factors. Please add some explanation why the cpuset interface is not usable for that usecase. > To solve the issue, this patch introduces a new syscall > pidfd_set_mempolicy(2). it sets the NUMA memory policy of the thread > specified in pidfd. > > In current process context there is no locking because only the process > accesses its own memory policy, so task_work is used in > pidfd_set_mempolicy() to update the mempolicy of the process specified > in pidfd, avoid using locks and race conditions. Why cannot you alter kernel_set_mempolicy (and do_set_mempolicy) to accept a task rather than operate on current? I have to really say that I dislike the task_work approach because it detaches the syscall from the actual operation and the caller simply doesn't know when the operation has been completed. > > The API is as follows, > > long pidfd_set_mempolicy(int pidfd, int mode, > const unsigned long __user *nmask, > unsigned long maxnode, > unsigned int flags); > > Set's the [pidfd] task's "task/process memory policy". The pidfd argument > is a PID file descriptor (see pidfd_open(2) man page) that specifies the > process to which the mempolicy is to be applied. The flags argument is > reserved for future use; currently, this argument must be specified as 0. > Please see the set_mempolicy(2) man page for more details about > other's arguments. Please also describe the security model. -- Michal Hocko SUSE Labs