# Configuring Linux for MariaDB

## Linux kernel settings

### IO scheduler

For optimal IO performance running a database on modern hardware we recommend using the *none* (previously called *noop*) scheduler.

Recommended schedulers are *none*, for SSDs and NVMes, and *mq-deadline* (previously called *deadline*) for hard disks.

You can check your scheduler setting with:

```bash
cat /sys/block/${DEVICE}/queue/scheduler
```

For instance, it should look like this output:

```bash
cat /sys/block/vdb/queue/scheduler
[none] mq-deadline kyber bfq
```

Older kernels may look like:

```bash
cat /sys/block/sda/queue/scheduler
[noop] deadline cfq
```

Writing the new scheduler name to the same `/sys` node will change the scheduler:

```bash
echo noop >  /sys/block/vdb/queue/scheduler
```

The impact of schedulers depend significantly on workload and hardware. You can measure the IO-latency using the [biolatency](https://github.com/iovisor/bcc/blob/master/tools/biolatency_example.txt) bcc-tools script with an aim to keep the mean as low as possible.

## Resource Limits

### Configuring the Open Files Limit

By default, the system limits how many open file descriptors a process can have open at one time. It has both a soft and hard limit. On many systems, both the soft and hard limit default to 1024. On an active database server, it is very easy to exceed 1024 open file descriptors. Therefore, you may need to increase the soft and hard limits. There are a few ways to do so.

If you are using [mysqld\_safe or mariadbd-safe](https://github.com/mariadb-corporation/mariadb-docs/blob/main/server/server-management/install-and-upgrade-mariadb/configuring-mariadb/starting-and-stopping-mariadb/mariadbd-safe.md) to start `mysqld`, then see the instructions at [mariadbd-safe: Configuring the Open Files Limit](https://gitbook-v2-q3lwp8faq-gitbook.vercel.app/url/mariadb.com/docs/server/starting-and-stopping-mariadb/mariadbd-safe#configuring-the-open-files-limit).

If you are using [systemd](https://gitbook-v2-q3lwp8faq-gitbook.vercel.app/url/mariadb.com/docs/server/server-management/starting-and-stopping-mariadb/systemd) to start `mysqld`, then see the instructions at [systemd: Configuring the Open Files Limit](https://gitbook-v2-q3lwp8faq-gitbook.vercel.app/url/mariadb.com/docs/server/starting-and-stopping-mariadb/systemd#configuring-the-open-files-limit).

Otherwise, you can set the soft and hard limits for the `mysql` user account by adding the following lines to [/etc/security/limits.conf](https://linux.die.net/man/5/limits.conf):

```bash
mysql soft nofile 65535
mysql hard nofile 65535
```

After the system is rebooted, the `mysql` user should use the new limits, and the user's `ulimit` output should look like the following:

```bash
$ ulimit -Sn
65535
$ ulimit -Hn
65535
```

### Configuring the Core File Size

By default, the system limits the size of core files that could be created. It has both a soft and hard limit. On many systems, the soft limit defaults to 0. If you want to [enable core dumps](https://app.gitbook.com/s/WCInJQ9cmGjq1lsTG91E/development-articles/debugging-mariadb/enabling-core-dumps), then you may need to increase this. Therefore, you may need to increase the soft and hard limits. There are a few ways to do so.

If you are using [mysqld\_safe or mariadbd-safe](https://github.com/mariadb-corporation/mariadb-docs/blob/main/server/server-management/install-and-upgrade-mariadb/configuring-mariadb/starting-and-stopping-mariadb/mariadbd-safe.md) to start `mysqld`, then see the instructions at [mariadb-safe: Configuring the Core File Size](https://gitbook-v2-q3lwp8faq-gitbook.vercel.app/url/mariadb.com/docs/server/starting-and-stopping-mariadb/mariadbd-safe#configuring-the-core-file-size).

If you are using [systemd](https://github.com/mariadb-corporation/mariadb-docs/blob/main/server/server-management/install-and-upgrade-mariadb/configuring-mariadb/starting-and-stopping-mariadb/systemd.md) to start `mysqld`, then see the instructions at [systemd: Configuring the Core File Size](https://gitbook-v2-q3lwp8faq-gitbook.vercel.app/url/mariadb.com/docs/server/starting-and-stopping-mariadb/systemd#configuring-the-core-file-size).

Otherwise, you can set the soft and hard limits for the `mysql` user account by adding the following lines to [/etc/security/limits.conf](https://linux.die.net/man/5/limits.conf):

```bash
mysql soft core unlimited
mysql hard core unlimited
```

After the system is rebooted, the `mysql` user should use the new limits, and the user's `ulimit` output should look like the following:

```bash
$ ulimit -Sc
unlimited
$ ulimit -Hc
unlimited
```

## Swappiness

See [configuring swappiness](https://gitbook-v2-q3lwp8faq-gitbook.vercel.app/url/mariadb.com/docs/server/server-management/install-and-upgrade-mariadb/configuring-mariadb/mariadb-performance-advanced-configurations/configuring-swappiness).

<sub>*This page is licensed: CC BY-SA / Gnu FDL*</sub>

{% @marketo/form formId="4316" %}
