Linux get page size

getpagesize(2) — Linux man page

getpagesize — get memory page size

Synopsis

Feature Test Macro Requirements for glibc (see feature_test_macros(7)): getpagesize(): Since glibc 2.12: Before glibc 2.12:
_BSD_SOURCE || _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED

Description

The function getpagesize() returns the number of bytes in a memory page, where «page» is a fixed-length block, the unit for memory allocation and file mapping performed by mmap(2).

Conforming To

SVr4, 4.4BSD, SUSv2. In SUSv2 the getpagesize() call is labeled LEGACY, and in POSIX.1-2001 it has been dropped; HP-UX does not have this call.

Notes

Portable applications should employ sysconf(_SC_PAGESIZE) instead of getpagesize(): (Most systems allow the synonym _SC_PAGE_SIZE for _SC_PAGESIZE.)

Whether getpagesize() is present as a Linux system call depends on the architecture. If it is, it returns the kernel symbol PAGE_SIZE, whose value depends on the architecture and machine model. Generally, one uses binaries that are dependent on the architecture but not on the machine model, in order to have a single binary distribution per architecture. This means that a user program should not find PAGE_SIZE at compile time from a header file, but use an actual system call, at least for those architectures (like sun4) where this dependency exists. Here libc4, libc5, glibc 2.0 fail because their getpagesize() returns a statically derived value, and does not use a system call. Things are OK in glibc 2.1.

Источник

find page size and number of pages of a process in linux

Given a PID of the process running in Linux (latest kernel), how do I find out:

  1. The number of pages it is using
  2. The size of each page it is using (4K, 2MB or 1GB)

This is for x86-64 architecture.

3 Answers 3

Pagesize is system wide and can be found with the getconf command

Читайте также:  Что значит класс не зарегистрирован windows

The mem_usage.py tool can provide some more detailed information on a processes memory usage.

Depending on how verbose the information you want should be, you want one of the following:

  • /proc/pid/statm : Provides information about memory usage, measured in pages.
  • /proc/pid/status : Provides much of the information from /proc/pid/statm , but is easier to read.

Check out the man-page for the proc-files for thorough documentation of what the different columns mean.

The number of pages it is using

According to the man proc, it is the number of pages the process has in real memory. Also take a look at the procstat.c to display proc stat in human readable format.

Not the answer you’re looking for? Browse other questions tagged linux unix process or ask your own question.

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.10.8.40416

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

how is page size determined in virtual address space?

Linux uses a virtual memory system where all of the addresses are virtual addresses and not physical addresses. These virtual addresses are converted into physical addresses by the processor.

To make this translation easier, virtual and physical memory are divided into pages. Each of these pages is given a unique number; the page frame number.

Some page sizes can be 2 KB, 4 KB, etc. But how is this page size number determined? Is it influenced by the size of the architecture? For example, a 32-bit bus will have 4 GB address space.

4 Answers 4

You can find out a system’s default page size by querying its configuration via the getconf command:

NOTE: The above units are typically in bytes, so the 4096 equates to 4096 bytes or 4kB.

This is hardwired in the Linux kernel’s source here:

Example

How does shifting give you 4096?

When you shift bits, you’re performing a binary multiplication by 2. So in effect a shifting of bits to the left ( 1 ) is doing the multiplication of 2^12 = 4096.

The hardware (specifically, the MMU, which is part of the CPU) determines what page sizes are possible. There is no relation to the processor register size and only an indirect relation to the address space size (in that the MMU determines both).

Читайте также:  Windows 10 сам перезагружается через минуту

Almost all architectures support a 4kB page size. Some architectures support larger pages (and a few also support smaller pages), but 4kB is a very widespread default.

Linux supports two page sizes:

  • Normal-sized pages, which I believe are 4kB by default on all architectures, though some architectures allow other values, e.g. 16kB on ARM64 or 8kB, 16kB or 64kB on IA64. These correspond to the deepest level of descriptors on the MMU (what Linux calls PTE).
  • Huge pages, if compiled in ( CONFIG_HUGETLB_PAGE is necessary, and CONFIG_HUGETLBFS as well for most uses). This corresponds to the second-deepest level of MMU descriptors (what Linux calls PMD) (or at least it usually does, I don’t know if this holds on all architectures).

The page size is a compromise between memory usage, memory usage and speed.

  • A larger page size means more waste when a page is partially used, so the system runs out of memory sooner.
  • A deeper MMU descriptor level means more kernel memory for page tables.
  • A deeper MMU descriptor level means more time spent in page table traversal.

The gains of larger page sizes are tiny for most applications, whereas the cost is substantial. This is why most systems use only normal-sized pages.

You can query the (normal) page size on your system with the getconf utility or the C function sysconf .

Using huge pages requires mounting the hugetlbfs filesystem and mmap ping files there.

Источник

Is there a way to find out SSD page size on Linux/Unix? What is «physical block» in fdisk output?

Everywhere I read that internally SSDs are structured in 4K or larger «pages», which grouped in «blocks» of about 128-256 pages (1, 2). SSDs work with these pages and blocks, «they can only erase data at the block level» (thus the block of pages is called «[NAND] erase block»). And the 512B blocks for the partition are emulated (which is done for legacy reasons).

I’m trying to get educated on SSDs, since I have some weird lags/freezes during writes to my Sandisk U100 on Samsung 9 np900x3c laptop. And one useful thing would be to correctly find out what pages/blocks my SSD has?

Читайте также:  Error installing microsoft windows sdk

Is there a utility or /sys/. file on Linux to determine the SSD page size?

Or «the drive and Googling the part numbers on the NAND chips may be needed», as in the comment?

Googling my Sandisk SSD I cannot find a proper datasheet/spec. But Sandisk and people do mention «4K random reads/writes». Does it mean the disk has 4K pages?

Also, fdisk shows me sector size (both physical and logical) and I/O 512 byte:

What is «physical» sector size here? It doesn’t seem to be the parameter of the SSD drive itself, since everybody say SSD pages are 4K+. Is it the emulated parameter for the disk? And «logical» is the sector size for the partition? Also, what is I/O size?

This question is probably the same as this one for USB flash — the answer is missing the point there, man fsstat says fsstat displays the details associated with a file system and the question is about the disk itself. My post has more details, maybe it would attract better responses?

Источник

detecting the memory page size

Is there a portable way to detect (programmatically) the memory page size using C or C++ code ?

7 Answers 7

Since Boost is a pretty portable library you could use mapped_region::get_page_size() function to retrieve the memory page size.

As for C++ Standard it gives no such a possibility.

C doesn’t know anything about memory pages. On posix systems you can use long pagesize = sysconf(_SC_PAGE_SIZE);

Windows 10, Visual Studio 2017, C++. Get the page size in bytes.

Yes, this is platform-specific. On Linux there’s sysconf(_SC_PAGESIZE) , which also seems to be POSIX. A typical C library implements this using the auxiliary vector. If for some reason you don’t have a C library or the auxiliary vector you could determine the page size like this:

That’s also POSIX, I think. It relies on there being some free memory, but it only needs two consecutive pages. It might be useful in some (weird) circumstances.

Across operating systems, no.

On Linux systems:

It is entirely platform dependent which address-ranges are mapped to which page-sizes. Further the pagesize is not system-wide. You can allocate memory from different page-size regions according to the use case. And you can even have platforms without any virtual memory managment.

So, code handling this topic must be platform specific.

Источник

Оцените статью