Re: Why is stat slow?

Brian Inglis via Cygwin <[email protected]>
Newsgroups gmane.os.cygwin
Organization Systematic Software
Message-ID <[email protected]>
On 2025-12-22 08:35, Eliot Moss via Cygwin wrote:
> On 12/22/2025 10:07 AM, Christian Franke via Cygwin wrote:
>> Eliot Moss via Cygwin wrote:
>>> I'm sure this has been asked before, more than once, but I am again wondering
>>> what, specifically, makes stat (the program, but presumably also the syscall)
>>> substantially slower on Cygwin compared to stat on WSL2.  I am talking about
>>> an external HDD (not solid state) on my D: drive.  It shows under WSL 2 as
>>> /mnt/d like this (output of mount):
>>>
>>> D:\ on /mnt/d type 9p (rw,noatime,aname=drvfs;path=D: 
>>> \;uid=0;gid=0;symlinkroot=/ 
>>> mnt/,cache=5,access=client,msize=65536,trans=fd,rfd=5,wfd=5)
>>>
>>> On Cygwin it shows up like this (yes, mount shows two lines):
>>>
>>> D: on /cygdrive/d type ntfs (binary,notexec,posix=0,user)
>>> D: on /cygdrive/d type ntfs (binary,noacl,posix=0,user,noumount,auto)
>>>
>>> My /etc/fstab lines are:
>>>
>>> none /cygdrive cygdrive binary,noacl,posix=0,user 0 0
>>> d: /cygdrive/d ntfs binary,posix=0,user,auto,notexec 0 0
>>
>> In the past, Cygwin did not support individual options for some /cygdrive/X. 
>> If this is still the case, "noacl" without "notexec" is effective for / 
>> cygdrive/d. Then Cygwin reads the header of each file to check for a possible 
>> "x" permission.

>>> (Presumably this has something to do with two mounts showing ...)
>>>
>>> On D; I have a folder with hundreds of 2Gb files (they are backups, split into
>>> 2Gb portions).  On Cygwin
>>>
>>> time stat <the files> gives
>>>
>>> real    2m12.425s
>>> user    0m0.249s
>>> sys     0m1.312s

>> This would explain this long duration.
>>
>> Quick test:
>>
>> $ echo '#!/bin/sh' > /cygdrive/d/script.tmp
>> $ ls -l /cygdrive/d/script.tmp
>> -rwxr-xr-x .... <== notexec unset
>> -rw-r--r-- .... <== notexec set

> Aha!  I changed my /etc/fstab to be like this:
> 
> none /cygdrive cygdrive binary,noacl,posix=0,user 0 0
> d: /d ntfs binary,posix=0,user 0 0
> 
> D: is still available via explicit /cygdrive/d, but that would be without the
> noacl option.  Using /d now the previously slow stat completes in a few
> seconds, reasonable for going over what is now 2000 files.  My memory of
> exactly why is dim, but the noacl seems important for my C: drive.  Using the
> ACLs on D: to determine executability seems good.

Mapping drives to /? causes an issue if you ever want to get help from any 
non-Cygwin Windows console program that uses Windows help conventions /? -> /d: 
I believe using /\? avoids that.

-- 
Take care. Thanks, Brian Inglis              Calgary, Alberta, Canada

La perfection est atteinte                   Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter  not when there is no more to add
mais lorsqu'il n'y a plus rien à retrancher  but when there is no more to cut
                                 -- Antoine de Saint-Exupéry

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.