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 D1041469D4; Tue, 17 Jun 2025 13:56:55 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9E07F40E2E; Tue, 17 Jun 2025 13:56:55 +0200 (CEST) Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by mails.dpdk.org (Postfix) with ESMTP id 35A6D4021E for ; Mon, 16 Jun 2025 18:11:14 +0200 (CEST) Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-742c73f82dfso3629043b3a.2 for ; Mon, 16 Jun 2025 09:11:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750090273; x=1750695073; darn=dpdk.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=0KDudeCLmYkLQg1jV5Q9Nt13uY35asDORNXX8yje3gE=; b=WwCmT8WJjMqWMl4j2MFr3fnvJzCT2nX8LUAlxV0gMzRVbfu8tQVNlBItMf5ufsc7zx erzqB125ciVed7MetbB8pN2SVdB4wtlr2YkZMpej+FxrR3UaBP1gGAbDEha9F50HXeWT 2Q1RlZx1b5n0x+rKoqsrcSmdrw7bWC9GyAZt+/S97akeVK8GnAju8/lehSETUvGCXtoT NoSX7n5rdReBqft+bztG+M2LNRdQvSw3xbo5mw1ni6McXaDt7qN0F0WH6Htq+w7TvqQz ktq9jRtPbbjuGDPoXuU8opw0YqyjrfddFypIFmTv2ezd07rv8S23m22iZ7+ccBjMmtJ4 Qmqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750090273; x=1750695073; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0KDudeCLmYkLQg1jV5Q9Nt13uY35asDORNXX8yje3gE=; b=B0o3cFbqDVfDdpaKv0a97etUAlZ+ivWjReAajwc+CVGBcQZcVsVQx7ZMYgxaEG+gfU YpbFKQovnfhsSfglLxZNCUVxPunYQYITXsxdagMRCACFF8vsSWOgaqhySmCOTY2T9fyn nY7QpZZuzP5RxiQKaBOjbqsOrL3xgMrvNqpeaa4MYWApux1b3vavGAl6mVqGQI4NvJsZ 93M1nIuTeBYRr/a1EGUeBCyi0k7eQK7zpIgpAW+cDnHyPiIaMUkjL5xLfPNBs0KzroFh 9Pmcmwh73UamAADDWXjJGMARU6/1FN9vvadRTXwoSX9oDhBb8oF/LzApQmLycUQMQC8g sCww== X-Gm-Message-State: AOJu0Yz1LBIUvA4nzzBPMOI+sp80pYVA8AS1ra07v8HpKK80SNHjj3No lj5vAsGsnm/MaIHzCQGzp2qz4P9/lZJdjt0ruWLl471E+bxIDaCx3wrsuavJYm2hwTg7uO+XnUR hcLV1kTPjVeeshBy8prWbPPdpyQSWB8o= X-Gm-Gg: ASbGnctbmXYP2HzWzn3e9DHh2Vm8OOXy7m7fBEFOuSv6GcUUM+3DMF4Ef31GgMmjdRW xnifYWbScUumdP8M7Lnxe6TmuMmY+vkIcOFwB7gjauP5H0j97fVuW1KGaigHtHaJLKFsXLsKiQF /R9xcmGavWxtjwDhl4DkoOQ3ybfTMygjdv+NQ7m0nj2h6rsvwc/60sllVyUOKiceuqOxMWcrIsB tUNApubg+BUEJqJ X-Google-Smtp-Source: AGHT+IFnJmMOHin2FHT9j7LH0c2nkyP0pv3QhEjBtjc3Qs1nvVcxKcEaKuBzLlT3BMHMArx3I7raPiZe6MHenHqP71I= X-Received: by 2002:a05:6a00:1c8c:b0:748:9d26:bb0a with SMTP id d2e1a72fcca58-7489d26c2a3mr13467761b3a.18.1750090273148; Mon, 16 Jun 2025 09:11:13 -0700 (PDT) MIME-Version: 1.0 References: <20250608084708.71377b9f@hermes.local> In-Reply-To: From: venkatesh bs Date: Mon, 16 Jun 2025 21:40:59 +0530 X-Gm-Features: AX0GCFv0yQa3iDhbpQWccqu2fcfG51lUj8EqZvDsBT_6ib9nFvQroJ-OHADYI1w Message-ID: Subject: Re: Question regarding rte_hash_hash and rte_hash_add_key_with_hash_data To: Stephen Hemminger Cc: dev@dpdk.org Content-Type: multipart/alternative; boundary="0000000000000e51ed0637b2a5ba" X-Mailman-Approved-At: Tue, 17 Jun 2025 13:56:54 +0200 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 --0000000000000e51ed0637b2a5ba Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi @Stephen Hemminger , We debugged further on this issue .. We see that position and entry_size(position * key_entry_size) crosses above int32_t it overflows and it will corrupt random index of hash table. in Nut shell hash table is only supporting upto 2topower32 size entries on the table. Below mentioned snapshot of the code change. Thanks, Venkatesh. struct rte_hash_key *k, *keys =3D h->key_store; Add comment63Plus - k =3D (struct rte_hash_key *) ((char *) keys + (positi= on + 1) * Add comment64Plus - h->key_entry_size); Add comment65Plus + k =3D (struct rte_hash_key *) ((char *) keys + (uint64_t) (position + 1) * Add comment66Plus + (uint64_t) h->key_entry_size); Add comment67Plus *key =3D k->key; Add comment68 On Tue, Jun 10, 2025 at 12:19=E2=80=AFPM venkatesh bs = wrote: > Hi @Stephen Hemminger , > > Thanks for the reply , please find the details below. > > DPDK version : 20.11.6 > > #define LOADBAL_HASH_ENTRIES_MAX (1024*1024*36) > #define LOADBAL_HASH_TABLE_SIZE_MULTIPLIER 2 > > hashSizeMultiplier =3D LOADBAL_HASH_TABLE_SIZE_MULTIPLIER; > > struct rte_hash_parameters loadbal_hash_params =3D { > .name =3D NULL, > .entries =3D LOADBAL_HASH_ENTRIES_MAX * hashSizeMultipl= ier, > .key_len =3D sizeof(flow_key_t), > .hash_func =3D app_hash_crc(internally it calls > rte_hash_crc_4byte for v4/v6) > .hash_func_init_val =3D 0, > }; > > First, what is the return value, which error? > we captured only the return value, and will check what error it is > returning. > > IPv4 Load-Bal Flow hash table: > numInsertions: 998214247 > numInsertionsFailures: 4252 > numRemovals: 997197485 > numRemovalFailures: 214902 > numObjects: 1016762 > NumBuckets: 75497472 > TableCapacity: 75497472 > LoadFactor: 1% > NumLookupSuccess: 389165605 > NumLookupFails: 2704814006 > Failure Analysis: > TableFull(>=3D95%): 0 > HighLoad(75-95%): 0 > MediumLoad(50-75%): 0 > LowLoad(<50%): 4252 > > We are try to analyze the code and find out the details, > Initially there will be no issues, insertion starts failing after 24 HRS > or so. > > Thanks, > Venkatesh. > > > On Sun, Jun 8, 2025 at 9:17=E2=80=AFPM Stephen Hemminger < > stephen@networkplumber.org> wrote: > >> On Sun, 8 Jun 2025 00:36:02 +0530 >> venkatesh bs wrote: >> >> > Hi @dpdk community, >> > >> > In my application, I am using the dpdk hash table as below. >> > >> > 1. calculate the hash value. >> > 2. using this signature add the key and data into a table. >> > 3. lock is used in the 2nd call (add). >> > >> > Below is the code sniffer for the same. >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> > hash_sig_t sig =3D rte_hash_hash(hash_tablele, (void *) &new_key)= ; >> > >> > pthread_mutex_lock(&lock); >> > int32_t ret =3D rte_hash_add_key_with_hash_data(hash_table, >> > (void *)&new_key, >> > sig, >> > info); >> > >> > if (ret < 0) >> > { >> > pthread_mutex_unlock(lock); >> > return TOS_E_FAIL; >> > } >> > pthread_mutex_unlock(lock); >> > >> > return OK.. >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> > >> > My application is having a lot of threads and when run with heavy load >> , I >> > am getting a lot of insertion failure, i felt the reason could be >> > calculating and adding the has value in 2 api's as opposed to >> > rte_hash_add() that is safe under a lock.. >> > >> > >> > Please let me know your thoughts. >> >> Which architecture and DPDK version? >> What flags did you use during hash creation? >> >> As always with open source, the first thing to do is look at the source >> and see what is really happening, rather than just relying on the >> documentation. >> >> I assume you are using the default hash function which is CRC. >> >> First what is the return value, which error? >> It might just be key collisions. How big is the table and how many >> inserts? >> >> Also, the current DPDK hash flags with better locking and RCU. >> This would be faster than simple pthread mutex. >> >> --0000000000000e51ed0637b2a5ba Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi=C2=A0@Stephen Hemmi= nger=C2=A0,

We debugged further on this issue ..

We see that position=C2=A0and entry_size(position * k= ey_entry_size) crosses above int32_t it overflows and it will corrupt rando= m index of hash table.

in Nut shell=C2=A0hash tabl= e is only supporting upto 2topower32=C2=A0size entries on the table.=C2=A0<= /div>

Below mentioned snapshot of the code change.
=

Thanks,
Venkatesh.

<= br>
struct rte_hash_key *k, *keys =3D h->key_= store;
Add comment63<= /span>= Plus=C2=A0=C2= =A0- k =3D (struct rte_hash_key *) ((char *) keys + (position + 1) *=
Add= comment= Plus=C2=A0=C2=A0- h= ->key_entry_size);
Add comment65Plus=C2=A0=C2=A0+ k =3D (struct rte_hash_key *) ((char *) keys + (uint64_t= ) (position + 1) *
Add comment66Pl= us=C2=A0=C2=A0= + (uint64_t) h->key_entry_size);
Add comment67= Plus=C2=A0=C2=A0 *key =3D k->key;<= /span>
Add comment68<= span class=3D"gmail-repos-line-number" style=3D"box-sizing:inherit">=

On Tue, Jun 10, 2025 at 12:19=E2= =80=AFPM venkatesh bs <venki.bsv@= gmail.com> wrote:
Hi=C2=A0@Stephen Hemminger=C2=A0,
Thanks for the reply , please find the details below.

DPDK version : 20.11.6

#define LOADBAL_H= ASH_ENTRIES_MAX (1024*1024*36)
#define LOADBAL_HASH_TABLE_SIZE_MULTIPLIE= R 2

hashSizeMultiplier =3D LOADBAL_HASH_TABLE_SIZE_MULTIPLIER;
=C2=A0 struct rte_hash_parameters loadbal_hash_params =3D {
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .name =3D NULL,
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .entries =3D LO= ADBAL_HASH_ENTRIES_MAX * hashSizeMultiplier,
=C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .key_len =3D sizeof(flow_key_t),
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .hash_func =3D = app_hash_crc(internally it calls rte_hash_crc_4byte for v4/v6)
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .hash_func_init_val= =3D 0,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 };

First= , what is the return value, which error?
we captured only the return va= lue, and will check what =C2=A0error it is returning.

IPv4 Load-Bal = Flow hash table:
=C2=A0 =C2=A0 numInsertions: =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0998214247
=C2=A0 =C2=A0 numInsertionsFailures: =C2=A04252
= =C2=A0 =C2=A0 numRemovals: =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A09971974= 85
=C2=A0 =C2=A0 numRemovalFailures: =C2=A0 =C2=A0 214902
=C2=A0 =C2= =A0 numObjects: =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 1016762
=C2=A0= =C2=A0 NumBuckets: =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 75497472
= =C2=A0 =C2=A0 TableCapacity: =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A075497472
= =C2=A0 =C2=A0 LoadFactor: =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 1%
= =C2=A0 =C2=A0 NumLookupSuccess: =C2=A0 =C2=A0 =C2=A0 389165605
=C2=A0 = =C2=A0 NumLookupFails: =C2=A0 =C2=A0 =C2=A0 =C2=A0 2704814006
=C2=A0 =C2= =A0 Failure Analysis:
=C2=A0 =C2=A0 =C2=A0 TableFull(>=3D95%): =C2=A0= =C2=A00
=C2=A0 =C2=A0 =C2=A0 HighLoad(75-95%): =C2=A0 =C2=A00
=C2=A0= =C2=A0 =C2=A0 MediumLoad(50-75%): =C2=A00
=C2=A0 =C2=A0 =C2=A0 LowLoad(= <50%): =C2=A0 =C2=A0 =C2=A0 4252
=C2=A0 =C2=A0
We are try = to analyze the code and find out=C2=A0the details,
Initially there will= be no issues, insertion starts failing after 24 HRS or so.

<= /div>
Thanks,
Venkatesh.


On Sun, Jun 8, 2025 at = 9:17=E2=80=AFPM Stephen Hemminger <stephen@networkplumber.org> wrote:
On Sun, 8 Jun 2025 00:= 36:02 +0530
venkatesh bs <v= enki.bsv@gmail.com> wrote:

> Hi @dpdk community,
>
> In my application, I am using the dpdk hash table as below.
>
> 1. calculate the hash value.
> 2. using this signature add the key and data into=C2=A0 a table.
> 3. lock is used in the 2nd call (add).
>
> Below is the code sniffer for the same.
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>=C2=A0 =C2=A0 =C2=A0 hash_sig_t sig =3D rte_hash_hash(hash_tablele, (vo= id *) &new_key);
>
>=C2=A0 =C2=A0 =C2=A0 pthread_mutex_lock(&lock);
>=C2=A0 =C2=A0 =C2=A0 =C2=A0int32_t ret =3D rte_hash_add_key_with_hash_d= ata(hash_table,
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0(void *)&new_key,
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 sig,
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 info);
>
> if (ret < 0)
> {
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 pthread_mutex_unlock(lock);
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return TOS_E_FAIL;
> }
> pthread_mutex_unlock(lock);
>
> return OK..
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>
> My application is having a lot of threads and when run with heavy load= , I
> am getting a lot of insertion failure, i felt the reason could be
> calculating and adding the has value in 2 api's as opposed to
> rte_hash_add() that is safe under a lock..
>
>
> Please let me know your thoughts.

Which architecture and DPDK version?
What flags did you use during hash creation?

As always with open source, the first thing to do is look at the source
and see what is really happening, rather than just relying on the documenta= tion.

I assume you are using the default hash function which is CRC.

First what is the return value, which error?
It might just be key collisions. How big is the table and how many inserts?=

Also, the current DPDK hash flags with better locking and RCU.
This would be faster than simple pthread mutex.

--0000000000000e51ed0637b2a5ba--