help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-smalltalk] Re: GNU Smalltalk and unix integration..


From: Paolo Bonzini
Subject: [Help-smalltalk] Re: GNU Smalltalk and unix integration..
Date: Wed, 07 Jan 2009 16:34:40 +0100
User-agent: Thunderbird 2.0.0.18 (Macintosh/20081105)

Sean Allen wrote:
> 
> On Jan 7, 2009, at 10:03 AM, Paolo Bonzini wrote:
> 
>>
>>>> You can look at the patch I sent, it only adds lines so it should be
>>>> easy to read.
>>>
>>> I never saw the patch. It wasn't included in the last message.
>>
>> http://permalink.gmane.org/gmane.comp.lang.smalltalk.gnu.general/3661
>>
> 
> Ah... very nice...
> Can we start a touch of learning with a question?
> What is the recursive_depth code?
> Link to existing explanations quite fine.

It's much more low-tech than you'd imagine. :-)  In particular, it does
not have anything to do with Smalltalk (even though it enables an
optimization used by the kernel/VFS.st part of the patch).  And it's
ad-hoc for chown (the variable is static), so there is no existing
explanation. :-)

I made chown take user/group names instead of uid/gid numbers, but the
getgrnam and getpwnam routines are potentially very slow, because they
have to lookup /etc/passwd and /etc/groups.  As a quick optimization,
I've made a simple 1-entry cache that should only be used while doing

  (File name: 'dir') all owner: 'root'

(that's "chown -R root dir") and not during normal single-file
operation.  recursive_depth refers to "usage of my_chown from recursive
operations, it doesn't have to do with the innards of the interpreter.
The cache is started by calling my_chown(NULL, "user", "group") and
ended by my_chown(NULL, NULL, NULL), which respectively increment and
decrement recursive_depth.  I made it a counter instead of a boolean in
case multiple Smalltalk threads are doing different recursive chowns at
the same time.

In this case, the cache will not eliminate all getgrnam/getpwnam calls
because it's only 1-entry, but it will eliminate most of them.  In order
to speed up the code a bit further if there is contention, I call
setgroupent/setpassent at the beginning of recursive operations (when
recursive_depths goes from 0 to 1), and endgrent/endpwent at the end
(when it goes from 1 to 0):

     The setgroupent() function opens the [/etc/groups] file.  If
     stayopen is non-zero, file descriptors are left open, signifi-
     cantly speeding functions subsequent calls.  This functionality is
     dangerous for long-running as the group file may be updated.

For this reason endgrent/endpwent are called to close the file when the
recursive updating is finished.

Paolo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]