“vmstat” says there is paging activity - how to identify the swapping process?

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











up vote
1
down vote

favorite
1












I have a scenario where I can see there is paging activity on my Ubuntu 16.04 laptop using vmstat 1 100.



Due to the sheer size of the current load it is expected that processes are more or less swapped out to disk which is fine. I would, however, like to identify those that cause pages to swapped in all the time (as identified by vmstat) as this might indicate that memory allocation could be improved.



My sysadmin skills are a bit rusty but I am comfortable in a root shell.



What commands should I use to identify the processes which are causing swapping activity?







share|improve this question


























    up vote
    1
    down vote

    favorite
    1












    I have a scenario where I can see there is paging activity on my Ubuntu 16.04 laptop using vmstat 1 100.



    Due to the sheer size of the current load it is expected that processes are more or less swapped out to disk which is fine. I would, however, like to identify those that cause pages to swapped in all the time (as identified by vmstat) as this might indicate that memory allocation could be improved.



    My sysadmin skills are a bit rusty but I am comfortable in a root shell.



    What commands should I use to identify the processes which are causing swapping activity?







    share|improve this question
























      up vote
      1
      down vote

      favorite
      1









      up vote
      1
      down vote

      favorite
      1






      1





      I have a scenario where I can see there is paging activity on my Ubuntu 16.04 laptop using vmstat 1 100.



      Due to the sheer size of the current load it is expected that processes are more or less swapped out to disk which is fine. I would, however, like to identify those that cause pages to swapped in all the time (as identified by vmstat) as this might indicate that memory allocation could be improved.



      My sysadmin skills are a bit rusty but I am comfortable in a root shell.



      What commands should I use to identify the processes which are causing swapping activity?







      share|improve this question














      I have a scenario where I can see there is paging activity on my Ubuntu 16.04 laptop using vmstat 1 100.



      Due to the sheer size of the current load it is expected that processes are more or less swapped out to disk which is fine. I would, however, like to identify those that cause pages to swapped in all the time (as identified by vmstat) as this might indicate that memory allocation could be improved.



      My sysadmin skills are a bit rusty but I am comfortable in a root shell.



      What commands should I use to identify the processes which are causing swapping activity?









      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 1 at 7:31









      galoget

      36319




      36319










      asked Jan 31 at 9:46









      Thorbjørn Ravn Andersen

      821714




      821714




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote













          With performance problems (e.g. high CPU iowait times) it's generally best to monitor these things over time rather than after the fact, especially when short-lived processes might be the culprit. On Linux one tool you can use interactively is iotop (fixed link) (see also the answers to this question about tracking disk I/O). You can script this (batch mode) or run it interactively like top, use the cursor keys to sort by SWAPIN, or use the -o option so the output isn't so cluttered. You will need Python ≥2.7 and various kernel configuration parameters enabled (see iotop's README or man page).



          Rather than use only data from /proc like vmstat, iotop uses taskstats, this uses netlink IPC to efficiently provide process accounting directly from the kernel to user space.



          On most flavours of Linux with the default "swappiness" setting of 60, it's fairly normal to see paging activity when the system is moderately busy: the kernel is pre-emptively writing little-used process pages to swap instead of purging more recently used disk cache pages. (There's a related parameter vfs_cache_pressure to tune some cacheing behaviour.) If you observe persistent ongoing paging, then there is likely more to it than just this.



          Otherwise, if you are concerned about swap use right now rather than over time: the kernel keeps track of swap use per process in /proc/PID/status. You can do something quick with gawk (≥v4.0):



          gawk '/^Name:/nm=$2 /^Pid:/pid=$2 /^VmSwap:/sw=$2 
          ENDFILEprintf("%-24s %6i %6ikiBn",nm,pid,sw)' /proc/[0-9]*/status |
          sort -h -k 3


          According to the documentation shmem (shared memory) that's swapped out is not counted here, but you hopefully won't need to care about that. Eric Ljungstrom's getswap.sh script can also be used, there's a more advanced version of it in this answer.






          share|improve this answer






















          • Just to be clear - I am not seeing swap usage increased but that apparently some processes are reading in pages all the time. I want to identify these. Can iotop do that?
            – Thorbjørn Ravn Andersen
            Feb 1 at 23:43










          • Yes, it will show swapin (as a %), apologies I linked to the wrong iotop (there are it seems at least four different ones...) Fixed link. The kernel does not "blame" a process for page out, they are not accounted for per PID.
            – mr.spuratic
            Feb 2 at 10:19


















          up vote
          -1
          down vote













          Try the command:



           ps -eo pid,cmd,vsz


          This will list process in the format process id, command executed, and virtual memory size of the process in KiB






          share|improve this answer




















          • From "man ps": _vsz VSZ virtual memory size of the process in KiB (1024-byte units). _ I need the activity, not the total size. These are page-ins. The total size will not change.
            – Thorbjørn Ravn Andersen
            Jan 31 at 10:24










          • You would need to run something like "find /proc -maxdepth 2 -name stat -exec cat '' ;" then and parse the output.
            – Raman Sailopal
            Jan 31 at 10:46










          • Did you actually try this?
            – Thorbjørn Ravn Andersen
            Jan 31 at 12:23










          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%2f420888%2fvmstat-says-there-is-paging-activity-how-to-identify-the-swapping-process%23new-answer', 'question_page');

          );

          Post as a guest






























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote













          With performance problems (e.g. high CPU iowait times) it's generally best to monitor these things over time rather than after the fact, especially when short-lived processes might be the culprit. On Linux one tool you can use interactively is iotop (fixed link) (see also the answers to this question about tracking disk I/O). You can script this (batch mode) or run it interactively like top, use the cursor keys to sort by SWAPIN, or use the -o option so the output isn't so cluttered. You will need Python ≥2.7 and various kernel configuration parameters enabled (see iotop's README or man page).



          Rather than use only data from /proc like vmstat, iotop uses taskstats, this uses netlink IPC to efficiently provide process accounting directly from the kernel to user space.



          On most flavours of Linux with the default "swappiness" setting of 60, it's fairly normal to see paging activity when the system is moderately busy: the kernel is pre-emptively writing little-used process pages to swap instead of purging more recently used disk cache pages. (There's a related parameter vfs_cache_pressure to tune some cacheing behaviour.) If you observe persistent ongoing paging, then there is likely more to it than just this.



          Otherwise, if you are concerned about swap use right now rather than over time: the kernel keeps track of swap use per process in /proc/PID/status. You can do something quick with gawk (≥v4.0):



          gawk '/^Name:/nm=$2 /^Pid:/pid=$2 /^VmSwap:/sw=$2 
          ENDFILEprintf("%-24s %6i %6ikiBn",nm,pid,sw)' /proc/[0-9]*/status |
          sort -h -k 3


          According to the documentation shmem (shared memory) that's swapped out is not counted here, but you hopefully won't need to care about that. Eric Ljungstrom's getswap.sh script can also be used, there's a more advanced version of it in this answer.






          share|improve this answer






















          • Just to be clear - I am not seeing swap usage increased but that apparently some processes are reading in pages all the time. I want to identify these. Can iotop do that?
            – Thorbjørn Ravn Andersen
            Feb 1 at 23:43










          • Yes, it will show swapin (as a %), apologies I linked to the wrong iotop (there are it seems at least four different ones...) Fixed link. The kernel does not "blame" a process for page out, they are not accounted for per PID.
            – mr.spuratic
            Feb 2 at 10:19















          up vote
          1
          down vote













          With performance problems (e.g. high CPU iowait times) it's generally best to monitor these things over time rather than after the fact, especially when short-lived processes might be the culprit. On Linux one tool you can use interactively is iotop (fixed link) (see also the answers to this question about tracking disk I/O). You can script this (batch mode) or run it interactively like top, use the cursor keys to sort by SWAPIN, or use the -o option so the output isn't so cluttered. You will need Python ≥2.7 and various kernel configuration parameters enabled (see iotop's README or man page).



          Rather than use only data from /proc like vmstat, iotop uses taskstats, this uses netlink IPC to efficiently provide process accounting directly from the kernel to user space.



          On most flavours of Linux with the default "swappiness" setting of 60, it's fairly normal to see paging activity when the system is moderately busy: the kernel is pre-emptively writing little-used process pages to swap instead of purging more recently used disk cache pages. (There's a related parameter vfs_cache_pressure to tune some cacheing behaviour.) If you observe persistent ongoing paging, then there is likely more to it than just this.



          Otherwise, if you are concerned about swap use right now rather than over time: the kernel keeps track of swap use per process in /proc/PID/status. You can do something quick with gawk (≥v4.0):



          gawk '/^Name:/nm=$2 /^Pid:/pid=$2 /^VmSwap:/sw=$2 
          ENDFILEprintf("%-24s %6i %6ikiBn",nm,pid,sw)' /proc/[0-9]*/status |
          sort -h -k 3


          According to the documentation shmem (shared memory) that's swapped out is not counted here, but you hopefully won't need to care about that. Eric Ljungstrom's getswap.sh script can also be used, there's a more advanced version of it in this answer.






          share|improve this answer






















          • Just to be clear - I am not seeing swap usage increased but that apparently some processes are reading in pages all the time. I want to identify these. Can iotop do that?
            – Thorbjørn Ravn Andersen
            Feb 1 at 23:43










          • Yes, it will show swapin (as a %), apologies I linked to the wrong iotop (there are it seems at least four different ones...) Fixed link. The kernel does not "blame" a process for page out, they are not accounted for per PID.
            – mr.spuratic
            Feb 2 at 10:19













          up vote
          1
          down vote










          up vote
          1
          down vote









          With performance problems (e.g. high CPU iowait times) it's generally best to monitor these things over time rather than after the fact, especially when short-lived processes might be the culprit. On Linux one tool you can use interactively is iotop (fixed link) (see also the answers to this question about tracking disk I/O). You can script this (batch mode) or run it interactively like top, use the cursor keys to sort by SWAPIN, or use the -o option so the output isn't so cluttered. You will need Python ≥2.7 and various kernel configuration parameters enabled (see iotop's README or man page).



          Rather than use only data from /proc like vmstat, iotop uses taskstats, this uses netlink IPC to efficiently provide process accounting directly from the kernel to user space.



          On most flavours of Linux with the default "swappiness" setting of 60, it's fairly normal to see paging activity when the system is moderately busy: the kernel is pre-emptively writing little-used process pages to swap instead of purging more recently used disk cache pages. (There's a related parameter vfs_cache_pressure to tune some cacheing behaviour.) If you observe persistent ongoing paging, then there is likely more to it than just this.



          Otherwise, if you are concerned about swap use right now rather than over time: the kernel keeps track of swap use per process in /proc/PID/status. You can do something quick with gawk (≥v4.0):



          gawk '/^Name:/nm=$2 /^Pid:/pid=$2 /^VmSwap:/sw=$2 
          ENDFILEprintf("%-24s %6i %6ikiBn",nm,pid,sw)' /proc/[0-9]*/status |
          sort -h -k 3


          According to the documentation shmem (shared memory) that's swapped out is not counted here, but you hopefully won't need to care about that. Eric Ljungstrom's getswap.sh script can also be used, there's a more advanced version of it in this answer.






          share|improve this answer














          With performance problems (e.g. high CPU iowait times) it's generally best to monitor these things over time rather than after the fact, especially when short-lived processes might be the culprit. On Linux one tool you can use interactively is iotop (fixed link) (see also the answers to this question about tracking disk I/O). You can script this (batch mode) or run it interactively like top, use the cursor keys to sort by SWAPIN, or use the -o option so the output isn't so cluttered. You will need Python ≥2.7 and various kernel configuration parameters enabled (see iotop's README or man page).



          Rather than use only data from /proc like vmstat, iotop uses taskstats, this uses netlink IPC to efficiently provide process accounting directly from the kernel to user space.



          On most flavours of Linux with the default "swappiness" setting of 60, it's fairly normal to see paging activity when the system is moderately busy: the kernel is pre-emptively writing little-used process pages to swap instead of purging more recently used disk cache pages. (There's a related parameter vfs_cache_pressure to tune some cacheing behaviour.) If you observe persistent ongoing paging, then there is likely more to it than just this.



          Otherwise, if you are concerned about swap use right now rather than over time: the kernel keeps track of swap use per process in /proc/PID/status. You can do something quick with gawk (≥v4.0):



          gawk '/^Name:/nm=$2 /^Pid:/pid=$2 /^VmSwap:/sw=$2 
          ENDFILEprintf("%-24s %6i %6ikiBn",nm,pid,sw)' /proc/[0-9]*/status |
          sort -h -k 3


          According to the documentation shmem (shared memory) that's swapped out is not counted here, but you hopefully won't need to care about that. Eric Ljungstrom's getswap.sh script can also be used, there's a more advanced version of it in this answer.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 2 at 10:20

























          answered Feb 1 at 18:26









          mr.spuratic

          6,4711027




          6,4711027











          • Just to be clear - I am not seeing swap usage increased but that apparently some processes are reading in pages all the time. I want to identify these. Can iotop do that?
            – Thorbjørn Ravn Andersen
            Feb 1 at 23:43










          • Yes, it will show swapin (as a %), apologies I linked to the wrong iotop (there are it seems at least four different ones...) Fixed link. The kernel does not "blame" a process for page out, they are not accounted for per PID.
            – mr.spuratic
            Feb 2 at 10:19

















          • Just to be clear - I am not seeing swap usage increased but that apparently some processes are reading in pages all the time. I want to identify these. Can iotop do that?
            – Thorbjørn Ravn Andersen
            Feb 1 at 23:43










          • Yes, it will show swapin (as a %), apologies I linked to the wrong iotop (there are it seems at least four different ones...) Fixed link. The kernel does not "blame" a process for page out, they are not accounted for per PID.
            – mr.spuratic
            Feb 2 at 10:19
















          Just to be clear - I am not seeing swap usage increased but that apparently some processes are reading in pages all the time. I want to identify these. Can iotop do that?
          – Thorbjørn Ravn Andersen
          Feb 1 at 23:43




          Just to be clear - I am not seeing swap usage increased but that apparently some processes are reading in pages all the time. I want to identify these. Can iotop do that?
          – Thorbjørn Ravn Andersen
          Feb 1 at 23:43












          Yes, it will show swapin (as a %), apologies I linked to the wrong iotop (there are it seems at least four different ones...) Fixed link. The kernel does not "blame" a process for page out, they are not accounted for per PID.
          – mr.spuratic
          Feb 2 at 10:19





          Yes, it will show swapin (as a %), apologies I linked to the wrong iotop (there are it seems at least four different ones...) Fixed link. The kernel does not "blame" a process for page out, they are not accounted for per PID.
          – mr.spuratic
          Feb 2 at 10:19













          up vote
          -1
          down vote













          Try the command:



           ps -eo pid,cmd,vsz


          This will list process in the format process id, command executed, and virtual memory size of the process in KiB






          share|improve this answer




















          • From "man ps": _vsz VSZ virtual memory size of the process in KiB (1024-byte units). _ I need the activity, not the total size. These are page-ins. The total size will not change.
            – Thorbjørn Ravn Andersen
            Jan 31 at 10:24










          • You would need to run something like "find /proc -maxdepth 2 -name stat -exec cat '' ;" then and parse the output.
            – Raman Sailopal
            Jan 31 at 10:46










          • Did you actually try this?
            – Thorbjørn Ravn Andersen
            Jan 31 at 12:23














          up vote
          -1
          down vote













          Try the command:



           ps -eo pid,cmd,vsz


          This will list process in the format process id, command executed, and virtual memory size of the process in KiB






          share|improve this answer




















          • From "man ps": _vsz VSZ virtual memory size of the process in KiB (1024-byte units). _ I need the activity, not the total size. These are page-ins. The total size will not change.
            – Thorbjørn Ravn Andersen
            Jan 31 at 10:24










          • You would need to run something like "find /proc -maxdepth 2 -name stat -exec cat '' ;" then and parse the output.
            – Raman Sailopal
            Jan 31 at 10:46










          • Did you actually try this?
            – Thorbjørn Ravn Andersen
            Jan 31 at 12:23












          up vote
          -1
          down vote










          up vote
          -1
          down vote









          Try the command:



           ps -eo pid,cmd,vsz


          This will list process in the format process id, command executed, and virtual memory size of the process in KiB






          share|improve this answer












          Try the command:



           ps -eo pid,cmd,vsz


          This will list process in the format process id, command executed, and virtual memory size of the process in KiB







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 31 at 10:16









          Raman Sailopal

          1,18117




          1,18117











          • From "man ps": _vsz VSZ virtual memory size of the process in KiB (1024-byte units). _ I need the activity, not the total size. These are page-ins. The total size will not change.
            – Thorbjørn Ravn Andersen
            Jan 31 at 10:24










          • You would need to run something like "find /proc -maxdepth 2 -name stat -exec cat '' ;" then and parse the output.
            – Raman Sailopal
            Jan 31 at 10:46










          • Did you actually try this?
            – Thorbjørn Ravn Andersen
            Jan 31 at 12:23
















          • From "man ps": _vsz VSZ virtual memory size of the process in KiB (1024-byte units). _ I need the activity, not the total size. These are page-ins. The total size will not change.
            – Thorbjørn Ravn Andersen
            Jan 31 at 10:24










          • You would need to run something like "find /proc -maxdepth 2 -name stat -exec cat '' ;" then and parse the output.
            – Raman Sailopal
            Jan 31 at 10:46










          • Did you actually try this?
            – Thorbjørn Ravn Andersen
            Jan 31 at 12:23















          From "man ps": _vsz VSZ virtual memory size of the process in KiB (1024-byte units). _ I need the activity, not the total size. These are page-ins. The total size will not change.
          – Thorbjørn Ravn Andersen
          Jan 31 at 10:24




          From "man ps": _vsz VSZ virtual memory size of the process in KiB (1024-byte units). _ I need the activity, not the total size. These are page-ins. The total size will not change.
          – Thorbjørn Ravn Andersen
          Jan 31 at 10:24












          You would need to run something like "find /proc -maxdepth 2 -name stat -exec cat '' ;" then and parse the output.
          – Raman Sailopal
          Jan 31 at 10:46




          You would need to run something like "find /proc -maxdepth 2 -name stat -exec cat '' ;" then and parse the output.
          – Raman Sailopal
          Jan 31 at 10:46












          Did you actually try this?
          – Thorbjørn Ravn Andersen
          Jan 31 at 12:23




          Did you actually try this?
          – Thorbjørn Ravn Andersen
          Jan 31 at 12:23












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f420888%2fvmstat-says-there-is-paging-activity-how-to-identify-the-swapping-process%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Displaying single band from multi-band raster using QGIS

          How many registers does an x86_64 CPU actually have?