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 E8872C433EF for ; Mon, 25 Apr 2022 09:43:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3CB316B0074; Mon, 25 Apr 2022 05:43:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 37A316B0075; Mon, 25 Apr 2022 05:43:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 21B7E6B007B; Mon, 25 Apr 2022 05:43:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 1369E6B0074 for ; Mon, 25 Apr 2022 05:43:02 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D942A63038 for ; Mon, 25 Apr 2022 09:43:01 +0000 (UTC) X-FDA: 79394912562.14.2FF281A Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf19.hostedemail.com (Postfix) with ESMTP id 01A001A0040 for ; Mon, 25 Apr 2022 09:42:57 +0000 (UTC) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 23P7Q8VO025664; Mon, 25 Apr 2022 09:42:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=pp1; bh=R4ypEaMOQY0KHvd2uV7dSmLY8n6xA4dFgKZ1nSotTI4=; b=f53wI8en5/EqT+SImdTTAiPovDdkHBd5HDeSvICUiMYQjIQeR+qWMdL+3Gvy8bfrMCmW hO93Z/YrxVE3OMEM7fOope6018wodh2dGce+pa1Ey1Z8bq2y9hbZnvtDcimruAcSlsDy leWcrHthoSZgqOXmKLy1hEMbxe+7zi8+fjl726IuXNBMnhknTzqhSADJpgR6RlFjLCHt mqP8ncGNx074c+kxouMQLdPyJ0DTSqwbPQ8NHsfDQaU7hJ3WJLhu/g76jjr4RYzMKeyd 1Ok8AXnbokaJeNQIeOhvrA7BU678yhNZtfQrwTxBRAwBSag0qrl+5e2BbKxKnuYn+h43 Ag== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3fnq8k2qvm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 25 Apr 2022 09:42:59 +0000 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 23P8jgHX009391; Mon, 25 Apr 2022 09:42:58 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3fnq8k2que-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 25 Apr 2022 09:42:58 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23P9RHS6026836; Mon, 25 Apr 2022 09:42:56 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma06ams.nl.ibm.com with ESMTP id 3fm8qj25sd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 25 Apr 2022 09:42:56 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23P9grBK41222538 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 25 Apr 2022 09:42:54 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DCFF34C046; Mon, 25 Apr 2022 09:42:53 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0A3084C040; Mon, 25 Apr 2022 09:42:51 +0000 (GMT) Received: from li-6e1fa1cc-351b-11b2-a85c-b897023bb5f3.ibm.com (unknown [9.43.47.198]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Mon, 25 Apr 2022 09:42:50 +0000 (GMT) Date: Mon, 25 Apr 2022 15:12:44 +0530 From: Jagdish Gediya To: "Aneesh Kumar K.V" Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, baolin.wang@linux.alibaba.com, dave.hansen@linux.intel.com, ying.huang@intel.com, shy828301@gmail.com, weixugc@google.com, gthelen@google.com, dan.j.williams@intel.com Subject: Re: [PATCH v3 3/7] drivers/base/node: Add support to write node_states[] via sysfs Message-ID: References: <20220422195516.10769-1-jvgediya@linux.ibm.com> <20220422195516.10769-4-jvgediya@linux.ibm.com> <87o80rgfpy.fsf@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87o80rgfpy.fsf@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: evQEf24PuF_IuaVM4_ueBWBr80G7uCpJ X-Proofpoint-GUID: aI2qlSCqcncFzpzDsqotX5LWGCEds5lc X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-25_06,2022-04-22_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 malwarescore=0 priorityscore=1501 suspectscore=0 spamscore=0 lowpriorityscore=0 bulkscore=0 phishscore=0 adultscore=0 mlxscore=0 mlxlogscore=999 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204250040 Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=f53wI8en; spf=pass (imf19.hostedemail.com: domain of jvgediya@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=jvgediya@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 01A001A0040 X-Stat-Signature: yb3itsf776aecy16d9zw5dgq3o9rffqg X-HE-Tag: 1650879777-866587 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 Sun, Apr 24, 2022 at 11:55:45AM +0530, Aneesh Kumar K.V wrote: > Jagdish Gediya writes: > > > Current /sys/devices/system/node/* interface doesn't support > > to write node_states[], however write support is needed in case > > users want to set them manually e.g. when user want to override > > default N_DEMOTION_TARGETS found by the kernel. > > > > Rename existing _NODE_ATTR to _NODE_ATTR_RO and introduce new > > _NODE_ATTR_RW which can be used for node_states[] which can > > be written from sysfs. > > > > It may be necessary to validate written values and take action > > based on them in a state specific way so a callback 'write' is > > introduced in 'struct node_attr'. > > > > A new function demotion_targets_write() is added to validate > > the input nodes for N_DEMOTION_TARGETS which should be subset > > of N_MEMORY and to build new demotion list based on new nodes. > > > > Signed-off-by: Jagdish Gediya > > --- > > drivers/base/node.c | 62 +++++++++++++++++++++++++++++++++++---------- > > 1 file changed, 49 insertions(+), 13 deletions(-) > > > > diff --git a/drivers/base/node.c b/drivers/base/node.c > > index 6eef22e6413e..e03eedbc421b 100644 > > --- a/drivers/base/node.c > > +++ b/drivers/base/node.c > > @@ -20,6 +20,7 @@ > > #include > > #include > > #include > > +#include > > > > static struct bus_type node_subsys = { > > .name = "node", > > @@ -1013,6 +1014,7 @@ void unregister_one_node(int nid) > > struct node_attr { > > struct device_attribute attr; > > enum node_states state; > > + int (*write)(nodemask_t nodes); > > }; > > > > static ssize_t show_node_state(struct device *dev, > > @@ -1024,23 +1026,57 @@ static ssize_t show_node_state(struct device *dev, > > nodemask_pr_args(&node_states[na->state])); > > } > > > > -#define _NODE_ATTR(name, state) \ > > - { __ATTR(name, 0444, show_node_state, NULL), state } > > +static ssize_t store_node_state(struct device *s, > > + struct device_attribute *attr, > > + const char *buf, size_t count) > > +{ > > + nodemask_t nodes; > > + struct node_attr *na = container_of(attr, struct node_attr, attr); > > + > > + if (nodelist_parse(buf, nodes)) > > + return -EINVAL; > > + > > + if (na->write) { > > + if (na->write(nodes)) > > + return -EINVAL; > > + } else { > > + node_states[na->state] = nodes; > > + } > > + > > + return count; > > +} > > + > > +static int demotion_targets_write(nodemask_t nodes) > > +{ > > + if (nodes_subset(nodes, node_states[N_MEMORY])) { > > + node_states[N_DEMOTION_TARGETS] = nodes; > > + set_migration_target_nodes(); > > + return 0; > > + } > > Does this require locking to avoid upating > node_states[N_DEMOTION_TARGETS] while a parallel > set_migratiotn_target_nodes() is running. I think locking is needed if set_migratiotn_target_nodes() is called form here because currently exclusion is provided by memory hotplug events being single-threaded, but as this path is not hot-plug event, separate lock is needed. > > + > > + return -EINVAL; > > +} > > + > > +#define _NODE_ATTR_RO(name, state) \ > > + { __ATTR(name, 0444, show_node_state, NULL), state, NULL } > > + > > +#define _NODE_ATTR_RW(name, state, write_fn) \ > > + { __ATTR(name, 0644, show_node_state, store_node_state), state, write_fn } > > > > static struct node_attr node_state_attr[] = { > > - [N_POSSIBLE] = _NODE_ATTR(possible, N_POSSIBLE), > > - [N_ONLINE] = _NODE_ATTR(online, N_ONLINE), > > - [N_NORMAL_MEMORY] = _NODE_ATTR(has_normal_memory, N_NORMAL_MEMORY), > > + [N_POSSIBLE] = _NODE_ATTR_RO(possible, N_POSSIBLE), > > + [N_ONLINE] = _NODE_ATTR_RO(online, N_ONLINE), > > + [N_NORMAL_MEMORY] = _NODE_ATTR_RO(has_normal_memory, N_NORMAL_MEMORY), > > #ifdef CONFIG_HIGHMEM > > - [N_HIGH_MEMORY] = _NODE_ATTR(has_high_memory, N_HIGH_MEMORY), > > + [N_HIGH_MEMORY] = _NODE_ATTR_RO(has_high_memory, N_HIGH_MEMORY), > > #endif > > - [N_MEMORY] = _NODE_ATTR(has_memory, N_MEMORY), > > - [N_CPU] = _NODE_ATTR(has_cpu, N_CPU), > > - [N_GENERIC_INITIATOR] = _NODE_ATTR(has_generic_initiator, > > - N_GENERIC_INITIATOR), > > - [N_DEMOTION_TARGETS] = _NODE_ATTR(demotion_targets, > > - N_DEMOTION_TARGETS), > > - > > + [N_MEMORY] = _NODE_ATTR_RO(has_memory, N_MEMORY), > > + [N_CPU] = _NODE_ATTR_RO(has_cpu, N_CPU), > > + [N_GENERIC_INITIATOR] = _NODE_ATTR_RO(has_generic_initiator, > > + N_GENERIC_INITIATOR), > > + [N_DEMOTION_TARGETS] = _NODE_ATTR_RW(demotion_targets, > > + N_DEMOTION_TARGETS, > > + demotion_targets_write), > > }; > > > > static struct attribute *node_state_attrs[] = { > > -- > > 2.35.1