this post was submitted on 11 Apr 2022
28 points (100.0% liked)

Linux

56105 readers
951 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 6 years ago
MODERATORS
 

This is a relief to find! I just looked at htop and panicked over the high amount of "used" memory.

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 1 points 3 years ago

As I said, every file read from disk, be it an executable, image or whatever gets cached in RAM automatically and always.

Having said that, if you read a file using read(2) (or like any API that uses read() internally, which is most), then you end up with two copies of the file in RAM, the version your OS put in the disk cache, and the copy you created in your process's memory. You can avoid this second copy by using mmap(2). In this case the copy of the file in the disk cache gets mapped into your process's memory, so the RAM is shared between your copy and the disk cache copy.

You can also give hints to the disk cache subsystem in the kernel using fadvise(2). Don't though unless you know what you're doing.