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 7646442B9B; Thu, 25 May 2023 16:26:32 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 04E5640DF8; Thu, 25 May 2023 16:26:32 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mails.dpdk.org (Postfix) with ESMTP id 7857C40DDB for ; Thu, 25 May 2023 16:26:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685024790; x=1716560790; h=message-id:date:subject:to:cc:references:from: in-reply-to:content-transfer-encoding:mime-version; bh=dT5wpqDRfvvP/U8PshY2Bk61AXxQ/b4A73d9KFcOCAs=; b=buiLgWJMsC/8j3pgn5tY0ga5MfDwSO2SdOLbICFke6rf1lxjaHUQxsjU KSa1BD/fnB3ZNfmcuQNNK6A65O7UWyEhTJ9HDjzxg6H60PWuqKKcXMavv YLZ2AsO8W3/O38gkjp1XapThLEg4NkyU75RHKZWDlnM8KCzuR011VIPhC XQbj+EVPIiTBx3Fmzduc3nVGgQSS/rggBvMlwwauHu4FC6Wmm32kB7KGj BaEngklpCQ+OGN+D0LRV/fdLE/gnnSfYIahQnXkmqN9Dijvt+4wYqEUUR hPa5F89B+egnlUsr3dG3CYFHoEDR18RBPrZzaaFZU2YYcBEgP0q+1hpdw A==; X-IronPort-AV: E=McAfee;i="6600,9927,10721"; a="440254679" X-IronPort-AV: E=Sophos;i="6.00,191,1681196400"; d="scan'208";a="440254679" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 May 2023 07:26:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10721"; a="704817851" X-IronPort-AV: E=Sophos;i="6.00,191,1681196400"; d="scan'208";a="704817851" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by orsmga002.jf.intel.com with ESMTP; 25 May 2023 07:26:29 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 25 May 2023 07:26:28 -0700 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23 via Frontend Transport; Thu, 25 May 2023 07:26:28 -0700 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (104.47.59.171) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.23; Thu, 25 May 2023 07:26:28 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OI75GXaotzwy5Cah8Ac2926B2SDM3dn6hVvpBtvN/oJy8O8KqaxDF9tqgLSY2bm7q1FbuCVrVPBhjR+2PW+Pu6AmCLClSNs/LEV9/SxfQrD+6HEGSj0L41IwvU1smWABv+xCvD8wPwzPdDgnFXyLuM8xpZeN+vGzBSlokvKywCshewtNkB4FMaSF5G6VI1rmD9sPCH2N0gsjj1ZZOq9foULaBRNiILK1XyqwUyzsqyAe/DRy2YZm+g9MM8d5lPMhTcdayI0p9s1p0xhjfasR3L9CN8Wn+LzLaIK0/s7uHBLmx0a8gFTFuJ6QyE2c372JLp4pOVgC+hQnLwNxdk/JlA== 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=aSlBF3Eo2mTrg/wQs6rjDFDWB8JrMmKcvW5yEWNfKtk=; b=VD0ITxW3gTObPnGCmxrn/tNliCYj/lCWPAPtADX56delfHUrWzBZX/y0zEoK1sUCuqXgkdofqs4BzMaY7HASWlpMypr71rrcYFuMYaEvHpUK1eFgLSwYQt1KAPb58qcDWjrM1bqDhm5TS/37mM5bzbd9sQ4L/III1XFoHiHzA581lruYDCZhBH3otSil9nmf/2Z7aq9eyrqXhl9C48kRx3GOQ0cFaVk0+lG2MMQpE/5JUfWvnwCquNPDV+uLnMZd+jWurbpkWan1K9PCFls0wjx0QUYDZSfHVcKWVWNAv3ijHImwKROja3ls3mOsNx5uB3ZO2m+D97+Ba2Q97BUPyA== 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 SA3PR11MB7553.namprd11.prod.outlook.com (2603:10b6:806:316::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.16; Thu, 25 May 2023 14:26:26 +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.6433.017; Thu, 25 May 2023 14:26:26 +0000 Message-ID: Date: Thu, 25 May 2023 15:26:18 +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: [External] 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: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: DB6PR0301CA0009.eurprd03.prod.outlook.com (2603:10a6:4:3e::19) To DM4PR11MB6502.namprd11.prod.outlook.com (2603:10b6:8:89::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB6502:EE_|SA3PR11MB7553:EE_ X-MS-Office365-Filtering-Correlation-Id: e3b540ac-e30a-4fac-9667-08db5d2c05d8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: X4Yar5Au16YnvqfjDJB4Pf1TBVannWlJitUojWo3+uWHKSoOumB9vz7CKrS2+ev9DTe++cQXiyvsSCGn2ZqI73OYbOicFTL+rsSN116MG+xxrZVpUDJ51d2dUoeHvawaPuvOxEp6/7xmZdyucpouyBizFS01Eh6PWCVobchI/BSGBXEmATGsWLzfiwIMNlvJf7dZEyWa1crKFvsS6pHDFZG+F8seh58cgy65WeOK2XXUqYEKdvDZNL/SFDRwI4r5a19YCPvlVnL6uy5HyLLlQIaRg9Lf/BE7ahvGuauz1FCnJOARu88Ohxzx1M9fZnpqn9rSM3TYfYCaMm0Sv8KRroGuh7IOPAlOptdWiV9BoahS6rn3H4psKfkXY1cukkbWJ1qI4T16bzTL9dQSNX87M84C2HTx8opdouFjYBzRRMWj4q3oylXVVV8cj5/mEMpREsnAHbNlyE8y5j+sQjd4tXmGlaGGnKyoqpX+ssDQVPM9ofbGqAXeUNdwyLtPOtNZr+5gPEUUYXvb7htq9UU0WDPh6MkDM20VyxY4ziwciLDen/x2TZZej0CJH1SuQatkJpJUZeJlgFUJlW0i0NAX8G1x4M6CjTQ3IZ/MzgR/JcvFabao6pf0STuB9884kQq8jx+A0WBcl5YEwzupivGviA== 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)(366004)(346002)(136003)(396003)(39860400002)(376002)(451199021)(6666004)(6486002)(41300700001)(53546011)(26005)(6512007)(6506007)(8936002)(8676002)(38100700002)(36756003)(5660300002)(2616005)(83380400001)(31696002)(2906002)(186003)(86362001)(82960400001)(6916009)(66476007)(4326008)(66946007)(66556008)(31686004)(478600001)(316002)(43740500002)(45980500001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?dWRpUFoxVDluZzdnS0hvUjhmejNEOTdKd1hlRSs0ZzlPSWlPMk1STExjb2xT?= =?utf-8?B?RG1TRWNjaFJqQlVMZEVROVZYc3AzTTRnaElONzBvQmJHdmhHNDZnSnUzZ0lC?= =?utf-8?B?UWtrNExtdUJMSFNOSEwwSkhXM0xLSWlWQzN0Q2tEbzNVdGlIMlJnZFN1N2FX?= =?utf-8?B?UkE1a1F3TW5xNGFIOW9VTEVNRWVqWWp3WnhzME9oZXdhTkRSMFRHZHU3dm0z?= =?utf-8?B?R2tPOEM0ZHFiRmttTGlsVmtJNndCMmIrWTJmc1U0YThIWkRuZVduZkVWb0Jo?= =?utf-8?B?ZXZQVjFnZ1hBcGlHL3FZaTVBcEZVVkxxVW5LKzZzNVowakpSODBwS1hrOFNR?= =?utf-8?B?ZnVWdDhjMEJiOEFUc2h6TmxzK0Qzb0xUMnNNWFdDZEMvcDB1dHdScEhIVjA4?= =?utf-8?B?UDNRMmo4Z0VuQnVkTkowc1ZIWjBHbEJvbTRmeXg2TmpncE55OG9xNXRtVXJj?= =?utf-8?B?V1pwUEdoSDVlWUF3Ym1jQU1INU9ibUlnK2l6Tld4S2hLRHlSem94ZXdQeTZX?= =?utf-8?B?aDlRM2puUmVsLytuMGNKTStKUVRKZEhNWUV5eTJWUE9WVzRHb044Z1AraXps?= =?utf-8?B?SUF5ZDQyTVRKd25iWXpsUVBTdDBocGdQNlYxdnRReUkvOFRIMFhmVHkyQXdU?= =?utf-8?B?SVplY3RXT3FzaHg0WHQ5UjZvcWhhNXFrcVY1azVNaFZoNU9wcUdyK3hERlNm?= =?utf-8?B?MEZZbGgzcUJyOUUxRFR5VlZSaVpQQnp2KzdBY3hua2kvUWZnK09PVXZmNHc0?= =?utf-8?B?SzRXQStNR09aYUdraUdqM0xDczhBaVNUOGtHaTFCNG45WWhySTRKUURwOFA5?= =?utf-8?B?VlhCbW03TktFQ2I1QVNvSDhUQm5YOEFWVnlSZGxlOTdDMUtlVnV0aDNmZ1g2?= =?utf-8?B?QUk3cWFRRDNQOUFRNDczN0V6UFU2RmlOd1BPelp5TjdHWUlLQUdmVmVvc0Fa?= =?utf-8?B?R2NEVmF3WXphaEQrVmlKYnVibGZYamlBN0d3cCt5ZDhTUDh2K1lzbkV4NzdN?= =?utf-8?B?emtTeDM3RE85WjlUYVluUVprZVV3aXJqY3A3eEVjNUZKMnhibnREVWRBb0c0?= =?utf-8?B?TzJiMUNacldjbUhkRjE3RmdRU3dFQ3JyaC9ncmhMQWZxdllURm5PeW1BUVhS?= =?utf-8?B?UDVFYWVhSmtGWlpLZEJidmtHT0R3OENtRTU2Q2dxVU1PQ01RRDlycllnTnh0?= =?utf-8?B?aUh5OTI2QU1zNktISFJVci8rdEgvZTlYbWNodDZYcGs4VVU2M0k1QU9yWWRT?= =?utf-8?B?cFY1QVVrVDR5bG43eTY2bTk1V1VEQnJrMkZ3cStndFZZT0F0ME8rQTV5VzZY?= =?utf-8?B?M2xaMFlUV3ZORTlLZFQ4OVUwZzBKUENRMjJTMm1ESjQ4R3JnMVpyaEFTdUp5?= =?utf-8?B?WGJQeG8zalk0TGdOU0dJdHNNeUxRWXQ5SFBrLythdkp0blpBbUNFNHE0a2Iw?= =?utf-8?B?TnE0SXA1YmdEeXdRbmV4UG1HYWVxd3hBMGFZWDA2VlRxSk5laUhadnQ5dmF0?= =?utf-8?B?eXFIS05jRHo2YXlxUjlCMWVNdFhibTZCeEVMSzRRcmdjVnJncmRYU2Q1T0cx?= =?utf-8?B?TDBBRkhLWTRVY29Tblh4UEplZ3F4MFZkTElQc0JlcE1MTXZQaEpwelZ6bW1T?= =?utf-8?B?WGREN1o2NFBrejBWblc5QU5SdWprVngwSDFESDNodVpSRU1qKzNCeTlzV3g1?= =?utf-8?B?MXJ5dy92Q29EN3JFenJpL2Y4Z0dTT0ZRMlMwa045czlWaDBocENTL1JWQU9l?= =?utf-8?B?enF4RE5oWitFc3JOL25ac20yK1JFMGY0WXh6TTB5Ykc0UC8yQmh4eWc4R1hB?= =?utf-8?B?UHJUWWZrbThNeEFiWWxZMTg4L2VFUnYvSVBJSlcxZGIvMklQMTNOTHU0MVFI?= =?utf-8?B?MXdtY1RWMlpYV1lDUzVMVnoybkwwZzdnVFNyN3JBQmlXdXkvQ2UxSDROWnNY?= =?utf-8?B?Tkh5eW1BUnIwTGxWWWpaMk4wdW1STDUrNlhraUZmaUNnRVh2UkNodlZnMTlN?= =?utf-8?B?Z0hxMmVaUG9TUTlmaDVDR0I5cTduSDluNEVEN25wNUlST0hCb0JwMGdMbS9s?= =?utf-8?B?eVRMeUVyL1VkY2xNaWgwU28xK3BISDJURWZMM0FpSFFvdzQzbWM1ME1qNHVp?= =?utf-8?B?ZHJTMG9PZkFkbDdncEx1OWQ3ZUgyM1hiTFl4RXFUUWdBbUYwTXlXVUtFclcx?= =?utf-8?B?QUE9PQ==?= X-MS-Exchange-CrossTenant-Network-Message-Id: e3b540ac-e30a-4fac-9667-08db5d2c05d8 X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB6502.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 May 2023 14:26:26.3095 (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: okqYCMLihLUox/hOvLNK5UgiLS5+I092VOBzlzEvecG6J82PDguSPk1JlzjimfDJYBXZlnJAHIjAe0oQe64oF5ORHcWzx+irrKbytFDBdZo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR11MB7553 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/25/2023 1:49 PM, Fengnan Chang wrote: > Burakov, Anatoly 于2023年5月22日周一 21:28写道: >> >> 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. > I take a simple look at FreeBSD and Windows code, FreeBSD don't have this > problem, FreeBSD map hugepage is one by one, not mapp multiple at once > and windows call eal_dynmem_hugepage_init when have hugepage. > So It seems just modify linux is ok. Right, OK then. -- Thanks, Anatoly