Getcwd performance issues

Hello everyone,
recently we have been experiencing performance issues with chmod. We managed to narrow it down to getcwd.

The following folder exists:
 /Folder1/subfol1/subfol2/subfol3

cd /Folder1/subfol1/subfol2/subfol3 

truss -D pwd 2>&1 | grep getcwd
 0.0001 getcwd("/folder1/subfol1/subfol2/subfol3", 1025) = 0

-- rename subfol3 to subfol4
cd ..
mv subfol3 subfol4

-enter new folder and analyze pwd

cd subfol4
truss -D pwd 2>&1 | grep getcwd
 0.2789 getcwd("/folder1/subfol1/subfol2/subfol4", 1025) = 0

-- rename to the original name
cd ..
mv subfol4 subfol3
cd subfol3

-- analyze pwd
truss -D pwd 2>&1 | grep getcwd
 0.0001 getcwd("/folder1/subfol1/subfol2/subfol3", 1025) = 0

Question: why is there a difference in a response time after renaming the folder ?

uname -a
SunOS algenib 5.10 Generic_147440-19 sun4u sparc SUNW,SPARC-Enterprise

Note that the cd utility is a shell built-in; so the results of a test like this could vary widely from shell to shell.

Most shells will need to set the variable PWD when they start. Some shells will remember some number of directories they have seen in calls to cd and if they have seen a target direcotry path before, they can change the value of PWD (a side effect of calling cd) by looking at an in memory cache of previously visited directories. When you renamed subfol3 to subfol4, the shell's cache didn't contain an entry for subfol4 and had to make at least one system call to determine if subfol4 was a real directory or a symbolic link to a directory.

When you renamed subfol4 back to subfol3, the shell's cache could have contained an entry for subfol3, so it may have assumed that its cache was still valid.

If you look at the truss output (instead of just looking at the getcwd line in the output) you might be able to glean what is going on under the covers. You haven't said whether either of the subfol3 or subfol4 directories had been visited before the output you showed. My guess would be that you had visited subfol3 before, to get the results you showed, but without a lot more details this is purely speculation.

thanks for the suggestion but I can also reproduce it with a newly created folder:

>> mkdir test
>> cd test
>> truss -D pwd 2>&1 | grep getcwd
0.0001 getcwd("/opt_local/product/test", 1025) = 0
>> cd ..
>> mv test test1
>> cd test1
>> truss -D pwd 2>&1 | grep getcwd
0.2130 getcwd("/opt_local/product/test1", 1025) = 0
>> cd ..
>> mv test1 test
>> cd test
>> truss -D pwd 2>&1 | grep getcwd
 0.0001 getcwd("/opt_local/product/test", 1025) = 0

As soon as I rename it back to test1 it becomes slow again.
Session or shell change has no effect on it.

The same does not happen on a similar server with a different OS level
SunOS 5.10 Generic_147147-26 sun4u sparc SUNW,SPARC-Enterprise

Of course. Renaming a directory or creating a new directory is exactly the same condition for this discussion; the shell is seeing a directory name that is not in its cache.

As I said before, different shells may show different results. Even if the pathname of the shell you're using on the two servers is the same, there is no guarantee that the shell's processing remains the same from release to release. Changes in the OS itself or the filesystem type underlying the directories involved could also have a profound effect.

I'm still not convienced about your argumentation. If the shell cache played a role then I would expect the exactly oposite results. How can you explain the fact that a newly created folder yields better results than a renamed one?
As you can see above I visited the 2 folders the same way and only once after the creation.
The issue does not seem to occour for new folders.

Moreover, the real directory under a question is an existing application folder, which have been visited hundreds of times over the last few years. We have noticed the drop in the response time only recently.
The above Code was just a demonstration of how we manged to reproduce the issue.

No changes were made to shell, OS or hardware that would explain any of this.

any other suggestions or am I missing something here ?