Discussion summary

Users discussed FreeBSD's memory management, caching, and heuristics for measuring used RAM, with some mentioning recent fixes and tools like zfs-stats and btop.

What the discussion says

  • Memory usage can be inaccurate due to caching and heuristics.
  • Tools like zfs-stats and btop help monitor system internals.
  • There is ongoing work to improve memory measurement accuracy.
Used memory for the system is always total minus available.
drdexebtjl
The system knows what is using every page, but measuring it precisely is complex.
toast0

Comments

Hacker News

I don’t understand the part about using heuristics and deciding what counts as used memory…

Used memory for the system is always total minus available.

Heuristics? I would hope that the system knows precisely what is using every single byte of physical and virtual memory. Is this a reporting problem? Why do we have to settle for heuristics and not the exact number?

by drdexebtjl

You will be surprised by how inaccurate memory measurements are.

by man8alexd

The thing is it's easy to define free, unused memory. But a lot of the used memory is your system caching stuff that would be free if you needed more than what's actually free. So you can see you have 1g of free memory out of your 4g, but then you allocate 3g and it will do without a sweat and you'd be confused. So you have to go and dig for what those caches are and report that they're effectively free too.

by CrociDB

> I would hope that the system knows precisely what is using every single byte of physical and virtual memory.

Of course the system knows what is using every page. The difficulty is really in how to account for pages that are backed by disk.

If you count all of those as free, that's not accurate. If you count all of those as used, that's not accurate either. Additionally, FreeBSD (at least) doesn't have separate queues for disk backed pages, so there's not really a good way to know how much of your active (or inactive) memory is disk backed.

As an additional caveat that measuring active/inactive has costs. In the past, FreeBSD wouldn't really do the work for that until it needed to... I know some stuff changed, but I don't remember where it ended up; it wasn't great when it bulk marked a ton of pages as inactive and then the active ones would fault back in.

by toast0

Great job on getting the fixes merged!

by efxhoy

I wonder if these btop fixes got into the standard ports collection? Or even upstream?

I like the command for viewing the ARC cache size, never knew that. It's only 2GB on my system (of 64GB RAM).

by wolvoleo

the end struck me - a picture of an os book. I wonder if students these days retain their books after college, or do they get returned as a rental?

by m463

In college ATM and while I usually keep old textbooks, I have sold a couple on ebay to free up shelf space.

by kogasa240p

I bought as few textbooks as I could, but the few that I did buy are sitting in my parents' basement bookshelves somewhere.

by post-it

I graduated a decade ago but there was a pretty decent post-semester market for people selling their textbooks to other students (mostly via posting in various Facebook groups). Given the cost of college nowadays, if that ends up saving students a bit of money, it's probably worth it over saving the textbooks themselves.

Most years my parents ended up just driving my stuff to my aunt's house where she kept it in her garage over the summer after I packed it all up since I grew up several states away but my aunt loved in the area, and by the end of senior year, the textbooks I never managed to sell had added up to almost an entire extra bin (which was heavier than any of the others because they mostly just had clothes). For people who didn't have parents who loved driving everywhere in a large enough car or relatives in the area, this seems like it would be even more annoying (potentially ending up with just donating the leftover textbooks or maybe leaving them on the street like furniture and stuff often is at the end of the year on campuses). If people want to keep their textbooks, more power to them, but I'm not convinced that having a cheaper way that also simplifies the logistics of moving isn't better.

by saghm

I'm a professor at a community college in Silicon Valley, and my students use online textbooks. I try to use Creative Commons or other libre textbooks, but sometimes I use paid textbooks when they are heads-and-shoulders better than their libre alternatives. Some e-textbooks can be accessed on a subscription basis. I admit I prefer non-subscription materials, but a colleague advised me that often the book that students learn from is different from a good reference book that students can use once they've already learned the material. For example, my colleagues and I have had great success with an online, interactive textbook for discrete math. While the subscription is unfortunately only valid for the duration of the course, once students have learned discrete math, they could buy a used copy of Rosen's discrete math textbook as a reference.

The nice thing about e-textbooks is not needing to carry around a bunch of heavy books. I remember the tomes I had in my college days, such as Stewart's Calculus.

by linguae

Thank you for such a quality post.

by duendefm

Interesting post, it made me wonder. At one time FreeBSD swap usage/logic was far better than what Linux did. Is that still the case ?

by jmclnx

Yes, It's just not every tool is aware of ZFS ARC. Which is what this post is about. Author just describes in an odd way.

by 0x457

I remember how NetBSD promoted itself as running on many more toasters than Linux once.

Then some NetBSD dev wrote on their mailing list that this is no longer true. Linux runs on more toasters now. (And also top 500 supercomputers, but toasters are the real metal to the petal test.)

These fights always remind me of:

https://www.jwz.org/doc/worse-is-better.html

It's an interesting piece of history too. I kind of evaluate it a bit differently, e. g. my summary is "momentum beats academic perfection". Which is not completely what it is about, but it is my own imperfect TL;DR summary.

by shevy-java

FreeBSD didn’t have memory overcommit and instead used strict swap reservation - each allocated anonymous memory page was supposed to have a corresponding swap page. This required 2x RAM swap space, otherwise you would get “out of swap” when forking a large process. FreeBSD implemented memory overcommit around 2000.

by man8alexd

htop explained*

I was looking forward for web protocol, but alas...

by NooneAtAll3

As for the “unauthorized” sign:

Book publishers used to print India/SEA-only editions of books only sold in those countries, significantly cheaper than in the US or Europe. Then a Thai guy realized that this would be a good business opportunity: buy cheaper books and then import them to the US. Wiley brought him to court, went to the SCOTUS, Wiley lost the case. So they ended up printing cheaper edition books.

https://en.wikipedia.org/wiki/Kirtsaeng_v._John_Wiley_%26_So....

Mind you "price discrimination" like this still exist in the digital world where locality is easier to be enforced. For example Steam has extensive regional pricing across countries so the same game can be significantly cheaper in Russia, India, Brazil etc. compared to US or EU

An example: https://steamdb.info/app/413150/

https://partner.steamgames.com/pricing/explorer

https://partner.steamgames.com/doc/store/pricing/currencies

by haunter

Wow, how did we go from "it's impossible to enforce region locking online because you can transmit information instantly across the world" to "locality more easily enforced in the digital world"?

by stavros

Wow, I've only ever heard of regional pricing being described as an overwhelmingly positive concept. When phrased as "price discrimination", it invokes a completely different set of (negative) emotions in me.

It's weirdly uncomfortable knowing that phrasing has such a big impact on one's emotions. It really shows how vulnerable we are to manipulation.

by regenschutz

    When Kirtsaeng moved to the US in 1997 to pursue an undergraduate degree in mathematics at
    Cornell University,[4] he discovered that textbooks (not just those published by Wiley, but
    of other publishers too) were considerably more expensive to buy in the United States than
    in his home country. Kirtsaeng asked his relatives from Thailand to buy such books at home
    and ship them to him to sell at a profit. He sold the imported books on eBay, making $1.2
    million in revenue, although the parties disputed the net profit amount.
A text book case (ha!) about one of the mechanisms that enable the free markets and trade to bring the prices of goods down.

by Joker_vD

Join the discussion

Write your take first — we'll ask for email only when you're ready to publish.

  • Hacker News
  • I don’t understand the part about using heuristics and deciding what counts as used memory…

    Used memory for the system is always total minus available.

    Heuristics? I would hope that the system knows precisely what is using every single byte of physical and virtual memory. Is this a reporting problem? Why do we have to settle for heuristics and not the exact number?

    by drdexebtjl
  • You will be surprised by how inaccurate memory measurements are.
    by man8alexd
  • The thing is it's easy to define free, unused memory. But a lot of the used memory is your system caching stuff that would be free if you needed more than what's actually free. So you can see you have 1g of free memory out of your 4g, but then you allocate 3g and it will do without a sweat and you'd be confused. So you have to go and dig for what those caches are and report that they're effectively free too.
    by CrociDB
  • > I would hope that the system knows precisely what is using every single byte of physical and virtual memory.

    Of course the system knows what is using every page. The difficulty is really in how to account for pages that are backed by disk.

    If you count all of those as free, that's not accurate. If you count all of those as used, that's not accurate either. Additionally, FreeBSD (at least) doesn't have separate queues for disk backed pages, so there's not really a good way to know how much of your active (or inactive) memory is disk backed.

    As an additional caveat that measuring active/inactive has costs. In the past, FreeBSD wouldn't really do the work for that until it needed to... I know some stuff changed, but I don't remember where it ended up; it wasn't great when it bulk marked a ton of pages as inactive and then the active ones would fault back in.

    by toast0
  • Great job on getting the fixes merged!
    by efxhoy
  • I wonder if these btop fixes got into the standard ports collection? Or even upstream?

    I like the command for viewing the ARC cache size, never knew that. It's only 2GB on my system (of 64GB RAM).

    by wolvoleo
  • >I like the command for viewing the ARC cache size

    zfs-stats is also nice for more zfs internals like hit-rate L2 etc..

    https://www.freshports.org/sysutils/zfs-stats

    by BSDobelix
  • Ports is on 1.4.7.

    * https://freshports.org/sysutils/btop/

    The fix is still pending being even made to the origin version.

    * https://github.com/aristocratos/btop/pull/1728

    by JdeBP
  • the end struck me - a picture of an os book. I wonder if students these days retain their books after college, or do they get returned as a rental?
    by m463
  • In college ATM and while I usually keep old textbooks, I have sold a couple on ebay to free up shelf space.
    by kogasa240p
  • I bought as few textbooks as I could, but the few that I did buy are sitting in my parents' basement bookshelves somewhere.
    by post-it
  • I graduated a decade ago but there was a pretty decent post-semester market for people selling their textbooks to other students (mostly via posting in various Facebook groups). Given the cost of college nowadays, if that ends up saving students a bit of money, it's probably worth it over saving the textbooks themselves.

    Most years my parents ended up just driving my stuff to my aunt's house where she kept it in her garage over the summer after I packed it all up since I grew up several states away but my aunt loved in the area, and by the end of senior year, the textbooks I never managed to sell had added up to almost an entire extra bin (which was heavier than any of the others because they mostly just had clothes). For people who didn't have parents who loved driving everywhere in a large enough car or relatives in the area, this seems like it would be even more annoying (potentially ending up with just donating the leftover textbooks or maybe leaving them on the street like furniture and stuff often is at the end of the year on campuses). If people want to keep their textbooks, more power to them, but I'm not convinced that having a cheaper way that also simplifies the logistics of moving isn't better.

    by saghm
  • I'm a professor at a community college in Silicon Valley, and my students use online textbooks. I try to use Creative Commons or other libre textbooks, but sometimes I use paid textbooks when they are heads-and-shoulders better than their libre alternatives. Some e-textbooks can be accessed on a subscription basis. I admit I prefer non-subscription materials, but a colleague advised me that often the book that students learn from is different from a good reference book that students can use once they've already learned the material. For example, my colleagues and I have had great success with an online, interactive textbook for discrete math. While the subscription is unfortunately only valid for the duration of the course, once students have learned discrete math, they could buy a used copy of Rosen's discrete math textbook as a reference.

    The nice thing about e-textbooks is not needing to carry around a bunch of heavy books. I remember the tomes I had in my college days, such as Stewart's Calculus.

    by linguae
  • Thank you for such a quality post.
    by duendefm
  • Interesting post, it made me wonder. At one time FreeBSD swap usage/logic was far better than what Linux did. Is that still the case ?
    by jmclnx
  • Yes, It's just not every tool is aware of ZFS ARC. Which is what this post is about. Author just describes in an odd way.
    by 0x457
  • I remember how NetBSD promoted itself as running on many more toasters than Linux once.

    Then some NetBSD dev wrote on their mailing list that this is no longer true. Linux runs on more toasters now. (And also top 500 supercomputers, but toasters are the real metal to the petal test.)

    These fights always remind me of:

    https://www.jwz.org/doc/worse-is-better.html

    It's an interesting piece of history too. I kind of evaluate it a bit differently, e. g. my summary is "momentum beats academic perfection". Which is not completely what it is about, but it is my own imperfect TL;DR summary.

    by shevy-java
  • FreeBSD didn’t have memory overcommit and instead used strict swap reservation - each allocated anonymous memory page was supposed to have a corresponding swap page. This required 2x RAM swap space, otherwise you would get “out of swap” when forking a large process. FreeBSD implemented memory overcommit around 2000.
    by man8alexd
  • If you like this kind of post, you might like this “htop explained” post.

    https://peteris.rocks/blog/htop/

    by tiffanyh
  • htop explained*

    I was looking forward for web protocol, but alas...

    by NooneAtAll3
  • As for the “unauthorized” sign:

    Book publishers used to print India/SEA-only editions of books only sold in those countries, significantly cheaper than in the US or Europe. Then a Thai guy realized that this would be a good business opportunity: buy cheaper books and then import them to the US. Wiley brought him to court, went to the SCOTUS, Wiley lost the case. So they ended up printing cheaper edition books.

    https://en.wikipedia.org/wiki/Kirtsaeng_v._John_Wiley_%26_So....

    Mind you "price discrimination" like this still exist in the digital world where locality is easier to be enforced. For example Steam has extensive regional pricing across countries so the same game can be significantly cheaper in Russia, India, Brazil etc. compared to US or EU

    An example: https://steamdb.info/app/413150/

    https://partner.steamgames.com/pricing/explorer

    https://partner.steamgames.com/doc/store/pricing/currencies

    by haunter
  • Wow, how did we go from "it's impossible to enforce region locking online because you can transmit information instantly across the world" to "locality more easily enforced in the digital world"?
    by stavros
  • Wow, I've only ever heard of regional pricing being described as an overwhelmingly positive concept. When phrased as "price discrimination", it invokes a completely different set of (negative) emotions in me.

    It's weirdly uncomfortable knowing that phrasing has such a big impact on one's emotions. It really shows how vulnerable we are to manipulation.

    by regenschutz
  •     When Kirtsaeng moved to the US in 1997 to pursue an undergraduate degree in mathematics at
        Cornell University,[4] he discovered that textbooks (not just those published by Wiley, but
        of other publishers too) were considerably more expensive to buy in the United States than
        in his home country. Kirtsaeng asked his relatives from Thailand to buy such books at home
        and ship them to him to sell at a profit. He sold the imported books on eBay, making $1.2
        million in revenue, although the parties disputed the net profit amount.
    
    A text book case (ha!) about one of the mechanisms that enable the free markets and trade to bring the prices of goods down.
    by Joker_vD

Related stories