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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D82E5C433EF for ; Thu, 11 Nov 2021 23:39:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B7B6E61267 for ; Thu, 11 Nov 2021 23:39:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234425AbhKKXmh (ORCPT ); Thu, 11 Nov 2021 18:42:37 -0500 Received: from mga06.intel.com ([134.134.136.31]:40980 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231918AbhKKXmf (ORCPT ); Thu, 11 Nov 2021 18:42:35 -0500 X-IronPort-AV: E=McAfee;i="6200,9189,10165"; a="293863419" X-IronPort-AV: E=Sophos;i="5.87,227,1631602800"; d="scan'208";a="293863419" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2021 15:39:45 -0800 X-IronPort-AV: E=Sophos;i="5.87,227,1631602800"; d="scan'208";a="492746838" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.239.159.101]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2021 15:39:42 -0800 From: "Huang, Ying" To: Baolin Wang Cc: , , , , , , , , Subject: Re: [PATCH v2 2/2] mm: migrate: Allocate the node_demotion structure dynamically References: <87pmr7m5wo.fsf@yhuang6-desk2.ccr.corp.intel.com> Date: Fri, 12 Nov 2021 07:39:39 +0800 In-Reply-To: (Baolin Wang's message of "Thu, 11 Nov 2021 19:20:11 +0800") Message-ID: <8735o2mfd0.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Baolin Wang writes: > On 2021/11/11 16:51, Huang, Ying wrote: >> Baolin Wang writes: >> >>> For the worst case (MAX_NUMNODES=1024), the node_demotion structure can >>> consume 32k bytes, which appears too large, so we can change to allocate >>> node_demotion dynamically at initialization time. Meanwhile allocating >>> the target demotion nodes array dynamically to select a suitable size >>> according to the MAX_NUMNODES. >>> >>> Signed-off-by: Baolin Wang >>> --- >>> mm/migrate.c | 38 +++++++++++++++++++++++++++++--------- >>> 1 file changed, 29 insertions(+), 9 deletions(-) >>> >>> diff --git a/mm/migrate.c b/mm/migrate.c >>> index 126e9e6..0145b38 100644 >>> --- a/mm/migrate.c >>> +++ b/mm/migrate.c >>> @@ -1152,10 +1152,11 @@ static int __unmap_and_move(struct page *page, struct page *newpage, >>> #define DEFAULT_DEMOTION_TARGET_NODES 15 >>> struct demotion_nodes { >>> unsigned short nr; >>> - short nodes[DEFAULT_DEMOTION_TARGET_NODES]; >>> + short nodes[]; >>> }; >>> -static struct demotion_nodes node_demotion[MAX_NUMNODES] >>> __read_mostly; >>> +static struct demotion_nodes *node_demotion[MAX_NUMNODES] __read_mostly; >>> +static unsigned short target_nodes_max; >> I think we can use something as below, >> #if MAX_NUMNODES < DEFAULT_DEMOTION_TARGET_NODES >> #define DEMOTION_TARGET_NODES (MAX_NUMNODES - 1) >> #else >> #define DEMOTION_TARGET_NODES DEFAULT_DEMOTION_TARGET_NODES >> #endif > > Yes, looks better. > >> static struct demotion_nodes *node_demotion; >> Then we can allocate nr_node_ids * sizeof(struct demotion_nodes) for >> node_demotion. > > Yeah, this is simple. The reason I want to declare the structure like > "struct demotion_nodes *node_demotion[MAX_NUMNODES]" is that, we can > validate the non-possible nodes which are invalid to demote memory, > and in case the node_demotion[nid] is failed to be allocated which can > be validated, though this is unlikely. In case allocation failure, we can still check "node_demotion == NULL". Best Regards, Huang, Ying > However, I agree with you to > keep things simple now and can be merged into patch 1. Will do in next > version. Thanks.