Skip to content

Fix file locking in EAL memory

Anatoly Burakov dpdk-dev 3 versions – Applied

Status from this message: Applied, thanks

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest2 patches 6 repliesApplied
  2. v22 patches 4 repliesSuperseded
  3. v12 patches 3 repliesSuperseded

Changes in v3 from the cover letter

- Made lockfile naming more consistent with hugetlbfs file naming

Patches in v3 Applied

#Subject and filesSizeRepliesApplied
1/2mem: add memalloc init stagelib/librte_eal/bsdapp/eal/eal_memalloc.c lib/librte_eal/common/eal_common_memory.c lib/librte_eal/common/eal_memalloc.h +1 more+52 -260 replies
2/2mem: revert to using flock() and add per-segment lockfileslib/librte_eal/common/eal_filesystem.h lib/librte_eal/linuxapp/eal/eal_hugepage_info.c lib/librte_eal/linuxapp/eal/eal_memalloc.c +1 more+368 -2385 replies

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchBruce RichardsonMaxime Coquelin
1/2A-b
2/2A-b T-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 0/2] Fix file locking in EAL memory

This patchset replaces the fcntl()-based locking used in the original DPDK memory hotplug patchset, to an flock()- and lockfile-based implementation, due to numerous (well, one, really) problems with how fcntl() locks work.

Long story short, fcntl() locks will be dropped if any fd referring to locked file, is closed - even if it's not the last fd, even if it wasn't even the fd that was used to lock the file in the first place, even if it wasn't you who closed that fd, but some other library.

This patchset corrects this saddening design defect in the original implementation.

One of the ways to work around this was using OFD locks, but they are only supported on kernels 3.15+, so we cannot rely on them if we want to support old kernels. Hence, we use per-segment lockfiles. The number of file descriptors we open does not end up more than in non-single file segments case - we still open the same amount of files (a file per page), plus a file per memseg list.

Additionally, since flock() is not atomic, we also lock the hugepage dir to prevent multiple processes from concurrently performing operations on hugetlbfs mounts.

If you know of a more enlightened way of fixing this limitation, you are certainly welcome to comment :)

v3:
- Made lockfile naming more consistent with hugetlbfs file naming

v2:
- Fixes as per review comments
- Make lockfiles hidden by default

Anatoly Burakov (2):
mem: add memalloc init stage
mem: revert to using flock() and add per-segment lockfiles

 lib/librte_eal/bsdapp/eal/eal_memalloc.c        |   6 +
 lib/librte_eal/common/eal_common_memory.c       |   3 +
 lib/librte_eal/common/eal_filesystem.h          |  17 +
 lib/librte_eal/common/eal_memalloc.h            |   3 +
 lib/librte_eal/linuxapp/eal/eal_hugepage_info.c |  28 +-
 lib/librte_eal/linuxapp/eal/eal_memalloc.c      | 605 +++++++++++++++---------
 lib/librte_eal/linuxapp/eal/eal_memory.c        |  22 +-
 7 files changed, 420 insertions(+), 264 deletions(-)
Signature · 1 line
2.7.4