Skip to content

Support explicitly call GC during idle times on SPIFFS #2870

Closed
@joelucid

Description

@joelucid

SPIFFS writes get very slow when there are no free blocks available. Therefore it makes sense to clear blocks in the background when the application is idle. The following patch exposes a gc() call which in turn calls SPIFFS_gc_quick which serves exactly this purpose.

diff --git a/cores/esp8266/FS.cpp b/cores/esp8266/FS.cpp
index 6ae11e1..6bd359c 100644
--- a/cores/esp8266/FS.cpp
+++ b/cores/esp8266/FS.cpp
@@ -173,6 +173,13 @@ void FS::end() {
}
}

+bool FS::gc() {

  • if (!_impl) {
  •    return false;
    
  • }
  • return _impl->gc();
    +}

bool FS::format() {
if (!_impl) {
return false;
diff --git a/cores/esp8266/FS.h b/cores/esp8266/FS.h
index 79620f9..ce42ccf 100644
--- a/cores/esp8266/FS.h
+++ b/cores/esp8266/FS.h
@@ -125,6 +125,7 @@ public:
bool rename(const char* pathFrom, const char* pathTo);
bool rename(const String& pathFrom, const String& pathTo);

  • bool gc();
    protected:
    FSImplPtr _impl;
    };
    diff --git a/cores/esp8266/FSImpl.h b/cores/esp8266/FSImpl.h
    index e5694b5..242811c 100644
    --- a/cores/esp8266/FSImpl.h
    +++ b/cores/esp8266/FSImpl.h
    @@ -71,6 +71,8 @@ public:
    virtual DirImplPtr openDir(const char* path) = 0;
    virtual bool rename(const char* pathFrom, const char* pathTo) = 0;
    virtual bool remove(const char* path) = 0;
  • virtual bool gc() = 0;

};

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SPIFFS)
diff --git a/cores/esp8266/spiffs_api.h b/cores/esp8266/spiffs_api.h
index f98df11..f42e43e 100644
--- a/cores/esp8266/spiffs_api.h
+++ b/cores/esp8266/spiffs_api.h
@@ -165,6 +165,12 @@ public:
return true;
}

  • bool gc() override {
  •   return SPIFFS_gc_quick( &_fs, 0 ) == SPIFFS_OK;
    
  • }

Metadata

Metadata

Assignees

No one assigned

    Labels

    waiting for feedbackWaiting on additional info. If it's not received, the issue may be closed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions