From patchwork Fri Jan 20 05:57:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 13109193 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 64786C38159 for ; Fri, 20 Jan 2023 05:57:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D6CC86B007B; Fri, 20 Jan 2023 00:57:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D1C8A6B007D; Fri, 20 Jan 2023 00:57:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE3EC6B007E; Fri, 20 Jan 2023 00:57:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id ACD096B007B for ; Fri, 20 Jan 2023 00:57:45 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8B2F6C071C for ; Fri, 20 Jan 2023 05:57:45 +0000 (UTC) X-FDA: 80374120890.06.9C53C70 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf28.hostedemail.com (Postfix) with ESMTP id C1E8BC0009 for ; Fri, 20 Jan 2023 05:57:42 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JB5FOiBT; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.hostedemail.com: domain of gshan@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=gshan@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674194262; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BbP4W57AMZS9MBlxZ+FGeKuIJTpb3nSR8+y62zx7ev0=; b=ipkBqL8Ep/fH3lXT2nCchZXtOaroh+JhL02AR/7gDdRV0hO6isBK+bxboupF2kUdjxJ5zg vJLM1VwtsDl4qzv/cP1dqHiyZV8cC4Y7YRClUFByPTm+N4xOOmy86vza2NLwYN2b375mPI RiklWMTibjTBWYsgHolO/Z0gGFVSwJI= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JB5FOiBT; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.hostedemail.com: domain of gshan@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=gshan@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674194262; a=rsa-sha256; cv=none; b=bZQo02u28614PVysUxi3gcr9pI42lcDh7LLDyodVSCT72cXxNujNN4k7/lI9YfA1jGMFtl Nh1j34B9EH632AqYgdvtLUrH3m6ZCdanwikhwu8t2mxZwhbt5fb1/AurshVw/ItyRfjIih +SQZqa9Hn4P5cnW15Cka9rgBV4uUqEI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674194262; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BbP4W57AMZS9MBlxZ+FGeKuIJTpb3nSR8+y62zx7ev0=; b=JB5FOiBT+RORVsYuHYBbPZM+DWj5d2oQ2V1mEzmdrGbAe7TvrdKz0qLlwt2XFbnj6Vd3rn q4rBj3bSbgiiOO6EfK4YP8GQP1+9mG8KkNGPUpGKPOKsFgAvUpJY9uy89vA8tBWCTOoMSf B0FTN4Ow4sgsxO9Q5ZSJmp7pGlku/N8= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-68-hsPSwQu1MzqPAF6P0cWtIQ-1; Fri, 20 Jan 2023 00:57:38 -0500 X-MC-Unique: hsPSwQu1MzqPAF6P0cWtIQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2C6B53C02556; Fri, 20 Jan 2023 05:57:38 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-98.bne.redhat.com [10.64.54.98]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 61BF340C6EC4; Fri, 20 Jan 2023 05:57:35 +0000 (UTC) From: Gavin Shan To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, david@redhat.com, osalvador@suse.de, gregkh@linuxfoundation.org, rafael@kernel.org, shan.gavin@gmail.com Subject: [PATCH 1/2] drivers/base/memory: Fix comments for phys_index_show() Date: Fri, 20 Jan 2023 13:57:26 +0800 Message-Id: <20230120055727.355483-2-gshan@redhat.com> In-Reply-To: <20230120055727.355483-1-gshan@redhat.com> References: <20230120055727.355483-1-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspamd-Queue-Id: C1E8BC0009 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: n89hpexkpgfujcp4rbqcmex154gjwdwu X-HE-Tag: 1674194262-424641 X-HE-Meta: U2FsdGVkX18n+tkkKggXTOj2zNStQcTY4rlGSZLFUHVlgoP2aYS3HUOzso3mo8hLJ/k/smMqv1OYRG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d2vl4b+6xL5XOc6QVh3Ps6wtEfyjp8LMVbjQ0nFBlm+Nq0pDz0Da4mnMIjOlSazrwad7phiSFCVgDYEqE22YqIrGyYZ13vO9uiWarCSuPoiuZTlqZHLSL/62/1FthH4HD5JLMfGxb2Pf/baB/kzbqZ7p/s 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: According to 'admin-guide/mm/memory-hotplug.rst', the memory block ID, instead of the section index, is shown by '/sys/devices/system/memory/ memoryX/phys_index'. Fix the comments to match with 'admin-guide/mm/memory-hotplug.rst'. Besides, use the existing helper memory_block_id() to convert the section index to the memory block index. No functional change intended. Signed-off-by: Gavin Shan Reviewed-by: David Hildenbrand --- drivers/base/memory.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index fe98fb8d94e5..b456ac213610 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -115,18 +115,13 @@ unsigned long __weak memory_block_size_bytes(void) } EXPORT_SYMBOL_GPL(memory_block_size_bytes); -/* - * Show the first physical section index (number) of this memory block. - */ +/* Show the memory block ID, relative to the memory block size */ static ssize_t phys_index_show(struct device *dev, struct device_attribute *attr, char *buf) { struct memory_block *mem = to_memory_block(dev); - unsigned long phys_index; - - phys_index = mem->start_section_nr / sections_per_block; - return sysfs_emit(buf, "%08lx\n", phys_index); + return sysfs_emit(buf, "%08lx\n", memory_block_id(mem->start_section_nr)); } /* From patchwork Fri Jan 20 05:57:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 13109194 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 7E88DC46467 for ; Fri, 20 Jan 2023 05:57:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 185EF6B007E; Fri, 20 Jan 2023 00:57:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 135BA6B0080; Fri, 20 Jan 2023 00:57:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF2BE6B0081; Fri, 20 Jan 2023 00:57:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id DE71D6B007E for ; Fri, 20 Jan 2023 00:57:47 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id A8F04160DE0 for ; Fri, 20 Jan 2023 05:57:47 +0000 (UTC) X-FDA: 80374120974.26.07F94E6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id F13CE40009 for ; Fri, 20 Jan 2023 05:57:45 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Q4lgTuYD; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.hostedemail.com: domain of gshan@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=gshan@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674194266; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=KjmOoqTkye3UNXuCyk++rWgNtMqygxPkyWDL4dhhiqM=; b=JY1Pdphc5/ASJVvy+zUkCtnp777tTC0RnrPUMSH99g+rpa7Iw6mn4ywToJHc4M2w33iaA0 sJl+pcfJNVyLCxqMO9kqfuKIlZcvkeNqezFSGUxZBqaWZRCNi1efXmLdpYPNA7wPY5RrVU vn7nWRLb8GX+nQmCKXUuCf8LXfNrlSY= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Q4lgTuYD; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.hostedemail.com: domain of gshan@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=gshan@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674194266; a=rsa-sha256; cv=none; b=L7qPNAWIQg8Hwq0HbQDGHYMa39kRuHFApXBYEJZmrHGNPnah2kK3UoW8SGozG+crtohwrk TIXb0XzT8pJd6vty0o/VIrcpaiEU/DDhxMcUldJFnVJpDIssnjl1PQ/M7xFq79R3GogcCz dxCJdur3jzUrXcwXhhh/3eqU4mqpU8g= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674194265; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KjmOoqTkye3UNXuCyk++rWgNtMqygxPkyWDL4dhhiqM=; b=Q4lgTuYDpqxk5bvhaGV/rgoqpV8vwq0SPXd8vlDXh8pQQDnlRYalp1nMiaxn7hRmiHlHn0 Lkx9mf0qbGOcE2WgjSG+jfcDZEJGRTNLfb0hUUjwK9DL2fOij2ck9zw5zPEEpO1eeoTEE+ b2P1TOQl7QBZ6S4yvYdi2Dps4QxUJNc= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-98-kgi0r40PNt-4Eh0V51Y9Ag-1; Fri, 20 Jan 2023 00:57:41 -0500 X-MC-Unique: kgi0r40PNt-4Eh0V51Y9Ag-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 66E4F2A5954E; Fri, 20 Jan 2023 05:57:41 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-98.bne.redhat.com [10.64.54.98]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BE79640C6EC4; Fri, 20 Jan 2023 05:57:38 +0000 (UTC) From: Gavin Shan To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, david@redhat.com, osalvador@suse.de, gregkh@linuxfoundation.org, rafael@kernel.org, shan.gavin@gmail.com Subject: [PATCH 2/2] drivers/base/memory: Use array to show memory block state Date: Fri, 20 Jan 2023 13:57:27 +0800 Message-Id: <20230120055727.355483-3-gshan@redhat.com> In-Reply-To: <20230120055727.355483-1-gshan@redhat.com> References: <20230120055727.355483-1-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspamd-Queue-Id: F13CE40009 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: gx9xf36u1ugrwdmyiy9eg1nxypy1jt5d X-HE-Tag: 1674194265-568669 X-HE-Meta: U2FsdGVkX19EA+7Oord5xRy+OYpklJFJl2HP7GevhujVffMboB34NV37ClF8kM1MLnR1r+ExWPn9ZryOhOtPJ1UmlOAqWoUcqgusQnFKBgd7DKg8prhrgsiiZzsxpfjMg1J4SP6Wgqwpl0kgQMitX4Yt7kWOotmCsVCSwdCaOQrrzHHUNzwF/www99tgVJ45CPZEXrVjA0UYuHbj9N8GrkMBq2fK33jtECfVGP06xvCIVFmMB3BC6i9ziUlkxsZeV9ce05K9JAlrr9F9RPceLzSm3zFxQbOcffjVF3m2tLUNsfOR4iiYQMld8BwWyioRQTxU/ukqQ/oSlRqzObpACZkujEpMIfqfnfX7m1Fd3iJvvDu3RtrQy9gJUzi5Esk+nnYphZ6AhP7lEQNHI0KjkeTvtRX7sAI8nas46ulDdMawH5SHkKCRv3UYaVfROeLtNKxiqlBUaJsHwLpAF/Gwi+YWH6nhoWpVz+8OuLpwfTcgKEjZqKKiRlDiuEnk+iSI/a3URm3/diMDq5lFqNI+6wxN08gJezPqm2yLUqXcHji9AfdTjrb2n27aOXE56cdB51wRII/4Pe3JvWhU6v+s6YdnCKExXxnvRFvYD+GzB6M0KcfEbddaPXvkLZLG6/RhAXK/rzZH5fVCbkJnwWQuhScFwWcuRmbqqEhTvTx/VbADEAFGG+QN+vgGs3vsD3zsRXZ1W2DsRm2tKjgU+u470hlwkxIGM/f5M3pZZeAnJrpKmZVueRZ7IFUH4IAUU4Xub3APuneas4RFmXLN5RInUBbGlS2bLCmkmUwndAoSgxR78KPSIRpSQvUpj//i8qj+73i2Kf1EngrnA8E4gg3TfnfEp8amkovuP5mI2NCJnZvjGzUOnvBxCd2vjmH5DYq+3Wteab8hIBJ8YWg9x0LcAvTk4EwlcKJU/K8LfT3BEJ9jOQ+rJiaxcbLPO23jlBXCiCS0+zcrIkfNKKyY31+ kn48ILze loWyxmyh1I9W9pFBBCT/3ZBWLV7rFngoCvAYQS/fWG+mX4ILPJx9VDfzAratNJNFUQKCEYhaMVJWCg80bBebtjfUXAHEtOP1CT1CiWu3pgjgVSsg0GMn6hDlqtjcIU1w/RUjezvZRjG/tlQ6NjrbMj0yyIIQ/EziMGIF5PMcDxZjSvkk1pRkJUpJg2hVM9GA0OyrPDUBsqStW79LNRmgFaIH+MnKDctldZ9BsqJHNmFNgrXfU6IJeqxXfwwy5BXEj08M/tGo95TKt11Q= 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: Use an array to show memory block state from '/sys/devices/system/ memory/memoryX/state', to simplify the code. No functional change intended. Signed-off-by: Gavin Shan --- drivers/base/memory.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index b456ac213610..9474f25c452c 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -141,28 +141,15 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr, char *buf) { struct memory_block *mem = to_memory_block(dev); - const char *output; + static const char *const mem_state_str[] = { + NULL, "online", "going-offline", NULL, "offline", + }; - /* - * We can probably put these states in a nice little array - * so that they're not open-coded - */ - switch (mem->state) { - case MEM_ONLINE: - output = "online"; - break; - case MEM_OFFLINE: - output = "offline"; - break; - case MEM_GOING_OFFLINE: - output = "going-offline"; - break; - default: - WARN_ON(1); + if (WARN_ON(mem->state >= ARRAY_SIZE(mem_state_str) || + !mem_state_str[mem->state])) return sysfs_emit(buf, "ERROR-UNKNOWN-%ld\n", mem->state); - } - return sysfs_emit(buf, "%s\n", output); + return sysfs_emit(buf, "%s\n", mem_state_str[mem->state]); } int memory_notify(unsigned long val, void *v)