Does Linux not use segmentation but only paging?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












The Linux Programming Interface shows the layout of a virtual address space of a process. Is each region in the diagram a segment?



enter image description here



From Understanding The Linux Kernel,



is it correct that the following means that the segmentation unit in MMU maps the segments and offsets within segments into the virtual memory address, and the paging unit then maps the virtual memory address to the physical memory address?




The Memory Management Unit (MMU) transforms a logical address into a linear
address by means of a hardware circuit called a segmentation unit; subsequently, a second hardware circuit called a paging unit transforms the linear address into a physical address (see Figure 2-1).




enter image description here



Then why does it say that Linux doesn't use segmentation but only paging?




Segmentation has been included in 80x86 microprocessors to encourage
program- mers to split their applications into logically related
entities, such as subroutines or global and local data areas. However,
Linux uses segmentation in a very limited way. In fact, segmentation and paging are somewhat redundant, because both can be
used to separate the physical address spaces of processes:
segmentation can assign a different linear address space to each
process, while paging can map the same linear address space into
different physical address spaces. Linux prefers paging to
segmentation for the following reasons:



• Memory management is simpler when all processes use the same segment
regis- ter values—that is, when they share the same set of linear
addresses.



• One of the design objectives of Linux is portability to a wide range
of architectures; RISC architectures in particular have limited
support for segmentation.



The 2.6 version of Linux uses segmentation only when required by the
80x86 architecture.











share|improve this question























  • Can you specify the editions please. It might also be helpful to specify author names. I know at least the first is from a prominent figure. However, both of the title names are a bit generic, it was not clear to me at first that you were talking about books :-).
    – sourcejedi
    23 mins ago














up vote
3
down vote

favorite












The Linux Programming Interface shows the layout of a virtual address space of a process. Is each region in the diagram a segment?



enter image description here



From Understanding The Linux Kernel,



is it correct that the following means that the segmentation unit in MMU maps the segments and offsets within segments into the virtual memory address, and the paging unit then maps the virtual memory address to the physical memory address?




The Memory Management Unit (MMU) transforms a logical address into a linear
address by means of a hardware circuit called a segmentation unit; subsequently, a second hardware circuit called a paging unit transforms the linear address into a physical address (see Figure 2-1).




enter image description here



Then why does it say that Linux doesn't use segmentation but only paging?




Segmentation has been included in 80x86 microprocessors to encourage
program- mers to split their applications into logically related
entities, such as subroutines or global and local data areas. However,
Linux uses segmentation in a very limited way. In fact, segmentation and paging are somewhat redundant, because both can be
used to separate the physical address spaces of processes:
segmentation can assign a different linear address space to each
process, while paging can map the same linear address space into
different physical address spaces. Linux prefers paging to
segmentation for the following reasons:



• Memory management is simpler when all processes use the same segment
regis- ter values—that is, when they share the same set of linear
addresses.



• One of the design objectives of Linux is portability to a wide range
of architectures; RISC architectures in particular have limited
support for segmentation.



The 2.6 version of Linux uses segmentation only when required by the
80x86 architecture.











share|improve this question























  • Can you specify the editions please. It might also be helpful to specify author names. I know at least the first is from a prominent figure. However, both of the title names are a bit generic, it was not clear to me at first that you were talking about books :-).
    – sourcejedi
    23 mins ago












up vote
3
down vote

favorite









up vote
3
down vote

favorite











The Linux Programming Interface shows the layout of a virtual address space of a process. Is each region in the diagram a segment?



enter image description here



From Understanding The Linux Kernel,



is it correct that the following means that the segmentation unit in MMU maps the segments and offsets within segments into the virtual memory address, and the paging unit then maps the virtual memory address to the physical memory address?




The Memory Management Unit (MMU) transforms a logical address into a linear
address by means of a hardware circuit called a segmentation unit; subsequently, a second hardware circuit called a paging unit transforms the linear address into a physical address (see Figure 2-1).




enter image description here



Then why does it say that Linux doesn't use segmentation but only paging?




Segmentation has been included in 80x86 microprocessors to encourage
program- mers to split their applications into logically related
entities, such as subroutines or global and local data areas. However,
Linux uses segmentation in a very limited way. In fact, segmentation and paging are somewhat redundant, because both can be
used to separate the physical address spaces of processes:
segmentation can assign a different linear address space to each
process, while paging can map the same linear address space into
different physical address spaces. Linux prefers paging to
segmentation for the following reasons:



• Memory management is simpler when all processes use the same segment
regis- ter values—that is, when they share the same set of linear
addresses.



• One of the design objectives of Linux is portability to a wide range
of architectures; RISC architectures in particular have limited
support for segmentation.



The 2.6 version of Linux uses segmentation only when required by the
80x86 architecture.











share|improve this question















The Linux Programming Interface shows the layout of a virtual address space of a process. Is each region in the diagram a segment?



enter image description here



From Understanding The Linux Kernel,



is it correct that the following means that the segmentation unit in MMU maps the segments and offsets within segments into the virtual memory address, and the paging unit then maps the virtual memory address to the physical memory address?




The Memory Management Unit (MMU) transforms a logical address into a linear
address by means of a hardware circuit called a segmentation unit; subsequently, a second hardware circuit called a paging unit transforms the linear address into a physical address (see Figure 2-1).




enter image description here



Then why does it say that Linux doesn't use segmentation but only paging?




Segmentation has been included in 80x86 microprocessors to encourage
program- mers to split their applications into logically related
entities, such as subroutines or global and local data areas. However,
Linux uses segmentation in a very limited way. In fact, segmentation and paging are somewhat redundant, because both can be
used to separate the physical address spaces of processes:
segmentation can assign a different linear address space to each
process, while paging can map the same linear address space into
different physical address spaces. Linux prefers paging to
segmentation for the following reasons:



• Memory management is simpler when all processes use the same segment
regis- ter values—that is, when they share the same set of linear
addresses.



• One of the design objectives of Linux is portability to a wide range
of architectures; RISC architectures in particular have limited
support for segmentation.



The 2.6 version of Linux uses segmentation only when required by the
80x86 architecture.








linux kernel virtual-memory






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 12 mins ago









Rui F Ribeiro

36.5k1271116




36.5k1271116










asked 32 mins ago









Tim

23k66225408




23k66225408











  • Can you specify the editions please. It might also be helpful to specify author names. I know at least the first is from a prominent figure. However, both of the title names are a bit generic, it was not clear to me at first that you were talking about books :-).
    – sourcejedi
    23 mins ago
















  • Can you specify the editions please. It might also be helpful to specify author names. I know at least the first is from a prominent figure. However, both of the title names are a bit generic, it was not clear to me at first that you were talking about books :-).
    – sourcejedi
    23 mins ago















Can you specify the editions please. It might also be helpful to specify author names. I know at least the first is from a prominent figure. However, both of the title names are a bit generic, it was not clear to me at first that you were talking about books :-).
– sourcejedi
23 mins ago




Can you specify the editions please. It might also be helpful to specify author names. I know at least the first is from a prominent figure. However, both of the title names are a bit generic, it was not clear to me at first that you were talking about books :-).
– sourcejedi
23 mins ago










3 Answers
3






active

oldest

votes

















up vote
4
down vote













The x86-64 architecture does not use segmentation in long mode (64-bit mode) [...] https://en.wikipedia.org/wiki/X86_memory_segmentation#Later_developments



Do not worry about the details which would only apply to the legacy 32-bit modes. Linux for the 32-bit modes is not used as much and may be considered "in a state of benign neglect for several years". See 32-Bit x86 support in Fedora [LWN.net, 2017].






share|improve this answer



























    up vote
    4
    down vote













    As the x86 has segments, it is not possible to not use them. But both cs (code segment) and ds(data segment) base addresses are set to zero, so the segmentation is not really used. An exception is thread local data, one of the normally unused segment registers points to thread local data. But that is mainly to avoid reserving one of the general purpose registers for this task.



    It doesn't say that Linux doesn't use segmentation on the x86, as that would not be possible. You already highlighted one part, Linux uses segmentation in a very limited way. The second part is Linux uses segmentation only when required by the 80x86 architecture



    You already quoted the reasons, paging is easier and more portable.






    share|improve this answer



























      up vote
      4
      down vote













      In one short sentence: The linux kernel is able to deal with segments and paging to some extend.



      Now, let's first clarify the difference between paging vs segmentation on a processor level.



      A processor that segments the memory actually uses two pointers to tell exactly what byte is addressed.



      First there is the segment which is an array of memory with a specific size. The first pointer just points to this segment and by this addresses the whole segment. To specify what byte is meant in that segment a second pointer is needed which is only local to the segment. So those two combined can address a singly byte. For example you could have a 16 bit pointer for the segments to address 65536 different segments and a 16 bit local pointer in them to address the bytes. The disadvantage of this is that the local pointer determines the maximum size of a continuous memory block. You might be able to use the whole memory, but each block you use can only be a fraction of the maximum memory you can address. Especially for programs that work on large data sets (move encoders, 3d renderer, databases...) this is a serious problem.



      Paging is somewhat the combination of the advantages of a flat memory model (only one pointer addressing the whole memory space), and the ability to define blocks of memory that are somewhat isolated from others. In a paging system you have one pointer addressing the whole memory space. So a 32 bit system with a 32 bit pointer is able to address 4GB of memory with each address pointing exactly to one byte. But that memory area is still broken down to "pages". A Page is just a block of memory of a defined size. And this is where the "magic" starts. The processor has a second mapping that tell exactly how each of those pages are mapped into the "flat" memory space. A program using the memory sees it as completely flat. It can address every byte exactly with only one pointer. But the kernel is able to shift memory blocks, define special attributes for them..and such things. For example the kernel is able to define such a memory block "read-only" and terminate every program that tries to write to it. Also swapping is based on this: Let's assume a program tries to access a memory address outside of the range of the physical available memory. The kernel can catch this, choose one memory block that wasn't used for some time an write it to the swap space, then take that memory page and map it to the place the application tired to write to and magically there is more memory for applications available than the machine has.



      This is all very low-level and what is meant when the linux kernel prefers paging over segmentation. But just to mention it, the linux kernel is able to deal with both to some extend, and sometimes even combine the approaches (32 bit linux PAE kernel for example).



      Now let's talk about segments in programs: While this is still pretty low level it is far higher than the segments on processor level, and again all a bit simplified just to give the idea. When you have an executable that is basically just a memory dump that needs to be loaded back in memory then executed. But not everything in the executable is code. Executables can contain data as well like the text on buttons and such things. So to make this easier, programs are divided into segments, for code, for data. When an executable is loaded those parts of it end up in different memory parts with different abilities. To make programs more secure it is for example good practise to only allow code in the code segment to be executed. That prevents any attacks that try to manipulate program data to valid binary code and then having it executed somehow. The kernel will notice that something in the data segment should be executed and will prevent that.



      More details can be found here






      share|improve this answer






















        Your Answer







        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "106"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        convertImagesToLinks: false,
        noModals: false,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













         

        draft saved


        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f469253%2fdoes-linux-not-use-segmentation-but-only-paging%23new-answer', 'question_page');

        );

        Post as a guest






























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        4
        down vote













        The x86-64 architecture does not use segmentation in long mode (64-bit mode) [...] https://en.wikipedia.org/wiki/X86_memory_segmentation#Later_developments



        Do not worry about the details which would only apply to the legacy 32-bit modes. Linux for the 32-bit modes is not used as much and may be considered "in a state of benign neglect for several years". See 32-Bit x86 support in Fedora [LWN.net, 2017].






        share|improve this answer
























          up vote
          4
          down vote













          The x86-64 architecture does not use segmentation in long mode (64-bit mode) [...] https://en.wikipedia.org/wiki/X86_memory_segmentation#Later_developments



          Do not worry about the details which would only apply to the legacy 32-bit modes. Linux for the 32-bit modes is not used as much and may be considered "in a state of benign neglect for several years". See 32-Bit x86 support in Fedora [LWN.net, 2017].






          share|improve this answer






















            up vote
            4
            down vote










            up vote
            4
            down vote









            The x86-64 architecture does not use segmentation in long mode (64-bit mode) [...] https://en.wikipedia.org/wiki/X86_memory_segmentation#Later_developments



            Do not worry about the details which would only apply to the legacy 32-bit modes. Linux for the 32-bit modes is not used as much and may be considered "in a state of benign neglect for several years". See 32-Bit x86 support in Fedora [LWN.net, 2017].






            share|improve this answer












            The x86-64 architecture does not use segmentation in long mode (64-bit mode) [...] https://en.wikipedia.org/wiki/X86_memory_segmentation#Later_developments



            Do not worry about the details which would only apply to the legacy 32-bit modes. Linux for the 32-bit modes is not used as much and may be considered "in a state of benign neglect for several years". See 32-Bit x86 support in Fedora [LWN.net, 2017].







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 15 mins ago









            sourcejedi

            19.8k42682




            19.8k42682






















                up vote
                4
                down vote













                As the x86 has segments, it is not possible to not use them. But both cs (code segment) and ds(data segment) base addresses are set to zero, so the segmentation is not really used. An exception is thread local data, one of the normally unused segment registers points to thread local data. But that is mainly to avoid reserving one of the general purpose registers for this task.



                It doesn't say that Linux doesn't use segmentation on the x86, as that would not be possible. You already highlighted one part, Linux uses segmentation in a very limited way. The second part is Linux uses segmentation only when required by the 80x86 architecture



                You already quoted the reasons, paging is easier and more portable.






                share|improve this answer
























                  up vote
                  4
                  down vote













                  As the x86 has segments, it is not possible to not use them. But both cs (code segment) and ds(data segment) base addresses are set to zero, so the segmentation is not really used. An exception is thread local data, one of the normally unused segment registers points to thread local data. But that is mainly to avoid reserving one of the general purpose registers for this task.



                  It doesn't say that Linux doesn't use segmentation on the x86, as that would not be possible. You already highlighted one part, Linux uses segmentation in a very limited way. The second part is Linux uses segmentation only when required by the 80x86 architecture



                  You already quoted the reasons, paging is easier and more portable.






                  share|improve this answer






















                    up vote
                    4
                    down vote










                    up vote
                    4
                    down vote









                    As the x86 has segments, it is not possible to not use them. But both cs (code segment) and ds(data segment) base addresses are set to zero, so the segmentation is not really used. An exception is thread local data, one of the normally unused segment registers points to thread local data. But that is mainly to avoid reserving one of the general purpose registers for this task.



                    It doesn't say that Linux doesn't use segmentation on the x86, as that would not be possible. You already highlighted one part, Linux uses segmentation in a very limited way. The second part is Linux uses segmentation only when required by the 80x86 architecture



                    You already quoted the reasons, paging is easier and more portable.






                    share|improve this answer












                    As the x86 has segments, it is not possible to not use them. But both cs (code segment) and ds(data segment) base addresses are set to zero, so the segmentation is not really used. An exception is thread local data, one of the normally unused segment registers points to thread local data. But that is mainly to avoid reserving one of the general purpose registers for this task.



                    It doesn't say that Linux doesn't use segmentation on the x86, as that would not be possible. You already highlighted one part, Linux uses segmentation in a very limited way. The second part is Linux uses segmentation only when required by the 80x86 architecture



                    You already quoted the reasons, paging is easier and more portable.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 14 mins ago









                    RalfFriedl

                    3,4601522




                    3,4601522




















                        up vote
                        4
                        down vote













                        In one short sentence: The linux kernel is able to deal with segments and paging to some extend.



                        Now, let's first clarify the difference between paging vs segmentation on a processor level.



                        A processor that segments the memory actually uses two pointers to tell exactly what byte is addressed.



                        First there is the segment which is an array of memory with a specific size. The first pointer just points to this segment and by this addresses the whole segment. To specify what byte is meant in that segment a second pointer is needed which is only local to the segment. So those two combined can address a singly byte. For example you could have a 16 bit pointer for the segments to address 65536 different segments and a 16 bit local pointer in them to address the bytes. The disadvantage of this is that the local pointer determines the maximum size of a continuous memory block. You might be able to use the whole memory, but each block you use can only be a fraction of the maximum memory you can address. Especially for programs that work on large data sets (move encoders, 3d renderer, databases...) this is a serious problem.



                        Paging is somewhat the combination of the advantages of a flat memory model (only one pointer addressing the whole memory space), and the ability to define blocks of memory that are somewhat isolated from others. In a paging system you have one pointer addressing the whole memory space. So a 32 bit system with a 32 bit pointer is able to address 4GB of memory with each address pointing exactly to one byte. But that memory area is still broken down to "pages". A Page is just a block of memory of a defined size. And this is where the "magic" starts. The processor has a second mapping that tell exactly how each of those pages are mapped into the "flat" memory space. A program using the memory sees it as completely flat. It can address every byte exactly with only one pointer. But the kernel is able to shift memory blocks, define special attributes for them..and such things. For example the kernel is able to define such a memory block "read-only" and terminate every program that tries to write to it. Also swapping is based on this: Let's assume a program tries to access a memory address outside of the range of the physical available memory. The kernel can catch this, choose one memory block that wasn't used for some time an write it to the swap space, then take that memory page and map it to the place the application tired to write to and magically there is more memory for applications available than the machine has.



                        This is all very low-level and what is meant when the linux kernel prefers paging over segmentation. But just to mention it, the linux kernel is able to deal with both to some extend, and sometimes even combine the approaches (32 bit linux PAE kernel for example).



                        Now let's talk about segments in programs: While this is still pretty low level it is far higher than the segments on processor level, and again all a bit simplified just to give the idea. When you have an executable that is basically just a memory dump that needs to be loaded back in memory then executed. But not everything in the executable is code. Executables can contain data as well like the text on buttons and such things. So to make this easier, programs are divided into segments, for code, for data. When an executable is loaded those parts of it end up in different memory parts with different abilities. To make programs more secure it is for example good practise to only allow code in the code segment to be executed. That prevents any attacks that try to manipulate program data to valid binary code and then having it executed somehow. The kernel will notice that something in the data segment should be executed and will prevent that.



                        More details can be found here






                        share|improve this answer


























                          up vote
                          4
                          down vote













                          In one short sentence: The linux kernel is able to deal with segments and paging to some extend.



                          Now, let's first clarify the difference between paging vs segmentation on a processor level.



                          A processor that segments the memory actually uses two pointers to tell exactly what byte is addressed.



                          First there is the segment which is an array of memory with a specific size. The first pointer just points to this segment and by this addresses the whole segment. To specify what byte is meant in that segment a second pointer is needed which is only local to the segment. So those two combined can address a singly byte. For example you could have a 16 bit pointer for the segments to address 65536 different segments and a 16 bit local pointer in them to address the bytes. The disadvantage of this is that the local pointer determines the maximum size of a continuous memory block. You might be able to use the whole memory, but each block you use can only be a fraction of the maximum memory you can address. Especially for programs that work on large data sets (move encoders, 3d renderer, databases...) this is a serious problem.



                          Paging is somewhat the combination of the advantages of a flat memory model (only one pointer addressing the whole memory space), and the ability to define blocks of memory that are somewhat isolated from others. In a paging system you have one pointer addressing the whole memory space. So a 32 bit system with a 32 bit pointer is able to address 4GB of memory with each address pointing exactly to one byte. But that memory area is still broken down to "pages". A Page is just a block of memory of a defined size. And this is where the "magic" starts. The processor has a second mapping that tell exactly how each of those pages are mapped into the "flat" memory space. A program using the memory sees it as completely flat. It can address every byte exactly with only one pointer. But the kernel is able to shift memory blocks, define special attributes for them..and such things. For example the kernel is able to define such a memory block "read-only" and terminate every program that tries to write to it. Also swapping is based on this: Let's assume a program tries to access a memory address outside of the range of the physical available memory. The kernel can catch this, choose one memory block that wasn't used for some time an write it to the swap space, then take that memory page and map it to the place the application tired to write to and magically there is more memory for applications available than the machine has.



                          This is all very low-level and what is meant when the linux kernel prefers paging over segmentation. But just to mention it, the linux kernel is able to deal with both to some extend, and sometimes even combine the approaches (32 bit linux PAE kernel for example).



                          Now let's talk about segments in programs: While this is still pretty low level it is far higher than the segments on processor level, and again all a bit simplified just to give the idea. When you have an executable that is basically just a memory dump that needs to be loaded back in memory then executed. But not everything in the executable is code. Executables can contain data as well like the text on buttons and such things. So to make this easier, programs are divided into segments, for code, for data. When an executable is loaded those parts of it end up in different memory parts with different abilities. To make programs more secure it is for example good practise to only allow code in the code segment to be executed. That prevents any attacks that try to manipulate program data to valid binary code and then having it executed somehow. The kernel will notice that something in the data segment should be executed and will prevent that.



                          More details can be found here






                          share|improve this answer
























                            up vote
                            4
                            down vote










                            up vote
                            4
                            down vote









                            In one short sentence: The linux kernel is able to deal with segments and paging to some extend.



                            Now, let's first clarify the difference between paging vs segmentation on a processor level.



                            A processor that segments the memory actually uses two pointers to tell exactly what byte is addressed.



                            First there is the segment which is an array of memory with a specific size. The first pointer just points to this segment and by this addresses the whole segment. To specify what byte is meant in that segment a second pointer is needed which is only local to the segment. So those two combined can address a singly byte. For example you could have a 16 bit pointer for the segments to address 65536 different segments and a 16 bit local pointer in them to address the bytes. The disadvantage of this is that the local pointer determines the maximum size of a continuous memory block. You might be able to use the whole memory, but each block you use can only be a fraction of the maximum memory you can address. Especially for programs that work on large data sets (move encoders, 3d renderer, databases...) this is a serious problem.



                            Paging is somewhat the combination of the advantages of a flat memory model (only one pointer addressing the whole memory space), and the ability to define blocks of memory that are somewhat isolated from others. In a paging system you have one pointer addressing the whole memory space. So a 32 bit system with a 32 bit pointer is able to address 4GB of memory with each address pointing exactly to one byte. But that memory area is still broken down to "pages". A Page is just a block of memory of a defined size. And this is where the "magic" starts. The processor has a second mapping that tell exactly how each of those pages are mapped into the "flat" memory space. A program using the memory sees it as completely flat. It can address every byte exactly with only one pointer. But the kernel is able to shift memory blocks, define special attributes for them..and such things. For example the kernel is able to define such a memory block "read-only" and terminate every program that tries to write to it. Also swapping is based on this: Let's assume a program tries to access a memory address outside of the range of the physical available memory. The kernel can catch this, choose one memory block that wasn't used for some time an write it to the swap space, then take that memory page and map it to the place the application tired to write to and magically there is more memory for applications available than the machine has.



                            This is all very low-level and what is meant when the linux kernel prefers paging over segmentation. But just to mention it, the linux kernel is able to deal with both to some extend, and sometimes even combine the approaches (32 bit linux PAE kernel for example).



                            Now let's talk about segments in programs: While this is still pretty low level it is far higher than the segments on processor level, and again all a bit simplified just to give the idea. When you have an executable that is basically just a memory dump that needs to be loaded back in memory then executed. But not everything in the executable is code. Executables can contain data as well like the text on buttons and such things. So to make this easier, programs are divided into segments, for code, for data. When an executable is loaded those parts of it end up in different memory parts with different abilities. To make programs more secure it is for example good practise to only allow code in the code segment to be executed. That prevents any attacks that try to manipulate program data to valid binary code and then having it executed somehow. The kernel will notice that something in the data segment should be executed and will prevent that.



                            More details can be found here






                            share|improve this answer














                            In one short sentence: The linux kernel is able to deal with segments and paging to some extend.



                            Now, let's first clarify the difference between paging vs segmentation on a processor level.



                            A processor that segments the memory actually uses two pointers to tell exactly what byte is addressed.



                            First there is the segment which is an array of memory with a specific size. The first pointer just points to this segment and by this addresses the whole segment. To specify what byte is meant in that segment a second pointer is needed which is only local to the segment. So those two combined can address a singly byte. For example you could have a 16 bit pointer for the segments to address 65536 different segments and a 16 bit local pointer in them to address the bytes. The disadvantage of this is that the local pointer determines the maximum size of a continuous memory block. You might be able to use the whole memory, but each block you use can only be a fraction of the maximum memory you can address. Especially for programs that work on large data sets (move encoders, 3d renderer, databases...) this is a serious problem.



                            Paging is somewhat the combination of the advantages of a flat memory model (only one pointer addressing the whole memory space), and the ability to define blocks of memory that are somewhat isolated from others. In a paging system you have one pointer addressing the whole memory space. So a 32 bit system with a 32 bit pointer is able to address 4GB of memory with each address pointing exactly to one byte. But that memory area is still broken down to "pages". A Page is just a block of memory of a defined size. And this is where the "magic" starts. The processor has a second mapping that tell exactly how each of those pages are mapped into the "flat" memory space. A program using the memory sees it as completely flat. It can address every byte exactly with only one pointer. But the kernel is able to shift memory blocks, define special attributes for them..and such things. For example the kernel is able to define such a memory block "read-only" and terminate every program that tries to write to it. Also swapping is based on this: Let's assume a program tries to access a memory address outside of the range of the physical available memory. The kernel can catch this, choose one memory block that wasn't used for some time an write it to the swap space, then take that memory page and map it to the place the application tired to write to and magically there is more memory for applications available than the machine has.



                            This is all very low-level and what is meant when the linux kernel prefers paging over segmentation. But just to mention it, the linux kernel is able to deal with both to some extend, and sometimes even combine the approaches (32 bit linux PAE kernel for example).



                            Now let's talk about segments in programs: While this is still pretty low level it is far higher than the segments on processor level, and again all a bit simplified just to give the idea. When you have an executable that is basically just a memory dump that needs to be loaded back in memory then executed. But not everything in the executable is code. Executables can contain data as well like the text on buttons and such things. So to make this easier, programs are divided into segments, for code, for data. When an executable is loaded those parts of it end up in different memory parts with different abilities. To make programs more secure it is for example good practise to only allow code in the code segment to be executed. That prevents any attacks that try to manipulate program data to valid binary code and then having it executed somehow. The kernel will notice that something in the data segment should be executed and will prevent that.



                            More details can be found here







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited 7 mins ago

























                            answered 14 mins ago









                            Goro

                            2,06441846




                            2,06441846



























                                 

                                draft saved


                                draft discarded















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f469253%2fdoes-linux-not-use-segmentation-but-only-paging%23new-answer', 'question_page');

                                );

                                Post as a guest













































































                                Comments

                                Popular posts from this blog

                                Long meetings (6-7 hours a day): Being “babysat” by supervisor

                                Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                                Confectionery