nfs-ganesha 1.4

cache_inode_lru.h

Go to the documentation of this file.
00001 /*
00002  * vim:expandtab:shiftwidth=8:tabstop=8:
00003  *
00004  * Copyright (C) 2012, The Linux Box Corporation
00005  * Contributor : Matt Benjamin <matt@linuxbox.com>
00006  *
00007  * Some portions Copyright CEA/DAM/DIF  (2008)
00008  * contributeur : Philippe DENIEL   philippe.deniel@cea.fr
00009  *                Thomas LEIBOVICI  thomas.leibovici@cea.fr
00010  *
00011  *
00012  * This program is free software; you can redistribute it and/or
00013  * modify it under the terms of the GNU Lesser General Public
00014  * License as published by the Free Software Foundation; either
00015  * version 3 of the License, or (at your option) any later version.
00016  *
00017  * This program is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020  * Lesser General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU Lesser General Public
00023  * License along with this library; if not, write to the Free Software
00024  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00025  *
00026  * -------------
00027  */
00028 
00029 #ifndef _CACHE_INODE_LRU_H
00030 #define _CACHE_INODE_LRU_H
00031 
00032 #ifdef HAVE_CONFIG_H
00033 #include "config.h"
00034 #endif                          /* HAVE_CONFIG_H */
00035 
00036 #ifdef _SOLARIS
00037 #include "solaris_port.h"
00038 #endif                          /* _SOLARIS */
00039 
00040 #include "log.h"
00041 #include "cache_inode.h"
00042 
00069 struct lru_state
00070 {
00071      uint64_t entries_hiwat;
00072      uint64_t entries_lowat;
00073      uint32_t fds_system_imposed;
00074      uint32_t fds_hard_limit;
00075      uint32_t fds_hiwat;
00076      uint32_t fds_lowat;
00077      /* This is the actual counter of 'futile' attempts at reaping
00078         made  in a given time period.  When it reaches the futility
00079         count, we turn off caching of file descriptors. */
00080      uint32_t futility;
00081      uint32_t per_lane_work;
00082      uint32_t biggest_window;
00083      uint32_t flags;
00084      uint64_t last_count;
00085      uint64_t threadwait;
00086      bool_t caching_fds;
00087 };
00088 
00089 extern struct lru_state lru_state;
00090 
00091 /* Flags for functions in the LRU package */
00092 
00096 static const uint32_t LRU_FLAG_NONE = 0x0000;
00097 
00101 static const uint32_t LRU_ENTRY_PINNED = 0x0001;
00102 
00106 static const uint32_t LRU_ENTRY_L2 = 0x0002;
00107 
00111 static const uint32_t LRU_ENTRY_CONDEMNED = 0x0004;
00112 
00118 static const uint32_t LRU_ENTRY_UNPINNABLE = 0x0008;
00119 
00124 static const uint32_t LRU_ENTRY_KILLED = 0x0010;
00125 
00129 static const uint32_t LRU_REQ_INITIAL = 0x0020;
00130 
00134 static const uint32_t LRU_REQ_SCAN = 0x0040;
00135 
00139 static const uint32_t LRU_FLAG_LOCKED = 0x0080;
00140 
00141 /* The minimum reference count for a cache entry not being recycled. */
00142 
00143 static const int32_t LRU_SENTINEL_REFCOUNT = 1;
00144 
00145 static const uint32_t LRU_STATE_NONE = 0x00;
00146 static const uint32_t LRU_STATE_RECLAIMING = 0x01;
00147 
00148 static const uint32_t LRU_SLEEPING = 0x00000001;
00149 static const uint32_t LRU_SHUTDOWN = 0x00000002;
00150 
00151 
00152 /* The number of lanes comprising a logical queue.  This must be
00153    prime. */
00154 
00155 #define LRU_N_Q_LANES 7
00156 
00157 static const uint32_t LRU_NO_LANE = ~0;
00158 
00159 extern void cache_inode_lru_pkginit(void);
00160 extern void cache_inode_lru_pkgshutdown(void);
00161 
00162 extern size_t open_fd_count;
00163 
00164 extern struct cache_entry_t *cache_inode_lru_get(cache_inode_status_t *status,
00165                                                  uint32_t flags);
00166 extern cache_inode_status_t cache_inode_lru_ref(
00167      cache_entry_t *entry,
00168      uint32_t flags) __attribute__((warn_unused_result));
00169 extern void cache_inode_lru_kill(cache_entry_t *entry);
00170 extern void cache_inode_lru_unref(cache_entry_t *entry,
00171                                   uint32_t flags);
00172 extern void lru_wake_thread(uint32_t flags);
00173 extern cache_inode_status_t cache_inode_inc_pin_ref(cache_entry_t *entry);
00174 extern void cache_inode_unpinnable(cache_entry_t *entry);
00175 extern cache_inode_status_t cache_inode_dec_pin_ref(cache_entry_t *entry);
00176 
00183 static inline bool_t
00184 cache_inode_lru_fds_available(void)
00185 {
00186      if (open_fd_count >= lru_state.fds_hard_limit) {
00187           LogCrit(COMPONENT_CACHE_INODE_LRU,
00188                   "FD Hard Limit Exceeded.  Disabling FD Cache and waking"
00189                   " LRU thread.");
00190           lru_state.caching_fds = FALSE;
00191           lru_wake_thread(LRU_FLAG_NONE);
00192           return FALSE;
00193      }
00194      if (open_fd_count >= lru_state.fds_hiwat) {
00195           LogInfo(COMPONENT_CACHE_INODE_LRU,
00196                   "FDs above high water mark, waking LRU thread.");
00197           lru_wake_thread(LRU_FLAG_NONE);
00198      }
00199 
00200      return TRUE;
00201 }
00202 
00207 static inline bool_t
00208 cache_inode_lru_caching_fds(void)
00209 {
00210      return lru_state.caching_fds;
00211 }
00212 #endif /* _CACHE_INODE_LRU_H */