Verified Commit a89f6ed3 authored by Marc Vef's avatar Marc Vef
Browse files

Cleanup, Readme, Changelog, Added env variable to LIBGKFS_DIR_CACHE

parent 22e94669
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -8,6 +8,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### New

- Added a directory cache for the file system client to improve `ls -l` type operations by avoiding consecutive stat calls
  ([!194](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/194)).
  - The cache is experimental and thus disabled by default and can be enabled with the env variable `LIBGKFS_DISABLE_DIR_CACHE` set to `ON`.
- Added file system expansion support ([!196](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/196)).
  - Added the tool `gkfs_malleability` to steer start, status, and finalize requests for expansion operations.
  - `-DGKFS_BUILD_TOOLS=ON` must be set for CMake to build the tool.
+3 −0
Original line number Diff line number Diff line
@@ -517,6 +517,9 @@ Client-metrics require the CMake argument `-DGKFS_ENABLE_CLIENT_METRICS=ON` (see
- `LIBGKFS_METRICS_IP_PORT` - Enable flushing to a set ZeroMQ server (replaces `LIBGKFS_METRICS_PATH`).
- `LIBGKFS_PROXY_PID_FILE` - Path to the proxy pid file (when using the GekkoFS proxy).
- `LIBGKFS_NUM_REPL` - Number of replicas for data.
#### Caching
- `LIBGKFS_DENTRY_CACHE` - Enable caching directory entries until closing the directory (default: OFF). 
Improves performance for `ls -l` type operations. Further compile-time settings available at `include/config.hpp`.

### Daemon
#### Logging
+51 −12
Original line number Diff line number Diff line
@@ -44,25 +44,44 @@ namespace gkfs::cache {

namespace dir {

/**
 * @brief Cache entry metadata.
 * The entries are limited to the get_dir_extended RPC.
 */
struct cache_entry {
    gkfs::filemap::FileType file_type;
    uint64_t size;
    time_t ctime;
};

/**
 * @brief Cache for directory entries to accelerate ls -l type operations
 */
class DentryCache {
private:
    // <dir_id, <name, cache_entry>>
    // <dir_id, <name, cache_entry>>: Associate a directory id with its entries
    // containing the directory name and cache entry metadata
    std::unordered_map<uint32_t, std::unordered_map<std::string, cache_entry>>
            entries_;
    // <dir_path, dir_id>
    // <dir_path, dir_id>: Associate a directory path with a unique id
    std::unordered_map<std::string, uint32_t> entry_dir_id_;
    std::mutex mtx_;
    std::hash<std::string> str_hash;
    std::mutex mtx_;                 // Mutex to protect the cache
    std::hash<std::string> str_hash; // hash to generate ids

    /**
     * @brief Generate a unique id for caching a directory
     * @param dir_path
     * @return id
     */
    uint32_t
    gen_dir_id(const std::string& dir_path);

    /**
     * @brief Get the unique id for a directory to retrieve its entries. Creates
     * an id if it does not exist.
     * @param dir_path
     * @return id
     */
    uint32_t
    get_dir_id(const std::string& dir_path);

@@ -71,28 +90,48 @@ public:

    virtual ~DentryCache() = default;

    /**
     * @brief Insert a new entry in the cache
     * @param parent_dir
     * @param name
     * @param value
     */
    void
    insert(const std::string& parent_dir, const std::string name,
           const cache_entry value);
    insert(const std::string& parent_dir, std::string name, cache_entry value);

    /**
     * @brief Get an entry from the cache for a given directory
     * @param parent_dir
     * @param name
     * @return std::optional<cache_entry>
     */
    std::optional<cache_entry>
    get(const std::string& parent_dir, const std::string& name);

    /**
     * @brief Clear the cache for a given directory. Called when a directory is
     * closed
     * @param dir_path
     */
    void
    clear_dir(const std::string& dir_path);

    /**
     * @brief Dump the cache to the log for debugging purposes. Not used in
     * production.
     * @param dir_path
     */
    void
    dump_cache_to_log(const std::string& dir_path);

    /**
     * @brief Clear the entire cache
     */
    void
    clear();
};
} // namespace dir

//// <path<cnt, size>>
// std::unordered_map<std::string, std::pair<size_t, size_t>> size_cache;


} // namespace gkfs::cache

#endif // GKFS_CLIENT_CACHE
+1 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ static constexpr auto METRICS_IP_PORT = ADD_PREFIX("METRICS_IP_PORT");

static constexpr auto NUM_REPL = ADD_PREFIX("NUM_REPL");
static constexpr auto PROXY_PID_FILE = ADD_PREFIX("PROXY_PID_FILE");
static constexpr auto DISABLE_DENTRY_CACHE = ADD_PREFIX("DISABLE_DENTRY_CACHE");
static constexpr auto DENTRY_CACHE = ADD_PREFIX("DENTRY_CACHE");

} // namespace gkfs::env

+1 −4
Original line number Diff line number Diff line
@@ -59,10 +59,7 @@ namespace cache {
namespace dir {
class DentryCache;
}
namespace file {
class WriteSizeCache;
}
}
} // namespace cache

namespace preload {
/*
Loading