Skip to content

Total and free size of filesystem reported in sites doesn't match actual values #341

Closed

Description

@fluiddot

Quick summary

The total and free size of filesystem reported in sites doesn't match the ones from the machine. This can lead to issues in plugins that rely on these values.

Steps to reproduce

  1. Open the app.
  2. Create/start a site.
  3. Edit the wp-config-php file of the site and add the following code at the bottom:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
error_log("Disk Free Space: " . print_r(disk_free_space('/'), true));
error_log("Disk Total Space: " . print_r(disk_total_space('/'), true));
  1. Navigate to the site.
  2. Open the logs file located in <SITE_PATH>/wp-content/debug.log.
  3. Observe that disk space values don't match the ones from the machine. E.g.:
    • Disk Free Space: 2048000000 (2GB)
    • Disk Total Space: 4096000000 (4GB)

What you expected to happen

The size of filesystem matches the values of the machine.

What actually happened

The size of the filesystem doesn't match the values of the machine.

Impact

All

Available workarounds?

No but the app is still usable

Platform

Mac Silicon

Logs or notes

No response

Activity

  1. fluiddot commented on Jul 4, 2024

    @fluiddot
    ContributorAuthor

    I explored the Playground code and noticed that the free and total values are fixed values. Let me briefly explain the references I found while debugging this:

    Free space

    Total space

    Filesystem values

    • The values used in the above calculations are obtained from NODEFS.statfs function which returns value is represented with the class statfs.
    • The implementation of this function can be seen here for the PHP version 8.1:
    HEAP32[(((buf) + (4)) >> 2)] = 4096;
    HEAP32[(((buf) + (40)) >> 2)] = 4096;   // f_bsize - Block size
    HEAP32[(((buf) + (8)) >> 2)] = 1e6;     // f_blocks - Total blocks
    HEAP32[(((buf) + (12)) >> 2)] = 5e5;    // f_bfree - Free blocks (not used in calculation)
    HEAP32[(((buf) + (16)) >> 2)] = 5e5;    // f_bavail - Available blocks
    HEAP32[(((buf) + (20)) >> 2)] = FS.nextInode;
    HEAP32[(((buf) + (24)) >> 2)] = 1e6;
    HEAP32[(((buf) + (28)) >> 2)] = 42;
    HEAP32[(((buf) + (44)) >> 2)] = 2;
    HEAP32[(((buf) + (36)) >> 2)] = 255;
    
    • As you can see, the values are fixed so as outlined in the issue, they don't reflect the actual total and free size of the file system. Here are the results:
      • Total available size: 4096 * 1^6 = 4.096.000.000 (4GB).
      • Total free size: 4096 * 5^5 = 2.048.000.000 (2GB).

    As a next step, we'd need to explore if this is set by Playground when compiling PHP source. Or if on the other hand, this is set by Emscripten.

    UPDATE: As shared in #341 (comment), the values are set by Emscripten here.

  2. wojtekn commented on Jul 8, 2024

    @wojtekn
    Contributor
  3. jeroenpf commented on Aug 22, 2024

    @jeroenpf
    Contributor

    @fluiddot I went a bit deeper and it looks like these values are set in emscripten:

    https://github.com/emscripten-core/emscripten/blob/7f8a05dd4e37cbd7ffde6d624f91fd545f7b52e3/src/library_syscall.js#L804
    https://github.com/emscripten-core/emscripten/blob/7f8a05dd4e37cbd7ffde6d624f91fd545f7b52e3/system/lib/wasmfs/syscalls.cpp#L1530

    With the various types of available VFS's it could be complicated to give a meaningful output of statfs which is probably why they settled on a stub with, as they call it, sane values.

    @adamziel Do you have any ideas of how we can proceed with this? I'm happy to have a deeper look but I'm out of my depth here so some pointers would be very welcome :-)

  4. adamziel commented on Sep 11, 2024

    @adamziel
    Contributor

    It seems like it's reporting the heap size, not the disk size. The 2GB comes up on this Emscripten doc page but not directly tied with this problem.

    The original commit introducing these constants in Emscripten says:

    // None of the constants here are true. We're just returning safe and
    // sane values.

    It sounds like this could be solved with an Emscripten PR that delegates the statfs call to the FS object which in turn delegates it to the underlying FS backend like NODEFS and falls back to the hardcoded constants if that backend doesn't support the statfs call. Opening an Emscripten issue first would be useful to validate the approach with the team.

  5. 13 remaining items

  6. bgrgicak commented on Feb 17, 2025

    @bgrgicak
    Contributor

    We update Emscripten in Playground.
    To resolve this issue, Studio will need to update Playground from our self-hosted packages.

    Also, the Playground still doesn't support browser cookies, so if Studio want's to update Playground, it will need to apply the cookie patch.

  7. removed their assignment
    on Feb 17, 2025
  8. bgrgicak commented on Mar 3, 2025

    @bgrgicak
    Contributor

    The Emscripten update didn't fix this issue. Related thread #959 (comment)

  9. bgrgicak commented on Mar 25, 2025

    @bgrgicak
    Contributor

    @wojtekn is there a specific example that we could use to test our fix?

  10. wojtekn commented on Mar 25, 2025

    @wojtekn
    Contributor

    @bgrgicak I don't know any specific example other than steps shown in the issue description.

  11. moved this from Needs Reply to Done in Playground Boardon Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions