By: ⚛ (0xe2.0x9a.0x9b.delete@this.gmail.com), September 27, 2021 7:37 am
Room: Moderated Discussions
Linus Torvalds (torvalds.delete@this.linux-foundation.org) on September 23, 2021 12:01 pm wrote:
> ⚛ (0xe2.0x9a.0x9b.delete@this.gmail.com) on September 23, 2021 9:37 am wrote:
> >
> > In other words, if I read your posts about segments correctly, you seem to be claiming
> > that there is zero correlation between the overly simplistic type system of the C programming
> > language (plus other languages from that era) and the downfall of segments.
>
> I don't think that's at all what I said.
>
> I said that segments are an extra complication, and that
> they don't add any value, so people dropped their use.
>
> I said nothing about the C language. In fact, it's an entirely language-agnostic statement.
>
> People love to blame C for various things, and claim that the "C model" made
> computer architecture much less interesting. You seem to be in that camp, and
> seem to try to claim that C had something to do with segments going away.
>
> Not so.
>
> C not wanting segments is not the cause, it's the correlation. Nobody wants
> segments. It's not that "C made computer architecture boring", it's that "learning
> what works and what does not" made for crazy useless features going away.
>
> Those crazy useless features may have been "exciting", but that doesn't make them good.
>
> If anything, the C language people bent over backwards to make excuses for horrible architecture features,
> and weakened the language more than they should have in order to allow for bad architecture decisions.
> Pretty much every single "undefined behavior" is about the language allowing for silly things.
>
> So what I am claiming is that segments - and by extension, "capability pointer architectures"
> - are a bad idea. They add unwanted complexity that doesn't actually buy users anything at
> all into one of the most important part of the CPU pipeline - the memory units.
>
> Don't do it. It's been a research subject for many decades, it's still a research
> subject (I see pointers to the ARM capability pointers in this thread), and it
> has never ever been successful. At what point do people just admit defeat?
>
> The fact is, the whole notion of passing magic pointers and trying to associate random state
> with them between two random untrusted but somehow cooperative entities is pure BS. And I claim
> that no amount of segmentation - whatever you call it - will make it anything else.
>
> Side note: that doesn't mean that you can't do other things. By all means add features like
> pointer coloring that is for debugging. The ARM memory tagging is actually very successful.
> It's not about some absolute pointer security, it's not about arbitrary segments, it's a reasonably
> low-overhead debugging aid that can catch bad uses early. And it still lives in the context
> of a regular flat address space, just one where you can add some region markers.
>
> So you can add exciting value add in the memory unit.
>
> It's just that segments or capabilities isn't it. Too much pain for no real gain.
>
> Linus
(I am writing this response without reading through the sub-tree of this forum node, so I would like to apologize in advance if I will write something that has been discussed there.)
You didn't write something unexpected, which is good from a certain viewpoint because it makes it easier to attack with some counter-arguments. You are defending the "paging-unit is superior to segments" viewpoint.
- Protected mode segments (80286 and later), with two privilege levels (kernel-space and user-space), are fully sufficient to implement a Unix-like operating system.
- A protected mode segment has a base address and a limit (usually with a granularity of at most 1 word) that only the kernel-space can modify directly.
- A downside of having a paging unit in a CPU is that the CPU must have L1+L2 caches (TLBs) storing virtual memory mappings (which is, in simplified terms, a hash-map implemented in hardware) and address-generation units (AGUs) which are separate from ALUs. In contrast to this, segments are much simpler: a linear GDT (global descriptor table, cached in L1D like any other data), adders, and comparators.
- Paging makes it more complicated to add more AGUs (in order to increase the number of loads&stores per cycle) compared to segment registers because the paging unit is logically a single shared resource - while segment registers (registers+adders+comparators) are more distributed/parallel in their nature.
- An instruction set architecture probably needs to support at least 8 segment registers in order to be future-proof and to make it a bit easier for the kernel and the user-space to manage memory.
- An issue on amd64/x86-64 is that it is impossible to disable the paging unit and to disable-or-repurpose AGUs so that, if you use just segments to implement an OS, you wouldn't need to pay the *implicit* tax associated with page translation. In other words: *not* using the MMU does, unfortunately, *not* result in more loads&stores per cycle on the CPU.
- Protected mode segments are fully sufficient to implement virtual memory, because exceeding the segment's limit is equivalent to a page fault. When a user-space instruction accesses memory beyond the segment's limit, the kernel can for example load missing data from a HDD/SSD drive, extend the limit of the segment in the global descriptor table (GDT on 80286+), and switch back to user-space which will re-execute the memory access instruction.
- Due to the linear nature of segments, segments are prone to memory fragmentation. This is *both* an issue and an advantage. One advantage for example is that, after memory defragmentation, related data is located closer together and related code is located closer together (in other words: segmentation can result in better L1D and L1I cache utilization compared to paging).
- Using protected mode segments to implement an OS requires a different style of thinking (different rules) than implementing an OS on top of paging. Going the way of segments means that the OS and user-space processes need to be more dynamic (i.e: somewhere between static compilation and just-in-time compilation).
- About pointers in the C programming language: C has a single pointer type. Nowadays, it tends to be either 32 or 64 bits in width. C doesn't support mixing 32-bit and 64-bit pointers in a single program because this would require the language to support two pointer types. Using '*' asterisk in the syntax of pointer types in C is, in hindsight, a clearly suboptimal programming language design decision both from run time performance viewpoint and from memory consumption viewpoint.
- Use of segments to implement an OS (without paging) depends on whether the programming language used to implement user-space apps supports multiple pointer types. For example, without multiple pointer types it is more complicated to safely distinguish a pointer to a local function from a pointer to a shared library function, or a pointer to local data from a pointer to shared data (irrespective of whether the pointers have different widths or the same width).
- If you would think about it more deeply and would not be resistant to thinking about large changes to an OS architecture, you wouldn't believe that (as you wrote) "C not wanting segments is not the cause, it's the correlation". You would believe the opposite: that programming languages with a single pointer type (which includes C) are among the primary causes of the downfall of segments. Eventually, you might also start to believe that there is a causal link between C's type system and the maximum number of loads&stores a CPU core can perform per cycle assuming a particular transistor budget.
- Your claim that "So what I am claiming is that segments [cut] are a bad idea. They add unwanted complexity that doesn't actually buy users anything at all into one of the most important part of the CPU pipeline - the memory units" - is a false statement. It is totally obvious that the hardware implementation of segments is simpler than the hardware implementation of paging, and it has a higher potential for concurrency inside of a CPU than paging. (I have removed/cut the part "... and by extension, capability pointer architectures" from the cited sentence.)
- Many programmers prefer to have a single pointer type in the programming language (and a single, extremely large, address space), instead of multiple pointer types. This has both positive and negative consequences. Not seeing, or on purpose ignoring, the negative consequences is a form of intellectual blindness.
- That said, an optimizing compiler and its runtime library can internally support multiple pointer types (widths) even if the programming language being compiled has a single pointer type. (Albeit, an optimizing compiler can in theory support any missing feature X irrespective of what X actually is, so the argument that "an optimizing compiler can support X even X isn't supported by the language" is a relatively weak argument.)
-atom
> ⚛ (0xe2.0x9a.0x9b.delete@this.gmail.com) on September 23, 2021 9:37 am wrote:
> >
> > In other words, if I read your posts about segments correctly, you seem to be claiming
> > that there is zero correlation between the overly simplistic type system of the C programming
> > language (plus other languages from that era) and the downfall of segments.
>
> I don't think that's at all what I said.
>
> I said that segments are an extra complication, and that
> they don't add any value, so people dropped their use.
>
> I said nothing about the C language. In fact, it's an entirely language-agnostic statement.
>
> People love to blame C for various things, and claim that the "C model" made
> computer architecture much less interesting. You seem to be in that camp, and
> seem to try to claim that C had something to do with segments going away.
>
> Not so.
>
> C not wanting segments is not the cause, it's the correlation. Nobody wants
> segments. It's not that "C made computer architecture boring", it's that "learning
> what works and what does not" made for crazy useless features going away.
>
> Those crazy useless features may have been "exciting", but that doesn't make them good.
>
> If anything, the C language people bent over backwards to make excuses for horrible architecture features,
> and weakened the language more than they should have in order to allow for bad architecture decisions.
> Pretty much every single "undefined behavior" is about the language allowing for silly things.
>
> So what I am claiming is that segments - and by extension, "capability pointer architectures"
> - are a bad idea. They add unwanted complexity that doesn't actually buy users anything at
> all into one of the most important part of the CPU pipeline - the memory units.
>
> Don't do it. It's been a research subject for many decades, it's still a research
> subject (I see pointers to the ARM capability pointers in this thread), and it
> has never ever been successful. At what point do people just admit defeat?
>
> The fact is, the whole notion of passing magic pointers and trying to associate random state
> with them between two random untrusted but somehow cooperative entities is pure BS. And I claim
> that no amount of segmentation - whatever you call it - will make it anything else.
>
> Side note: that doesn't mean that you can't do other things. By all means add features like
> pointer coloring that is for debugging. The ARM memory tagging is actually very successful.
> It's not about some absolute pointer security, it's not about arbitrary segments, it's a reasonably
> low-overhead debugging aid that can catch bad uses early. And it still lives in the context
> of a regular flat address space, just one where you can add some region markers.
>
> So you can add exciting value add in the memory unit.
>
> It's just that segments or capabilities isn't it. Too much pain for no real gain.
>
> Linus
(I am writing this response without reading through the sub-tree of this forum node, so I would like to apologize in advance if I will write something that has been discussed there.)
You didn't write something unexpected, which is good from a certain viewpoint because it makes it easier to attack with some counter-arguments. You are defending the "paging-unit is superior to segments" viewpoint.
- Protected mode segments (80286 and later), with two privilege levels (kernel-space and user-space), are fully sufficient to implement a Unix-like operating system.
- A protected mode segment has a base address and a limit (usually with a granularity of at most 1 word) that only the kernel-space can modify directly.
- A downside of having a paging unit in a CPU is that the CPU must have L1+L2 caches (TLBs) storing virtual memory mappings (which is, in simplified terms, a hash-map implemented in hardware) and address-generation units (AGUs) which are separate from ALUs. In contrast to this, segments are much simpler: a linear GDT (global descriptor table, cached in L1D like any other data), adders, and comparators.
- Paging makes it more complicated to add more AGUs (in order to increase the number of loads&stores per cycle) compared to segment registers because the paging unit is logically a single shared resource - while segment registers (registers+adders+comparators) are more distributed/parallel in their nature.
- An instruction set architecture probably needs to support at least 8 segment registers in order to be future-proof and to make it a bit easier for the kernel and the user-space to manage memory.
- An issue on amd64/x86-64 is that it is impossible to disable the paging unit and to disable-or-repurpose AGUs so that, if you use just segments to implement an OS, you wouldn't need to pay the *implicit* tax associated with page translation. In other words: *not* using the MMU does, unfortunately, *not* result in more loads&stores per cycle on the CPU.
- Protected mode segments are fully sufficient to implement virtual memory, because exceeding the segment's limit is equivalent to a page fault. When a user-space instruction accesses memory beyond the segment's limit, the kernel can for example load missing data from a HDD/SSD drive, extend the limit of the segment in the global descriptor table (GDT on 80286+), and switch back to user-space which will re-execute the memory access instruction.
- Due to the linear nature of segments, segments are prone to memory fragmentation. This is *both* an issue and an advantage. One advantage for example is that, after memory defragmentation, related data is located closer together and related code is located closer together (in other words: segmentation can result in better L1D and L1I cache utilization compared to paging).
- Using protected mode segments to implement an OS requires a different style of thinking (different rules) than implementing an OS on top of paging. Going the way of segments means that the OS and user-space processes need to be more dynamic (i.e: somewhere between static compilation and just-in-time compilation).
- About pointers in the C programming language: C has a single pointer type. Nowadays, it tends to be either 32 or 64 bits in width. C doesn't support mixing 32-bit and 64-bit pointers in a single program because this would require the language to support two pointer types. Using '*' asterisk in the syntax of pointer types in C is, in hindsight, a clearly suboptimal programming language design decision both from run time performance viewpoint and from memory consumption viewpoint.
- Use of segments to implement an OS (without paging) depends on whether the programming language used to implement user-space apps supports multiple pointer types. For example, without multiple pointer types it is more complicated to safely distinguish a pointer to a local function from a pointer to a shared library function, or a pointer to local data from a pointer to shared data (irrespective of whether the pointers have different widths or the same width).
- If you would think about it more deeply and would not be resistant to thinking about large changes to an OS architecture, you wouldn't believe that (as you wrote) "C not wanting segments is not the cause, it's the correlation". You would believe the opposite: that programming languages with a single pointer type (which includes C) are among the primary causes of the downfall of segments. Eventually, you might also start to believe that there is a causal link between C's type system and the maximum number of loads&stores a CPU core can perform per cycle assuming a particular transistor budget.
- Your claim that "So what I am claiming is that segments [cut] are a bad idea. They add unwanted complexity that doesn't actually buy users anything at all into one of the most important part of the CPU pipeline - the memory units" - is a false statement. It is totally obvious that the hardware implementation of segments is simpler than the hardware implementation of paging, and it has a higher potential for concurrency inside of a CPU than paging. (I have removed/cut the part "... and by extension, capability pointer architectures" from the cited sentence.)
- Many programmers prefer to have a single pointer type in the programming language (and a single, extremely large, address space), instead of multiple pointer types. This has both positive and negative consequences. Not seeing, or on purpose ignoring, the negative consequences is a form of intellectual blindness.
- That said, an optimizing compiler and its runtime library can internally support multiple pointer types (widths) even if the programming language being compiled has a single pointer type. (Albeit, an optimizing compiler can in theory support any missing feature X irrespective of what X actually is, so the argument that "an optimizing compiler can support X even X isn't supported by the language" is a relatively weak argument.)
-atom
Topic | Posted By | Date |
---|---|---|
POWER10 SAP SD benchmark | anon2 | 2021/09/06 03:36 PM |
POWER10 SAP SD benchmark | Daniel B | 2021/09/07 02:31 AM |
"Cores" (and SPEC) | Rayla | 2021/09/07 07:51 AM |
"Cores" (and SPEC) | anon | 2021/09/07 03:56 PM |
POWER10 SAP SD benchmark | Anon | 2021/09/07 03:24 PM |
POWER10 SAP SD benchmark | Anon | 2021/09/07 03:27 PM |
Virtually tagged L1-caches | sr | 2021/09/08 05:49 AM |
Virtually tagged L1-caches | dmcq | 2021/09/08 08:22 AM |
Virtually tagged L1-caches | sr | 2021/09/08 08:56 AM |
Virtually tagged L1-caches | Hugo Décharnes | 2021/09/08 08:58 AM |
Virtually tagged L1-caches | sr | 2021/09/08 10:09 AM |
Virtually tagged L1-caches | Hugo Décharnes | 2021/09/08 10:46 AM |
Virtually tagged L1-caches | sr | 2021/09/08 11:35 AM |
Virtually tagged L1-caches | Hugo Décharnes | 2021/09/08 12:23 PM |
Virtually tagged L1-caches | sr | 2021/09/08 12:40 PM |
Virtually tagged L1-caches | anon | 2021/09/09 03:16 AM |
Virtually tagged L1-caches | Konrad Schwarz | 2021/09/10 05:19 AM |
Virtually tagged L1-caches | Hugo Décharnes | 2021/09/10 06:59 AM |
Virtually tagged L1-caches | anon | 2021/09/14 03:17 AM |
Virtually tagged L1-caches | dmcq | 2021/09/14 09:34 AM |
Or use a PLB (NT) | Paul A. Clayton | 2021/09/14 09:45 AM |
Or use a PLB | Linus Torvalds | 2021/09/14 03:27 PM |
Or use a PLB | anon | 2021/09/15 12:15 AM |
Or use a PLB | Michael S | 2021/09/15 03:21 AM |
Or use a PLB | dmcq | 2021/09/15 03:42 PM |
Or use a PLB | Konrad Schwarz | 2021/09/16 04:24 AM |
Or use a PLB | Michael S | 2021/09/16 10:13 AM |
Or use a PLB | --- | 2021/09/16 01:02 PM |
PLB reference | Paul A. Clayton | 2021/09/18 02:35 PM |
PLB reference | Michael S | 2021/09/18 04:14 PM |
Demand paging/translation orthogonal | Paul A. Clayton | 2021/09/19 07:33 AM |
Demand paging/translation orthogonal | Michael S | 2021/09/19 09:10 AM |
PLB reference | Carson | 2021/09/20 10:19 PM |
PLB reference | sr | 2021/09/20 06:02 AM |
PLB reference | Michael S | 2021/09/20 07:03 AM |
PLB reference | Linus Torvalds | 2021/09/20 12:10 PM |
Or use a PLB | sr | 2021/09/20 04:32 AM |
Or use a PLB | sr | 2021/09/21 09:36 AM |
Or use a PLB | Linus Torvalds | 2021/09/21 10:04 AM |
Or use a PLB | sr | 2021/09/21 10:48 AM |
Or use a PLB | Linus Torvalds | 2021/09/21 01:55 PM |
Or use a PLB | sr | 2021/09/22 06:55 AM |
Or use a PLB | rwessel | 2021/09/22 07:09 AM |
Or use a PLB | Linus Torvalds | 2021/09/22 11:50 AM |
Or use a PLB | sr | 2021/09/22 01:00 PM |
Or use a PLB | dmcq | 2021/09/22 04:07 PM |
Or use a PLB | Etienne Lorrain | 2021/09/23 08:50 AM |
Or use a PLB | anon2 | 2021/09/22 04:09 PM |
Or use a PLB | dmcq | 2021/09/23 02:35 AM |
Or use a PLB | ⚛ | 2021/09/23 09:37 AM |
Or use a PLB | Linus Torvalds | 2021/09/23 12:01 PM |
Or use a PLB | gpd | 2021/09/24 03:59 AM |
Or use a PLB | Linus Torvalds | 2021/09/24 10:45 AM |
Or use a PLB | dmcq | 2021/09/24 12:43 PM |
Or use a PLB | sr | 2021/09/25 10:19 AM |
Or use a PLB | Linus Torvalds | 2021/09/25 10:44 AM |
Or use a PLB | sr | 2021/09/25 11:11 AM |
Or use a PLB | Linus Torvalds | 2021/09/25 11:31 AM |
Or use a PLB | sr | 2021/09/25 11:52 AM |
Or use a PLB | Linus Torvalds | 2021/09/25 12:05 PM |
Or use a PLB | sr | 2021/09/25 12:23 PM |
Or use a PLB | rwessel | 2021/09/25 03:29 PM |
Or use a PLB | sr | 2021/10/01 12:22 AM |
Or use a PLB | rwessel | 2021/10/01 06:19 AM |
Or use a PLB | David Hess | 2021/10/01 10:35 AM |
Or use a PLB | rwessel | 2021/10/02 04:47 AM |
Or use a PLB | sr | 2021/10/02 11:16 AM |
Or use a PLB | rwessel | 2021/10/02 11:53 AM |
Or use a PLB | Linus Torvalds | 2021/09/25 11:57 AM |
Or use a PLB | sr | 2021/09/25 12:07 PM |
Or use a PLB | Linus Torvalds | 2021/09/25 12:21 PM |
Or use a PLB | sr | 2021/09/25 12:40 PM |
Or use a PLB | nksingh | 2021/09/27 09:07 AM |
Or use a PLB | ⚛ | 2021/09/27 09:02 AM |
Or use a PLB | Linus Torvalds | 2021/09/27 10:20 AM |
Or use a PLB | Linus Torvalds | 2021/09/27 12:58 PM |
Or use a PLB | dmcq | 2021/09/28 10:59 AM |
Or use a PLB | sr | 2021/09/25 10:34 AM |
Or use a PLB | rwessel | 2021/09/25 03:44 PM |
Or use a PLB | sr | 2021/10/01 01:04 AM |
Or use a PLB | rwessel | 2021/10/01 06:33 AM |
I386 segmentation highlights | sr | 2021/10/04 07:53 AM |
I386 segmentation highlights | Adrian | 2021/10/04 09:53 AM |
I386 segmentation highlights | sr | 2021/10/04 10:19 AM |
I386 segmentation highlights | rwessel | 2021/10/04 04:57 PM |
I386 segmentation highlights | sr | 2021/10/05 11:16 AM |
I386 segmentation highlights | Michael S | 2021/10/05 12:27 PM |
I386 segmentation highlights | rwessel | 2021/10/05 04:20 PM |
Or use a PLB | JohnG | 2021/09/25 10:18 PM |
Or use a PLB | ⚛ | 2021/09/27 07:37 AM |
Or use a PLB | Heikki Kultala | 2021/09/28 03:53 AM |
Or use a PLB | rwessel | 2021/09/28 07:29 AM |
Or use a PLB | David Hess | 2021/09/23 06:00 PM |
Or use a PLB | Adrian | 2021/09/24 01:21 AM |
Or use a PLB | dmcq | 2021/09/25 12:41 PM |
Or use a PLB | blaine | 2021/09/26 11:19 PM |
Or use a PLB | David Hess | 2021/09/27 11:35 AM |
Or use a PLB | blaine | 2021/09/27 05:19 PM |
Or use a PLB | Adrian | 2021/09/27 10:40 PM |
Or use a PLB | Adrian | 2021/09/27 10:59 PM |
Or use a PLB | dmcq | 2021/09/28 07:45 AM |
Or use a PLB | rwessel | 2021/09/28 07:45 AM |
Or use a PLB | David Hess | 2021/09/28 12:50 PM |
Or use a PLB | Etienne Lorrain | 2021/09/30 01:25 AM |
Or use a PLB | David Hess | 2021/10/01 10:40 AM |
MMU privileges | sr | 2021/09/21 11:07 AM |
MMU privileges | Linus Torvalds | 2021/09/21 01:49 PM |
Virtually tagged L1-caches | Konrad Schwarz | 2021/09/16 04:18 AM |
Virtually tagged L1-caches | Carson | 2021/09/16 01:12 PM |
Virtually tagged L1-caches | anon2 | 2021/09/16 05:16 PM |
Virtually tagged L1-caches | rwessel | 2021/09/16 06:29 PM |
Virtually tagged L1-caches | sr | 2021/09/20 04:20 AM |
Virtually tagged L1-caches | --- | 2021/09/08 02:28 PM |
Virtually tagged L1-caches | anonymou5 | 2021/09/08 08:28 PM |
Virtually tagged L1-caches | anonymou5 | 2021/09/08 08:34 PM |
Virtually tagged L1-caches | --- | 2021/09/09 10:14 AM |
Virtually tagged L1-caches | anonymou5 | 2021/09/09 10:44 PM |
Multi-threading? | David Kanter | 2021/09/09 09:32 PM |
Multi-threading? | --- | 2021/09/10 09:19 AM |
Virtually tagged L1-caches | sr | 2021/09/11 01:19 AM |
Virtually tagged L1-caches | sr | 2021/09/11 01:36 AM |
Virtually tagged L1-caches | --- | 2021/09/11 09:53 AM |
Virtually tagged L1-caches | sr | 2021/09/12 12:43 AM |
Virtually tagged L1-caches | Linus Torvalds | 2021/09/12 11:10 AM |
Virtually tagged L1-caches | sr | 2021/09/12 11:57 AM |
Virtually tagged L1-caches | dmcq | 2021/09/13 08:31 AM |
Virtually tagged L1-caches | sr | 2021/09/20 04:11 AM |
Virtually tagged L1-caches | sr | 2021/09/11 02:49 AM |
Virtually tagged L1-caches | Linus Torvalds | 2021/09/08 12:34 PM |
Virtually tagged L1-caches | dmcq | 2021/09/09 02:46 AM |
Virtually tagged L1-caches | dmcq | 2021/09/09 02:58 AM |
Virtually tagged L1-caches | sr | 2021/09/11 01:29 AM |
Virtually tagged L1-caches | dmcq | 2021/09/11 08:59 AM |
Virtually tagged L1-caches | sr | 2021/09/12 12:57 AM |
Virtually tagged L1-caches | dmcq | 2021/09/12 08:44 AM |
Virtually tagged L1-caches | sr | 2021/09/12 09:48 AM |
Virtually tagged L1-caches | dmcq | 2021/09/12 01:22 PM |
Virtually tagged L1-caches | sr | 2021/09/20 04:40 AM |
Where do you see this information? (NT) | anon2 | 2021/09/09 02:45 AM |
Where do you see this information? | sr | 2021/09/11 01:40 AM |
Where do you see this information? | anon2 | 2021/09/11 01:53 AM |
Where do you see this information? | sr | 2021/09/11 02:08 AM |
Thank you (NT) | anon2 | 2021/09/11 04:31 PM |