Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Can some one help me understand how memory mapping is done

Gone through this

Why does Linux show both more and less memory than I physically have installed?

but still i am not able to understand fully.

using Ubuntu 12.04 with 2 Gb DDR3 ram with 3.2.0-39-generic

free -k
         total       used       free     shared    buffers     cached
Mem:       2012040    1726616     285424          0       2612     245560
-/+ buffers/cache:    1478444     533596
Swap:      2057212     745152    1312060

2 GB in KB:

2097152

2097152-2012040=85112

Memory used by kernel

dmesg|grep Memory

(6571k kernel code, 452k absent, 63360k reserved, 6632k data, 920k init)

6571+452+63360+6632=77015k

85112-77015=8097k

Where can i see this 8 Mb of used ram.If its used by Devices through DMA can it be visible.

Also is reserved refers to memory reserved for BIOS?

http://pastebin.com/GrvrfzUu

[    0.000000] BIOS-provided physical RAM map:
[    0.000000]  BIOS-e820: 0000000000000000 - 000000000009fc00 (usable)
[    0.000000]  BIOS-e820: 00000000000f0000 - 0000000000100000 (reserved)
[    0.000000]  BIOS-e820: 0000000000100000 - 000000007da08c00 (usable)
[    0.000000]  BIOS-e820: 000000007da08c00 - 000000007da5cc00 (ACPI NVS)
[    0.000000]  BIOS-e820: 000000007da5cc00 - 000000007da5ec00 (ACPI data)
[    0.000000]  BIOS-e820: 000000007da5ec00 - 0000000080000000 (reserved)
[    0.000000]  BIOS-e820: 00000000e0000000 - 00000000f0000000 (reserved)
[    0.000000]  BIOS-e820: 00000000fec00000 - 00000000fed00400 (reserved)
[    0.000000]  BIOS-e820: 00000000fed20000 - 00000000feda0000 (reserved)
[    0.000000]  BIOS-e820: 00000000fee00000 - 00000000fef00000 (reserved)
[    0.000000]  BIOS-e820: 00000000ffb00000 - 0000000100000000 (reserved)
[    0.000000] NX (Execute Disable) protection: active
[    0.000000] SMBIOS 2.5 present.
[    0.000000] DMI: Dell Inc. OptiPlex 380                 /0F0TGN, BIOS A05 02/24/2011
[    0.000000] e820 update range: 0000000000000000 - 0000000000010000 (usable) ==> (reserved)
[    0.000000] e820 remove range: 00000000000a0000 - 0000000000100000 (usable)

dmesg|grep Memory

Memory: 1994460k/2058272k available (6571k kernel code, 452k absent, 63360k reserved, 6632k data, 920k init)
share|improve this question
    
So… what is your question? –  Gilles Jul 11 '13 at 13:48
    
@Gilles ohhh the same person that explained,memory split for almost similar question,i am really honored :).I am trying to understand why reserved memory varies with installed ram,all are saying its system reservation,but why this reservation varies with different ram size on same hardware and OS.if its memory for hardware devices using DMA,then can we see that. –  kevin Jul 11 '13 at 13:55
    
@kevin It would IMHO be better to update your question to make it more clear, so other don't have to read the small print (= your comment) to understand it. –  Anthon Nov 20 '13 at 6:00
add comment

3 Answers

I think I looked into this once and concluded that before the kernel's virtual memory system is initialized it uses a primitive boot memory allocator to allocate things like the structures required to manage virtual memory, and the pages consumed by the boot allocator are not accounted for properly.

share|improve this answer
    
This is correct - as a coincidence, I just happened to be doing the same. –  mikeserv Apr 8 at 22:28
add comment

Use free -b.

$ free -b
             total       used       free     shared    buffers     cached
Mem:    2147483648  237707264 1909776384          0          0          0
-/+ buffers/cache:  237707264 1909776384
Swap:            0          0          0
$ echo $(( 237707264 + 1909776384 ))
2147483648
share|improve this answer
    
i dont have any confusion in available ram,but confused about ra split among kernel,device and user –  kevin Jul 11 '13 at 11:18
    
The memory used by the kernel is within the used column, not in the free column. –  ott-- Jul 11 '13 at 11:53
    
ott, will free -m shows ram used by kernel?isnt it report user space available ram.Moreover my question is not that,why total ram is 2012040 when i have 2058272k as available. –  kevin Jul 11 '13 at 12:28
    
Can you add the complete output of free? –  ott-- Jul 11 '13 at 12:54
    
can you please check now? –  kevin Jul 11 '13 at 13:56
show 2 more comments

/proc/meminfo will tell you how free works, but /proc/kcore can tell you what the kernel uses. From the same page:

/proc/kcore

          This file represents the physical memory of the system and is
          stored in the ELF core file format.  With this pseudo-file,
          and an unstripped kernel (/usr/src/linux/vmlinux) binary, GDB
          can be used to examine the current state of any kernel data
          structures.

          The total length of the file is the size of physical memory
          (RAM) plus 4KB.

/proc/meminfo

          This file reports statistics about memory usage on the system.
          It is used by free(1) to report the amount of free and used
          memory (both physical and swap) on the system as well as the
          shared memory and buffers used by the kernel.  Each line of
          the file consists of a parameter name, followed by a colon,
          the value of the parameter, and an option unit of measurement
          (e.g., "kB").  The list below describes the parameter names
          and the format specifier required to read the field value.
          Except as noted below, all of the fields have been present
          since at least Linux 2.6.0.  Some fileds are displayed only if
          the kernel was configured with various options; those
          dependencies are noted in the list.

          MemTotal %lu
                 Total usable RAM (i.e., physical RAM minus a few
                 reserved bits and the kernel binary code).

          MemFree %lu
                 The sum of LowFree+HighFree.

          Buffers %lu
                 Relatively temporary storage for raw disk blocks that
                 shouldn't get tremendously large (20MB or so).

          Cached %lu
                 In-memory cache for files read from the disk (the page
                 cache).  Doesn't include SwapCached.

          SwapCached %lu
                 Memory that once was swapped out, is swapped back in
                 but still also is in the swap file.  (If memory
                 pressure is high, these pages don't need to be swapped
                 out again because they are already in the swap file.
                 This saves I/O.)

          Active %lu
                 Memory that has been used more recently and usually not
                 reclaimed unless absolutely necessary.

          Inactive %lu
                 Memory which has been less recently used.  It is more
                 eligible to be reclaimed for other purposes.

          Active(anon) %lu (since Linux 2.6.28)
                 [To be documented.]

          Inactive(anon) %lu (since Linux 2.6.28)
                 [To be documented.]

          Active(file) %lu (since Linux 2.6.28)
                 [To be documented.]

          Inactive(file) %lu (since Linux 2.6.28)
                 [To be documented.]

          Unevictable %lu (since Linux 2.6.28)
                 (From Linux 2.6.28 to 2.6.30, CONFIG_UNEVICTABLE_LRU
                 was required.)  [To be documented.]

          Mlocked %lu (since Linux 2.6.28)
                 (From Linux 2.6.28 to 2.6.30, CONFIG_UNEVICTABLE_LRU
                 was required.)  [To be documented.]

          HighTotal %lu
                 (Starting with Linux 2.6.19, CONFIG_HIGHMEM is
                 required.)  Total amount of highmem.  Highmem is all
                 memory above ~860MB of physical memory.  Highmem areas
                 are for use by user-space programs, or for the page
                 cache.  The kernel must use tricks to access this
                 memory, making it slower to access than lowmem.

          HighFree %lu
                 (Starting with Linux 2.6.19, CONFIG_HIGHMEM is
                 required.)  Amount of free highmem.

          LowTotal %lu
                 (Starting with Linux 2.6.19, CONFIG_HIGHMEM is
                 required.)  Total amount of lowmem.  Lowmem is memory
                 which can be used for everything that highmem can be
                 used for, but it is also available for the kernel's use
                 for its own data structures.  Among many other things,
                 it is where everything from Slab is allocated.  Bad
                 things happen when you're out of lowmem.

          LowFree %lu
                 (Starting with Linux 2.6.19, CONFIG_HIGHMEM is
                 required.)  Amount of free lowmem.

          MmapCopy %lu (since Linux 2.6.29)
                 (CONFIG_MMU is required.)  [To be documented.]

          SwapTotal %lu
                 Total amount of swap space available.

          SwapFree %lu
                 Amount of swap space that is currently unused.

          Dirty %lu
                 Memory which is waiting to get written back to the
                 disk.

          Writeback %lu
                 Memory which is actively being written back to the
                 disk.

          AnonPages %lu (since Linux 2.6.18)
                 Non-file backed pages mapped into user-space page
                 tables.

          Mapped %lu
                 Files which have been mmaped, such as libraries.

          Shmem %lu (since Linux 2.6.32)
                 [To be documented.]

          Slab %lu
                 In-kernel data structures cache.

          SReclaimable %lu (since Linux 2.6.19)
                 Part of Slab, that might be reclaimed, such as caches.

          SUnreclaim %lu (since Linux 2.6.19)
                 Part of Slab, that cannot be reclaimed on memory
                 pressure.

          KernelStack %lu (since Linux 2.6.32)
                 Amount of memory allocated to kernel stacks.

          PageTables %lu (since Linux 2.6.18)
                 Amount of memory dedicated to the lowest level of page
                 tables.

          Quicklists %lu (since Linux 2.6.27)
                 (CONFIG_QUICKLIST is required.)  [To be documented.]

          NFS_Unstable %lu (since Linux 2.6.18)
                 NFS pages sent to the server, but not yet committed to
                 stable storage.

          Bounce %lu (since Linux 2.6.18)
                 Memory used for block device "bounce buffers".

          WritebackTmp %lu (since Linux 2.6.26)
                 Memory used by FUSE for temporary writeback buffers.

          CommitLimit %lu (since Linux 2.6.10)
                 Based on the overcommit ratio ('vm.overcommit_ratio'),
                 this is the total amount of  memory currently available
                 to be allocated on the system.  This limit is adhered
                 to only if strict overcommit accounting is enabled
                 (mode 2 in /proc/sys/vm/overcommit_ratio).  The
                 CommitLimit is calculated using the following formula:

                     CommitLimit =
                         ([total RAM pages] - [total huge TLB pages]) *
                         overcommit_ratio / 100 + [total swap pages]

                 For example, on a system with 1GB of physical RAM and
                 7GB of swap with a overcommit_ratio of 30, this formula
                 yields a CommitLimit of 7.3GB.  For more details, see
                 the memory overcommit documentation in the kernel
                 source file Documentation/vm/overcommit-accounting.

          Committed_AS %lu
                 The amount of memory presently allocated on the system.
                 The committed memory is a sum of all of the memory
                 which has been allocated by processes, even if it has
                 not been "used" by them as of yet.  A process which
                 allocates 1GB of memory (using malloc(3) or similar),
                 but touches only 300MB of that memory will show up as
                 using only 300MB of memory even if it has the address
                 space allocated for the entire 1GB.  This 1GB is memory
                 which has been "committed" to by the VM and can be used
                 at any time by the allocating application.  With strict
                 overcommit enabled on the system (mode 2
                 /proc/sys/vm/overcommit_memory), allocations which
                 would exceed the CommitLimit (detailed above) will not
                 be permitted.  This is useful if one needs to guarantee
                 that processes will not fail due to lack of memory once
                 that memory has been successfully allocated.

          VmallocTotal %lu
                 Total size of vmalloc memory area.

          VmallocUsed %lu
                 Amount of vmalloc area which is used.

          VmallocChunk %lu
                 Largest contiguous block of vmalloc area which is free.

          HardwareCorrupted %lu (since Linux 2.6.32)
                 (CONFIG_MEMORY_FAILURE is required.)  [To be
                 documented.]

          AnonHugePages %lu (since Linux 2.6.38)
                 (CONFIG_TRANSPARENT_HUGEPAGE is required.)  Non-file
                 backed huge pages mapped into user-space page tables.

          HugePages_Total %lu
                 (CONFIG_HUGETLB_PAGE is required.)  The size of the
                 pool of huge pages.

          HugePages_Free %lu
                 (CONFIG_HUGETLB_PAGE is required.)  The number of huge
                 pages in the pool that are not yet allocated.

          HugePages_Rsvd %lu (since Linux 2.6.17)
                 (CONFIG_HUGETLB_PAGE is required.)  This is the number
                 of huge pages for which a commitment to allocate from
                 the pool has been made, but no allocation has yet been
                 made.  These reserved huge pages guarantee that an
                 application will be able to allocate a huge page from
                 the pool of huge pages at fault time.

          HugePages_Surp %lu (since Linux 2.6.24)
                 (CONFIG_HUGETLB_PAGE is required.)  This is the number
                 of huge pages in the pool above the value in
                 /proc/sys/vm/nr_hugepages.  The maximum number of
                 surplus huge pages is controlled by
                 /proc/sys/vm/nr_overcommit_hugepages.

          Hugepagesize %lu
                 (CONFIG_HUGETLB_PAGE is required.)  The size of huge
                 pages.
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.