RasPiの空きメモリを増やしたい

RasPiで作業をしていると、もう少しだけメモリがほしいと思うことがあります（ウソ）。
だいたい、RasPi3だと1GBのメモリがあるんだから、普通は足らないことはないです。
ちょっと遅くなっても良ければ、swapを増やせばいいですし、、、
なので、メモリが足らない状態というのは、道を外れた時に限ります！（決めつけ）

##0.設定を変更する前、ログイン直後のfreeの結果

```
pi@raspberrypi:~ $ free -h
             total       used       free     shared    buffers     cached
Mem:          923M        69M       854M       6.2M       6.6M        34M
-/+ buffers/cache:        28M       895M
Swap:          99M         0B        99M
pi@raspberrypi:~ $
```

##1.GPUに64MBもいらないって!
てっとり早いのはGPUに割り当てられているメモリを少なくする方法ですね。

```
pi@raspberrypi:~ $ sudo raspi-config
```


```
  1 Change User Password           Change password for the default u
  2 Hostname                       Set the visible name for this Pi
  3 Boot Options                   Configure options for start-up
  4 Localisation Options           Set up language and regional sett
  5 Interfacing Options            Configure connections to peripher
  6 Overclock                      Configure overclocking for your P
  7 Advanced Options               Configure advanced settings
  8 Update                         Update this tool to the latest ve
  9 About raspi-config             Information about this configurat

                   <Select>                     <Finish>
```
7 Advanced Optionsを選択します。

```

  A1 Expand Filesystem             Ensures that all of the SD card s
  A2 Overscan                      You may need to configure oversca
  A3 Memory Split                  Change the amount of memory made
  A4 Audio                         Force audio out through HDMI or 3
  A5 Resolution                    Set a specific screen resolution
  A6 GL Driver                     Enable/Disable experimental deskt

                   <Select>                     <Back>
```
A3 Memory Splitを選択します。

```
 How much memory should the GPU have?  e.g. 16/32/64/128/256

 64________________________________________________________________

                 <Ok>                   <Cancel>
```
初期値の64MBを16MBにしましょう。再起動すると、、、

```
pi@raspberrypi:~ $ free -h
             total       used       free     shared    buffers     cached
Mem:          970M        69M       901M       6.5M       6.6M        34M
-/+ buffers/cache:        28M       942M
Swap:          99M         0B        99M
pi@raspberrypi:~ $
```
おー、Totalが923MBから970MBになってます。ん？47MB増えたの？1MBはどこへ？

##2.swap止めちゃう？

```
pi@raspberrypi:~ $ sudo dphys-swapfile swapoff
pi@raspberrypi:~ $
```
再起動して

```
pi@raspberrypi:~ $ free -h
             total       used       free     shared    buffers     cached
Mem:          970M        69M       901M       6.5M       6.6M        34M
-/+ buffers/cache:        28M       942M
Swap:          99M         0B        99M
pi@raspberrypi:~ $
```

あれ？増えてない。

##3.サービス止めちゃう？
ひとまず、chkconfigをインストールしましょう。

```
pi@raspberrypi:~ $ sudo apt-get install chkconfig
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  chkconfig
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/9766 B of archives.
After this operation, 59.4 kB of additional disk space will be used.
Selecting previously unselected package chkconfig.
(Reading database ... 31532 files and directories currently installed.)
Preparing to unpack .../chkconfig_11.4.54.60.1debian1_all.deb ...
Unpacking chkconfig (11.4.54.60.1debian1) ...
Processing triggers for man-db (2.7.5-1~bpo8+1) ...
Setting up chkconfig (11.4.54.60.1debian1) ...
pi@raspberrypi:~ $
```

動作しているサービスは、、、

```
pi@raspberrypi:~ $ chkconfig --list
alsa-utils                0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on
avahi-daemon              0:off  1:off  2:on   3:on   4:on   5:on   6:off
bluetooth                 0:off  1:off  2:on   3:on   4:on   5:on   6:off
bootlogs                  0:off  1:on   2:on   3:on   4:on   5:on   6:off
bootmisc.sh               0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on
checkfs.sh                0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on
checkroot-bootclean.sh    0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on
checkroot.sh              0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on
console-setup             0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on
cron                      0:off  1:off  2:on   3:on   4:on   5:on   6:off
dbus                      0:off  1:off  2:on   3:on   4:on   5:on   6:off
dhcpcd                    0:off  1:off  2:on   3:on   4:on   5:on   6:off
dphys-swapfile            0:off  1:off  2:on   3:on   4:on   5:on   6:off
fake-hwclock              0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on
hostname.sh               0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on
hwclock.sh                0:off  1:off  2:off  3:off  4:off  5:off  6:off
kbd                       0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on
keyboard-setup            0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on
killprocs                 0:off  1:on   2:off  3:off  4:off  5:off  6:off
kmod                      0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on
motd                      0:off  1:on   2:on   3:on   4:on   5:on   6:off
mountall-bootclean.sh     0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on
mountall.sh               0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on
mountdevsubfs.sh          0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on
mountkernfs.sh            0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on
mountnfs-bootclean.sh     0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on
mountnfs.sh               0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on
networking                0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on
nfs-common                0:off  1:off  2:off  3:off  4:off  5:off  6:off
ntp                       0:off  1:off  2:on   3:on   4:on   5:on   6:off
plymouth                  0:off  1:off  2:on   3:on   4:on   5:on   6:off
plymouth-log              0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on
procps                    0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on
raspi-config              0:off  1:off  2:on   3:on   4:on   5:on   6:off  S:on
rc.local                  0:off  1:off  2:on   3:on   4:on   5:on   6:off
rcS                       0:off  1:off  2:off  3:off  4:off  5:off  6:off
rmnologin                 0:off  1:off  2:on   3:on   4:on   5:on   6:off
rpcbind                   0:off  1:off  2:off  3:off  4:off  5:off  6:off
rsyslog                   0:off  1:off  2:on   3:on   4:on   5:on   6:off
sendsigs                  0:off  1:off  2:off  3:off  4:off  5:off  6:off
ssh                       0:off  1:off  2:on   3:on   4:on   5:on   6:off
sudo                      0:off  1:off  2:off  3:off  4:off  5:off  6:off
triggerhappy              0:off  1:off  2:on   3:on   4:on   5:on   6:off
udev                      0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on
udev-finish               0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on
umountfs                  0:off  1:off  2:off  3:off  4:off  5:off  6:off
umountnfs.sh              0:off  1:off  2:off  3:off  4:off  5:off  6:off
umountroot                0:off  1:off  2:off  3:off  4:off  5:off  6:off
urandom                   0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on
pi@raspberrypi:~ $
```

いらなさそうなの止めちゃいましょう(自己責任で)

```
sudo chkconfig avahi-daemon off
sudo chkconfig bluetooth off
sudo chkconfig cron off
sudo chkconfig dbus off
sudo chkconfig dhcpcd off
sudo chkconfig dphys-swapfile off
sudo chkconfig motd off
sudo chkconfig ntp off
sudo chkconfig plymouth off
sudo chkconfig triggerhappy off
```
dhcpcdやntpを止めるとまずいことが多いですが、固定IPアドレスにしたり、時間にこだわらないときは止めちゃいましょう。再起動してすると

```
pi@raspberrypi:~ $ free -h
             total       used       free     shared    buffers     cached
Mem:          970M        67M       903M       6.5M       6.6M        33M
-/+ buffers/cache:        27M       943M
Swap:           0B         0B         0B
pi@raspberrypi:~ $
```

マジか！freeが2MBだけ増えてる。ついでにswapもゼロになってます。
ただ、手間の割には、んーーーーー。まあ、増えたのは事実。



参考にさせていただいたのはコチラ

メモのページ　-　チラシの裏メモ 別紙
http://d.hatena.ne.jp/debslink/20160827/1472285472