From 1df6f7c9d86364d4d77ed7eddd96f76634abffb7 Mon Sep 17 00:00:00 2001 From: T-O-R-U-S Date: Tue, 15 Feb 2022 10:27:08 +0400 Subject: [PATCH 01/12] doc: capitalize valgrind --- ...d => investigating-native-memory-leaks.md} | 55 ++++++++++--------- 1 file changed, 29 insertions(+), 26 deletions(-) rename doc/contributing/{investigating_native_memory_leak.md => investigating-native-memory-leaks.md} (94%) diff --git a/doc/contributing/investigating_native_memory_leak.md b/doc/contributing/investigating-native-memory-leaks.md similarity index 94% rename from doc/contributing/investigating_native_memory_leak.md rename to doc/contributing/investigating-native-memory-leaks.md index 8c193d1285fe29..6e3acd5a8eff73 100644 --- a/doc/contributing/investigating_native_memory_leak.md +++ b/doc/contributing/investigating-native-memory-leaks.md @@ -1,28 +1,28 @@ -# Investigating memory leaks with valgrind +# Investigating memory leaks with Valgrind -A Node.js process may run out of memory due to excessive consumption of -native memory. Native Memory is memory which is not managed by the -V8 Garbage collector and is allocated either by the Node.js runtime, its -dependencies or native [addons](https://nodejs.org/docs/latest/api/n-api.html). + A Node.js process may run out of memory due to excessive consumption of + native memory. Native Memory is memory which is not managed by the + V8 Garbage collector and is allocated either by the Node.js runtime, its + dependencies or native [addons](https://nodejs.org/docs/latest/api/n-api.html). -This guide provides information on how to use valgrind to investigate these -issues on Linux platforms. + This guide provides information on how to use Valgrind to investigate these + issues on Linux platforms. -## valgrind + ## valgrind -[Valgrind](https://valgrind.org/docs/manual/quick-start.html) is a -tool available on Linux distributions which can be used to investigate -memory usage including identifying memory leaks (memory which is -allocated and not freed) and other memory related problems -like double freeing memory. + [Valgrind](https://valgrind.org/docs/manual/quick-start.html) is a + tool available on Linux distributions which can be used to investigate + memory usage including identifying memory leaks (memory which is + allocated and not freed) and other memory related problems + like double freeing memory. -To use valgrind: + To use Valgrind: -* Be patient, running under valgrind slows execution significantly - due to the checks being performed. -* Reduce your test case to the smallest reproduce. Due to the slowdown it is - important to run the minimum test case in order to be able to do it in - a reasonable time. + * Be patient, running under Valgrind slows execution significantly + due to the checks being performed. + * Reduce your test case to the smallest reproduce. Due to the slowdown it is + important to run the minimum test case in order to be able to do it in + a reasonable time. ## Installation @@ -35,7 +35,7 @@ apt-get install valgrind ## Invocation -The simplest invocation of valgrind is: +The simplest invocation of Valgrind is: ```console valgrind node test.js @@ -133,7 +133,7 @@ it along with the allocations (since it is not used) and Valgrind will not find any leaks since they will no longer exist in the code being run. -Running valgrind on this code shows the following: +Running Valgrind on this code shows the following: ```console user1@minikube1:~/valgrind/node-addon-examples/1_hello_world/napi$ valgrind node hello.js @@ -317,7 +317,7 @@ From the stack trace we can tell that the leak came from a native addon: What we can't tell is where in the native addon the memory is being allocated. This is because by default the addon is compiled without -the debug symbols which valgrind needs to be able to provide more +the debug symbols which Valgrind needs to be able to provide more information. ## Enabling debug symbols to get more information @@ -345,7 +345,7 @@ npm install --debug npm rebuild ``` -The next step is to run valgrind after the rebuild. This time the information +The next step is to run Valgrind after the rebuild. This time the information for the leaking location includes the name of the source file and the line number: @@ -385,7 +385,7 @@ This new output shows us exactly where the leak is occurring in the file `hello. If the leak is not in an addon and is instead in the Node.js binary itself, you may need to compile node yourself and turn on debug symbols. Looking at -this entry reported by valgrind, with a release binary we see: +this entry reported by Valgrind, with a release binary we see: ```console ==4174== 304 bytes in 1 blocks are possibly lost in loss record 27 of 35 @@ -409,7 +409,7 @@ its symbols using `-rdynamic` so that they can be used by addons. If the stack gives you enough information to track down where the leak is, that's great, otherwise the next step is to compile a debug build of Node.js. -To get additional information with valgrind: +To get additional information with Valgrind: * Check out the Node.js source corresponding to the release that you want to debug. For example: @@ -432,7 +432,7 @@ make -j4 `./configure --debug`, two binaries will have been built when `make` was run. You must use the one which is in `out/Debug`. -Running valgrind using the debug build of Node.js shows: +Running Valgrind using the debug build of Node.js shows: ```console ==44112== 592 bytes in 1 blocks are possibly lost in loss record 26 of 27 @@ -450,3 +450,6 @@ Running valgrind using the debug build of Node.js shows: Now we can see the specific file name and line in the Node.js code which caused the allocation (inspector\_agent.cc:140). + +Thusly, we can examine the line (and its surrounding code) in order +to find a potential solution for the memory leak. From 1a063917d4569d04064f137009b1fd3d5c5200c6 Mon Sep 17 00:00:00 2001 From: T-O-R-U-S Date: Tue, 15 Feb 2022 10:28:12 +0400 Subject: [PATCH 02/12] doc: fixed missing capitalization --- doc/contributing/investigating-native-memory-leaks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/contributing/investigating-native-memory-leaks.md b/doc/contributing/investigating-native-memory-leaks.md index 6e3acd5a8eff73..43cb3c31a52cc2 100644 --- a/doc/contributing/investigating-native-memory-leaks.md +++ b/doc/contributing/investigating-native-memory-leaks.md @@ -8,7 +8,7 @@ This guide provides information on how to use Valgrind to investigate these issues on Linux platforms. - ## valgrind + ## Valgrind [Valgrind](https://valgrind.org/docs/manual/quick-start.html) is a tool available on Linux distributions which can be used to investigate From 1e3825ec69e24520c56411b29eaf1649aade2b85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=E2=80=A2=C3=98=E2=80=A2R=E2=80=A2=C3=9C=E2=80=A2S?= Date: Tue, 15 Feb 2022 11:08:08 +0400 Subject: [PATCH 03/12] Update doc/contributing/investigating-native-memory-leaks.md Co-authored-by: Rich Trott --- doc/contributing/investigating-native-memory-leaks.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/contributing/investigating-native-memory-leaks.md b/doc/contributing/investigating-native-memory-leaks.md index 43cb3c31a52cc2..ab252b2696fa65 100644 --- a/doc/contributing/investigating-native-memory-leaks.md +++ b/doc/contributing/investigating-native-memory-leaks.md @@ -1,9 +1,9 @@ # Investigating memory leaks with Valgrind - A Node.js process may run out of memory due to excessive consumption of - native memory. Native Memory is memory which is not managed by the - V8 Garbage collector and is allocated either by the Node.js runtime, its - dependencies or native [addons](https://nodejs.org/docs/latest/api/n-api.html). +A Node.js process may run out of memory due to excessive consumption of +native memory. Native Memory is memory which is not managed by the +V8 Garbage collector and is allocated either by the Node.js runtime, its +dependencies or native [addons](https://nodejs.org/docs/latest/api/n-api.html). This guide provides information on how to use Valgrind to investigate these issues on Linux platforms. From 5cfd4cbbbfb9d0ad486ba76490bf9bb50290474f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=E2=80=A2=C3=98=E2=80=A2R=E2=80=A2=C3=9C=E2=80=A2S?= Date: Tue, 15 Feb 2022 11:08:17 +0400 Subject: [PATCH 04/12] Update doc/contributing/investigating-native-memory-leaks.md Co-authored-by: Rich Trott --- doc/contributing/investigating-native-memory-leaks.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/contributing/investigating-native-memory-leaks.md b/doc/contributing/investigating-native-memory-leaks.md index ab252b2696fa65..a4d7b0f86c3a00 100644 --- a/doc/contributing/investigating-native-memory-leaks.md +++ b/doc/contributing/investigating-native-memory-leaks.md @@ -5,8 +5,8 @@ native memory. Native Memory is memory which is not managed by the V8 Garbage collector and is allocated either by the Node.js runtime, its dependencies or native [addons](https://nodejs.org/docs/latest/api/n-api.html). - This guide provides information on how to use Valgrind to investigate these - issues on Linux platforms. +This guide provides information on how to use Valgrind to investigate these +issues on Linux platforms. ## Valgrind From fe9627eca86a15d81ef723d8bb6ff35ce0d0e4da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=E2=80=A2=C3=98=E2=80=A2R=E2=80=A2=C3=9C=E2=80=A2S?= Date: Tue, 15 Feb 2022 11:08:48 +0400 Subject: [PATCH 05/12] fix lint at doc/contributing/investigating-native-memory-leaks.md Co-authored-by: Rich Trott --- doc/contributing/investigating-native-memory-leaks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/contributing/investigating-native-memory-leaks.md b/doc/contributing/investigating-native-memory-leaks.md index a4d7b0f86c3a00..838d03156af532 100644 --- a/doc/contributing/investigating-native-memory-leaks.md +++ b/doc/contributing/investigating-native-memory-leaks.md @@ -8,7 +8,7 @@ dependencies or native [addons](https://nodejs.org/docs/latest/api/n-api.html). This guide provides information on how to use Valgrind to investigate these issues on Linux platforms. - ## Valgrind +## Valgrind [Valgrind](https://valgrind.org/docs/manual/quick-start.html) is a tool available on Linux distributions which can be used to investigate From d03a93a0e39e89a7217095364d6a645a94ba51bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=E2=80=A2=C3=98=E2=80=A2R=E2=80=A2=C3=9C=E2=80=A2S?= Date: Tue, 15 Feb 2022 11:08:58 +0400 Subject: [PATCH 06/12] fix lint at doc/contributing/investigating-native-memory-leaks.md Co-authored-by: Rich Trott --- doc/contributing/investigating-native-memory-leaks.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/contributing/investigating-native-memory-leaks.md b/doc/contributing/investigating-native-memory-leaks.md index 838d03156af532..8a13b8812644bf 100644 --- a/doc/contributing/investigating-native-memory-leaks.md +++ b/doc/contributing/investigating-native-memory-leaks.md @@ -10,11 +10,11 @@ issues on Linux platforms. ## Valgrind - [Valgrind](https://valgrind.org/docs/manual/quick-start.html) is a - tool available on Linux distributions which can be used to investigate - memory usage including identifying memory leaks (memory which is - allocated and not freed) and other memory related problems - like double freeing memory. +[Valgrind](https://valgrind.org/docs/manual/quick-start.html) is a +tool available on Linux distributions which can be used to investigate +memory usage including identifying memory leaks (memory which is +allocated and not freed) and other memory related problems +like double freeing memory. To use Valgrind: From 32cf332b2259110c0f12127981316a11ee93b128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=E2=80=A2=C3=98=E2=80=A2R=E2=80=A2=C3=9C=E2=80=A2S?= Date: Tue, 15 Feb 2022 11:09:08 +0400 Subject: [PATCH 07/12] fix lint at doc/contributing/investigating-native-memory-leaks.md Co-authored-by: Rich Trott --- doc/contributing/investigating-native-memory-leaks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/contributing/investigating-native-memory-leaks.md b/doc/contributing/investigating-native-memory-leaks.md index 8a13b8812644bf..b1dda233a19ac9 100644 --- a/doc/contributing/investigating-native-memory-leaks.md +++ b/doc/contributing/investigating-native-memory-leaks.md @@ -18,7 +18,7 @@ like double freeing memory. To use Valgrind: - * Be patient, running under Valgrind slows execution significantly +* Be patient, running under Valgrind slows execution significantly due to the checks being performed. * Reduce your test case to the smallest reproduce. Due to the slowdown it is important to run the minimum test case in order to be able to do it in From df4304dd544e058336f09ffa42ac3f039a7b8dc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=E2=80=A2=C3=98=E2=80=A2R=E2=80=A2=C3=9C=E2=80=A2S?= Date: Tue, 15 Feb 2022 11:09:19 +0400 Subject: [PATCH 08/12] fix lint at doc/contributing/investigating-native-memory-leaks.md Co-authored-by: Rich Trott --- doc/contributing/investigating-native-memory-leaks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/contributing/investigating-native-memory-leaks.md b/doc/contributing/investigating-native-memory-leaks.md index b1dda233a19ac9..81d8554fc97c0f 100644 --- a/doc/contributing/investigating-native-memory-leaks.md +++ b/doc/contributing/investigating-native-memory-leaks.md @@ -16,7 +16,7 @@ memory usage including identifying memory leaks (memory which is allocated and not freed) and other memory related problems like double freeing memory. - To use Valgrind: +To use Valgrind: * Be patient, running under Valgrind slows execution significantly due to the checks being performed. From 57d9bdb81e506383f40ef5269c6028f7bff251a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=E2=80=A2=C3=98=E2=80=A2R=E2=80=A2=C3=9C=E2=80=A2S?= Date: Tue, 15 Feb 2022 11:09:32 +0400 Subject: [PATCH 09/12] fix lint at doc/contributing/investigating-native-memory-leaks.md Co-authored-by: Rich Trott --- doc/contributing/investigating-native-memory-leaks.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/contributing/investigating-native-memory-leaks.md b/doc/contributing/investigating-native-memory-leaks.md index 81d8554fc97c0f..9bd015577513bd 100644 --- a/doc/contributing/investigating-native-memory-leaks.md +++ b/doc/contributing/investigating-native-memory-leaks.md @@ -19,8 +19,8 @@ like double freeing memory. To use Valgrind: * Be patient, running under Valgrind slows execution significantly - due to the checks being performed. - * Reduce your test case to the smallest reproduce. Due to the slowdown it is + due to the checks being performed. +* Reduce your test case to the smallest reproduce. Due to the slowdown it is important to run the minimum test case in order to be able to do it in a reasonable time. From 813c87899e31cd070619ea148ee017811aba3bc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=E2=80=A2=C3=98=E2=80=A2R=E2=80=A2=C3=9C=E2=80=A2S?= Date: Tue, 15 Feb 2022 11:09:44 +0400 Subject: [PATCH 10/12] fix lint at doc/contributing/investigating-native-memory-leaks.md Thanks @Trott! Co-authored-by: Rich Trott --- doc/contributing/investigating-native-memory-leaks.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/contributing/investigating-native-memory-leaks.md b/doc/contributing/investigating-native-memory-leaks.md index 9bd015577513bd..3e3e9d0a0b8113 100644 --- a/doc/contributing/investigating-native-memory-leaks.md +++ b/doc/contributing/investigating-native-memory-leaks.md @@ -21,8 +21,8 @@ To use Valgrind: * Be patient, running under Valgrind slows execution significantly due to the checks being performed. * Reduce your test case to the smallest reproduce. Due to the slowdown it is - important to run the minimum test case in order to be able to do it in - a reasonable time. + important to run the minimum test case in order to be able to do it in + a reasonable time. ## Installation From d09ac1c697d340daec32bb7be58b4816e00517ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=E2=80=A2=C3=98=E2=80=A2R=E2=80=A2=C3=9C=E2=80=A2S?= Date: Tue, 15 Feb 2022 15:44:34 +0400 Subject: [PATCH 11/12] Thusly -> thus in doc/contributing/investigating-native-memory-leaks.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks @tniessen! Co-authored-by: Tobias Nießen --- doc/contributing/investigating-native-memory-leaks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/contributing/investigating-native-memory-leaks.md b/doc/contributing/investigating-native-memory-leaks.md index 3e3e9d0a0b8113..3e629464f67bfe 100644 --- a/doc/contributing/investigating-native-memory-leaks.md +++ b/doc/contributing/investigating-native-memory-leaks.md @@ -451,5 +451,5 @@ Running Valgrind using the debug build of Node.js shows: Now we can see the specific file name and line in the Node.js code which caused the allocation (inspector\_agent.cc:140). -Thusly, we can examine the line (and its surrounding code) in order +Thus, we can examine the line (and its surrounding code) in order to find a potential solution for the memory leak. From 4fd894a7e07ad5e8d254fe67d8b47665b3527a63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=E2=80=A2=C3=98=E2=80=A2R=E2=80=A2=C3=9C=E2=80=A2S?= Date: Tue, 15 Feb 2022 16:56:25 +0400 Subject: [PATCH 12/12] Update doc/contributing/investigating-native-memory-leaks.md Co-authored-by: Rich Trott --- doc/contributing/investigating-native-memory-leaks.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/contributing/investigating-native-memory-leaks.md b/doc/contributing/investigating-native-memory-leaks.md index 3e629464f67bfe..f9345b092737fa 100644 --- a/doc/contributing/investigating-native-memory-leaks.md +++ b/doc/contributing/investigating-native-memory-leaks.md @@ -451,5 +451,5 @@ Running Valgrind using the debug build of Node.js shows: Now we can see the specific file name and line in the Node.js code which caused the allocation (inspector\_agent.cc:140). -Thus, we can examine the line (and its surrounding code) in order -to find a potential solution for the memory leak. +We can examine that line (and its surrounding code) to +find a solution for the memory leak.