0

A misconfigured logrotate produced a lot of files in a directory on my server. ls | wc -l showed 5,387,172 files and according to du -sh this summed up to about 8 GB. dmesg showed many errors like this:

[16718682.749947] EXT4-fs warning (device dm-5): ext4_dx_add_entry:2209: Directory (ino: 4194315) index full, reach max htree level :2
[16718682.750028] EXT4-fs warning (device dm-5): ext4_dx_add_entry:2213: Large directory feature is not enabled on this filesystem

The configuration is fixed now and I deleted all the files that were not supposed to be there. After cleaning up, I got this:

# ls -l roundcube/logs/
total 20
-rw-r--r-- 1 www-data www-data   0 Mär 21 06:25 errors.log
-rw-r--r-- 1 www-data www-data 315 Mär 21 06:25 errors.log.1
-rw-r--r-- 1 www-data www-data   0 Jan  7 06:36 errors.log.10.gz
-rw-r--r-- 1 www-data www-data   0 Dez 18 06:26 errors.log.11.gz
-rw-r--r-- 1 www-data www-data   0 Dez 10 06:25 errors.log.12.gz
-rw-r--r-- 1 www-data www-data 321 Mär 14 06:25 errors.log.2.gz
-rw-r--r-- 1 www-data www-data 272 Mär  7 06:25 errors.log.3.gz
-rw-r--r-- 1 www-data www-data 354 Feb 28 06:25 errors.log.4.gz
-rw-r--r-- 1 www-data www-data  20 Feb 18 16:07 errors.log.5.gz
-rw-r--r-- 1 www-data www-data   0 Feb 18 18:14 errors.log.6.gz
-rw-r--r-- 1 www-data www-data   0 Feb  5 13:36 errors.log.7.gz
-rw-r--r-- 1 www-data www-data   0 Jan 29 09:17 errors.log.8.gz
-rw-r--r-- 1 www-data www-data   0 Jan 14 06:49 errors.log.9.gz
# du -sh roundcube/logs/
632M    roundcube/logs/

However the ls call still took a long time (I did not look at the clock but I think it was >10 minutes). Might also be >60 minutes. And also it is strange, that du still reports 632MB.

I started a rescue system and ran fsck:

root@rescue /dev/mapper # fsck.ext4 vg0-mail 
e2fsck 1.44.5 (15-Dec-2018)
vg0-mail: clean, 300078/13107200 files, 13579986/52428800 blocks
root@rescue /dev/mapper # fsck.ext4 -f vg0-mail 
e2fsck 1.44.5 (15-Dec-2018)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
vg0-mail: 300078/13107200 files (0.5% non-contiguous), 13579986/52428800 blocks

So it does seem like everything is alright. I rebooted back into the normal system, but ls is still slow.

Just to make sure that there are no processes interfering, I rebooted back into the rescue system, mounted the volume there and tried to list directory contents. It also hangs.

strace ls shows many lines. The last couple of lines are:

fstat(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
read(3, "nodev\tsysfs\nnodev\ttmpfs\nnodev\tbd"..., 1024) = 309
read(3, "", 1024)                       = 0
close(3)                                = 0
access("/etc/selinux/config", F_OK)     = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=5547600, ...}) = 0
mmap(NULL, 5547600, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f0bd79c6000
close(3)                                = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(1, TIOCGWINSZ, {ws_row=66, ws_col=271, ws_xpixel=0, ws_ypixel=0}) = 0
stat("roundcube/logs/", {st_mode=S_IFDIR|0755, st_size=662331392, ...}) = 0
openat(AT_FDCWD, "roundcube/logs/", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 3
fstat(3, {st_mode=S_IFDIR|0755, st_size=662331392, ...}) = 0
getdents64(3

So it seems to hang on getdents64? I am somewhat confused that it ends with seemingly an incomplete line.

I read that this might be caused by a hardware defect, so I tried to run an smartctl -t long analysis on both disks (raid 1). Here are the results:

/dev/sda

smartctl 6.6 2017-11-05 r4594 [x86_64-linux-4.19.0-14-amd64] (local build)
Copyright (C) 2002-17, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family:     Seagate Constellation ES.3
Device Model:     ST2000NM0033-9ZM175
Serial Number:    Z1X0QWWG
LU WWN Device Id: 5 000c50 064a202c3
Firmware Version: SN07
User Capacity:    2.000.398.934.016 bytes [2,00 TB]
Sector Size:      512 bytes logical/physical
Rotation Rate:    7200 rpm
Form Factor:      3.5 inches
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   ACS-2 (minor revision not indicated)
SATA Version is:  SATA 3.0, 6.0 Gb/s (current: 3.0 Gb/s)
Local Time is:    Tue Mar 23 21:24:30 2021 CET
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

General SMART Values:
Offline data collection status:  (0x82) Offline data collection activity
                    was completed without error.
                    Auto Offline Data Collection: Enabled.
Self-test execution status:      (   0) The previous self-test routine completed
                    without error or no self-test has ever 
                    been run.
Total time to complete Offline 
data collection:        (  592) seconds.
Offline data collection
capabilities:            (0x7b) SMART execute Offline immediate.
                    Auto Offline data collection on/off support.
                    Suspend Offline collection upon new
                    command.
                    Offline surface scan supported.
                    Self-test supported.
                    Conveyance Self-test supported.
                    Selective Self-test supported.
SMART capabilities:            (0x0003) Saves SMART data before entering
                    power-saving mode.
                    Supports SMART auto save timer.
Error logging capability:        (0x01) Error logging supported.
                    General Purpose Logging supported.
Short self-test routine 
recommended polling time:    (   1) minutes.
Extended self-test routine
recommended polling time:    ( 245) minutes.
Conveyance self-test routine
recommended polling time:    (   2) minutes.
SCT capabilities:          (0x50bd) SCT Status supported.
                    SCT Error Recovery Control supported.
                    SCT Feature Control supported.
                    SCT Data Table supported.

SMART Attributes Data Structure revision number: 10
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x000f   070   063   044    Pre-fail  Always       -       11974882
  3 Spin_Up_Time            0x0003   096   096   000    Pre-fail  Always       -       0
  4 Start_Stop_Count        0x0032   100   100   020    Old_age   Always       -       25
  5 Reallocated_Sector_Ct   0x0033   100   100   010    Pre-fail  Always       -       0
  7 Seek_Error_Rate         0x000f   088   060   030    Pre-fail  Always       -       706711710
  9 Power_On_Hours          0x0032   033   033   000    Old_age   Always       -       59193
 10 Spin_Retry_Count        0x0013   100   100   097    Pre-fail  Always       -       0
 12 Power_Cycle_Count       0x0032   100   100   020    Old_age   Always       -       24
184 End-to-End_Error        0x0032   100   100   099    Old_age   Always       -       0
187 Reported_Uncorrect      0x0032   100   100   000    Old_age   Always       -       0
188 Command_Timeout         0x0032   100   100   000    Old_age   Always       -       0
189 High_Fly_Writes         0x003a   059   059   000    Old_age   Always       -       41
190 Airflow_Temperature_Cel 0x0022   060   050   045    Old_age   Always       -       40 (Min/Max 36/44)
191 G-Sense_Error_Rate      0x0032   100   100   000    Old_age   Always       -       0
192 Power-Off_Retract_Count 0x0032   100   100   000    Old_age   Always       -       18
193 Load_Cycle_Count        0x0032   099   099   000    Old_age   Always       -       2459
194 Temperature_Celsius     0x0022   040   050   000    Old_age   Always       -       40 (0 21 0 0 0)
195 Hardware_ECC_Recovered  0x001a   042   015   000    Old_age   Always       -       11974882
197 Current_Pending_Sector  0x0012   100   100   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0010   100   100   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x003e   200   200   000    Old_age   Always       -       0

SMART Error Log Version: 1
No Errors Logged

SMART Self-test log structure revision number 1
Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Extended offline    Completed without error       00%     59192         -
# 2  Short offline       Interrupted (host reset)      10%     59185         -
# 3  Extended offline    Completed without error       00%     53208         -
# 4  Extended offline    Completed without error       00%     53191         -
# 5  Extended offline    Completed without error       00%     53178         -
# 6  Short offline       Completed without error       00%     53170         -
# 7  Extended offline    Completed without error       00%     53056         -
# 8  Extended offline    Completed without error       00%     53040         -
# 9  Extended offline    Completed without error       00%     53025         -
#10  Short offline       Completed without error       00%     53017         -
#11  Extended offline    Completed without error       00%     51660         -
#12  Extended offline    Completed without error       00%     51643         -
#13  Extended offline    Completed without error       00%      2411         -
#14  Extended offline    Completed without error       00%      2383         -

SMART Selective self-test log data structure revision number 1
 SPAN  MIN_LBA  MAX_LBA  CURRENT_TEST_STATUS
    1        0        0  Not_testing
    2        0        0  Not_testing
    3        0        0  Not_testing
    4        0        0  Not_testing
    5        0        0  Not_testing
Selective self-test flags (0x0):
  After scanning selected spans, do NOT read-scan remainder of disk.
If Selective self-test is pending on power-up, resume after 0 minute delay.




/dev/sdb

smartctl 6.6 2017-11-05 r4594 [x86_64-linux-4.19.0-14-amd64] (local build)
Copyright (C) 2002-17, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family:     Hitachi/HGST Ultrastar 7K4000
Device Model:     HGST HUS724020ALA640
Serial Number:    PN2138P2GNK30J
LU WWN Device Id: 5 000cca 24bc9579a
Firmware Version: MF6OAA70
User Capacity:    2.000.398.934.016 bytes [2,00 TB]
Sector Size:      512 bytes logical/physical
Rotation Rate:    7200 rpm
Form Factor:      3.5 inches
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   ATA8-ACS T13/1699-D revision 4
SATA Version is:  SATA 3.0, 6.0 Gb/s (current: 3.0 Gb/s)
Local Time is:    Tue Mar 23 22:38:27 2021 CET
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

General SMART Values:
Offline data collection status:  (0x84) Offline data collection activity
                    was suspended by an interrupting command from host.
                    Auto Offline Data Collection: Enabled.
Self-test execution status:      (   0) The previous self-test routine completed
                    without error or no self-test has ever 
                    been run.
Total time to complete Offline 
data collection:        (   24) seconds.
Offline data collection
capabilities:            (0x5b) SMART execute Offline immediate.
                    Auto Offline data collection on/off support.
                    Suspend Offline collection upon new
                    command.
                    Offline surface scan supported.
                    Self-test supported.
                    No Conveyance Self-test supported.
                    Selective Self-test supported.
SMART capabilities:            (0x0003) Saves SMART data before entering
                    power-saving mode.
                    Supports SMART auto save timer.
Error logging capability:        (0x01) Error logging supported.
                    General Purpose Logging supported.
Short self-test routine 
recommended polling time:    (   1) minutes.
Extended self-test routine
recommended polling time:    ( 314) minutes.
SCT capabilities:          (0x003d) SCT Status supported.
                    SCT Error Recovery Control supported.
                    SCT Feature Control supported.
                    SCT Data Table supported.

SMART Attributes Data Structure revision number: 16
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x000b   100   100   016    Pre-fail  Always       -       0
  2 Throughput_Performance  0x0005   136   136   054    Pre-fail  Offline      -       80
  3 Spin_Up_Time            0x0007   163   163   024    Pre-fail  Always       -       367 (Average 396)
  4 Start_Stop_Count        0x0012   100   100   000    Old_age   Always       -       28
  5 Reallocated_Sector_Ct   0x0033   100   100   005    Pre-fail  Always       -       0
  7 Seek_Error_Rate         0x000b   100   100   067    Pre-fail  Always       -       0
  8 Seek_Time_Performance   0x0005   145   145   020    Pre-fail  Offline      -       24
  9 Power_On_Hours          0x0012   095   095   000    Old_age   Always       -       37639
 10 Spin_Retry_Count        0x0013   100   100   060    Pre-fail  Always       -       0
 12 Power_Cycle_Count       0x0032   100   100   000    Old_age   Always       -       27
192 Power-Off_Retract_Count 0x0032   099   099   000    Old_age   Always       -       1311
193 Load_Cycle_Count        0x0012   099   099   000    Old_age   Always       -       1311
194 Temperature_Celsius     0x0002   150   150   000    Old_age   Always       -       40 (Min/Max 22/60)
196 Reallocated_Event_Count 0x0032   100   100   000    Old_age   Always       -       0
197 Current_Pending_Sector  0x0022   100   100   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0008   100   100   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x000a   200   200   000    Old_age   Always       -       0

SMART Error Log Version: 1
No Errors Logged

SMART Self-test log structure revision number 1
Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Extended offline    Completed without error       00%     37638         -
# 2  Short offline       Interrupted (host reset)      90%     37630         -
# 3  Extended offline    Completed without error       00%     31654         -
# 4  Extended offline    Completed without error       00%     31637         -
# 5  Extended offline    Completed without error       00%     30951         -
# 6  Extended offline    Completed without error       00%     30932         -
# 7  Extended offline    Completed without error       00%     30927         -
# 8  Short offline       Completed without error       00%     30919         -
# 9  Extended offline    Completed without error       00%     30882         -
#10  Extended offline    Completed without error       00%     30866         -
#11  Extended offline    Completed without error       00%     19849         -
#12  Extended offline    Completed without error       00%     19832         -

SMART Selective self-test log data structure revision number 1
 SPAN  MIN_LBA  MAX_LBA  CURRENT_TEST_STATUS
    1        0        0  Not_testing
    2        0        0  Not_testing
    3        0        0  Not_testing
    4        0        0  Not_testing
    5        0        0  Not_testing
Selective self-test flags (0x0):
  After scanning selected spans, do NOT read-scan remainder of disk.
If Selective self-test is pending on power-up, resume after 0 minute delay.

I don't understand most of it, but it does not look "bad" to me?!

Eventually I just executed mv logs logs-old; mv logs-old/* logs; rm -r logs-old And this does seem to "solve" my problem for now. But I wonder if this could really be it or whether there might be more to it.

What could have happened here to cause this behaviour of extremely slow directory listing? Could the problem be gone now? Could there be some damage that I should find?

yankee
  • 177
  • 2
  • 6

1 Answers1

2

This is a know issue: when having so many files, the directory entry (dentry) become very big and deleting the files will not shrink it.

The easier solution is to remove and recreate the directory itself (ie: in your case, something as rm -rf roundcube/logs/ ; mkdir roundcube/logs/)

See here for more informations

shodanshok
  • 47,711
  • 7
  • 111
  • 180