7

When I see that phrase (or similar), as e.g. today in How to Use the free Command on Linux (article with 2020 date):

RAM that isn’t being used for something is wasted RAM

I recall about LPDDR used for mobile devices:

Additional savings come from temperature-compensated refresh (DRAM requires refresh less often at low temperatures), partial array self refresh, and a "deep power down" mode which sacrifices all memory contents.

As Android is based on Linux kernel, does it already supports putting part of memory in "deep power down"? Some kernel parameters to enable managing data in a way to minimize total memory usage?

In total: has Linux kernel abandoned universally applying "RAM that isn’t being used for something is wasted RAM" approach?

Martian2020
  • 1,039
  • 7
  • 20
  • Wouldn't deep power down apply to a whole DIMM? With dual-channel memory with the memory controller interleaving between DIMMs to increase bandwidth, powering down a DIMM would lose every other cache line in every page. Maybe you could use a different interleave strategy, coarser which wouldn't help as much with bandwidth for a single stream... – Peter Cordes Dec 24 '21 at 22:40
  • 2
    What is meant by "wasted"? As in a waste of electricity if it's not going to be used by the system, or a waste of money to have if it won't be used? – cat Dec 24 '21 at 23:03
  • @PeterCordes, doesn't dual-channel pairs modules, so that a pair can be powered down? I'm not sure I understand properly yours: "would lose every other cache line in every page" - like every page in the whole system or on that DIMM? – Martian2020 Dec 24 '21 at 23:47
  • 1
    @cat: It is wasted because it carries an [opportunity cost](https://en.wikipedia.org/wiki/Opportunity_cost), which may in some cases be low but will almost always be nonzero. – Kevin Dec 25 '21 at 05:06
  • Prompt reaction to the question hints on importance of wording. My previous one on the same subject got lost w/out answers. https://unix.stackexchange.com/questions/678980/is-memory-deep-power-down-lpddr-mode-where-memory-contents-are-not-retained-su. I think I try to vote previous as duplicate. Though it is for a different angle... – Martian2020 Dec 29 '21 at 02:32

1 Answers1

13

Has Linux kernel abandoned universally applying "RAM that isn’t being used for something is wasted RAM" approach?

No, it hasn’t: it is still the case that the kernel will not try to avoid using memory which is available. However, it supports memory hotplug, which could conceivably be paired with features such as those offered by LPDDR to reduce power consumption: a given memory chip could be relinquished, hot-“unplugged”, and powered down.

Whether all that would actually result in reduced power consumption overall is a whole other debate.

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
  • Thank you for quick and at first glance close to complete answer. You have noted "universally" is the question? If yes, does your answer mean kernel supports, but never recommends? One of uses in the document is stated as: "Reducing energy consumption" II ) I've read most of the document, tried to put some offline, got `busy` - in short: do you advice to ask additional questions on the hotplug as 1) comments here, 2) expanding the question, 3) creating other questions? – Martian2020 Dec 24 '21 at 12:38
  • I've found https://unix.stackexchange.com/questions/312312/on-linux-how-can-i-hot-unplug-memory where a person have not got answer how to use the feature to reduce memory for VM - same as me "busy" - any pointers how to unplug in practice? – Martian2020 Dec 24 '21 at 12:45
  • Yes, I had noticed the use of “universally” in the question. The kernel always tries to use all available memory, or rather, it doesn’t try to avoid using all available memory; but it also supports changes to available memory at runtime. The usual rules regarding questions apply here: questions which arise from an answer should be asked as new questions, with context. [This Q&A](https://unix.stackexchange.com/q/312312/86440) *does* have answers; the first one provides an important hint: you need to prepare your system to allow memory hot-unplugging, it won’t work with a default setup. – Stephen Kitt Dec 24 '21 at 13:09
  • I've read it and mentioned above but initially misunderstood. I thought kernel parameters are passed at boot time. Now I see (obviously) some parameters can be changed at run-time, correct? – Martian2020 Dec 24 '21 at 13:15
  • Could "not try to avoid using" be simplified to "use"? – Jeff Schaller Dec 24 '21 at 13:23
  • 2
    @Jeff I’m trying to distinguish between “actively tries to use all available memory” and “doesn’t use more memory than it needs, but doesn’t put huge effort into curtailing its use of memory”. – Stephen Kitt Dec 24 '21 at 13:25
  • @Martian2020 that depends on the kernel parameter in question. In this instance, you need to specify `kernelcore` with an appropriate value when booting; it can’t be changed afterwards (at least, memory blocks can’t be moved to the movable zone, which is what you need to be able to offline them). – Stephen Kitt Dec 24 '21 at 13:28
  • I see now more clearly. kernel would use only part of ram to load itself, but it can load userspace data - other apps, files etc. to the rest of RAM. Is it correct? Why doesn't it try to occupy some RAM close to each other just in case for that by default (maybe worth another question...)? – Martian2020 Dec 24 '21 at 13:38
  • 1
    The default setup should minimise surprises. If the kernel tries to reserve memory for movable zones, it’s bound to get it wrong in some cases, which would lead to obscure and hard-to-diagnose errors. With the current situation, the default setup works for everyone who doesn’t need memory hotplugging, which is most users of non-specific systems. Designers of systems where hotplugging is helpful (including phones, perhaps) know this, and can adjust settings as appropriate. – Stephen Kitt Dec 24 '21 at 13:57
  • thanks, looks like for me to understand more it needs more reading and maybe another question later. – Martian2020 Dec 24 '21 at 14:17
  • hi again. Please see https://unix.stackexchange.com/questions/678980/is-memory-deep-power-down-lpddr-mode-where-memory-contents-are-not-retained-su, can it be considered duplicate? In fact your answer does not cover command of putting memory in "deep power down", is it done automatically after memory is marked as unplugged? thank you – Martian2020 Dec 29 '21 at 02:40
  • I wouldn’t consider it a duplicate, since it’s specifically about powering memory down. Here I addressed the “in total” part of your question. – Stephen Kitt Dec 29 '21 at 22:15
  • @Martian2020 you should understand, that while Android uses Linux kernel, it uses heavily patched version of it. – Reishin Jun 27 '22 at 08:54