From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2987642B71; Mon, 22 May 2023 15:28:28 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C533A40EE7; Mon, 22 May 2023 15:28:27 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id 4630F40EE5 for ; Mon, 22 May 2023 15:28:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684762105; x=1716298105; h=message-id:date:subject:to:cc:references:from: in-reply-to:content-transfer-encoding:mime-version; bh=yeHhzFxQjFCmgBxOvVUGks28nY5fTzLBrlmzgZsaeXk=; b=Q9u2ZofzAU+quUmQsDYGz0gIl/13zQsJJQR4BTH2tf1vbHTtowJGvOup hfxTS5EMnbZi2/7nT5Pf6ety2HgYEeZPMYeLM13BngqFQ01AAUjzE9WDB +0spttm6A285bz5xJY23Sdx9G2yilSn4mqgbcCFeRXqr8UAN33V8xY117 WcPxzVfGisnuJLAUkhLrJpZ8esOYODNkxKheFur4Alf3rd/a2hunU/5Pi impN/kV4SW15uPHJSqJPJ3fbOntwfbnt6sMjs3qkVcMxmhwH89HUw6jXW VlnSDYnAeFJ0JWp777e6bQS72ZM1fmNbirMN/17GqA8LkhgU2WkRwv2yB w==; X-IronPort-AV: E=McAfee;i="6600,9927,10718"; a="418627558" X-IronPort-AV: E=Sophos;i="6.00,184,1681196400"; d="scan'208";a="418627558" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 May 2023 06:28:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10718"; a="793285475" X-IronPort-AV: E=Sophos;i="6.00,184,1681196400"; d="scan'208";a="793285475" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by FMSMGA003.fm.intel.com with ESMTP; 22 May 2023 06:28:23 -0700 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Mon, 22 May 2023 06:28:23 -0700 Received: from fmsmsx601.amr.corp.intel.com (10.18.126.81) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Mon, 22 May 2023 06:28:23 -0700 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23 via Frontend Transport; Mon, 22 May 2023 06:28:23 -0700 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (104.47.55.171) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.23; Mon, 22 May 2023 06:28:22 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nfeJLrMCpVT7ds0bjMhUvZSc3ptn6s2Aaf8lN0aHECx0ZR2KmlpkW8QYtRd53bjjqHsaordiMYmHSbNIeXbkPWOu9z6fPOs49OToGolbYjyRL9s/9bDUULPkNgHnoYRM/TYeDEG26vqHXSncV6M4xHWjK9RMkqbQEUtaMththj9nq0YBRo0A0pEHhwwtOHtWDf7KJanBVMTVuKNOYvd1pgRckgDDrWVam5gTndtE7ycppVz+mnV2STIsZfWYUs8nVZd4ekbIfIJEiguhc1G51J/3ar2v53PxEEea602YqMBHlFp6Y0tU7MZ53wDcIXRHwnNRwXmvVPCc716ntiWKHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+FhIulKhNQFCjBuj5e1eheNB/VWPJf60GKpdNJpavOw=; b=e/b4N3MCSkF/nJ546LVYcJwKhlFs7iAmmKCjHeH165HAJqBoJMTRBQYX/2iKeJ7iKEdQsElzOis8xoibkd5oli232yUdqXJsYlJQXGe9Ew7eOI3GSkVGomYPNFeGu5+YOZk7zZWPP94Wm8alk+e7rBoeHHh5h1CBThdE/cVuA4pjX011GyMGGICaF9lrd707M6uoAJRyIqPsrcYu1kCQ50k0H/EUf535LaUGuZcUlkUpPnzH/0v89tb4/9HvZoKfvsDqA+mJgGExuXuEi8HNHUAQNZT48L7vO1AUvS4G6obTOtVOSXQbESvzz/4hpSZNo1f04Wbbw1bhhYQ1DKcZtA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DM4PR11MB6502.namprd11.prod.outlook.com (2603:10b6:8:89::7) by CY5PR11MB6318.namprd11.prod.outlook.com (2603:10b6:930:3e::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.28; Mon, 22 May 2023 13:28:20 +0000 Received: from DM4PR11MB6502.namprd11.prod.outlook.com ([fe80::49c0:aa4c:e5b4:e718]) by DM4PR11MB6502.namprd11.prod.outlook.com ([fe80::49c0:aa4c:e5b4:e718%5]) with mapi id 15.20.6411.028; Mon, 22 May 2023 13:28:20 +0000 Message-ID: Date: Mon, 22 May 2023 14:28:15 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0 Thunderbird/102.11.0 Subject: Re: [PATCH v2] eal: fix eal init may failed when too much continuous memsegs under legacy mode Content-Language: en-US To: Fengnan Chang , CC: Lin Li References: <20230522124107.99877-1-changfengnan@bytedance.com> From: "Burakov, Anatoly" In-Reply-To: <20230522124107.99877-1-changfengnan@bytedance.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: DU2PR04CA0159.eurprd04.prod.outlook.com (2603:10a6:10:2b0::14) To DM4PR11MB6502.namprd11.prod.outlook.com (2603:10b6:8:89::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB6502:EE_|CY5PR11MB6318:EE_ X-MS-Office365-Filtering-Correlation-Id: c3c8f4ab-2504-469d-35eb-08db5ac868bb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: twlMER0uPyMoSsb5TS/obZlJB387jkh6SAYYeEFHhybAHLaeikPAhvNjoOqB3elwL8Le7Jvnqs7RkY1fr/7EqWuCUYANCNIevGchEMh3HjiZ+HSl1ihDR5Pdk+aBnWm+w1hYHpDULELHqII/bRXzEAqxBotPBamw/48hYbfbPa9d5Jka7xuT3V8ZMiLCND+1pfVah+u4fuLks+3tsHefcTPVpvpkZ50+dNgsBTJBDogWEeapmN7Cd8aDStC8PsfrritdlzNKPzBHgHuDJu8ZS3jiYk/qpyigPBEQmkp9VWUIDTBglclN+45HLrYS56VztBRBlSHjCkPnk3YUBOwQEF+hqWQqMn2/m8O2CPdqlieIGOkbX2tebMCwEAO0MYqrKmzJBeI5jrkuda+oIabOOaz6eliMwPywqvZ7XHnCrbNY3ux9ktekA+yh73GOexf4nys6bfTnT2bNXmGFvib5VjmM2VllucLcthLR1FGEp4CY6avAPIkTUvN7Z2IJjATuA099OOyyjH6Zb7p/GaeU3WQmj23NLR0nHr5BmGh9AiXccHapwNPiVvLKsqhn86M1nxOMBrzaCtXYvzK7ZSDiJE2LCq1o9KIr7SH9CQV0vvqZpCUb0/Wp0jtWTj0s9UMB9M502cttolQuJYL4xMX3ew== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR11MB6502.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(39850400004)(136003)(376002)(396003)(366004)(346002)(451199021)(31686004)(2906002)(5660300002)(8676002)(8936002)(41300700001)(316002)(66476007)(66556008)(66946007)(478600001)(4326008)(36756003)(6666004)(6486002)(53546011)(6506007)(6512007)(38100700002)(31696002)(86362001)(2616005)(26005)(186003)(83380400001)(82960400001)(45980500001)(43740500002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?bE9ySVFlckRjYisyZ0JSbW4ySjhSRmZmY3NlRWNtS3ZicmdyaU5FSGJVYlZH?= =?utf-8?B?dExyM2k4bXF3ZE5FS1A1MnRuM3F1emU0Ym1tWEd3aCtnSGkrQTRMc3RjSWFR?= =?utf-8?B?NGdtZmVaenBEYVdLZmkvZWhqQnE3UmsycFB2RkIxNDRaZlZwWlQ4Z2lQRzNm?= =?utf-8?B?VUpWWUJrbWlYK0RRTkRIc2N6UDRCZHJKd3AzQzJ1ODFocDNjcFhiUExrdE9S?= =?utf-8?B?NnRWVnJ0Zm9pdEhuTlNLSEFKOFVYSEVzeDFXY2VpeHJyTzhBWk4zbnZQcklS?= =?utf-8?B?Y1hpYWpBbEE0bVplcmxqaEJRY2RFdkowSDhWSzFMdjNKWlZEU3Nac1VUNDk5?= =?utf-8?B?UVdhUlB4SmJRcFk0R1dnanBISk8rd2IydUo2aUt6Y0FnSXh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-CrossTenant-Network-Message-Id: c3c8f4ab-2504-469d-35eb-08db5ac868bb X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB6502.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 May 2023 13:28:20.3415 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ZVoIH9qVE+AFibDVU1dH0EYDPL5OYeKCb8y4ZQE9i6mhXsTjWN5h2TTHNCWyd05NApdlmTCMC0pD5HjRfB4ZMVhHEWk/kPcJleXO5NhJPUo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR11MB6318 X-OriginatorOrg: intel.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On 5/22/2023 1:41 PM, Fengnan Chang wrote: > Under legacy mode, if the number of continuous memsegs greater > than RTE_MAX_MEMSEG_PER_LIST, eal init will failed even though > another memseg list is empty, because only one memseg list used > to check in remap_needed_hugepages. > Fix this by add a argment indicate how many pages mapped in > remap_segment, remap_segment try to mapped most pages it can, if > exceed it's capbility, remap_needed_hugepages will continue to > map other left pages. > > For example: > hugepage configure: > cat /sys/devices/system/node/node*/hugepages/hugepages-2048kB/nr_hugepages > 10241 > 10239 > > startup log: > EAL: Detected memory type: socket_id:0 hugepage_sz:2097152 > EAL: Detected memory type: socket_id:1 hugepage_sz:2097152 > EAL: Creating 4 segment lists: n_segs:8192 socket_id:0 hugepage_sz:2097152 > EAL: Creating 4 segment lists: n_segs:8192 socket_id:1 hugepage_sz:2097152 > EAL: Requesting 13370 pages of size 2MB from socket 0 > EAL: Requesting 7110 pages of size 2MB from socket 1 > EAL: Attempting to map 14220M on socket 1 > EAL: Allocated 14220M on socket 1 > EAL: Attempting to map 26740M on socket 0 > EAL: Could not find space for memseg. Please increase 32768 and/or 65536 in > configuration. > EAL: Couldn't remap hugepage files into memseg lists > EAL: FATAL: Cannot init memory > EAL: Cannot init memory > > Signed-off-by: Fengnan Chang > Signed-off-by: Lin Li > --- > lib/eal/linux/eal_memory.c | 33 +++++++++++++++++++++------------ > 1 file changed, 21 insertions(+), 12 deletions(-) > > diff --git a/lib/eal/linux/eal_memory.c b/lib/eal/linux/eal_memory.c > index 60fc8cc6ca..b2e6453fbe 100644 > --- a/lib/eal/linux/eal_memory.c > +++ b/lib/eal/linux/eal_memory.c > @@ -657,12 +657,12 @@ unmap_unneeded_hugepages(struct hugepage_file *hugepg_tbl, > } > > static int > -remap_segment(struct hugepage_file *hugepages, int seg_start, int seg_end) > +remap_segment(struct hugepage_file *hugepages, int seg_start, int seg_end, int *mapped_seg_len) > { > struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; > struct rte_memseg_list *msl; > struct rte_fbarray *arr; > - int cur_page, seg_len; > + int cur_page, seg_len, cur_len; > unsigned int msl_idx; > int ms_idx; > uint64_t page_sz; > @@ -692,8 +692,9 @@ remap_segment(struct hugepage_file *hugepages, int seg_start, int seg_end) > > /* leave space for a hole if array is not empty */ > empty = arr->count == 0; > + cur_len = RTE_MIN((unsigned int)seg_len, arr->len - arr->count - (empty ? 0 : 1)); > ms_idx = rte_fbarray_find_next_n_free(arr, 0, > - seg_len + (empty ? 0 : 1)); > + cur_len + (empty ? 0 : 1)); > > /* memseg list is full? */ > if (ms_idx < 0) > @@ -704,12 +705,12 @@ remap_segment(struct hugepage_file *hugepages, int seg_start, int seg_end) > */ > if (!empty) > ms_idx++; > + *mapped_seg_len = cur_len; > break; > } > if (msl_idx == RTE_MAX_MEMSEG_LISTS) { > - RTE_LOG(ERR, EAL, "Could not find space for memseg. Please increase %s and/or %s in configuration.\n", > - RTE_STR(RTE_MAX_MEMSEG_PER_TYPE), > - RTE_STR(RTE_MAX_MEM_MB_PER_TYPE)); > + RTE_LOG(ERR, EAL, "Could not find space for memseg. Please increase RTE_MAX_MEMSEG_PER_LIST " > + "RTE_MAX_MEMSEG_PER_TYPE and/or RTE_MAX_MEM_MB_PER_TYPE in configuration.\n"); > return -1; > } > > @@ -725,6 +726,8 @@ remap_segment(struct hugepage_file *hugepages, int seg_start, int seg_end) > void *addr; > int fd; > > + if (cur_page - seg_start == *mapped_seg_len) > + break; > fd = open(hfile->filepath, O_RDWR); > if (fd < 0) { > RTE_LOG(ERR, EAL, "Could not open '%s': %s\n", > @@ -986,7 +989,7 @@ prealloc_segments(struct hugepage_file *hugepages, int n_pages) > static int > remap_needed_hugepages(struct hugepage_file *hugepages, int n_pages) > { > - int cur_page, seg_start_page, new_memseg, ret; > + int cur_page, seg_start_page, new_memseg, ret, mapped_seg_len = 0; > > seg_start_page = 0; > for (cur_page = 0; cur_page < n_pages; cur_page++) { > @@ -1023,21 +1026,27 @@ remap_needed_hugepages(struct hugepage_file *hugepages, int n_pages) > /* if this isn't the first time, remap segment */ > if (cur_page != 0) { > ret = remap_segment(hugepages, seg_start_page, > - cur_page); > + cur_page, &mapped_seg_len); > if (ret != 0) > return -1; > } > + cur_page = seg_start_page + mapped_seg_len; > /* remember where we started */ > seg_start_page = cur_page; > + mapped_seg_len = 0; > } > /* continuation of previous memseg */ > } > /* we were stopped, but we didn't remap the last segment, do it now */ > if (cur_page != 0) { > - ret = remap_segment(hugepages, seg_start_page, > - cur_page); > - if (ret != 0) > - return -1; > + while (seg_start_page < n_pages) { > + ret = remap_segment(hugepages, seg_start_page, > + cur_page, &mapped_seg_len); > + if (ret != 0) > + return -1; > + seg_start_page = seg_start_page + mapped_seg_len; > + mapped_seg_len = 0; > + } > } > return 0; > } This works, but I feel like it's overcomplicated - the same logic you're trying to use can just be implemented using `find_biggest_free()` + `find_contig_free()` and returning `seg_len` from `remap_segment()`? Something like the following: --- diff --git a/lib/eal/linux/eal_memory.c b/lib/eal/linux/eal_memory.c index 60fc8cc6ca..08acc787fc 100644 --- a/lib/eal/linux/eal_memory.c +++ b/lib/eal/linux/eal_memory.c @@ -681,6 +681,7 @@ remap_segment(struct hugepage_file *hugepages, int seg_start, int seg_end) /* find free space in memseg lists */ for (msl_idx = 0; msl_idx < RTE_MAX_MEMSEG_LISTS; msl_idx++) { + int free_len; bool empty; msl = &mcfg->memsegs[msl_idx]; arr = &msl->memseg_arr; @@ -692,18 +693,27 @@ remap_segment(struct hugepage_file *hugepages, int seg_start, int seg_end) /* leave space for a hole if array is not empty */ empty = arr->count == 0; - ms_idx = rte_fbarray_find_next_n_free(arr, 0, - seg_len + (empty ? 0 : 1)); - /* memseg list is full? */ - if (ms_idx < 0) - continue; + /* find start of the biggest contiguous block and its size */ + ms_idx = rte_fbarray_find_biggest_free(arr, 0); + free_len = rte_fbarray_find_contig_free(arr, ms_idx); /* leave some space between memsegs, they are not IOVA * contiguous, so they shouldn't be VA contiguous either. */ - if (!empty) + if (!empty) { ms_idx++; + free_len--; + } + + /* memseg list is full? */ + if (free_len < 1) + continue; + + /* we might not get all of the space we wanted */ + free_len = RTE_MIN(seg_len, free_len); + seg_end = seg_start + free_len; + seg_len = seg_end - seg_start; break; } if (msl_idx == RTE_MAX_MEMSEG_LISTS) { @@ -787,7 +797,7 @@ remap_segment(struct hugepage_file *hugepages, int seg_start, int seg_end) } RTE_LOG(DEBUG, EAL, "Allocated %" PRIu64 "M on socket %i\n", (seg_len * page_sz) >> 20, socket_id); - return 0; + return seg_len; } static uint64_t @@ -1022,10 +1032,17 @@ remap_needed_hugepages(struct hugepage_file *hugepages, int n_pages) if (new_memseg) { /* if this isn't the first time, remap segment */ if (cur_page != 0) { - ret = remap_segment(hugepages, seg_start_page, - cur_page); - if (ret != 0) - return -1; + int n_remapped = 0; + int n_needed = cur_page - seg_start_page; + + while (n_remapped < n_needed) { + ret = remap_segment(hugepages, + seg_start_page, + cur_page); + if (ret < 0) + return -1; + n_remapped += ret; + } } /* remember where we started */ seg_start_page = cur_page; @@ -1034,10 +1051,16 @@ remap_needed_hugepages(struct hugepage_file *hugepages, int n_pages) } /* we were stopped, but we didn't remap the last segment, do it now */ if (cur_page != 0) { - ret = remap_segment(hugepages, seg_start_page, - cur_page); - if (ret != 0) - return -1; + int n_remapped = 0; + int n_needed = cur_page - seg_start_page; + + while (n_remapped < n_needed) { + ret = remap_segment( + hugepages, seg_start_page, cur_page); + if (ret < 0) + return -1; + n_remapped += ret; + } } return 0; } --- This should do the trick? Also, this probably needs to be duplicated for Windows and FreeBSD init as well, because AFAIK they follow the legacy mem init logic. -- Thanks, Anatoly