This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit a05b1f8cb8846db29f19bfd24e15877b1bb28b10
Author: zhaoxingyu1 <[email protected]>
AuthorDate: Fri Nov 21 15:35:13 2025 +0800

    vfs: change fs_heap to lib_tempbuffer
    
    The scratch buffers under fs/ are freed before the call returns.  Take
    them from the global temp buffer pool instead of fs_heap: allocation
    becomes a bitmap lookup, and the transient traffic no longer fragments
    fs_heap.
    
    Signed-off-by: zhaoxingyu1 <[email protected]>
---
 fs/driver/fs_blockproxy.c  | 1 -
 fs/inode/fs_foreachinode.c | 5 ++---
 fs/nxffs/nxffs_dump.c      | 7 +++----
 fs/partition/fs_gpt.c      | 4 ++--
 fs/partition/fs_mbr.c      | 9 ++++-----
 fs/partition/fs_ptable.c   | 5 ++---
 fs/partition/fs_txtable.c  | 9 ++++-----
 fs/spiffs/src/spiffs_vfs.c | 6 +++---
 fs/unionfs/fs_unionfs.c    | 7 +++++--
 fs/vfs/fs_select.c         | 7 ++++---
 fs/vfs/fs_sendfile.c       | 6 +++---
 11 files changed, 32 insertions(+), 34 deletions(-)

diff --git a/fs/driver/fs_blockproxy.c b/fs/driver/fs_blockproxy.c
index da718a5fe87..e72bf4a8b50 100644
--- a/fs/driver/fs_blockproxy.c
+++ b/fs/driver/fs_blockproxy.c
@@ -44,7 +44,6 @@
 #include <nuttx/mutex.h>
 
 #include "driver.h"
-#include "fs_heap.h"
 
 #if !defined(CONFIG_DISABLE_MOUNTPOINT) && \
     !defined(CONFIG_DISABLE_PSEUDOFS_OPERATIONS)
diff --git a/fs/inode/fs_foreachinode.c b/fs/inode/fs_foreachinode.c
index d456dcfd695..fafa8f86d09 100644
--- a/fs/inode/fs_foreachinode.c
+++ b/fs/inode/fs_foreachinode.c
@@ -35,7 +35,6 @@
 #include <nuttx/fs/fs.h>
 
 #include "inode/inode.h"
-#include "fs_heap.h"
 
 /****************************************************************************
  * Pre-processor Definitions
@@ -173,7 +172,7 @@ int foreach_inode(foreach_inode_t handler, FAR void *arg)
 
   /* Allocate the mountpoint info structure */
 
-  info = fs_heap_malloc(sizeof(struct inode_path_s));
+  info = lib_get_tempbuffer(sizeof(struct inode_path_s));
   if (!info)
     {
       return -ENOMEM;
@@ -193,7 +192,7 @@ int foreach_inode(foreach_inode_t handler, FAR void *arg)
 
   /* Free the info structure and return the result */
 
-  fs_heap_free(info);
+  lib_put_tempbuffer(info);
   return ret;
 
 #else
diff --git a/fs/nxffs/nxffs_dump.c b/fs/nxffs/nxffs_dump.c
index d75c63f40e0..45f8b330fa7 100644
--- a/fs/nxffs/nxffs_dump.c
+++ b/fs/nxffs/nxffs_dump.c
@@ -36,7 +36,6 @@
 #include <nuttx/mtd/mtd.h>
 
 #include "nxffs.h"
-#include "fs_heap.h"
 
 /****************************************************************************
  * Pre-processor Definitions
@@ -446,7 +445,7 @@ int nxffs_dump(FAR struct mtd_dev_s *mtd, bool verbose)
 
   /* Allocate a buffer to hold one block */
 
-  blkinfo.buffer = fs_heap_malloc(blkinfo.geo.blocksize);
+  blkinfo.buffer = lib_get_tempbuffer(blkinfo.geo.blocksize);
   if (!blkinfo.buffer)
     {
       ferr("ERROR: Failed to allocate block cache\n");
@@ -473,7 +472,7 @@ int nxffs_dump(FAR struct mtd_dev_s *mtd, bool verbose)
           /* Read errors are fatal */
 
           ferr("ERROR: Failed to read block %d\n", blkinfo.block);
-          fs_heap_free(blkinfo.buffer);
+          lib_put_tempbuffer(blkinfo.buffer);
           return ret;
 #else
           /* A read error is probably fatal on all media but NAND.
@@ -496,7 +495,7 @@ int nxffs_dump(FAR struct mtd_dev_s *mtd, bool verbose)
 
   syslog(LOG_NOTICE, "%" PRIiOFF " blocks analyzed\n", blkinfo.nblocks);
 
-  fs_heap_free(blkinfo.buffer);
+  lib_put_tempbuffer(blkinfo.buffer);
   return OK;
 
 #else
diff --git a/fs/partition/fs_gpt.c b/fs/partition/fs_gpt.c
index e349b657eb3..fc8dbe26a00 100644
--- a/fs/partition/fs_gpt.c
+++ b/fs/partition/fs_gpt.c
@@ -403,7 +403,7 @@ int parse_gpt_partition(FAR struct partition_state_s *state,
 
   count = (sizeof(struct gpt_ptable_s) + (state->blocksize - 1)) /
           state->blocksize;
-  ptbl = fs_heap_malloc(count * state->blocksize);
+  ptbl = lib_get_tempbuffer(count * state->blocksize);
   if (!ptbl)
     {
       return -ENOMEM;
@@ -491,6 +491,6 @@ int parse_gpt_partition(FAR struct partition_state_s *state,
 
   fs_heap_free(ptes);
 err:
-  fs_heap_free(ptbl);
+  lib_put_tempbuffer(ptbl);
   return ret;
 }
diff --git a/fs/partition/fs_mbr.c b/fs/partition/fs_mbr.c
index 2e5c1a4d601..5fae67a04bb 100644
--- a/fs/partition/fs_mbr.c
+++ b/fs/partition/fs_mbr.c
@@ -32,7 +32,6 @@
 #include <nuttx/kmalloc.h>
 
 #include "partition.h"
-#include "fs_heap.h"
 
 /****************************************************************************
  * Pre-processor Definitions
@@ -112,7 +111,7 @@ int parse_mbr_partition(FAR struct partition_state_s *state,
   int i;
 
   num = (MBR_SIZE + state->blocksize - 1) / state->blocksize;
-  buffer = fs_heap_malloc(num * state->blocksize);
+  buffer = lib_get_tempbuffer(num * state->blocksize);
   if (!buffer)
     {
       return -ENOMEM;
@@ -121,13 +120,13 @@ int parse_mbr_partition(FAR struct partition_state_s 
*state,
   ret = read_partition_block(state, buffer, 0, num);
   if (ret < 0)
     {
-      fs_heap_free(buffer);
+      lib_put_tempbuffer(buffer);
       return ret;
     }
 
   if (buffer[0x1fe] != 0x55 || buffer[0x1ff] != 0xaa)
     {
-      fs_heap_free(buffer);
+      lib_put_tempbuffer(buffer);
       return -EINVAL;
     }
 
@@ -214,6 +213,6 @@ int parse_mbr_partition(FAR struct partition_state_s *state,
     }
 
 out:
-  fs_heap_free(buffer);
+  lib_put_tempbuffer(buffer);
   return ret;
 }
diff --git a/fs/partition/fs_ptable.c b/fs/partition/fs_ptable.c
index 29708d551ea..da801e27b6b 100644
--- a/fs/partition/fs_ptable.c
+++ b/fs/partition/fs_ptable.c
@@ -29,7 +29,6 @@
 #include <nuttx/kmalloc.h>
 
 #include "partition.h"
-#include "fs_heap.h"
 
 /****************************************************************************
  * Pre-processor Definitions
@@ -94,7 +93,7 @@ int parse_ptable_partition(FAR struct partition_state_s 
*state,
 
   /* Allocate one erase block memory */
 
-  ptable = fs_heap_malloc(state->erasesize);
+  ptable = lib_get_tempbuffer(state->erasesize);
   if (ptable == NULL)
     {
       return -ENOMEM;
@@ -152,6 +151,6 @@ int parse_ptable_partition(FAR struct partition_state_s 
*state,
     }
 
 out:
-  fs_heap_free(ptable);
+  lib_put_tempbuffer(ptable);
   return ret;
 }
diff --git a/fs/partition/fs_txtable.c b/fs/partition/fs_txtable.c
index 2c62c38d88d..a507c88f59b 100644
--- a/fs/partition/fs_txtable.c
+++ b/fs/partition/fs_txtable.c
@@ -34,7 +34,6 @@
 #include <nuttx/macro.h>
 
 #include "partition.h"
-#include "fs_heap.h"
 
 /****************************************************************************
  * Pre-processor Definitions
@@ -83,9 +82,9 @@ int parse_txtable_partition(FAR struct partition_state_s 
*state,
 
   /* Allocate memory for table of parsed and raw */
 
-  part = fs_heap_malloc(CONFIG_TXTABLE_PARTITION_MAX_NUM *
-                    sizeof(struct partition_s) +
-                    TXTABLE_LENGTH);
+  part = lib_get_tempbuffer(CONFIG_TXTABLE_PARTITION_MAX_NUM *
+                            sizeof(struct partition_s) +
+                            TXTABLE_LENGTH);
   if (part == NULL)
     {
       return -ENOMEM;
@@ -225,6 +224,6 @@ int parse_txtable_partition(FAR struct partition_state_s 
*state,
   handler(&part[j], arg);
 
 out:
-  fs_heap_free(part);
+  lib_put_tempbuffer(part);
   return ret;
 }
diff --git a/fs/spiffs/src/spiffs_vfs.c b/fs/spiffs/src/spiffs_vfs.c
index 4cd92948180..d9cf6e2dff6 100644
--- a/fs/spiffs/src/spiffs_vfs.c
+++ b/fs/spiffs/src/spiffs_vfs.c
@@ -1700,7 +1700,7 @@ static int spiffs_unlink(FAR struct inode *mountpt, FAR 
const char *relpath)
        */
 
       fobj = (FAR struct spiffs_file_s *)
-        fs_heap_zalloc(sizeof(struct spiffs_file_s));
+        lib_get_tempbuffer(sizeof(struct spiffs_file_s));
       if (fobj == NULL)
         {
           fwarn("WARNING: Failed to allocate fobj\n");
@@ -1714,14 +1714,14 @@ static int spiffs_unlink(FAR struct inode *mountpt, FAR 
const char *relpath)
       if (ret < 0)
         {
           ferr("ERROR: spiffs_fobj_open_bypage failed: %d\n", ret);
-          fs_heap_free(fobj);
+          lib_put_tempbuffer(fobj);
           goto errout_with_lock;
         }
 
       /* Now we can remove the file by truncating it to zero length */
 
       ret = spiffs_fobj_truncate(fs, fobj, 0, true);
-      fs_heap_free(fobj);
+      lib_put_tempbuffer(fobj);
 
       if (ret < 0)
         {
diff --git a/fs/unionfs/fs_unionfs.c b/fs/unionfs/fs_unionfs.c
index d0d9d777728..276f80f903d 100644
--- a/fs/unionfs/fs_unionfs.c
+++ b/fs/unionfs/fs_unionfs.c
@@ -2163,6 +2163,7 @@ static int unionfs_rewinddir(FAR struct inode *mountpt,
 static int unionfs_bind(FAR struct inode *blkdriver, FAR const void *data,
                         FAR void **handle)
 {
+  size_t data_size = strlen(data) + 1;
   FAR const char *fspath1 = "";
   FAR const char *prefix1 = "";
   FAR const char *fspath2 = "";
@@ -2174,12 +2175,14 @@ static int unionfs_bind(FAR struct inode *blkdriver, 
FAR const void *data,
 
   /* Parse options from mount syscall */
 
-  dup = tmp = fs_heap_strdup(data);
+  dup = tmp = lib_get_tempbuffer(data_size);
   if (!dup)
     {
       return -ENOMEM;
     }
 
+  memcpy(dup, data, data_size);
+
   while ((tok = strsep(&tmp, ",")))
     {
       if (tok == strstr(tok, "fspath1="))
@@ -2203,7 +2206,7 @@ static int unionfs_bind(FAR struct inode *blkdriver, FAR 
const void *data,
   /* Call unionfs_dobind to do the real work. */
 
   ret = unionfs_dobind(fspath1, prefix1, fspath2, prefix2, handle);
-  fs_heap_free(dup);
+  lib_put_tempbuffer(dup);
 
   return ret;
 }
diff --git a/fs/vfs/fs_select.c b/fs/vfs/fs_select.c
index b3c77b84ec1..7d31c6cb9ce 100644
--- a/fs/vfs/fs_select.c
+++ b/fs/vfs/fs_select.c
@@ -42,7 +42,6 @@
 #include <nuttx/fs/fs.h>
 
 #include "inode/inode.h"
-#include "fs_heap.h"
 
 /****************************************************************************
  * Pre-processor Definitions
@@ -170,7 +169,7 @@ int select(int nfds, FAR fd_set *readfds, FAR fd_set 
*writefds,
   if (npfds > 0)
     {
       pollset = (FAR struct pollfd *)
-        fs_heap_zalloc(npfds * sizeof(struct pollfd));
+        lib_get_tempbuffer(npfds * sizeof(struct pollfd));
 
       if (pollset == NULL)
         {
@@ -179,6 +178,8 @@ int select(int nfds, FAR fd_set *readfds, FAR fd_set 
*writefds,
         }
     }
 
+  memset(pollset, 0, npfds * sizeof(struct pollfd));
+
   /* Initialize the descriptor list for poll() */
 
   for (fd = 0, ndx = 0; fd < nfds; fd++)
@@ -309,6 +310,6 @@ int select(int nfds, FAR fd_set *readfds, FAR fd_set 
*writefds,
         }
     }
 
-  fs_heap_free(pollset);
+  lib_put_tempbuffer(pollset);
   return ret;
 }
diff --git a/fs/vfs/fs_sendfile.c b/fs/vfs/fs_sendfile.c
index 9c3780eaa60..add5224ba0b 100644
--- a/fs/vfs/fs_sendfile.c
+++ b/fs/vfs/fs_sendfile.c
@@ -33,8 +33,8 @@
 
 #include <nuttx/fs/fs.h>
 #include <nuttx/kmalloc.h>
+#include <nuttx/lib/lib.h>
 #include <nuttx/net/net.h>
-#include "fs_heap.h"
 
 /****************************************************************************
  * Private Functions
@@ -76,7 +76,7 @@ static ssize_t copyfile(FAR struct file *outfile, FAR struct 
file *infile,
 
   /* Allocate an I/O buffer */
 
-  iobuffer = fs_heap_malloc(CONFIG_SENDFILE_BUFSIZE);
+  iobuffer = lib_get_tempbuffer(CONFIG_SENDFILE_BUFSIZE);
   if (!iobuffer)
     {
       return -ENOMEM;
@@ -199,7 +199,7 @@ static ssize_t copyfile(FAR struct file *outfile, FAR 
struct file *infile,
 
   /* Release the I/O buffer */
 
-  fs_heap_free(iobuffer);
+  lib_put_tempbuffer(iobuffer);
 
   /* Return the current file position */
 

Reply via email to