All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Andreas Bießmann" <andreas.devel@googlemail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] lib/hashtable.c: add algorithm for small buffer import
Date: Wed, 29 Sep 2010 21:28:06 +0200	[thread overview]
Message-ID: <1285788486-43901-1-git-send-email-andreas.devel@googlemail.com> (raw)

This patch adds a new flag to influence the hashtable internal algorithm
for creation size when importing a buffer.

When importing a extremely small buffer (e.g. the default_environment)
the current algorithm cuts down the size of hash table to extremely
small size. In some cases this may render the device unusable until one
saves the environment to non volatile memory and restarts the device.

Signed-off-by: Andreas Bie?mann <andreas.devel@googlemail.com>
---
In my case i had to import 5 key/value pairs from default_environment which
was about 30 byte buffer. These key/values fit in my hash table but the
ethernet driver would like to setenv() another key/value which returned with
error.

 common/env_common.c |    2 +-
 include/search.h    |    4 +++-
 lib/hashtable.c     |   15 ++++++++++++---
 3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/common/env_common.c b/common/env_common.c
index a415ef8..bd6eae4 100644
--- a/common/env_common.c
+++ b/common/env_common.c
@@ -188,7 +188,7 @@ void set_default_env(const char *s)
 	}
 
 	if (himport((char *)default_environment,
-		    sizeof(default_environment), '\0', 0) == 0) {
+		    sizeof(default_environment), '\0', H_ALG_SMALL_BUF) == 0) {
 		error("Environment import failed: errno = %d\n", errno);
 	}
 	gd->flags |= GD_FLG_ENV_READY;
diff --git a/include/search.h b/include/search.h
index fccc757..e6cd189 100644
--- a/include/search.h
+++ b/include/search.h
@@ -102,5 +102,7 @@ extern int himport_r(struct hsearch_data *__htab,
 
 /* Flags for himport() / himport_r() */
 #define	H_NOCLEAR	1	/* do not clear hash table before importing */
-
+#define H_ALG_SMALL_BUF	2	/* use another algorithm for small buffers to
+				   calculate hashtable size.
+				 */
 #endif /* search.h */
diff --git a/lib/hashtable.c b/lib/hashtable.c
index b747f1f..82a4d00 100644
--- a/lib/hashtable.c
+++ b/lib/hashtable.c
@@ -636,7 +636,7 @@ int himport_r(struct hsearch_data *htab,
 	}
 
 	/*
-	 * Create new hash table (if needed).  The computation of the hash
+	 * Create new hash table (if needed). The computation of the hash
 	 * table size is based on heuristics: in a sample of some 70+
 	 * existing systems we found an average size of 39+ bytes per entry
 	 * in the environment (for the whole key=value pair). Assuming a
@@ -644,16 +644,25 @@ int himport_r(struct hsearch_data *htab,
 	 * safety margin for any existing environment definitions and still
 	 * allow for more than enough dynamic additions. Note that the
 	 * "size" argument is supposed to give the maximum enviroment size
-	 * (CONFIG_ENV_SIZE).  This heuristics will result in
+	 * (CONFIG_ENV_SIZE). This heuristics will result in
 	 * unreasonably large numbers (and thus memory footprint) for
 	 * big flash environments (>8,000 entries for 64 KB
 	 * envrionment size), so we clip it to a reasonable value
 	 * (which can be overwritten in the board config file if
 	 * needed).
+	 *
+	 * But in some cases it is necessary to have another algorithm to
+	 * get the size of hash table. Especially for extremely small buffers
+	 * there is the flag H_ALG_SMALL_BUF which takes another factor to
+	 * calculate the hash table size.
 	 */
 
 	if (!htab->table) {
-		int nent = size / 8;
+		int nent;
+		if (flag & H_ALG_SMALL_BUF)
+			nent = size / 2;
+		else
+			nent = size / 8;
 
 		if (nent > CONFIG_ENV_MAX_ENTRIES)
 			nent = CONFIG_ENV_MAX_ENTRIES;
-- 
1.7.3

             reply	other threads:[~2010-09-29 19:28 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-29 19:28 Andreas Bießmann [this message]
2010-09-29 20:01 ` [U-Boot] [PATCH] lib/hashtable.c: add algorithm for small buffer import Wolfgang Denk
2010-09-29 20:43   ` Andreas Bießmann
2010-09-29 21:02     ` Wolfgang Denk
2010-09-29 21:43       ` Andreas Bießmann
2010-10-01 20:51 ` [U-Boot] [PATCH v2] lib/hashtable.c: add CONFIG_ENV_MIN_ENTRIES Andreas Bießmann
2010-10-06 20:47   ` Wolfgang Denk
2010-10-08  6:28     ` Andreas Bießmann
2010-10-08  8:15       ` Wolfgang Denk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1285788486-43901-1-git-send-email-andreas.devel@googlemail.com \
    --to=andreas.devel@googlemail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.