Diff for /libaitsess/src/Attic/mem.c between versions 1.1.2.3 and 1.1.2.6

version 1.1.2.3, 2012/02/27 23:57:12 version 1.1.2.6, 2012/02/28 09:28:00
Line 49  SUCH DAMAGE. Line 49  SUCH DAMAGE.
 /*  /*
  * mpool_init() - Init memory pool   * mpool_init() - Init memory pool
  *   *
    * @maxmem = If !=0 set maximum memory quota
  * return: =NULL error or !=NULL new allocated pool   * return: =NULL error or !=NULL new allocated pool
  */   */
 mpool_t *  mpool_t *
mpool_init(void)mpool_init(u_long maxmem)
 {  {
         mpool_t *mp;          mpool_t *mp;
         register int i;          register int i;
Line 66  mpool_init(void) Line 67  mpool_init(void)
   
         pthread_mutex_init(&mp->pool_mtx, NULL);          pthread_mutex_init(&mp->pool_mtx, NULL);
   
           mp->pool_quota.max = maxmem;
   
         mpool_lock(mp);          mpool_lock(mp);
         for (i = 0; i < MEM_BUCKETS; i++) {          for (i = 0; i < MEM_BUCKETS; i++) {
                 TAILQ_INIT(&mp->pool_active[i]);                  TAILQ_INIT(&mp->pool_active[i]);
Line 235  mpool_malloc(mpool_t * __restrict mp, u_int size, cons Line 238  mpool_malloc(mpool_t * __restrict mp, u_int size, cons
  * return: -1 error or 0 ok   * return: -1 error or 0 ok
  */   */
 int  int
mpool_purge(mpool_t * __restrict mp, int atmost)mpool_purge(mpool_t * __restrict mp, u_int atmost)
 {  {
        register int i, cx = 0;        register int i, cx;
         struct tagAlloc *m, *tmp;          struct tagAlloc *m, *tmp;
   
         if (!mp) {          if (!mp) {
Line 247  mpool_purge(mpool_t * __restrict mp, int atmost) Line 250  mpool_purge(mpool_t * __restrict mp, int atmost)
   
         mpool_lock(mp);          mpool_lock(mp);
   
        for (i = 0; i < MEM_BUCKETS; i++) {        for (i = cx = 0; i < MEM_BUCKETS; cx = 0, i++) {
                 TAILQ_FOREACH_SAFE(m, &mp->pool_inactive[i], alloc_node, tmp) {                  TAILQ_FOREACH_SAFE(m, &mp->pool_inactive[i], alloc_node, tmp) {
                        /* count barrier for purge */                        /* barrier for purge */
                        if (cx++ < atmost)                        if (cx < atmost) {
                                 cx++;
                                 continue;                                  continue;
                           }
   
                         TAILQ_REMOVE(&mp->pool_inactive[i], m, alloc_node);                          TAILQ_REMOVE(&mp->pool_inactive[i], m, alloc_node);
                         /* statistics */                          /* statistics */
Line 296  mpool_free(mpool_t * __restrict mp, void * __restrict  Line 301  mpool_free(mpool_t * __restrict mp, void * __restrict 
                 sess_SetErr(EFAULT, "Corrupted memory address");                  sess_SetErr(EFAULT, "Corrupted memory address");
                 return -2;                  return -2;
         } else          } else
                idx = BucketIndex(((u_int*)data)[-2]);                idx = BucketIndex(((u_int*)data)[-2] * sizeof(u_int));
   
         mpool_lock(mp);          mpool_lock(mp);
         TAILQ_FOREACH(m, &mp->pool_active[idx], alloc_node)          TAILQ_FOREACH(m, &mp->pool_active[idx], alloc_node)
Line 438  mpool_chkaddr(void * __restrict data) Line 443  mpool_chkaddr(void * __restrict data)
                 return 1;                  return 1;
         /* data address is ok! */          /* data address is ok! */
         return 0;          return 0;
   }
   
   /*
    * mpool_setquota() - Change maximum memory quota
    *
    * @mp = Memory pool
    * @maxmem = New max quota size
    * return: old maximum memory quota size
    */
   inline u_long
   mpool_setquota(mpool_t * __restrict mp, u_long maxmem)
   {
           u_long ret;
   
           if (!mp)
                   return 0;
   
           ret = mp->pool_quota.max;
           mp->pool_quota.max = maxmem;
   
           /* if new max quota is less then current allocated memory, 
            *      try to purge memory cache blocks
            */
           if (mp->pool_quota.max < mp->pool_quota.curr)
                   mpool_purge(mp, 0);
   
           return ret;
   }
   
   /* ----------------------------------------------------------- */
   
   /*
    * mpool_statistics() - Dump statistics from memory pool buckets
    *
    * @mp = Memory pool
    * @cb = Export statistics to callback
    * return: none
    */
   void
   mpool_statistics(mpool_t * __restrict mp, mpool_stat_cb cb)
   {
           struct tagAlloc *m;
           register int i, act, inact;
   
           if (!mp || !cb)
                   return;
   
           for (i = act = inact = 0; i < MEM_BUCKETS; act = inact = 0, i++) {
                   TAILQ_FOREACH(m, &mp->pool_active[i], alloc_node)
                           act++;
                   TAILQ_FOREACH(m, &mp->pool_inactive[i], alloc_node)
                           inact++;
   
                   cb(1 << (i + MEM_MIN_BUCKET), act, inact);
           }
 }  }

Removed from v.1.1.2.3  
changed lines
  Added in v.1.1.2.6


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>