News for hackers. Stuff that matters.
Re:Replacing a $3000/mo Heroku bill with a $55/mo server by bayindirh on Tuesday October 21, 2025 @06:48PM (#45662707)
A long running Linux system uses 100% of its RAM. Every byte unused for applications will be used as a disk cache, given you read more data than your total RAM amount.

This cache is evictable, but it'll be there eventually.

Linux used to don't touch unused pages in the RAM in the older days if your RAM was not under pressure, but now it swaps out pages unused for a long time. This allows more cache space in RAM.

> how does caching to swap help?

I think I failed to convey what I tried to say. Let me retry:

Kernel doesn't cache to SSD. It swaps out unused (not accessed) but unevictable pages to SWAP, assuming that these pages will stay stale for a very long time, allowing more RAM to be used as cache.

When I look to my desktop system, in 12 days, Kernel moved 2592MB of my RAM to SWAP despite having ~20GB of free space. ~15GB of this free space is used as disk cache.

So, to have 2.5GB more disk cache, Kernel moved 2592 MB of non-accessed pages to SWAP.

Re:Replacing a $3000/mo Heroku bill with a $55/mo server by adastra22 on Tuesday October 21, 2025 @07:43PM (#45663196)
Yes, and if I am writing an API service, for example, I don’t want to suddenly add latency because I hit pages that have been swapped out. I want guarantees about my API call latency variance, at least when the server isn’t overloaded.

I DON’T WANT THE KERNEL PRIORITIZING CACHE OVER NRU PAGES. The easiest way to do this is to disable swap.

Re:Replacing a $3000/mo Heroku bill with a $55/mo server by eru on Tuesday October 21, 2025 @07:55PM (#45663291)
You better not write your API in Python, or any language/library that uses amortised algorithms in the standard (like Rust and C++ do). And let's not mention garbage collection.
Re:Replacing a $3000/mo Heroku bill with a $55/mo server by pdimitar on Wednesday October 22, 2025 @09:46AM (#45669082)
Huh? Could you please clarify wrt to Rust and C++? Can't they use another allocator if needed? Or that's not the problem?
Re:Replacing a $3000/mo Heroku bill with a $55/mo server by sethherr on Tuesday October 21, 2025 @07:55PM (#45663295)
I’m asking because I genuinely don’t know - what are “pages” here?
Re:Replacing a $3000/mo Heroku bill with a $55/mo server by adastra22 on Tuesday October 21, 2025 @08:00PM (#45663328)
That’s a fair question. A page is the smallest allocatable unit of RAM, from the OS/kernel perspective. The size is set by the CPU, traditionally 4kB, but these days 8kB-4MB are also common.
Re:Replacing a $3000/mo Heroku bill with a $55/mo server by gnosek on Wednesday October 22, 2025 @12:08AM (#45664809)
Or you can set the vm.swappiness sysctl to 0.
Re:Replacing a $3000/mo Heroku bill with a $55/mo server by baq on Wednesday October 22, 2025 @12:54AM (#45665015)
If you’re writing services in anything higher level than C you’re leaking something somewhere that you probably have no idea exists and the runtime won’t ever touch again.
Re:Replacing a $3000/mo Heroku bill with a $55/mo server by bayindirh on Wednesday October 22, 2025 @06:44AM (#45667197)
> I DON’T WANT THE KERNEL PRIORITIZING CACHE OVER NRU PAGES.

Then tell the Kernel about it. Don't remove a feature which might benefit other things running on your system.

Re:Replacing a $3000/mo Heroku bill with a $55/mo server by dwattttt on Wednesday October 22, 2025 @06:55AM (#45667278)
If you're getting this far into the details of your memory usage, shouldn't you use mlock to actually lock in the parts of memory you need to stay there? Then you get to have three tiers of priority: pages you never want swapped, cache, then pages that haven't been used recently.
Re:Replacing a $3000/mo Heroku bill with a $55/mo server by pdimitar on Wednesday October 22, 2025 @09:49AM (#45669131)
Can mlock be instructed to f.ex. "never swap pages from this pid"?
Re:Replacing a $3000/mo Heroku bill with a $55/mo server by bayindirh on Wednesday October 22, 2025 @09:51AM (#45669173)
The application requests this itself from the Kernel. See https://man7.org/linux/man-pages/man2/mlock.2.html
Re:Replacing a $3000/mo Heroku bill with a $55/mo server by dwattttt on Wednesday October 22, 2025 @04:47PM (#45674932)
From the link, mlockall with MCL_CURRENT | MCL_FUTURE

> Lock all pages which are currently mapped into the address space of the process.

> Lock all pages which will become mapped into the address space of the process in the future.

Re:Replacing a $3000/mo Heroku bill with a $55/mo server by wallstop on Tuesday October 21, 2025 @06:56PM (#45662776)
> Memory usage: 59%

wallstop@fridge:~$ swapon --show NAME TYPE SIZE USED PRIO /swap.img file 4G 0B -2

wallstop@fridge:~$ uptime 22:59:29 up 37 days, 21:39, 1 user, load average: 0.00, 0.00, 0.00

Re:Replacing a $3000/mo Heroku bill with a $55/mo server by bayindirh on Tuesday October 21, 2025 @07:04PM (#45662870)
The command you want to use is "free -m".

This is from another system I have close:

                   total        used        free      shared  buff/cache   available
    Mem:           31881        1423        1042          10       29884       30457
    Swap:            976           2         974
2MB of SWAP used, 1423 MB RAM used, 29GB cache, 1042 MB Free. Total RAM 32 GB.
Re:Replacing a $3000/mo Heroku bill with a $55/mo server by eru on Tuesday October 21, 2025 @07:58PM (#45663312)
If you are interested in human consumption, there's "free --human" which decided on useful units by itself. The "--human" switch is also available for "du --human" or "df --human" or "ls -l --human". It's often abbreviated as "-h", but not always, since that also often stands for "--help".
Re:Replacing a $3000/mo Heroku bill with a $55/mo server by bayindirh on Wednesday October 22, 2025 @06:46AM (#45667223)
Thanks, I generally use free -m since my brain can unconsciously parse it after all these years. ls -lh is one of my learned commands though. I type it in automatically when analyzing things.

ls -lrt, ls -lSh and ls -lShr are also very common in my daily use, depending on what I'm doing.

Re:Replacing a $3000/mo Heroku bill with a $55/mo server by wallstop on Tuesday October 21, 2025 @08:44PM (#45663669)
Thanks! My other problem was formatting. Just wanted to share that I see 0 swap usage and nowhere near 100% memory usage as a counterpoint.
Re:Replacing a $3000/mo Heroku bill with a $55/mo server by ta1243 on Wednesday October 22, 2025 @08:10AM (#45667833)
So that 2M of used swap is completely irrelevant. Same on my laptop

               total        used        free      shared  buff/cache   available
    Mem:           31989       11350        4474        2459       16164       19708
    Swap:           6047          20        6027
My syslog server on the other hand (which does a ton of stuff on disk) does use swap

    Mem:            1919         333          75           0        1511        1403
    Swap:           2047         803        1244
With uptime of 235 days.

If I were to increase this to 8G of ram instead of 2G, but for arguments sake had to have no swap as the tradeoff, would that be better or worse. Swap fans say worse.

Re:Replacing a $3000/mo Heroku bill with a $55/mo server by bayindirh on Wednesday October 22, 2025 @08:21AM (#45667951)
> So that 2M of used swap is completely irrelevant.

As I noted somewhere, my other system has 2,5GB of SWAP allocated over 13 days. That system is a desktop system and juggles tons of things everyday.

I have another server with tons of RAM, and the Kernel decided not to evict anything to SWAP (yet).

> If I were to increase this to 8G of ram instead of 2G, but for arguments sake had to have no swap as the tradeoff, would that be better or worse. Swap fans say worse.

I'm not a SWAP fan, but I support its use. On the other hand I won't say it'd be worse, but it'd be overkill for that server. Maybe I can try 4, but that doesn't seem to be necessary if these numbers are stable over time.

Re:Replacing a $3000/mo Heroku bill with a $55/mo server by ta1243 on Wednesday October 22, 2025 @08:10AM (#45667848)
> A long running Linux system uses 100% of its RAM.

How about this server:

             total       used       free     shared    buffers     cached
  Mem:          8106       7646        459          0        149       6815
  -/+ buffers/cache:        681       7424
  Swap:         6228         25       6202
Uptime of 2,105 days - nearly 6 years.

How long does the server have to run to reach 100% of ram?

Re:Replacing a $3000/mo Heroku bill with a $55/mo server by bayindirh on Wednesday October 22, 2025 @08:15AM (#45667890)
You already maxed it from Kernel's PoV. 8GB of RAM, where 6.8GB is cache. ~700MB is resident and 459 is free because I assume Kernel wants to have some free space to allocate something quite fast.

25MB swap use seems normal for a server which doesn't juggle much tasks, but works on one.

Re:Replacing a $3000/mo Heroku bill with a $55/mo server by ta1243 on Wednesday October 22, 2025 @01:14PM (#45672180)
So not 100% of ram, less than 95%