Skip to content

Commit

Permalink
[BZ #5381]
Browse files Browse the repository at this point in the history
2009-02-13  Ulrich Drepper  <drepper@redhat.com>
	[BZ #5381]
	* nscd/nscd.h: Remove definitions and declarations for mem_in_flight.
	Change mempool_alloc prototype.
	* nscd/mem.c (gc): Don't handle mem_in_flight.
	(mempool_alloc): Third parameter now only indicates whether this is the
	first call (to allocate data) or not.  If it is, get db rdlock.
	Release it on error.  Don't handle mem_in_flight.
	* nscd/aicache.c (addhstaiX): Mark he parameter as const.
	Adjust third parameter of mempool_alloc calls.
	Nothing to do here in case mempool_alloc fails.
	Avoid local variable shadowing parameter.  No need to get db rdlock
	before calling cache_add.
	* nscd/cache.c (cache_add): Adjust call to mempool_alloc.  There is
	no mem_in_flight array anymore.
	* nscd/connections.c: Remove definition and handling of mem_in_flight.
	* nscd/grpcache.c (cache_addgr): Adjust third parameter of
	mempool_alloc calls.  Mark he parameter as const.  Nothing to do here
	in case mempool_alloc fails. No need to get db rdlock before calling
	cache_add.
	* nscd/hstcache.c (cache_addhst): Likewise.
	* nscd/initgrcache.c (addinitgroupsX): Likewise.
	* nscd/servicescache.c (cache_addserv): Likewise.
	* nscd/pwdcache.c (cache_addpw): Likewise.  Remove some debugging code.
  • Loading branch information
Ulrich Drepper committed Feb 13, 2009
1 parent d8111ea commit 20e498b
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 236 deletions.
26 changes: 26 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
2009-02-13 Ulrich Drepper <drepper@redhat.com>

[BZ #5381]
* nscd/nscd.h: Remove definitions and declarations for mem_in_flight.
Change mempool_alloc prototype.
* nscd/mem.c (gc): Don't handle mem_in_flight.
(mempool_alloc): Third parameter now only indicates whether this is the
first call (to allocate data) or not. If it is, get db rdlock.
Release it on error. Don't handle mem_in_flight.
* nscd/aicache.c (addhstaiX): Mark he parameter as const.
Adjust third parameter of mempool_alloc calls.
Nothing to do here in case mempool_alloc fails.
Avoid local variable shadowing parameter. No need to get db rdlock
before calling cache_add.
* nscd/cache.c (cache_add): Adjust call to mempool_alloc. There is
no mem_in_flight array anymore.
* nscd/connections.c: Remove definition and handling of mem_in_flight.
* nscd/grpcache.c (cache_addgr): Adjust third parameter of
mempool_alloc calls. Mark he parameter as const. Nothing to do here
in case mempool_alloc fails. No need to get db rdlock before calling
cache_add.
* nscd/hstcache.c (cache_addhst): Likewise.
* nscd/initgrcache.c (addinitgroupsX): Likewise.
* nscd/servicescache.c (cache_addserv): Likewise.
* nscd/pwdcache.c (cache_addpw): Likewise. Remove some debugging code.

2009-02-11 Ulrich Drepper <drepper@redhat.com>

* po/lt.po: Update from translation team.
Expand Down
47 changes: 15 additions & 32 deletions nscd/aicache.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Cache handling for host lookup.
Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
Copyright (C) 2004-2008, 2009 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
Expand Down Expand Up @@ -60,7 +60,8 @@ static const ai_response_header notfound =

static void
addhstaiX (struct database_dyn *db, int fd, request_header *req,
void *key, uid_t uid, struct hashentry *he, struct datahead *dh)
void *key, uid_t uid, struct hashentry *const he,
struct datahead *dh)
{
/* Search for the entry matching the key. Please note that we don't
look again in the table whether the dataset is now available. We
Expand Down Expand Up @@ -172,13 +173,8 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,
/* Now we can allocate the data structure. If the TTL of the
entry is reported as zero do not cache the entry at all. */
if (ttl != 0 && he == NULL)
{
dataset = (struct dataset *) mempool_alloc (db, total
+ req->key_len,
IDX_result_data);
if (dataset == NULL)
++db->head->addfailed;
}
dataset = (struct dataset *) mempool_alloc (db, total
+ req->key_len, 1);

if (dataset == NULL)
{
Expand Down Expand Up @@ -300,9 +296,9 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,
}
else
{
struct hostent *he = NULL;
struct hostent *hstent = NULL;
int herrno;
struct hostent he_mem;
struct hostent hstent_mem;
void *addr;
size_t addrlen;
int addrfamily;
Expand All @@ -326,8 +322,8 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,
while (1)
{
rc = __gethostbyaddr2_r (addr, addrlen, addrfamily,
&he_mem, tmpbuf, tmpbuflen,
&he, &herrno, NULL);
&hstent_mem, tmpbuf, tmpbuflen,
&hstent, &herrno, NULL);
if (rc != ERANGE || herrno != NETDB_INTERNAL)
break;
tmpbuf = extend_alloca (tmpbuf, tmpbuflen,
Expand All @@ -336,8 +332,8 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,

if (rc == 0)
{
if (he != NULL)
canon = he->h_name;
if (hstent != NULL)
canon = hstent->h_name;
else
canon = key;
}
Expand All @@ -352,13 +348,8 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,
/* Now we can allocate the data structure. If the TTL of the
entry is reported as zero do not cache the entry at all. */
if (ttl != 0 && he == NULL)
{
dataset = (struct dataset *) mempool_alloc (db, total
+ req->key_len,
IDX_result_data);
if (dataset == NULL)
++db->head->addfailed;
}
dataset = (struct dataset *) mempool_alloc (db, total
+ req->key_len, 1);

if (dataset == NULL)
{
Expand Down Expand Up @@ -436,7 +427,7 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,
appropriate memory and copy it. */
struct dataset *newp
= (struct dataset *) mempool_alloc (db, total + req->key_len,
IDX_result_data);
1);
if (__builtin_expect (newp != NULL, 1))
{
/* Adjust pointer into the memory block. */
Expand All @@ -445,8 +436,6 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,
dataset = memcpy (newp, dataset, total + req->key_len);
alloca_used = false;
}
else
++db->head->addfailed;

/* Mark the old record as obsolete. */
dh->usable = false;
Expand Down Expand Up @@ -515,8 +504,7 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,
if (fd != -1)
TEMP_FAILURE_RETRY (send (fd, &notfound, total, MSG_NOSIGNAL));

dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len,
IDX_result_data);
dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len, 1);
/* If we cannot permanently store the result, so be it. */
if (dataset != NULL)
{
Expand All @@ -535,8 +523,6 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,
/* Copy the key data. */
key_copy = memcpy (dataset->strdata, key, req->key_len);
}
else
++db->head->addfailed;
}

out:
Expand All @@ -554,9 +540,6 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,
MS_ASYNC);
}

/* Now get the lock to safely insert the records. */
pthread_rwlock_rdlock (&db->lock);

(void) cache_add (req->type, key_copy, req->key_len, &dataset->head,
true, db, uid, he == NULL);

Expand Down
14 changes: 2 additions & 12 deletions nscd/cache.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 1998, 1999, 2003-2007, 2008 Free Software Foundation, Inc.
/* Copyright (c) 1998, 1999, 2003-2008, 2009 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
Expand Down Expand Up @@ -155,21 +155,15 @@ cache_add (int type, const void *key, size_t len, struct datahead *packet,
unsigned long int hash = __nis_hash (key, len) % table->head->module;
struct hashentry *newp;

newp = mempool_alloc (table, sizeof (struct hashentry), IDX_record_data);
newp = mempool_alloc (table, sizeof (struct hashentry), 0);
/* If we cannot allocate memory, just do not do anything. */
if (newp == NULL)
{
++table->head->addfailed;

/* If necessary mark the entry as unusable so that lookups will
not use it. */
if (first)
packet->usable = false;

/* Mark the in-flight memory as unused. */
for (enum in_flight idx = 0; idx < IDX_record_data; ++idx)
mem_in_flight.block[idx].dbidx = -1;

return -1;
}

Expand Down Expand Up @@ -234,10 +228,6 @@ cache_add (int type, const void *key, size_t len, struct datahead *packet,
pthread_cond_signal (&table->prune_cond);
}

/* Mark the in-flight memory as unused. */
for (enum in_flight idx = 0; idx < IDX_last; ++idx)
mem_in_flight.block[idx].dbidx = -1;

return 0;
}

Expand Down
15 changes: 0 additions & 15 deletions nscd/connections.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,6 @@ static int have_accept4;
/* Number of times clients had to wait. */
unsigned long int client_queued;

/* Data structure for recording in-flight memory allocation. */
__thread struct mem_in_flight mem_in_flight attribute_tls_model_ie;
/* Global list of the mem_in_flight variables of all the threads. */
struct mem_in_flight *mem_in_flight_list;


ssize_t
writeall (int fd, const void *buf, size_t len)
Expand Down Expand Up @@ -1584,16 +1579,6 @@ nscd_run_worker (void *p)
{
char buf[256];

/* Initialize the memory-in-flight list. */
for (enum in_flight idx = 0; idx < IDX_last; ++idx)
mem_in_flight.block[idx].dbidx = -1;
/* And queue this threads structure. */
do
mem_in_flight.next = mem_in_flight_list;
while (atomic_compare_and_exchange_bool_acq (&mem_in_flight_list,
&mem_in_flight,
mem_in_flight.next) != 0);

/* Initial locking. */
pthread_mutex_lock (&readylist_lock);

Expand Down
26 changes: 5 additions & 21 deletions nscd/grpcache.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Cache handling for group lookup.
Copyright (C) 1998-2005, 2006, 2007, 2008 Free Software Foundation, Inc.
Copyright (C) 1998-2008, 2009 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
Expand Down Expand Up @@ -74,7 +74,7 @@ static const gr_response_header notfound =
static void
cache_addgr (struct database_dyn *db, int fd, request_header *req,
const void *key, struct group *grp, uid_t owner,
struct hashentry *he, struct datahead *dh, int errval)
struct hashentry *const he, struct datahead *dh, int errval)
{
ssize_t total;
ssize_t written;
Expand Down Expand Up @@ -114,7 +114,7 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req,
MSG_NOSIGNAL));

dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len,
IDX_result_data);
1);
/* If we cannot permanently store the result, so be it. */
if (dataset != NULL)
{
Expand Down Expand Up @@ -143,9 +143,6 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req,
+ sizeof (struct dataset) + req->key_len, MS_ASYNC);
}

/* Now get the lock to safely insert the records. */
pthread_rwlock_rdlock (&db->lock);

(void) cache_add (req->type, &dataset->strdata, req->key_len,
&dataset->head, true, db, owner, he == NULL);

Expand All @@ -155,8 +152,6 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req,
if (dh != NULL)
dh->usable = false;
}
else
++db->head->addfailed;
}
}
else
Expand Down Expand Up @@ -202,12 +197,7 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req,
dataset = NULL;

if (he == NULL)
{
dataset = (struct dataset *) mempool_alloc (db, total + n,
IDX_result_data);
if (dataset == NULL)
++db->head->addfailed;
}
dataset = (struct dataset *) mempool_alloc (db, total + n, 1);

if (dataset == NULL)
{
Expand Down Expand Up @@ -277,8 +267,7 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req,
/* We have to create a new record. Just allocate
appropriate memory and copy it. */
struct dataset *newp
= (struct dataset *) mempool_alloc (db, total + n,
IDX_result_data);
= (struct dataset *) mempool_alloc (db, total + n, 1);
if (newp != NULL)
{
/* Adjust pointers into the memory block. */
Expand All @@ -289,8 +278,6 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req,
dataset = memcpy (newp, dataset, total + n);
alloca_used = false;
}
else
++db->head->addfailed;

/* Mark the old record as obsolete. */
dh->usable = false;
Expand Down Expand Up @@ -343,9 +330,6 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req,
MS_ASYNC);
}

/* Now get the lock to safely insert the records. */
pthread_rwlock_rdlock (&db->lock);

/* NB: in the following code we always must add the entry
marked with FIRST first. Otherwise we end up with
dangling "pointers" in case a latter hash entry cannot be
Expand Down
Loading

0 comments on commit 20e498b

Please sign in to comment.