aboutsummaryrefslogtreecommitdiff
path: root/nscd/mem.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2009-02-13 20:36:37 +0000
committerUlrich Drepper <drepper@redhat.com>2009-02-13 20:36:37 +0000
commit20e498bdb0608ae6ca431cb49d66d2ed6f5304f5 (patch)
tree55ff7b1aeaaefd6e82c5370ed0fdd91673cd92e5 /nscd/mem.c
parentd8111eac5422eded7a8680ca198eb5d149a38550 (diff)
downloadglibc-20e498bdb0608ae6ca431cb49d66d2ed6f5304f5.zip
glibc-20e498bdb0608ae6ca431cb49d66d2ed6f5304f5.tar.gz
glibc-20e498bdb0608ae6ca431cb49d66d2ed6f5304f5.tar.bz2
[BZ #5381]
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.
Diffstat (limited to 'nscd/mem.c')
-rw-r--r--nscd/mem.c42
1 files changed, 9 insertions, 33 deletions
diff --git a/nscd/mem.c b/nscd/mem.c
index 7f3ea06..fcea6db 100644
--- a/nscd/mem.c
+++ b/nscd/mem.c
@@ -197,32 +197,6 @@ gc (struct database_dyn *db)
}
assert (cnt == db->head->nentries);
- /* Go through the list of in-flight memory blocks. */
- struct mem_in_flight *mrunp = mem_in_flight_list;
- while (mrunp != NULL)
- {
- /* NB: There can be no race between this test and another thread
- setting the field to the index we are looking for because
- this would require the other thread to also have the memlock
- for the database.
-
- NB2: we do not have to look at latter blocks (higher indices) if
- earlier blocks are not in flight. They are always allocated in
- sequence. */
- for (enum in_flight idx = IDX_result_data;
- idx < IDX_last && mrunp->block[idx].dbidx == db - dbs; ++idx)
- {
- assert (mrunp->block[idx].blockoff >= 0);
- assert (mrunp->block[idx].blocklen < db->memsize);
- assert (mrunp->block[idx].blockoff
- + mrunp->block[0].blocklen <= db->memsize);
- markrange (mark, mrunp->block[idx].blockoff,
- mrunp->block[idx].blocklen);
- }
-
- mrunp = mrunp->next;
- }
-
/* Sort the entries by the addresses of the referenced data. All
the entries pointing to the same DATAHEAD object will have the
same key. Stability of the sorting is unimportant. */
@@ -540,13 +514,16 @@ gc (struct database_dyn *db)
void *
-mempool_alloc (struct database_dyn *db, size_t len, enum in_flight idx)
+mempool_alloc (struct database_dyn *db, size_t len, int data_alloc)
{
/* Make sure LEN is a multiple of our maximum alignment so we can
keep track of used memory is multiples of this alignment value. */
if ((len & BLOCK_ALIGN_M1) != 0)
len += BLOCK_ALIGN - (len & BLOCK_ALIGN_M1);
+ if (data_alloc)
+ pthread_rwlock_rdlock (&db->lock);
+
pthread_mutex_lock (&db->memlock);
assert ((db->head->first_free & BLOCK_ALIGN_M1) == 0);
@@ -589,6 +566,9 @@ mempool_alloc (struct database_dyn *db, size_t len, enum in_flight idx)
}
}
+ if (data_alloc)
+ pthread_rwlock_unlock (&db->lock);
+
if (! db->last_alloc_failed)
{
dbg_log (_("no more memory for database '%s'"), dbnames[db - dbs]);
@@ -596,17 +576,13 @@ mempool_alloc (struct database_dyn *db, size_t len, enum in_flight idx)
db->last_alloc_failed = true;
}
+ ++db->head->addfailed;
+
/* No luck. */
res = NULL;
}
else
{
- /* Remember that we have allocated this memory. */
- assert (idx >= 0 && idx < IDX_last);
- mem_in_flight.block[idx].dbidx = db - dbs;
- mem_in_flight.block[idx].blocklen = len;
- mem_in_flight.block[idx].blockoff = db->head->first_free;
-
db->head->first_free += len;
db->last_alloc_failed = false;