# Memory usage will drop after I use trtexec

**URL:** <https://forums.developer.nvidia.com/t/memory-usage-will-drop-after-i-use-trtexec/192535>\
**Category:** Jetson Xavier NX\
**Tags:** tensorrt\
**Created:** [October 20, 2021, 7:08am UTC](https://forums.developer.nvidia.com/t/memory-usage-will-drop-after-i-use-trtexec/192535 "2021-10-20T07:08:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![haoliuhust](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@haoliuhust](https://forums.developer.nvidia.com/u/haoliuhust)\
**Post date:** [October 20, 2021, 7:08am UTC](https://forums.developer.nvidia.com/t/memory-usage-will-drop-after-i-use-trtexec/192535/1 "2021-10-20T07:08:39Z")

</div>

A very strange thing, when I start my app which load a serveral models, it will use about 3G RAM. and the total free RAM was about 1G。After I run trtexec --loadEngine=XXX at the same time when the app is running, the app will use only 1.3G RAM. the memory usage will drop. Why this could be happen?

---

<div class="post-metadata">

**Author:** ![AastaLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/aastalll/32/14043_2.png) [@AastaLLL](https://forums.developer.nvidia.com/u/AastaLLL)\
**Post date:** [October 20, 2021, 7:39am UTC](https://forums.developer.nvidia.com/t/memory-usage-will-drop-after-i-use-trtexec/192535/3 "2021-10-20T07:39:01Z")

</div>

Hi,

The memory is used for both workspaces and loading the essential libraries.

When you deserialize an engine file, TensorRT doesn’t need to load the model conversion library (ex. onnxparser).  
And this will save memory usage.

Thansk.

---

<div class="post-metadata">

**Author:** ![haoliuhust](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@haoliuhust](https://forums.developer.nvidia.com/u/haoliuhust)\
**Post date:** [October 20, 2021, 7:45am UTC](https://forums.developer.nvidia.com/t/memory-usage-will-drop-after-i-use-trtexec/192535/4 "2021-10-20T07:45:37Z")

</div>

maybe I mislead you, the phenomenon is when I start my app(which load a serveral models(already serialize to engine file) alone, it will use about 3G RAM after start up, when my app is running, I run trtexec --loadEngine=XXX to test some model in other shell, my app will only use 1.3G RAM(without restart it, it’s memory usage dropped directly). I wonder if there are some cache in cuda or tensorrt when start up, and can be free when the RAM is not sufficent for other app to load one more model

---

<div class="post-metadata">

**Author:** ![haoliuhust](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@haoliuhust](https://forums.developer.nvidia.com/u/haoliuhust)\
**Post date:** [October 22, 2021, 2:51am UTC](https://forums.developer.nvidia.com/t/memory-usage-will-drop-after-i-use-trtexec/192535/5 "2021-10-22T02:51:17Z")

</div>

Any advice to investgate the strange problem?

---

<div class="post-metadata">

**Author:** ![AastaLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/aastalll/32/14043_2.png) [@AastaLLL](https://forums.developer.nvidia.com/u/AastaLLL)\
**Post date:** [October 25, 2021, 3:09am UTC](https://forums.developer.nvidia.com/t/memory-usage-will-drop-after-i-use-trtexec/192535/6 "2021-10-25T03:09:37Z")

</div>

Hi,

How do you measure the memory usage of your app?  
Do you cat the data at `/proc/self/stat`?

More, could you test the similar with our default TensorRT example?  
It will be good to know if this issue is app-dependent.

Thanks.

---

<div class="post-metadata">

**Author:** ![haoliuhust](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@haoliuhust](https://forums.developer.nvidia.com/u/haoliuhust)\
**Post date:** [October 26, 2021, 8:08am UTC](https://forums.developer.nvidia.com/t/memory-usage-will-drop-after-i-use-trtexec/192535/7 "2021-10-26T08:08:08Z")

</div>

> [@AastaLLL](#):
>
> /proc/self/stat

Thanks for your reply, I have tested it with only trtexec, when start with one trtexec process(very long runs to keep it running), it cost 1.8G RAM, and then start with another two trtexec, the first trtexec process will cost 1.4G（without restart). I was measure RAM with “top”. According to jtop, the CPU RAM dropped

---

<div class="post-metadata">

**Author:** ![AastaLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/aastalll/32/14043_2.png) [@AastaLLL](https://forums.developer.nvidia.com/u/AastaLLL)\
**Post date:** [October 28, 2021, 5:19am UTC](https://forums.developer.nvidia.com/t/memory-usage-will-drop-after-i-use-trtexec/192535/8 "2021-10-28T05:19:52Z")

</div>

Hi,

It’s more recommended to monitor the process memory usage in a similar way as below.  
It can give you a more accurate memory usage for each process.

```auto
void process_mem_usage(double & vm_usage, double & resident_set)
{
   std::ifstream stat("/proc/self/stat", std::ios::in);

   // dummy vars for leading entries in stat that we don't care about
   std::string pid, comm, state, ppid, pgrp, session, tty_nr;
   std::string tpgid, flags, minflt, cminflt, majflt, cmajflt;
   std::string utime, stime, cutime, cstime, priority, nice;
   std::string O, itrealvalue, starttime;

   // the two fields we want
   unsigned long vsize;
   long rss;

   stat >> pid >> comm >> state >> ppid >> pgrp >> session >> tty_nr
       >> tpgid >> flags >> minflt >> cminflt >> majflt >> cmajflt
       >> utime >> stime >> cutime >> cstime >> priority >> nice
       >> O >> itrealvalue >> starttime >> vsize >> rss;

   vm_usage = vsize;
   resident_set = rss * sysconf(_SC_PAGE_SIZE);
}

void print_mem_usage(const char * description)
{
    double vm_usage, resident_set;
    process_mem_usage(vm_usage, resident_set);
    std::cout << "Memory usage " << description << ": " << vm_usage / (1024*1024) << " MiB virtual, "
        << resident_set / (1024*1024) << " MiB resident" << std::endl;
}

```

Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/system/32/68080_2.png) [@system](https://forums.developer.nvidia.com/u/system)\
**Post date:** [November 17, 2021, 5:58am UTC](https://forums.developer.nvidia.com/t/memory-usage-will-drop-after-i-use-trtexec/192535/10 "2021-11-17T05:58:45Z")

</div>

Closed on November 17, 2021, 5:58am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
