From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.208.169 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796295473; b=27cHM/lL7xARZ+FExoygkk52FdZ/z6bGO5uVGkufCaQazt2xGx3gfDRufo0402BzUM1t Qcaji4fAe9Bf8tlUGAmbu6k8LXeEa2PGUqpq9l4rTaWDkFYnhFp+Qjsq5aLnnuaz7Hosv POrPy1Qkk7bfmg/ti6idg7d6BWAEOdvSme1ugJGzzMeOCzgUxhjtwbOei/4hEjPZrxG1t VtG+YEfbuOgREf2f1JE9pP0ArIObo49RJm3KDx+ua8cTx/jOouIP+4b0/IXU4aOEMMujO URCjmN4mmUkkZhl04lPV6pGJNr7hPUPWi2JzWSHu9caVONEzPestDp6AxboE9cfih5g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796295473; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Content-Language:To:Cc:From: Subject:Content-Type:Content-Transfer-Encoding; bh=9BVJiToG0Gj79FJfB+S+/TfJQikjd4c+3gLQBELMhHY=; b=F5FnSFc3HjzWzaDIJBNtaQ13DEfTwcUPIoIJ16rxEoiAzZjx1XKHA77r18mCG974xPBP i/EvRehueNljFUSI+hN+ZSPNAHAjMXw2rXFTxvazdYjwWxClEFCbwhTTfVX5jktFQUR+y 7YfhEFIGsNC0rSlT+7IoQ2UfN8MitC2Y8EDlC0VfWsveQxXO9WwEmrC58l91UUMpqQPVX HqieZJ3Px1vxe+IHUTkwoSrdq3xeA9OZsnIM01/jsjiTrpaA7NvarQFdiNrlUU/nQyYzh xlEKWrZBWvcFcuLb7HT4mEMwPQSdZqJEqdLR8D6OK4kaNlO5nFG7SB2qWg1fw8Go4WA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=hRcE9W3U; arc=none smtp.remote-ip=209.85.208.169 Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0FC36606A322 for ; Thu, 3 Dec 2026 10:57:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0FC36606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=hRcE9W3U Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-3aff2ab0808so4233821fa.0 for ; Thu, 03 Dec 2026 02:57:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796295471; x=1796900271; darn=vger.kernel.org; h=content-transfer-encoding:content-type:subject:from:cc:to :content-language:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to:content-type; bh=9BVJiToG0Gj79FJfB+S+/TfJQikjd4c+3gLQBELMhHY=; b=hRcE9W3U3uVXJdOaW0+LObr+JURTJ/1qeVKFANd2H0ZiFH1IY0hkkUrR15B/gqxYbk G8MXupHXqB5DHTk/n1IpRNZf5qwLQdYkveyHT6kOkvjYGrNWRJnJQq+ONpcSzEMDKrr+ XCgqWTkVs4JEAy1PPx/E8PkVFGMo/RTU/J+g7nbiXQYYXTpKeaVg5jgUO2sLaezyLtxS nn4HjpWtEHBEUEpAYXa/WDxOzJGdM/OPyCJkdScWJtakwiJvl+Eu+VK8TEOZqPqNoRNY CG37aXmtKyWDhH145gMHRKjYutmiTN/TPpWlyxQFDyFueyF0jxOmsInYvzi7TQjL22hx i25w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796295471; x=1796900271; h=content-transfer-encoding:content-type:subject:from:cc:to :content-language:user-agent:mime-version:date:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=9BVJiToG0Gj79FJfB+S+/TfJQikjd4c+3gLQBELMhHY=; b=IxtJAiOqKJXxsKwSrB2fd+HxGsvxjc5x2EHbReUvBn5fRtS/t9XmT7tNOGafDYoXbI XAGA8BFSjH2UDzIkI2e/B1uJdqkFrR82BdtDQO/aLSltkhj3QuZNh5YlJtyBC/P6JZwt mpFxpSmoV3N+qNIjh2MWpdgWhx6j/oopZ+WxWaHMEw6PVd4K6BhURdd+R1WXeY70NyG0 xIaPVvJ1zVuZJfYtOQL/g4nr7AGIJJ94lendk3sp9IeRGoHcZroTmtlRewFi3Slro6ER 9T0Q8A9HrISZDhmhY8+aHv0y0QRpGZFcXUxDH+F8LVnEedzVGNYIVeOTRTCDAB83pbpx BMMg== X-Forwarded-Encrypted: i=1; AL+hErEHpQ5U+GdbUOCjp1s2oxBPa3GM+K4Z8LtqxGduoULYa87dSd7YDf9wQk5WWaic+P1DFQL6qzDJuukvC5g=@vger.kernel.org X-Gm-Message-State: APuU4Z8R2jvSza6SbDp7QJC1RHISvrXmKPywkORNZnQoxJGm7IoQy82Z wwJjDJ6kTgCu9AuwU7cbV6LVVTWs1ZkUFhJwUAIBthixd9GAh430BMBq X-Gm-Gg: AZFdTZcTvuGI7ZUfu85UCZtUVF0r3sigH/YgHCwwhfW/Ia/w2x+Dc984Doy66zVYk0p cKHinPHpGY2cArFjw8WtvdlcbfLtPMixmDZjA5FjlJGxLgfMyv2rU5hILZA9EfqEAD9a/OEoDhZ eS9nY6la5YBYQf0beMhEK61HzUQHOFqhh1UqXQ3grI9XZ1QDSHpdM4hKw4cce3JBAqp7M2oQbAF Y558fEBo/Yy/0fPWlDJjO/srv+4J4dK+x/kZ25bIHwn3JGRNBB+sXA3XDHo7S833tQ0SYsj2K6o 5Z0kVksVXmPlj46K340o8Z2SRBtb7UkidyJfGe8RPiluFUlv4PzOSKygmi0pSLEeGjYiQ4e3Tw1 xHtIfaPhC+29gX80OyJRSdo36QnSKhZy6JBXrYfE3ANyZwu+vaIAcpKLVikCjDHwH9vIsUgmL4L Peg9MoUC2hYRl6Z/DIoEUsxP0UksW4fGNf6BgBsebKHinVq7ysRiAtIYol7Uxq3+qaA4QPPFIxH sfjqqJdSZwrhA8oGMk1uHzipc0ktgMKItGhlrWoF6PYuWfkBg4da0LGTwt/XPqLd1iP+mXTKZR1 gkuVNWz0L9nKW0ha90RhazZnIYchD7Aj7XRK35H4j5/DmtlLhYWu+SCudOF+Kzdy5x8GMYo= X-Received: by 2002:a2e:b8c3:0:b0:3ac:dc93:c82f with SMTP id 38308e7fff4ca-3ae7f9d997emr134830051fa.11.1796295470882; Thu, 03 Dec 2026 02:57:50 -0800 (PST) Received: from [10.128.170.180] ([77.234.210.12]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3ae8044e8e0sm112934521fa.5.2026.12.03.02.57.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Dec 2026 02:57:50 -0800 (PST) Message-ID: <3b9f8264-c72e-4050-ade4-424255bf05d4@gmail.com> Date: Thu, 3 Dec 2026 13:57:43 +0300 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: jaegeuk@kernel.org, chao@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org From: Vyacheslav Kovalevsky Subject: f2fs: creating, syncing and removing directories in parallel increases number of orphan inodes and used space Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hello, there seems to be an issue with F2FS (default configuration). Consider this sequence of operations: 1. Create a directory 2. Call sync() 3. Sleep for some time (less than 1ms, 100us works best on my machine) 4. Remove the directory 5. Repeat from step 1 When running multiple instances of this script (each one creates its own directory with fixed name), the number of orphan inodes grows (and free space decreases). Example: running 10 instances on 2 CPU virtual machine on 500 MB ram disk. `sar` command output (last measure after all instances stopped): ``` Linux 7.4.0-rc5 (ubuntu)     12/03/26     _x86_64_    (2 CPU) 09:58:23     MBfsfree  MBfsused   %fsused  %ufsused     Ifree  Iused    %Iused FILESYSTEM 09:58:33          436        62     12.45     12.45    111613    3      0.00 /dev/ram0 09:59:23     MBfsfree  MBfsused   %fsused  %ufsused     Ifree  Iused    %Iused FILESYSTEM 09:59:33          405        93     18.60     18.60    103771 7845      7.03 /dev/ram0 10:00:23     MBfsfree  MBfsused   %fsused  %ufsused     Ifree  Iused    %Iused FILESYSTEM 10:00:33          375       123     24.64     24.64     96074  15542     13.92 /dev/ram0 10:01:23     MBfsfree  MBfsused   %fsused  %ufsused     Ifree  Iused    %Iused FILESYSTEM 10:01:33          349       149     30.02     30.02     89218  22398     20.07 /dev/ram0 10:02:23     MBfsfree  MBfsused   %fsused  %ufsused     Ifree  Iused    %Iused FILESYSTEM 10:02:33          325       173     34.80     34.80     83121  28495     25.53 /dev/ram0 10:03:23     MBfsfree  MBfsused   %fsused  %ufsused     Ifree  Iused    %Iused FILESYSTEM 10:03:33          302       196     39.31     39.31     77375  34241     30.68 /dev/ram0 10:04:23     MBfsfree  MBfsused   %fsused  %ufsused     Ifree  Iused    %Iused FILESYSTEM 10:04:33          282       216     43.43     43.43     72126  39490     35.38 /dev/ram0 10:05:23     MBfsfree  MBfsused   %fsused  %ufsused     Ifree  Iused    %Iused FILESYSTEM 10:05:33          262       236     47.29     47.29     67193  44423     39.80 /dev/ram0 10:06:23     MBfsfree  MBfsused   %fsused  %ufsused     Ifree  Iused    %Iused FILESYSTEM 10:06:33          244       254     50.98     50.98     62497  49119     44.01 /dev/ram0 10:07:23     MBfsfree  MBfsused   %fsused  %ufsused     Ifree  Iused    %Iused FILESYSTEM 10:07:33          234       264     53.05     53.05     59854  51762     46.38 /dev/ram0 ``` Triggering GC or removing all directories in the file system does not frees orphan inodes, only remounting does. See below for debug information and steps to reproduce. As a side note, this seems to cause a slight performance degradation as the number of used inodes grows. NOTE: I am not sure if this is intended behavior or whether this issue can affect real users at all. Would like to read your comments, thanks. System info =========== Linux version 7.4.0-rc5, also tested on 7.0.0-34-generic (Ubuntu 26.04.1 LTS) How to reproduce ================ Test (C++): ``` #include #include #include #include #include #include #include #include #include #include #include #include #include int main(int argc, char *argv[]) {   if (argc != 3) {     fprintf(stderr,             "expected directory name and delay in microseconds as arguments");     return EXIT_FAILURE;   }   char *dir = argv[1];   long delay = atoi(argv[2]);   std::random_device rd;   std::mt19937 gen(rd());   std::exponential_distribution dist(1.0 / (double)delay);   int status;   while (1) {     status = mkdir(dir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);     if (status) {       fprintf(stderr, "failed: mkdir %s (%s)\n", dir, strerror(errno));       return EXIT_FAILURE;     }     sync();     struct timespec rem;     struct timespec req = {.tv_sec = 0, .tv_nsec = ((long)dist(gen)) * 1000L};     nanosleep(&req, &rem);     std::error_code ec;     // NOTE: can use rmdir directly, but the effect will be smaller     std::filesystem::remove_all(dir, ec);     if (ec) {       fprintf(stderr, "failed: remove %s (%s)\n", dir, ec.message().c_str());       return EXIT_FAILURE;     }   } } ``` Steps: ``` root@ubuntu:/# modprobe brd rd_nr=1 rd_size=512000 root@ubuntu:/# mkfs.f2fs /dev/ram0     F2FS-tools: mkfs.f2fs Ver: 1.16.0 (2023-04-11) Info: Disable heap-based policy Info: Debug level = 0 Info: Trim is enabled Info: Segments per section = 1 Info: Sections per zone = 1 Info: sector size = 512 Info: total sectors = 1024000 (500 MB) Info: zone aligned segment0 blkaddr: 512 Info: format version with   "Linux version 7.4.0-rc5 (root@ubuntu) (gcc (Ubuntu 15.2.0-16ubuntu1) 15.2.0, GNU ld (GNU Binutils for Ubuntu) 2.46) #1 SMP PREEMPT_DYNAMIC Thu Dec  3 09:27:09 UTC 2026" Info: [/dev/ram0] Discarding device Info: This device doesn't support BLKSECDISCARD Info: Discarded 500 MB Info: Overprovision ratio = 10.000% Info: Overprovision segments = 24 (GC reserved = 17) Info: format successful root@ubuntu:/# mkdir /mnt/fstest/ root@ubuntu:/# mount -t f2fs /dev/ram0 /mnt/fstest/ root@ubuntu:/# mkdir /mnt/fstest/dir root@ubuntu:/# g++ test.cpp root@ubuntu:/# ./a.out /mnt/fstest/dir/0 100 & root@ubuntu:/# ./a.out /mnt/fstest/dir/1 100 & root@ubuntu:/# ./a.out /mnt/fstest/dir/2 100 & ... # spawn 10 (can be less or more) instances in total ``` FS stats can be monitored with `sar -F --fs=/dev/ram0 10`. Debug output in the end: ``` root@ubuntu:~# cat /sys/kernel/debug/f2fs/status =====[ partition info(ram0). #0, RW, CP: Good]===== [SB: 1] [CP: 2] [SIT: 2] [NAT: 2] [SSA: 1] [MAIN: 242(OverProv:24 Resv:17)] Current Time Sec: 717 / Mounted Time Sec: 41 Policy:   - IPU: [ FORCE HONOR_OPU_WRITE ] Utilization: 46% (51762 valid blocks, 0 discard blocks)   - Node: 51761 (Inode: 51761, Other: 0)   - Data: 1   - Inline_xattr Inode: 51760   - Inline_data Inode: 0   - Inline_dentry Inode: 51760   - Compressed Inode: 0, Blocks: 0   - Swapfile Inode: 0   - Donate Inode: 0   - Orphan/Append/Update Inode: 51750, 0, 0 Main area: 242 segs, 242 secs 242 zones     TYPE           blkoff    segno    secno   zoneno  dirty_seg  full_seg  valid_blk   - COLD   data:        0       59       59       59          0       0          0   - WARM   data:        0      120      120      120          0       0          0   - HOT    data:        2        3        3        3          1       0          1   - Dir   dnode:      473      110      110      110        202       0      51761   - File  dnode:        0        1        1        1          0       0          0   - Indir nodes:        0        2        2        2          0       0          0   - Pinned file:        0       -1       -1       -1   - ATGC   data:        0       -1       -1       -1   - Valid: 6   - Dirty: 201   - Prefree: 0   - Free: 35 (35) CP calls: 5954685 (BG: 5) CP count: 2055736   - cp blocks : 55399824   - sit blocks : 58307   - nat blocks : 1337406   - ssa blocks : 24992 CP merge:   - Queued :    0   - Issued : 3102788   - Total : 5954685   - Cur time :    0(ms)   - Peak time :    1(ms) GC calls: 1 (gc_thread: 1)   - data segments : 0 (BG: 0)   - node segments : 0 (BG: 0)   - Reclaimed segs :     - Normal : 0     - Idle CB : 0     - Idle Greedy : 0     - Idle AT : 0     - Urgent High : 0     - Urgent Mid : 0     - Urgent Low : 0 Try to move 0 blocks (BG: 0)   - data blocks : 0 (0)   - node blocks : 0 (0) BG skip : IO: 0, Other: 1 defrag blocks : 0 Extent Cache (Read):   - Hit Count: L1-1:0 L1-2:0 L2:0   - Hit Ratio: 0% (0 / 0)   - Inner Struct Count: tree: 0(0), node: 0 Extent Cache (Block Age):   - Allocated Data Blocks: 1   - Hit Count: L1:0 L2:0   - Hit Ratio: 0% (0 / 0)   - Inner Struct Count: tree: 0(0), node: 0 Balancing F2FS Async:   - DIO (R:    0, W:    0)   - IO_R (Data:    0, Node:    0, Meta:    0   - IO_W (CP:    0, Data:    0, Flush: (   0    0    1), Discard: (   0 12002)) cmd: 14052 undiscard:27802   - atomic IO:    0 (Max.    0)   - compress:    0, hit:       0   - nodes:    0 in 50354   - dents:    0 in dirs:   0 (   0)   - data:    0 in files:   0   - quota data:    0 in quota files:   0   - meta:    0 in  559   - imeta:    0   - fsync mark:    0   - NATs:         0/    54597   - SITs:         0/      242   - free_nids:      2836/   181196   - alloc_nids:         0 Distribution of User Blocks: [ valid | invalid | free ]   [-----------------------|-------------------------|--] IPU: 0 blocks SSR: 9150170 blocks in 24731 segments LFS: 134144 blocks in 261 segments BDF: 16, avg. vblocks: 254 Memory: 211498 KB   - static: 133 KB   - cached all: 7712 KB   - read extent cache: 0 KB   - block age extent cache: 0 KB   - meta entry: 34 KB, meta cache: 2236 KB   - node entry: 3147 KB, node cache: 201416 KB   - paged : 203652 KB ```