Re: Proper use of mlock(2)



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Daniel Rudy wrote:
What is the proper use of mlock(2)? In the man page, it states that the
addr param *should* be aligned on a page boundary. The question is how
do you find out if it is or isn't? Or better yet, how do you force an
allocation on a page boundary?

I can use getpagesize(2) to find out what the page size is, but with
FreeBSD and it's virtual address memory model, how do you force a memory
allocation in the virtual address space to align to a physical page
boundary?

My OS is FreeBSD 6.0.

Thanks.


you don't have to care about virtual to physical mapping. If your
virtual address is a multiple of pagesize everything is fine. You cannot
force a malloc to return a multiple of pagesize as the base address of
the allocated memory block, but you can allocate a big enough block, so
that you can calculate an aligned address within that block.

Tom
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (SunOS)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEKmgz6U+hp8PKQZIRAhZwAKC/JkccwNeDYNfmy9457FzZ6bvGVQCfQU/a
4hlFLvcBLsfhgDY2dd7Vd/A=
=Y5Jn
-----END PGP SIGNATURE-----
.



Relevant Pages

  • Re: [PATCH 4/4] fdtable: Implement new pagesize-based fdtable allocation scheme.
    ... The allocation algorithm sizes the fdarray in such a way that its memory ... pagesize / 4 ...
    (Linux-Kernel)
  • Re: How to release heap memory that is marked as free
    ... As I said, fragmentation is a very serious problem, and one of the most serious problems ... my allocator was accused of using massive amounts of memory. ... I'm going to have to re-think the memory allocation that I'm ... process's 'working set'. ...
    (microsoft.public.vc.mfc)
  • Re: [PATCH 00/28] Swap over NFS -v16
    ... memory they can consume. ... So we need the extra (skb) ... included in the reserve? ... if the allocation had to dip into emergency reserves, ...
    (Linux-Kernel)
  • Re: Memory leak with CAsyncSocket::Create
    ... read my essay on how storage allocators work. ... Create method is consuming system memory that is not released back to ... The memory consumption is either shown as "Mem Usage" on the Task ... many levels of allocation going ...
    (microsoft.public.vc.mfc)
  • Re: OT: C++ overloading operators
    ... dynamic allocation, no matter how many "clever tricks" are used... ... though there's enough memory in the system, ... all these "flexible data types" map into CPU command ... The computing environment is completely ...
    (comp.dsp)