Mongodb mmapv1 stops due to out of memory issue on 32 bit system with version 2.4.10

A. I am using mongodb version 2.4.10 on my 32 bit system. I use debian 8 OS image. My application has backend in python and uses pymongo version 3.4.0 to access mongodb. However, I have less flash memory available after loading my application - 2.3 G flash available. I want to restrict Mongodb’s flash memory usage on my system. Mongodb uses all flash memory and shuts down.

Below are the log file error messages that I get:

Thu Jan  1 06:57:21.848 [initandlisten] MongoDB starting : pid=32080 port=27017 dbpath=/var/lib/mongodb 32-bit host=FriendlyELEC
Thu Jan  1 06:57:21.848 [initandlisten] 
Thu Jan  1 06:57:21.849 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary.
Thu Jan  1 06:57:21.849 [initandlisten] **       32 bit builds are limited to less than 2GB of data (or less with --journal).
Thu Jan  1 06:57:21.849 [initandlisten] **       See http://dochub.mongodb.org/core/32bit
Thu Jan  1 06:57:21.849 [initandlisten] 
Thu Jan  1 06:57:21.849 [initandlisten] db version v2.4.10
Thu Jan  1 06:57:21.850 [initandlisten] git version: nogitversion
Thu Jan  1 06:57:21.850 [initandlisten] build info: Linux hartmann 3.16.0-4-armmp-lpae #1 SMP Debian 3.16.39-1 (2016-12-30) armv7l BOOST_LIB_VERSION=1_55
Thu Jan  1 06:57:21.850 [initandlisten] allocator: system
Thu Jan  1 06:57:21.850 [initandlisten] options: { bind_ip: "127.0.0.1", config: "/etc/mongodb.conf", dbpath: "/var/lib/mongodb", journal: "true", logappend: "true", logpath: "/var/log/mongodb/mongodb.log" }
Thu Jan  1 06:57:22.005 [initandlisten] journal dir=/var/lib/mongodb/journal
Thu Jan  1 06:57:22.005 [initandlisten] recover : no journal files present, no recovery needed
Thu Jan  1 06:57:22.398 [initandlisten] ERROR: mmap private failed with out of memory. You are using a 32-bit build and probably need to upgrade to 64
Thu Jan  1 06:57:22.398 [initandlisten] Assertion: 13636:file /var/lib/mongodb/mydata.6 open/create failed in createPrivateMap (look in log for more information)
0x48e13c 0x46f83a 0x45d190 0x45d238 0x30ab84 0x32cade 0x252b98 0x252e3c 0x25351a 0x253a6e 0x203130 0x20326a 0x16836a 0x1699dc 0x15004c 0xb67f0632 
 /usr/bin/mongod(_ZN5mongo15printStackTraceERSo+0x17) [0x48e13c]
 /usr/bin/mongod(_ZN5mongo10logContextEPKc+0xa9) [0x46f83a]
 /usr/bin/mongod(_ZN5mongo11msgassertedEiPKc+0x67) [0x45d190]
 /usr/bin/mongod(_ZN5mongo11msgassertedEiRKSs+0x7) [0x45d238]
 /usr/bin/mongod(_ZN5mongo8MongoMMF13finishOpeningEv+0x1bb) [0x30ab84]
 /usr/bin/mongod(_ZN5mongo13MongoDataFile12openExistingEPKc+0x65) [0x32cade]
 /usr/bin/mongod(_ZN5mongo8Database16openExistingFileEi+0x19b) [0x252b98]
 /usr/bin/mongod(_ZN5mongo8Database12openAllFilesEv+0x13) [0x252e3c]
 /usr/bin/mongod(_ZN5mongo8DatabaseC2EPKcRbRKSs+0xdd) [0x25351a]
 /usr/bin/mongod(_ZN5mongo14DatabaseHolder11getOrCreateERKSsS2_Rb+0x33d) [0x253a6e]
 /usr/bin/mongod(_ZN5mongo6Client7Context11_finishInitEv+0x23) [0x203130]
 /usr/bin/mongod(_ZN5mongo6Client7ContextC1ERKSsS3_b+0x4d) [0x20326a]
 /usr/bin/mongod(_ZN5mongo14_initAndListenEi+0x839) [0x16836a]
 /usr/bin/mongod(_ZN5mongo13initAndListenEi+0xb) [0x1699dc]
 /usr/bin/mongod(main+0x1d3) [0x15004c]
 /lib/arm-linux-gnueabihf/libc.so.6(__libc_start_main+0x99) [0xb67f0632]
Thu Jan  1 06:57:22.424 [initandlisten] warning database /var/lib/mongodb mydata could not be opened
Thu Jan  1 06:57:22.424 [initandlisten] DBException 13636: file /var/lib/mongodb/mydata.6 open/create failed in createPrivateMap (look in log for more information)
Thu Jan  1 06:57:22.427 [initandlisten] exception in initAndListen: 13636 file /var/lib/mongodb/mydata.6 open/create failed in createPrivateMap (look in log for more information), terminating
Thu Jan  1 06:57:22.427 dbexit: 
Thu Jan  1 06:57:22.427 [initandlisten] shutdown: going to close listening sockets...
Thu Jan  1 06:57:22.427 [initandlisten] shutdown: going to flush diaglog...
Thu Jan  1 06:57:22.427 [initandlisten] shutdown: going to close sockets...
Thu Jan  1 06:57:22.428 [initandlisten] shutdown: waiting for fs preallocator...
Thu Jan  1 06:57:22.428 [initandlisten] shutdown: lock for final commit...
Thu Jan  1 06:57:22.428 [initandlisten] shutdown: final commit...
Thu Jan  1 06:57:22.428 [initandlisten] shutdown: closing all files...
Thu Jan  1 06:57:22.428 [initandlisten] closeAllFiles() finished
Thu Jan  1 06:57:22.428 [initandlisten] journalCleanup...
Thu Jan  1 06:57:22.428 [initandlisten] removeJournalFiles
Thu Jan  1 06:57:22.533 [initandlisten] shutdown: removing fs lock...
Thu Jan  1 06:57:22.534 dbexit: really exiting now
Thu Jan  1 17:03:33.339 [initandlisten] MongoDB starting : pid=21109 port=27017 dbpath=/var/lib/mongodb 32-bit host=FriendlyELEC
Thu Jan  1 17:03:33.340 [initandlisten] 
Thu Jan  1 17:03:33.340 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary.
Thu Jan  1 17:03:33.340 [initandlisten] **       32 bit builds are limited to less than 2GB of data (or less with --journal).
Thu Jan  1 17:03:33.340 [initandlisten] **       See http://dochub.mongodb.org/core/32bit
Thu Jan  1 17:03:33.340 [initandlisten] 
Thu Jan  1 17:03:33.341 [initandlisten] db version v2.4.10
Thu Jan  1 17:03:33.341 [initandlisten] git version: nogitversion
Thu Jan  1 17:03:33.341 [initandlisten] build info: Linux hartmann 3.16.0-4-armmp-lpae #1 SMP Debian 3.16.39-1 (2016-12-30) armv7l BOOST_LIB_VERSION=1_55
Thu Jan  1 17:03:33.341 [initandlisten] allocator: system
Thu Jan  1 17:03:33.341 [initandlisten] options: { bind_ip: "127.0.0.1", config: "/etc/mongodb.conf", dbpath: "/var/lib/mongodb", journal: "true", logappend: "true", logpath: "/var/log/mongodb/mongodb.log" }
Thu Jan  1 17:03:33.345 [initandlisten] journal dir=/var/lib/mongodb/journal
Thu Jan  1 17:03:33.345 [initandlisten] recover : no journal files present, no recovery needed
Thu Jan  1 17:03:33.345 [initandlisten] 
Thu Jan  1 17:03:33.346 [initandlisten] ERROR: Insufficient free space for journal files
Thu Jan  1 17:03:33.346 [initandlisten] Please make at least 844MB available in /var/lib/mongodb/journal or use --smallfiles
Thu Jan  1 17:03:33.346 [initandlisten] 
Thu Jan  1 17:03:33.346 [initandlisten] exception in initAndListen: 15926 Insufficient free space for journals, terminating
Thu Jan  1 17:03:33.346 dbexit: 
Thu Jan  1 17:03:33.346 [initandlisten] shutdown: going to close listening sockets...
Thu Jan  1 17:03:33.347 [initandlisten] shutdown: going to flush diaglog...
Thu Jan  1 17:03:33.347 [initandlisten] shutdown: going to close sockets...
Thu Jan  1 17:03:33.347 [initandlisten] shutdown: waiting for fs preallocator...
Thu Jan  1 17:03:33.347 [initandlisten] shutdown: lock for final commit...
Thu Jan  1 17:03:33.347 [initandlisten] shutdown: final commit...
Thu Jan  1 17:03:33.347 [initandlisten] shutdown: closing all files...
Thu Jan  1 17:03:33.347 [initandlisten] closeAllFiles() finished
Thu Jan  1 17:03:33.347 [initandlisten] journalCleanup...
Thu Jan  1 17:03:33.347 [initandlisten] removeJournalFiles
Thu Jan  1 17:03:33.348 [initandlisten] shutdown: removing fs lock...
Thu Jan  1 17:03:33.349 dbexit: really exiting now

B. I tried to reduce Mongodb’s flash memory usage by editing the mongo.conf file as below:

# mongodb.conf
# Where to store the data.
dbpath=/var/lib/mongodb
bind_ip = 127.0.0.1
journal = false
smallfiles = true
nssize = 10
noprealloc = true
quota = true
quotaFiles = 2

(Stopped storing mongodb logs to save space )
However, mongodb still stops and I am trying to restart it within my python code using “os.system (service mongodb start)” but that doesn’t help.
However, I tried the following commands on my system terminal as root user:

  1. cd /var/lib/mongodb
  2. rm mongodb.lock
  3. mongodb --dbpath /var/lib/mongodb --repair
  4. chown -R mongodb:mongodb /var/lib/mongodb
  5. service mongodb restart
    These commands work and I am able to restart mongodb, but after I shut down my system and start again (power cycle), I face the same issue that mongodb has stopped.

a. Why does my mongodb keep stopping?
b. Is there an option to automatically run these commands when mongodb stops?
c. Why do I have to change /var/lib/mongodb permissions every time?
d. Is it possible to load 64 bit mongodb version on a 32 bit processor (since log file gives message to upgrade) and how can I manage flash memory usage then?

I would really appreciate if someone can help me with this issue. Thanks !