From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-eopbgr130055.outbound.protection.outlook.com [40.107.13.55]) by dpdk.org (Postfix) with ESMTP id 6659B1B94E for ; Fri, 14 Dec 2018 10:33:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8AtlMvegWDlDBRSR+KjcZZeTaSivSIFBeh9zKFE/q2o=; b=ET5alezMhce5w5pDGFoxwj1LOzJBUJoIZ1eq9qtfl9tQ+bSagyDfnvveh6r2LYs9fVXejtLJzixWFg2DcOgM7JshO6N/Zg3c/VMfFvHdt59wuahDOfkeugCXcwwtN3C+eiXBuMkrEkm5b3g2mQVJDS7jLMBmuhFupNKwgd5L5is= Received: from DB3PR0502MB3980.eurprd05.prod.outlook.com (52.134.72.27) by DB3PR0502MB4090.eurprd05.prod.outlook.com (52.134.72.159) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1425.22; Fri, 14 Dec 2018 09:33:38 +0000 Received: from DB3PR0502MB3980.eurprd05.prod.outlook.com ([fe80::dcbc:4578:3018:50f3]) by DB3PR0502MB3980.eurprd05.prod.outlook.com ([fe80::dcbc:4578:3018:50f3%5]) with mapi id 15.20.1404.026; Fri, 14 Dec 2018 09:33:38 +0000 From: Yongseok Koh To: Anatoly Burakov CC: "dev@dpdk.org" , Shahaf Shuler , Thomas Monjalon , "shreyansh.jain@nxp.com" Thread-Topic: [PATCH 1/4] malloc: separate creating memseg list and malloc heap Thread-Index: AQHUh+o9b2DomFnAAEudd9cLkR4QpaV+EE+A Date: Fri, 14 Dec 2018 09:33:38 +0000 Message-ID: <20181214093328.GA12221@mtidpdk.mti.labs.mlnx> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR01CA0033.prod.exchangelabs.com (2603:10b6:a02:80::46) To DB3PR0502MB3980.eurprd05.prod.outlook.com (2603:10a6:8:10::27) authentication-results: spf=none (sender IP is ) smtp.mailfrom=yskoh@mellanox.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [209.116.155.178] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB3PR0502MB4090; 6:Pltp2YPRmgfSLPTu/W//IHu0HwEs0g+SKQq5LDx95AtsR/a/+eCQPJ/iPpmEU7ISnmA5U6Apmlrd6c4bu67YAwhTy9xMgOxG+vSwXoYilOdsdGuAOSP0j/yBhYcAO5Z3DmhSU5yFpV8ROwn30CgUgEuqFiegkfbmEKwfqXVdWkqMo8WUeYD+AnCg+Wq7nZIx3lEIxxbPCO0/8Gxi7KltIyn+BTMp/HJPPv+nsmJAo/nK/BqiBTFQ3k5Yosr3XSuzkv0nlrwFfy9sdIjicHyfUXU41ljBgo3foOcwxkTKeQVFXTBFE+rlGv1Qa9Equg8WmH5SnIMSeW+GCKmzt1ciAVMphSR5X4Ng1mgZetUhNBlmU5hzh+XpTGDC66snaEFY/1n7Y/1+qZaqYMaQj8bBOIPKpIGkRWus5Tps+pO9PhubucbOdIckxxURyhoxusYS4VOgLrtIbdAcCg6Jwu8FdQ==; 5:e7DMP77ZHd1GVCADct3R8Tj3P0JuKBtJ60wtpFF8Eh88ebfqIQTVUVEeoU7sOeojG8GEsGfUcr19jpEFxGkdXxNGEIR9SJTSFKNnmuvq1qgnBm8M+h9BowMjPzyP4yLTP42Ado5xobVlLgiasnkM5oQPJvlPBQGi9S+q0sXyASM=; 7:sV8Clow+FPhSC3VFfHKTlDXjvImo/xmSXAbCr6tgslZfbMjC57vS/4zUde4FI7BIsvsKAaoh2LvrTqElbnLzIeX5U9ReZgcCuG+nZI5K/pjekN/r/62R+6ER0slK0wY+JmCTS9e3itqbqI4kZt3D0A== x-ms-office365-filtering-correlation-id: e553e253-6328-4169-ea91-08d661a73a35 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:DB3PR0502MB4090; x-ms-traffictypediagnostic: DB3PR0502MB4090: x-ld-processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(3230021)(999002)(6040522)(2401047)(5005006)(8121501046)(3231475)(944501520)(52105112)(93006095)(93001095)(10201501046)(3002001)(6055026)(148016)(149066)(150057)(6041310)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(201708071742011)(7699051)(76991095); SRVR:DB3PR0502MB4090; BCL:0; PCL:0; RULEID:; SRVR:DB3PR0502MB4090; x-forefront-prvs: 08864C38AC x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(346002)(376002)(396003)(136003)(39860400002)(366004)(189003)(199004)(6436002)(102836004)(105586002)(6506007)(33896004)(386003)(8936002)(81166006)(52116002)(2906002)(7736002)(81156014)(8676002)(76176011)(256004)(316002)(99286004)(71200400001)(71190400001)(66066001)(86362001)(54906003)(97736004)(14444005)(446003)(5660300001)(476003)(25786009)(68736007)(305945005)(486006)(14454004)(11346002)(53936002)(26005)(229853002)(6916009)(3846002)(6512007)(9686003)(6246003)(106356001)(6116002)(4326008)(33656002)(1076002)(478600001)(186003)(6486002); DIR:OUT; SFP:1101; SCL:1; SRVR:DB3PR0502MB4090; H:DB3PR0502MB3980.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: MmsAs6Mzh/OO8W2UXTZMyj3du7r6xZvhd7v8wwZXHojPwHzPM5YKqTpehfg9SfbPUulcJ4gDIpd3IoM7vTQ+Cmsyt7z78fYz9Jvl6K98oeyx9BQgkA7VQOEdrncyGHNIfjsiDBVoiqSaCgCGEuW2m2Um1VWl8P9Cn+XXTpVGI8WgoJyZnr8FcBSGbK/6z4TCp8IqvPAejxfvsr2dfBDKe8xTfhw4IzUROwISbeLy+jT9hi0K/Th8kziS5YwwUFmZ5Y5gc6pT5+QHMyzadC6dE/X6rjd9OlX9VxgryWZDIYcadQlQnFNInztsRTVl9Zcp spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-ID: <55DC7D17611C7744B355629CC5B9EB06@eurprd05.prod.outlook.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: e553e253-6328-4169-ea91-08d661a73a35 X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Dec 2018 09:33:38.7241 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR0502MB4090 Subject: Re: [dpdk-dev] [PATCH 1/4] malloc: separate creating memseg list and malloc heap X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 Dec 2018 09:33:43 -0000 On Thu, Nov 29, 2018 at 01:48:32PM +0000, Anatoly Burakov wrote: > Currently, creating external malloc heap involves also creating > a memseg list backing that malloc heap. We need to have them as > separate functions, to allow creating memseg lists without > creating a malloc heap. >=20 > Signed-off-by: Anatoly Burakov > --- Acked-by: Yongseok Koh Thanks > lib/librte_eal/common/malloc_heap.c | 34 ++++++++++++++++++----------- > lib/librte_eal/common/malloc_heap.h | 9 ++++++-- > lib/librte_eal/common/rte_malloc.c | 11 ++++++++-- > 3 files changed, 37 insertions(+), 17 deletions(-) >=20 > diff --git a/lib/librte_eal/common/malloc_heap.c b/lib/librte_eal/common/= malloc_heap.c > index c6a6d4f6b..25693481f 100644 > --- a/lib/librte_eal/common/malloc_heap.c > +++ b/lib/librte_eal/common/malloc_heap.c > @@ -1095,9 +1095,10 @@ destroy_seg(struct malloc_elem *elem, size_t len) > return 0; > } > =20 > -int > -malloc_heap_add_external_memory(struct malloc_heap *heap, void *va_addr, > - rte_iova_t iova_addrs[], unsigned int n_pages, size_t page_sz) > +struct rte_memseg_list * > +malloc_heap_create_external_seg(void *va_addr, rte_iova_t iova_addrs[], > + unsigned int n_pages, size_t page_sz, const char *seg_name, > + unsigned int socket_id) > { > struct rte_mem_config *mcfg =3D rte_eal_get_configuration()->mem_config= ; > char fbarray_name[RTE_FBARRAY_NAME_LEN]; > @@ -1117,17 +1118,17 @@ malloc_heap_add_external_memory(struct malloc_hea= p *heap, void *va_addr, > if (msl =3D=3D NULL) { > RTE_LOG(ERR, EAL, "Couldn't find empty memseg list\n"); > rte_errno =3D ENOSPC; > - return -1; > + return NULL; > } > =20 > snprintf(fbarray_name, sizeof(fbarray_name) - 1, "%s_%p", > - heap->name, va_addr); > + seg_name, va_addr); > =20 > /* create the backing fbarray */ > if (rte_fbarray_init(&msl->memseg_arr, fbarray_name, n_pages, > sizeof(struct rte_memseg)) < 0) { > RTE_LOG(ERR, EAL, "Couldn't create fbarray backing the memseg list\n")= ; > - return -1; > + return NULL; > } > arr =3D &msl->memseg_arr; > =20 > @@ -1143,32 +1144,39 @@ malloc_heap_add_external_memory(struct malloc_hea= p *heap, void *va_addr, > ms->len =3D page_sz; > ms->nchannel =3D rte_memory_get_nchannel(); > ms->nrank =3D rte_memory_get_nrank(); > - ms->socket_id =3D heap->socket_id; > + ms->socket_id =3D socket_id; > } > =20 > /* set up the memseg list */ > msl->base_va =3D va_addr; > msl->page_sz =3D page_sz; > - msl->socket_id =3D heap->socket_id; > + msl->socket_id =3D socket_id; > msl->len =3D seg_len; > msl->version =3D 0; > msl->external =3D 1; > =20 > + return msl; > +} > + > +int > +malloc_heap_add_external_memory(struct malloc_heap *heap, > + struct rte_memseg_list *msl) > +{ > /* erase contents of new memory */ > - memset(va_addr, 0, seg_len); > + memset(msl->base_va, 0, msl->len); > =20 > /* now, add newly minted memory to the malloc heap */ > - malloc_heap_add_memory(heap, msl, va_addr, seg_len); > + malloc_heap_add_memory(heap, msl, msl->base_va, msl->len); > =20 > - heap->total_size +=3D seg_len; > + heap->total_size +=3D msl->len; > =20 > /* all done! */ > RTE_LOG(DEBUG, EAL, "Added segment for heap %s starting at %p\n", > - heap->name, va_addr); > + heap->name, msl->base_va); > =20 > /* notify all subscribers that a new memory area has been added */ > eal_memalloc_mem_event_notify(RTE_MEM_EVENT_ALLOC, > - va_addr, seg_len); > + msl->base_va, msl->len); > =20 > return 0; > } > diff --git a/lib/librte_eal/common/malloc_heap.h b/lib/librte_eal/common/= malloc_heap.h > index e48996d52..255a315b8 100644 > --- a/lib/librte_eal/common/malloc_heap.h > +++ b/lib/librte_eal/common/malloc_heap.h > @@ -39,9 +39,14 @@ malloc_heap_create(struct malloc_heap *heap, const cha= r *heap_name); > int > malloc_heap_destroy(struct malloc_heap *heap); > =20 > +struct rte_memseg_list * > +malloc_heap_create_external_seg(void *va_addr, rte_iova_t iova_addrs[], > + unsigned int n_pages, size_t page_sz, const char *seg_name, > + unsigned int socket_id); > + > int > -malloc_heap_add_external_memory(struct malloc_heap *heap, void *va_addr, > - rte_iova_t iova_addrs[], unsigned int n_pages, size_t page_sz); > +malloc_heap_add_external_memory(struct malloc_heap *heap, > + struct rte_memseg_list *msl); > =20 > int > malloc_heap_remove_external_memory(struct malloc_heap *heap, void *va_ad= dr, > diff --git a/lib/librte_eal/common/rte_malloc.c b/lib/librte_eal/common/r= te_malloc.c > index 0da5ad5e8..66bfe63c3 100644 > --- a/lib/librte_eal/common/rte_malloc.c > +++ b/lib/librte_eal/common/rte_malloc.c > @@ -340,6 +340,7 @@ rte_malloc_heap_memory_add(const char *heap_name, voi= d *va_addr, size_t len, > { > struct rte_mem_config *mcfg =3D rte_eal_get_configuration()->mem_config= ; > struct malloc_heap *heap =3D NULL; > + struct rte_memseg_list *msl; > unsigned int n; > int ret; > =20 > @@ -373,9 +374,15 @@ rte_malloc_heap_memory_add(const char *heap_name, vo= id *va_addr, size_t len, > goto unlock; > } > =20 > + msl =3D malloc_heap_create_external_seg(va_addr, iova_addrs, n, page_sz= , > + heap_name, heap->socket_id); > + if (msl =3D=3D NULL) { > + ret =3D -1; > + goto unlock; > + } > + > rte_spinlock_lock(&heap->lock); > - ret =3D malloc_heap_add_external_memory(heap, va_addr, iova_addrs, n, > - page_sz); > + ret =3D malloc_heap_add_external_memory(heap, msl); > rte_spinlock_unlock(&heap->lock); > =20 > unlock: > --=20 > 2.17.1