Print this page
5045 use atomic_{inc,dec}_* instead of atomic_add_*


 237         (hp)->hash_next = (ncp); \
 238 }
 239 
 240 /*
 241  * Remove entry from hash queue
 242  */
 243 #define nc_rmhash(ncp) \
 244 { \
 245         (ncp)->hash_prev->hash_next = (ncp)->hash_next; \
 246         (ncp)->hash_next->hash_prev = (ncp)->hash_prev; \
 247         (ncp)->hash_prev = NULL; \
 248         (ncp)->hash_next = NULL; \
 249 }
 250 
 251 /*
 252  * Free an entry.
 253  */
 254 #define dnlc_free(ncp) \
 255 { \
 256         kmem_free((ncp), sizeof (ncache_t) + (ncp)->namlen); \
 257         atomic_add_32(&dnlc_nentries, -1); \
 258 }
 259 
 260 
 261 /*
 262  * Cached directory info.
 263  * ======================
 264  */
 265 
 266 /*
 267  * Cached directory free space hash function.
 268  * Needs the free space handle and the dcp to get the hash table size
 269  * Returns the hash index.
 270  */
 271 #define DDFHASH(handle, dcp) ((handle >> 2) & (dcp)->dc_fhash_mask)
 272 
 273 /*
 274  * Cached directory name entry hash function.
 275  * Uses the name and returns in the input arguments the hash and the name
 276  * length.
 277  */


1007  * is short then just return NULL. If we're over ncsize then kick off a
1008  * thread to free some in use entries down to dnlc_nentries_low_water.
1009  * Caller must initialise all fields except namlen.
1010  * Component names are defined to be less than MAXNAMELEN
1011  * which includes a null.
1012  */
1013 static ncache_t *
1014 dnlc_get(uchar_t namlen)
1015 {
1016         ncache_t *ncp;
1017 
1018         if (dnlc_nentries > dnlc_max_nentries) {
1019                 dnlc_max_nentries_cnt++; /* keep a statistic */
1020                 return (NULL);
1021         }
1022         ncp = kmem_alloc(sizeof (ncache_t) + namlen, KM_NOSLEEP);
1023         if (ncp == NULL) {
1024                 return (NULL);
1025         }
1026         ncp->namlen = namlen;
1027         atomic_add_32(&dnlc_nentries, 1);
1028         dnlc_reduce_cache(NULL);
1029         return (ncp);
1030 }
1031 
1032 /*
1033  * Taskq routine to free up name cache entries to reduce the
1034  * cache size to the low water mark if "reduce_percent" is not provided.
1035  * If "reduce_percent" is provided, reduce cache size by
1036  * (ncsize_onepercent * reduce_percent).
1037  */
1038 /*ARGSUSED*/
1039 static void
1040 do_dnlc_reduce_cache(void *reduce_percent)
1041 {
1042         nc_hash_t *hp = dnlc_free_rotor, *start_hp = hp;
1043         vnode_t *vp;
1044         ncache_t *ncp;
1045         int cnt;
1046         uint_t low_water = dnlc_nentries_low_water;
1047 




 237         (hp)->hash_next = (ncp); \
 238 }
 239 
 240 /*
 241  * Remove entry from hash queue
 242  */
 243 #define nc_rmhash(ncp) \
 244 { \
 245         (ncp)->hash_prev->hash_next = (ncp)->hash_next; \
 246         (ncp)->hash_next->hash_prev = (ncp)->hash_prev; \
 247         (ncp)->hash_prev = NULL; \
 248         (ncp)->hash_next = NULL; \
 249 }
 250 
 251 /*
 252  * Free an entry.
 253  */
 254 #define dnlc_free(ncp) \
 255 { \
 256         kmem_free((ncp), sizeof (ncache_t) + (ncp)->namlen); \
 257         atomic_dec_32(&dnlc_nentries); \
 258 }
 259 
 260 
 261 /*
 262  * Cached directory info.
 263  * ======================
 264  */
 265 
 266 /*
 267  * Cached directory free space hash function.
 268  * Needs the free space handle and the dcp to get the hash table size
 269  * Returns the hash index.
 270  */
 271 #define DDFHASH(handle, dcp) ((handle >> 2) & (dcp)->dc_fhash_mask)
 272 
 273 /*
 274  * Cached directory name entry hash function.
 275  * Uses the name and returns in the input arguments the hash and the name
 276  * length.
 277  */


1007  * is short then just return NULL. If we're over ncsize then kick off a
1008  * thread to free some in use entries down to dnlc_nentries_low_water.
1009  * Caller must initialise all fields except namlen.
1010  * Component names are defined to be less than MAXNAMELEN
1011  * which includes a null.
1012  */
1013 static ncache_t *
1014 dnlc_get(uchar_t namlen)
1015 {
1016         ncache_t *ncp;
1017 
1018         if (dnlc_nentries > dnlc_max_nentries) {
1019                 dnlc_max_nentries_cnt++; /* keep a statistic */
1020                 return (NULL);
1021         }
1022         ncp = kmem_alloc(sizeof (ncache_t) + namlen, KM_NOSLEEP);
1023         if (ncp == NULL) {
1024                 return (NULL);
1025         }
1026         ncp->namlen = namlen;
1027         atomic_inc_32(&dnlc_nentries);
1028         dnlc_reduce_cache(NULL);
1029         return (ncp);
1030 }
1031 
1032 /*
1033  * Taskq routine to free up name cache entries to reduce the
1034  * cache size to the low water mark if "reduce_percent" is not provided.
1035  * If "reduce_percent" is provided, reduce cache size by
1036  * (ncsize_onepercent * reduce_percent).
1037  */
1038 /*ARGSUSED*/
1039 static void
1040 do_dnlc_reduce_cache(void *reduce_percent)
1041 {
1042         nc_hash_t *hp = dnlc_free_rotor, *start_hp = hp;
1043         vnode_t *vp;
1044         ncache_t *ncp;
1045         int cnt;
1046         uint_t low_water = dnlc_nentries_low_water;
1047