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 4C664C433FE for ; Wed, 12 Oct 2022 04:16:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E6E46B0071; Wed, 12 Oct 2022 00:16:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 96E376B0073; Wed, 12 Oct 2022 00:16:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F47D8E0001; Wed, 12 Oct 2022 00:16:40 -0400 (EDT) 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 63E386B0071 for ; Wed, 12 Oct 2022 00:16:40 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 33377A9065 for ; Wed, 12 Oct 2022 04:16:40 +0000 (UTC) X-FDA: 80010986160.18.B086E1E Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by imf13.hostedemail.com (Postfix) with ESMTP id ACD9220032 for ; Wed, 12 Oct 2022 04:16:38 +0000 (UTC) Received: by mail-pj1-f45.google.com with SMTP id g8-20020a17090a128800b0020c79f987ceso868663pja.5 for ; Tue, 11 Oct 2022 21:16:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=OJHfxSkAdEzE02kXCOugwTptSZXfoXHK5Lb1A5ICHqE=; b=Rrlze0pGp+8MKXLRlhhIebryFh3ieyIMcB2o/aN8bjOFElKnqhRCzRyHGrM5Ozy7As XhXjKxEggNG5Lq8X0WD11nEVuFKlpRcousRl0vhe9BDA1cQ3rvLIzKYMScw5Z4eWQDiV kkU2o8DvnldcSo7CAhpg17gqnMnuxSzNkSBjav+oezmEK2JTYHvS8CgGOe3YKMHbfvbN ZYWbRgD1IQojFQlnXpywJWIdifq69Fkn1ebFLY2WDVr30lmWm6GK06Wy7ukasO1ixAex rzBeX3Nx/p2r6SDE10qwD7taeC/QpSgCiEajfmS1rQVxcAnLQgman2U5iQSqlAoY8DvT Fndw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=OJHfxSkAdEzE02kXCOugwTptSZXfoXHK5Lb1A5ICHqE=; b=3/s1c7JFXZeGprtGRTPypfDDnn2uFpB35KJCIgmvh1OaZJSDf7rF5lP/V/a9QcBidY 46ae7OBhWGr9qd2/eluLu5i0lDYBHgViX/Yw5alrbTARJCmp24+ySmoVPBUKGhdUXdBR lyAZ8H6VaauDM0468guECt9raFkNKymAr3B4KPvfTNfxDNsQOcrdYwOQEXZQGYn87VKL U/3Uh22OylwqJ71YkowDS7DQO3orbW5UsygCwXrW3csZxjDP3qcIVz0HgPT6Sb3UhvPc QkDtNQulhXGlQt6SKKK2QtWWq1e/+YyUn2F0wcN/s6EcuWFC1hYZp9u2hnks2OVkWKe7 DNLA== X-Gm-Message-State: ACrzQf3VoAGztRNaf48i2yJIMwaoW5OPMhlw0ROeiKgJkD/tj38IazcJ vjyats2j71gWRm1l152M0+U= X-Google-Smtp-Source: AMsMyM7rH8I0S5TWLH2Y55oSGySHBD+eCj3dU5URWQ7rKYl8bkEET6BJVaqQnparD2Ld5bLDcnLWuQ== X-Received: by 2002:a17:90a:bd91:b0:20d:2add:96a4 with SMTP id z17-20020a17090abd9100b0020d2add96a4mr2849825pjr.195.1665548197414; Tue, 11 Oct 2022 21:16:37 -0700 (PDT) Received: from debian.me (subs02-180-214-232-2.three.co.id. [180.214.232.2]) by smtp.gmail.com with ESMTPSA id x12-20020aa78f0c000000b0052c849d0886sm9816734pfr.86.2022.10.11.21.16.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Oct 2022 21:16:36 -0700 (PDT) Received: by debian.me (Postfix, from userid 1000) id D02D41005BB; Wed, 12 Oct 2022 11:16:32 +0700 (WIB) Date: Wed, 12 Oct 2022 11:16:32 +0700 From: Bagas Sanjaya To: Zhongkun He Cc: corbet@lwn.net, mhocko@suse.com, 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: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="kr4kyCS+bdnKay0q" Content-Disposition: inline In-Reply-To: <20221010094842.4123037-1-hezhongkun.hzk@bytedance.com> ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Rrlze0pG; spf=pass (imf13.hostedemail.com: domain of bagasdotme@gmail.com designates 209.85.216.45 as permitted sender) smtp.mailfrom=bagasdotme@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665548198; a=rsa-sha256; cv=none; b=Fxm5p3JSruhRC17qrRfEelhHhmq1Y7EuIHxvj33VVVK3HulmKHVcPi5nVG+F/iFZ9WKPX1 aYfI5iDXoYAxU2txW0idtOAdsDisnMtZQ7eN2X7UaBwpdZk+dZE4NOquyfJAadejyeVpZh 2X/VChcEixe2XMeUuoX1THG+Wk7rnPQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665548198; 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=OJHfxSkAdEzE02kXCOugwTptSZXfoXHK5Lb1A5ICHqE=; b=SQE/szix8eMpthhL1nAmwuAuSJbxpaqUaEnYR6nULoGKq7h1zXzKZDUo2foXdhf1VhaUbA MthRcB+RXCb7r0819iTZOl2+A1l4IR9lVZNcaXKk4dPGs8LGG+12uRfT5vs+PK/AA3ZZ6A 58Ww57PrvOv/JnKpPhbVreszMWfhw54= X-Rspam-User: X-Stat-Signature: tben9agh6facna447h9of8knzricasc7 X-Rspamd-Queue-Id: ACD9220032 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Rrlze0pG; spf=pass (imf13.hostedemail.com: domain of bagasdotme@gmail.com designates 209.85.216.45 as permitted sender) smtp.mailfrom=bagasdotme@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam07 X-HE-Tag: 1665548198-110437 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: --kr4kyCS+bdnKay0q Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Oct 10, 2022 at 05:48:42PM +0800, 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. >=20 Better say "There are usecases when system management utilities want to apply memory policy to 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. >=20 Better say "These utilities doesn't set memory usage policy, but rather the job of reporting memory usage and setting the policy is offloaded to an userspace daemon." > 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. >=20 Better say "To solve the issue above, introduce new syscall pidfd_set_mempolicy(2). The syscall sets NUMA memory policy for 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. >=20 Better say "In current process context there is no locking because only processes access their own memory policy. For this reason, task_work is used in pidfd_set_mempolicy() to set or update the mempolicy of process specified in pid. Thuse, it avoids into race conditions." > The API is as follows, >=20 > long pidfd_set_mempolicy(int pidfd, int mode, > const unsigned long __user *nmask, > unsigned long maxnode, > unsigned int flags); >=20 > 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. >=20 Why duplicating from the Documentation/ below? > Suggested-by: Michal Hocko > Signed-off-by: Zhongkun He > --- > .../admin-guide/mm/numa_memory_policy.rst | 21 ++++- > arch/alpha/kernel/syscalls/syscall.tbl | 1 + > arch/arm/tools/syscall.tbl | 1 + > arch/arm64/include/asm/unistd.h | 2 +- > arch/arm64/include/asm/unistd32.h | 3 +- > arch/ia64/kernel/syscalls/syscall.tbl | 1 + > arch/m68k/kernel/syscalls/syscall.tbl | 1 + > arch/microblaze/kernel/syscalls/syscall.tbl | 1 + > arch/mips/kernel/syscalls/syscall_n32.tbl | 1 + > arch/mips/kernel/syscalls/syscall_n64.tbl | 1 + > arch/mips/kernel/syscalls/syscall_o32.tbl | 1 + > arch/parisc/kernel/syscalls/syscall.tbl | 1 + > arch/powerpc/kernel/syscalls/syscall.tbl | 1 + > arch/s390/kernel/syscalls/syscall.tbl | 1 + > arch/sh/kernel/syscalls/syscall.tbl | 1 + > arch/sparc/kernel/syscalls/syscall.tbl | 1 + > arch/x86/entry/syscalls/syscall_32.tbl | 1 + > arch/x86/entry/syscalls/syscall_64.tbl | 1 + > arch/xtensa/kernel/syscalls/syscall.tbl | 1 + > include/linux/mempolicy.h | 11 +++ > include/linux/syscalls.h | 4 + > include/uapi/asm-generic/unistd.h | 5 +- > kernel/sys_ni.c | 1 + > mm/mempolicy.c | 89 +++++++++++++++++++ > 24 files changed, 146 insertions(+), 6 deletions(-) >=20 > diff --git a/Documentation/admin-guide/mm/numa_memory_policy.rst b/Docume= ntation/admin-guide/mm/numa_memory_policy.rst > index 5a6afecbb0d0..b864dd88b2d2 100644 > --- a/Documentation/admin-guide/mm/numa_memory_policy.rst > +++ b/Documentation/admin-guide/mm/numa_memory_policy.rst > @@ -408,9 +408,10 @@ follows: > Memory Policy APIs > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > =20 > -Linux supports 4 system calls for controlling memory policy. These APIS > -always affect only the calling task, the calling task's address space, or > -some shared object mapped into the calling task's address space. > +Linux supports 5 system calls for controlling memory policy. The first = four > +APIS affect only the calling task, the calling task's address space, or = some > +shared object mapped into the calling task's address space. The last one= can > +set the mempolicy of task specified in pidfd. > =20 > .. note:: > the headers that define these APIs and the parameter data types for > @@ -473,6 +474,20 @@ closest to which page allocation will come from. Spe= cifying the home node overri > the default allocation policy to allocate memory close to the local node= for an > executing CPU. > =20 > +Set [pidfd Task] Memory Policy:: > + > + long sys_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 argumen= t is > +a PID file descriptor (see pidfd_open(2) man page) that specifies the pr= ocess > +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. > + > + > =20 > Memory Policy Command Line Interface > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D The wording can be improved: ---- >8 ---- diff --git a/Documentation/admin-guide/mm/numa_memory_policy.rst b/Document= ation/admin-guide/mm/numa_memory_policy.rst index b864dd88b2d236..6df35bf4f960bd 100644 --- a/Documentation/admin-guide/mm/numa_memory_policy.rst +++ b/Documentation/admin-guide/mm/numa_memory_policy.rst @@ -410,8 +410,8 @@ Memory Policy APIs =20 Linux supports 5 system calls for controlling memory policy. The first fo= ur APIS affect only the calling task, the calling task's address space, or so= me -shared object mapped into the calling task's address space. The last one c= an -set the mempolicy of task specified in pidfd. +shared object mapped into the calling task's address space. The last one +sets the mempolicy of task specified in the pidfd. =20 .. note:: the headers that define these APIs and the parameter data types for @@ -481,11 +481,11 @@ Set [pidfd Task] Memory Policy:: unsigned long maxnode, unsigned int flags); =20 -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 proc= ess -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. +Sets the task/process memory policy for the [pidfd] task. The pidfd argume= nt +is a PID file descriptor (see pidfd_open(2) man page for details) that +specifies the process for which the mempolicy is applied to. The flags +argument is reserved for future use; currently, it must be specified as 0. +For the description of all other arguments, see set_mempolicy(2) man page. =20 =20 =20 Thanks. --=20 An old man doll... just what I always wanted! - Clara --kr4kyCS+bdnKay0q Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQSSYQ6Cy7oyFNCHrUH2uYlJVVFOowUCY0Y/nAAKCRD2uYlJVVFO oy70AP4wEUgCFmmVfoPF+Ih5oXK6spLPS9lHk0Dk31CIgVAE7wEAgMChcWW248/J DbLqTdkHQzGWPrcJVo3ID2vm6Zz2MgQ= =8XfN -----END PGP SIGNATURE----- --kr4kyCS+bdnKay0q--