[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference noted::hackers_v1

Title:-={ H A C K E R S }=-
Notice:Write locked - see NOTED::HACKERS
Moderator:DIEHRD::MORRIS
Created:Thu Feb 20 1986
Last Modified:Mon Aug 03 1992
Last Successful Update:Fri Jun 06 1997
Number of topics:680
Total number of notes:5456

264.0. "How to allocate memory on VMS?" by BACH::VANROGGEN () Fri Jun 20 1986 20:19

    What's the best way to allocate segments of contiguous, aligned
    blocks of memory of size 64kbyte (or any similarly large power
    of two)? LIB$GET_VM_PAGE won't fetch memory that's aligned,
    and besides doesn't guarantee that it's all-zeros (but I could
    use SYS$CRETVA). SYS$CRETVA might overwrite existing allocated
    memory, so I can't use it to search for the lowest address range
    where it might be successful.
    			---Walter
T.RTitleUserPersonal
Name
DateLines
264.1$EXPREG not $CRETVATHEBAY::MTHOMASMatt Thomas -- the mad hackerSat Jun 21 1986 01:250
264.2Huh?TLE::BRETTSat Jun 21 1986 03:2311
    
    I don't understand what you mean by "aligned" - LIB$GET_VM_PAGE
    returns PAGES, ie: aligned on a 512 byte boundary.  Isn't this what
    you want?
    
    The easiest way to make them 0 is to MOVC5 across them (64K-512
    bytes at a time, of course).  An alternative way is the $CRETVA
    DZRO across the.  This is cheaper if the pages are paged out, but
    more expensive if they're not.
    
    /Bevin                        
264.3THEBAY::MTHOMASMatt Thomas -- the mad hackerSat Jun 21 1986 18:566
    For copy or zeroing memory blocks of ANY length, use either

	OTS$MOVE3 (length, source, dest)
or	OTS$MOVE5 (srclen, source, fillchar, destlen, dest)
    
    matt
264.4$EXPREG Is Low-LevelVAXUUM::DYERBanish BigotryMon Jun 23 1986 03:385
	    $EXPREG (or SYS$EXPREG, if you will) is the fastest and
	most straightforward way to do it, but it's what you'd call
	"low-level."  This is no problem, of course, if you're using
	a groovy language like C.
			<_Jym_>
264.5???BACH::VANROGGENMon Jun 23 1986 14:096
    I want to allocate/reserve segments of memory that are 64Kbyte
    long and aligned such that the first address in the segment has
    its last 16 bits be zero. If something has already done EXPREG
    or CRETVA, then I want to skip past it to allocate the first 64Kbyte
    segment that's free starting at a multiple of 64Kbyte.
    			---Walter
264.6QAR seems in order...TLE::BRETTMon Jun 23 1986 14:354
    Sounds like an extension of LIB$GET_VM_PAGE should be contemplated.
    Why don't you QAR it...
    
    /Bevin 
264.7Yes, you CAN use address 0 on VMS !ROXIE::OSMANand silos to fill before I feep, and silos to fill before I feepMon Jun 23 1986 15:0519
Let me guess that perhaps the reason you want 64k with low 16 bits 0
is that you are emulating some other machine.

If so, perhaps you only need ONE instance of the memory block.  To
this end, it ought to be possible, using PSECTS, to instruct the
linker to start your program space with 64K-512 bytes starting at
page 1.  Many VAX/VMS languages allow this via ARRAYS or VECTORS.

Then, you can use $CRETVA to create page 0, and you've got your
aligned 64K.

If I'm wrong, and you actually need multiple instances, then another
solution could be to allocate a HUGE block of memory with plain old
LIB$GET_VM, and then dish out the aligned segments yourself.  (I assume
you know what I mean, but please write if this isn't clear yet).

Savvie ?

/Eric
264.8CLT::GILBERTJuggler of NoterdomTue Jun 24 1986 16:3512
    Disable ASTs with $SETAST, get JPI$_FREP0VA from $GETJPI,
    calculate the next acceptable range of addresses, probe
    the pages (check whether they already exist), call $CRETVA
    to create the pages, and re-enable the ASTs.

    If any of the pages already exist, bump the range of acceptable
    addresses by 2^16 (your alignment criterion), and check again.


    An alternative approach is to use a based image.  I heartily
    endorse this method, since it gives you job security -- it
    is something you can fix again and again, as images grow, ...
264.9ok, but...BACH::VANROGGENThu Jun 26 1986 17:4212
    Aha, something like .8 is what I was afraid of.
    
    I do indeed want to allocate many of the 64Kbyte segments at
    arbitrary times.
    
    How do I probe the pages for existence--do I need to worry
    about pages without user mode read/write access?
    
    Also, does anyone know how to do this on Ultrix?
    
    Thanks			---Walter
    
264.10That page is mine, NO ITS MINE, its mine, ITS MINETLE::BRETTThu Jun 26 1986 20:2311
    
    You must *NOT* probe the pages for existence.   The existence or
    non-existence of a page is NOT A VALID FORM of claiming a page
    of memory on VMS.
    
    The only two legal forms are LIB$GET_VM (_PAGE) and EXPREG.
    
    All others are liable to lead to multiple subsystems believing they
    own the same pages.
    
    /Bevin
264.12Documentation -- it works!CLT::COWANKen Cowan, 381-2198Fri Jun 27 1986 22:028
    LIB$FREE_VM_PAGE does indeed permit you to free part of a block
    allocated in one call to LIB$GET_VM_PAGE.   It is even documented
    to permit it.
    
    Indeed, my vote for the best is GET_VM_PAGE 255 pages and free
    the ones you don't need.
    
    	KC
264.13BACH::VANROGGENSat Jun 28 1986 17:027
    OK, but where does LIB$GET/FREE_VM[_PAGE] keep its own bookkeeping
    information? If it's right nearby, wouldn't this cause a lot of
    waste, since it would "dirty" that 64Kbyte segment?
    
    Also, how can one do this on Ultrix?
    
    			---Walter
264.14CLT::COWANKen Cowan, 381-2198Mon Jun 30 1986 13:5613
    If I remember correctly, the VM routines keep track of space
    allocated via $EXPREG that is not currently allocated to a user.
    To do this, it uses a few longwords of the free block.  When the
    block get allocated, those longwords become the domain of the
    application.   In most cases, there is no per-block overhead for
    allocated blocks.    The exception is if you ask for boundary
    tags.
    
    As for Ultrix, I think the system routine alloc or malloc 
    works like GET_VM; but it has been too long since I did 
    un*x.
    
    	KC
264.15Another schemeSKYLAB::FISHERBurns Fisher 381-1466, ZKO1-1/D42Wed Jul 09 1986 16:528
    How about this scheme:  With AST disabled, do $EXPREG one page.
    This will give you the highest VA that has been allocated.  Then
    do $CRETVA on the first address range above that which meets your
    criteria.  This will waste the VA between the first address that
    you got and the 64K block.
    
    Burns
    
264.16Nope, no goodTLE::BRETTWed Jul 09 1986 22:259
    
    The *only* arbitrators of "who owns what storage" are LIB_VM and
    EXPREG.
    
    For example: What happens if a supervisor-mode AST goes off while
    you have USER-MODE ast's disabled?  Unlikely? ^Y and VAX PCA both
    result in supervisor mode asts.
    
    /Bevin
264.17Dead Horse! Let's beat it!CLT::GILBERT$ no /nono vaxnotesThu Jul 10 1986 19:347
    I s'pose this means that CRETVA and DELTVA have no use and should
    be yanked?

    If the only arbiters of "who owns what storage" are LIB_VM and EXPREG,
    then there should be no problem using CRETVA when supervisor-mode ASTs
    are considered, assuming that the supervisor-mode code also plays by
    the 'rules' (using only LIB_VM or EXPREG).
264.18Is the dead horse a bloody pulp yet?SKYLAB::FISHERBurns Fisher 381-1466, ZKO1-1/D42Fri Jul 11 1986 03:1321
    re .16 and super asts:  You're right...I forgot the user mode
    restrictions and assumed they would all be off.  I disagree with
    the literalness of your statement that LIB_VM and EXPREG are the
    sole arbiters..., however.
    
    In fact, EXPREG is the sole arbiter if it comes down to that.  It
    just has some restrictions (like CNTREG having to work in LIFO order)
    which LIB_VM works around.  If someone wanted to implement his/her
    own LIB_VM-like scheme, it would be perfectly acceptable as long
    as no memory was interchanged amoung schemes.  Just have the new
    allocator get its basic hunk of memory via EXPREG and then divide
    it as it chooses.
    
    In addition, (empirically, at least...I don't know the code) CRETVA
    does an implicit EXPREG if the VA which has been created is beyond
    the current region.
    
    Burns
    
    
    
264.19For reliable products, use documented behavioursTLE::BRETTFri Jul 11 1986 04:1624
    Thats true, at the VERY bottom, $EXPREG is the single source...
    
    RE: Yanking $CRETVA/$DELTVA;
    
    Apart from upward compatibility issues this has a LOT to recommend it!
    
    Give people the rope and
    they WILL hang themselves, as the replies to this note have
    illustrated.  Of course the fundamental operations are still needed
    for the $IMGACT support, and very occassionally you find routines
    doing $CRETVA's and $DELTVA's on storage which they definitely own
    (for example: having obtained it by calling $EXPREG in the first
    place)...
    
    Unusual things do $EXPREG's behind your back.  For example RMS places
    buffer's there, and $GETMSG loads message files there!  Most people
    are not aware of the numerous such subtle pitfalls that await those
    who believe that they know when memory is being allocated.
    
    I know this is the hackers notes file, but some of this gory garbage
    gets put into products that break years after the original mistake
    was made, for "totally unrelated" changes.
    
    /Bevin
264.20I want this page, then that one...GALLO::RASPUZZIMichael RaspuzziFri Jul 11 1986 15:004
    Demand paging would be easier but I guess VMS does not have that
    feature....
    
    Mike
264.21Pardon?TLE::BRETTSat Jul 12 1986 00:028
    Of course VMS has demand paging, that is the automatic movement
    of pages from disk to main memory without user-level intervention.
    
    What is being debated here is how to control the allocation of the
    VIRTUAL address space, not the physical (main memory) address space.
    
    /Bevin
    
264.22You touch it, you get itLATOUR::RASPUZZIMichael RaspuzziMon Jul 14 1986 00:376
    By demand paging, I meant if you want a page of memory, all you
    have to do is reference it and you have it. If I want to use a
    particular page of memory, I just touch a location on that page
    and I am given that page (in my virtual address space).
    
    Mike
264.23Demand paging -- yuck!CLT::COWANKen Cowan, 381-2198Mon Jul 14 1986 22:5210
    RE: .22
    
    	I'm really glad it doesn't.   I watched a friend debug some
    code before memory management was running.   His problem was simply
    that he lost his pointer to some memory.   When memory management
    is running, you get an accvio.   Without it (or with demand paging)
    memory materializes.  Yuck!
    
    	KC
    
264.24Still need a memory allocatorSKYLAB::FISHERBurns Fisher 381-1466, ZKO1-1/D42Wed Jul 16 1986 16:028
    .22's demand paging would be really n.g. for a lot of reasons. 
    The most important function of the memory allocation routines is
    arbitration.  Yes, VMS happens to  also use the routines to map
    virtual addresses, but the central problem is deciding what virtual
    addresses a particular piece of code is to use.  "Demand paging"
    would not solve that problem.
    
    Burns
264.25Some nits, a year laterMDVAX3::COARA wretched hive of bugs and flamers.Sat Nov 21 1987 22:0124
    I think I disagree with the statement that $CRETVA does an implicit
    $EXPREG if the requested addresses are beyond those already existent.
    In fact, if you ask $CRETVA for a page at 0000F000, and the last
    (highest) page used at the moment is at 0000A000, $CRETVA will create
    the requested page and fill the intervening process PTEs with 'null
    page' pointers.  So you'll have your page, but nothing between it and
    last one you had before.  At least, I *think* that's what happens..
    
    I also have a bicker with the statement that $EXPREG and LIB$VM
    are the `sole' arbiters.  Actually, if you decide to use one, then
    you must use it throughout your application, and ensure that neither
    your code nor any code you call (such as RTL routines) use any other
    method than the one you have selected.  If your program uses $CRETVA,
    $DELTVA, and some magic, then never call LIB$VM or any *other* RTL
    or LSR (Language Support Routines, like FOR$OPEN) routines AT ALL.
    If you can't keep this commitment, don't do it.
    
    RMS buffers, by the way, live in P1 space, as do all message file
    maps, unless you've used LINK /P0IMAGE.  So, if you're working with
    addresses below 40000000, those should not present a problem.
    
    #ken	:-)}
    
    #ken	:-)}
264.26PSW::WINALSKIPaul S. WinalskiSun Dec 06 1987 22:067
RE: .25

Last time I looked, message file maps lived in P0 space.  The PL/I compiler
used to use $CRETVA to allocate memory and it fell afoul of the allocation
of message sections in P0 space.

--PSW
264.27We're both right - I thinkMDVAX3::COARMy hero? Vax Headroom, of course!Thu Dec 17 1987 21:116
    Message sections that are part of the image live in P0, and those
    that get mapped because of a message file using the /FILE qualifier,
    but the one I was thinking of is that defined by SET MESSAGE filespec,
    which gets mapped into P1 space.
    
    #ken	:-)}
264.28does SETP0 also set P1 space too?FROST::HARRIMANHow do I work this?Fri Dec 18 1987 16:2110
>    Message sections that are part of the image live in P0, and those
>    that get mapped because of a message file using the /FILE qualifier,
>    but the one I was thinking of is that defined by SET MESSAGE filespec,
>    which gets mapped into P1 space.
    
    Then why is SETP0 the image that does the deed?
    
    /pjh_who_is_just_curious
    
    
264.29SETP0 does P1-specific functionsJON::MORONEYQuestion Authority (and the Authorities will question you)Fri Dec 18 1987 16:408
re .28:

>    Then why is SETP0 the image that does the deed?

SETP0 is a SET image that lives exclusively in P0 space (including the stack)
so it can play with P1 space without clobbering its own data structures.

-Mike
264.30Because! ;-)MDVAX3::COARMy hero? Vax Headroom, of course!Fri Dec 18 1987 20:326
    Because, in order to map the process-permanent section, P1 space
    may need to expand downwards, which would mung the stack.  SETP0
    is linked /P0IMAGE, which means that the stack and RMS buffers are
    allocated in P0 space, leaving P1 space free to expand.
    
    #ken	:-)}
264.31Perhaps a better answerMDVAX3::COARMy hero? Vax Headroom, of course!Fri Dec 18 1987 20:335
    Sorry, I just realised the question may be different than I first
    interpreted.  SETP0 means `version of SET that lives exclusively
    in P0 space so it can frobnicate P1 space.'  Better answer?
    
    #ken	:-)}
264.32Re .29-31 Not only that, but M. Moroney beat me to it!MDVAX3::COARMy hero? Vax Headroom, of course!Fri Dec 18 1987 20:510
264.33FROST::HARRIMANHow do I work this?Mon Dec 21 1987 12:055
    
    re: .29, .30, .31
    
    Sounds more reasonable than any other explanation I've heard. Thanx.