Skip to contentSkip to conversation

rbd kernel block driver memory usage

DISCUSSION Stefan Hajnoczi 4 participants 8 messages Jan 25, 2023 – Jan 27, 2023

lore
Share & tools
lore
#0 lore raw

Hi,
What sort of memory usage is expected under heavy I/O to an rbd block device with O_DIRECT?

For example:
- Page cache: none (O_DIRECT)
- Socket snd/rcv buffers: yes
- Internal rbd buffers?

I am trying to understand how similar Linux rbd block devices behave compared to local block device memory consumption (like NVMe PCI).

Thanks,
Stefan

#1 lore raw
Quoted 8 lines · Stefan Hajnoczi

Hi,
What sort of memory usage is expected under heavy I/O to an rbd block device with O_DIRECT?

For example:
- Page cache: none (O_DIRECT)
- Socket snd/rcv buffers: yes

Hi Stefan,

There is a socket open to each OSD (object storage daemon). A Ceph cluster may have tens, hundreds or even thousands of OSDs (although the latter is rare -- usually folks end up with several smaller clusters instead a single large cluster). Under heavy random I/O and given a big enough RBD image, it's reasonable to assume that most if not all OSDs would be involved and therefore their sessions would be active.

A thing to note is that, by default, OSD sessions are shared between RBD devices. So as long as all RBD images that are mapped on a node belong to the same cluster, the same set of sockets would be used.

Idle OSD sockets get closed after 60 seconds of inactivity.

Quoted 4 lines

- Internal rbd buffers?

I am trying to understand how similar Linux rbd block devices behave compared to local block device memory consumption (like NVMe PCI).

RBD doesn't do any internal buffering. Data is read from/written to the wire directly to/from BIO pages. The only exception to that is the "secure" mode -- built-in encryption for Ceph on-the-wire protocol. In that case the data is buffered, partly because RBD obviously can't mess with plaintext data in the BIO and partly because the Linux kernel crypto API isn't flexible enough.

There is some memory overhead associated with each I/O (OSD request metadata encoding, mostly). It's surely larger than in the NVMe PCI case. I don't have the exact number but it should be less than 4K per I/O in almost all cases. This memory is coming out of private SLAB caches and could be reclaimable had we set SLAB_RECLAIM_ACCOUNT on them.

Thanks,

Ilya

#2 lore raw
Quoted 38 lines · Ilya Dryomov
Quoted 8 lines · Stefan Hajnoczi

Hi,
What sort of memory usage is expected under heavy I/O to an rbd block device with O_DIRECT?

For example:
- Page cache: none (O_DIRECT)
- Socket snd/rcv buffers: yes

Hi Stefan,

There is a socket open to each OSD (object storage daemon). A Ceph cluster may have tens, hundreds or even thousands of OSDs (although the latter is rare -- usually folks end up with several smaller clusters instead a single large cluster). Under heavy random I/O and given a big enough RBD image, it's reasonable to assume that most if not all OSDs would be involved and therefore their sessions would be active.

A thing to note is that, by default, OSD sessions are shared between RBD devices. So as long as all RBD images that are mapped on a node belong to the same cluster, the same set of sockets would be used.

Idle OSD sockets get closed after 60 seconds of inactivity.

Quoted 4 lines

- Internal rbd buffers?

I am trying to understand how similar Linux rbd block devices behave compared to local block device memory consumption (like NVMe PCI).

RBD doesn't do any internal buffering. Data is read from/written to the wire directly to/from BIO pages. The only exception to that is the "secure" mode -- built-in encryption for Ceph on-the-wire protocol. In that case the data is buffered, partly because RBD obviously can't mess with plaintext data in the BIO and partly because the Linux kernel crypto API isn't flexible enough.

Quoted 6 lines

There is some memory overhead associated with each I/O (OSD request metadata encoding, mostly). It's surely larger than in the NVMe PCI case. I don't have the exact number but it should be less than 4K per I/O in almost all cases. This memory is coming out of private SLAB caches and could be reclaimable had we set SLAB_RECLAIM_ACCOUNT on them.

Thanks, this information is very useful. I was trying to get a sense of whether to look deeper into the rbd driver in a OOM kill scenario.

Stefan

#3 lore raw
Quoted 2 lines
Quoted 2 lines

There is a socket open to each OSD (object storage daemon).

I’ve always understood that there were *two* to each OSD, was I misinformed?

Quoted 3 lines
Quoted 3 lines

A Ceph cluster may have tens, hundreds or even thousands of OSDs (although the
latter is rare -- usually folks end up with several smaller clusters instead a single large cluster).

… though if a client has multiple RBD volumes attached, it may be talking to more than one cluster. I’ve seen a client exhaust the file descriptor limit on a hypervisor doing this after a cluster expansion.

Quoted 3 lines
Quoted 3 lines

A thing to note is that, by default, OSD sessions are shared between RBD devices. So as long as all RBD images that are mapped on a node belong to the same cluster, the same set of sockets would be used.

Before … Luminous was it? AIUI they weren’t pooled, so older releases may have higher consumption.

Quoted 1 line
#5 lore raw
In reply to Stefan Hajnoczi

in case of object map which the driver loads, takes 2 bits per 4 MB of image size. 16 TB image requires 1 MB of memory.

Quoted 1 line
Quoted 1 line

I was trying to get a sense ofwhether to look deeper into the rbd driver in a OOM kill scenario.

If you are looking into OOM, maybe look into lowering queue_depth which you can specify when you map the image. Technically it belongs to the block layer queue rather than the rbd driver itself, If you write 4MB block size and your queue_depth is 1000, you need 4GB memory for inflight data for that single image, if you have many images it could add up.

/maged

Quoted 46 lines · Stefan Hajnoczi
Quoted 35 lines · Ilya Dryomov
Quoted 7 lines · Stefan Hajnoczi

Hi,
What sort of memory usage is expected under heavy I/O to an rbd block device with O_DIRECT?

For example:
- Page cache: none (O_DIRECT)
- Socket snd/rcv buffers: yes

Hi Stefan,

There is a socket open to each OSD (object storage daemon). A Ceph cluster may have tens, hundreds or even thousands of OSDs (although the latter is rare -- usually folks end up with several smaller clusters instead a single large cluster). Under heavy random I/O and given a big enough RBD image, it's reasonable to assume that most if not all OSDs would be involved and therefore their sessions would be active.

A thing to note is that, by default, OSD sessions are shared between RBD devices. So as long as all RBD images that are mapped on a node belong to the same cluster, the same set of sockets would be used.

Idle OSD sockets get closed after 60 seconds of inactivity.

Quoted 4 lines

- Internal rbd buffers?

I am trying to understand how similar Linux rbd block devices behave compared to local block device memory consumption (like NVMe PCI).

RBD doesn't do any internal buffering. Data is read from/written to the wire directly to/from BIO pages. The only exception to that is the "secure" mode -- built-in encryption for Ceph on-the-wire protocol. In that case the data is buffered, partly because RBD obviously can't mess with plaintext data in the BIO and partly because the Linux kernel crypto API isn't flexible enough.

Quoted 6 lines

There is some memory overhead associated with each I/O (OSD request metadata encoding, mostly). It's surely larger than in the NVMe PCI case. I don't have the exact number but it should be less than 4K per I/O in almost all cases. This memory is coming out of private SLAB caches and could be reclaimable had we set SLAB_RECLAIM_ACCOUNT on them.

Thanks, this information is very useful. I was trying to get a sense of whether to look deeper into the rbd driver in a OOM kill scenario.

Stefan

#6 lore raw
Quoted 6 lines · Maged Mokhtar

in case of object map which the driver loads, takes 2 bits per 4 MB of image size. 16 TB image requires 1 MB of memory.

Quoted 1 line
Quoted 1 line

I was trying to get a sense ofwhether to look deeper into the rbd driver in a OOM kill scenario.

If you are looking into OOM, maybe look into lowering queue_depth which you can specify when you map the image. Technically it belongs to the block layer queue rather than the rbd driver itself, If you write 4MB block size and your queue_depth is 1000, you need 4GB memory for inflight data for that single image, if you have many images it could add up.

Thanks!

Stefan

#7 lore raw

another thing that can help OOM cases, avoid using rbd client on same host as OSDs. This was a general recommendation aseptically with earlier kernels (3.x).

Quoted 9 lines · Stefan Hajnoczi
Quoted 5 lines · Maged Mokhtar

in case of object map which the driver loads, takes 2 bits per 4 MB of image size. 16 TB image requires 1 MB of memory.

Quoted 1 line
Quoted 1 line

I was trying to get a sense ofwhether to look deeper into the rbd driver in a OOM kill scenario.

If you are looking into OOM, maybe look into lowering queue_depth which you can specify when you map the image. Technically it belongs to the block layer queue rather than the rbd driver itself, If you write 4MB block size and your queue_depth is 1000, you need 4GB memory for inflight data for that single image, if you have many images it could add up.

Thanks!

Stefan

#4 lore raw
In reply to Anthony D'Atri
Quoted 5 lines · Anthony D'Atri
Quoted 3 lines
Quoted 3 lines

There is a socket open to each OSD (object storage daemon).

I’ve always understood that there were *two* to each OSD, was I misinformed?

Hi Anthony,

It looks like you were misinformed -- there is just one client -> OSD socket.

Quoted 5 lines
Quoted 4 lines
Quoted 4 lines

A Ceph cluster may have tens, hundreds or even thousands of OSDs (although the
latter is rare -- usually folks end up with several smaller clusters instead a single large cluster).

Quoted 7 lines

… though if a client has multiple RBD volumes attached, it may be talking to more than one cluster. I’ve seen a client exhaust the file descriptor limit on a hypervisor doing this after a cluster expansion.

Quoted 3 lines
Quoted 3 lines

A thing to note is that, by default, OSD sessions are shared between RBD devices. So as long as all RBD images that are mapped on a node belong to the same cluster, the same set of sockets would be used.

Before … Luminous was it? AIUI they weren’t pooled, so older releases may have higher consumption.

No, this behavior goes back to when RBD was introduced in 2010. It has always been enabled by default so nothing changed in this regard around Luminous.

Thanks,

Ilya