Skip to content

blk/kernel: use open file description lock if available - #37153

Merged
tchaikov merged 4 commits into
ceph:masterfrom
tchaikov:wip-46124
Sep 27, 2020
Merged

tchaikov merged 4 commits into
ceph:masterfrom
tchaikov:wip-46124

Conversation

@tchaikov

Copy link
Copy Markdown
Contributor

Checklist

  • References tracker ticket
  • Updates documentation if necessary
  • Includes tests for new functionality or reproducer for bug

Show available Jenkins commands
  • jenkins retest this please
  • jenkins test classic perf
  • jenkins test crimson perf
  • jenkins test signed
  • jenkins test make check
  • jenkins test make check arm64
  • jenkins test submodules
  • jenkins test dashboard
  • jenkins test api
  • jenkins test docs
  • jenkins render docs
  • jenkins test ceph-volume all
  • jenkins test ceph-volume tox

@tchaikov

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@nh2 nh2 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good and addresses all my concerns from #34566 (comment), but https://github.com/X0Ken/ceph/blob/23f8c323d2ba9133c3ef5834ae93115425c862d1/src/common/options.cc#L3998 now needs to mention that negative means unlimited, e.g.

    .set_long_description(
        "The number of times to retry on getting the block device lock. "
        "Programs such as systemd-udevd may compete with Ceph for this lock. "
        "A negative number means 'unlimited'."),

Independent question: Is 3 still the best default, should it be longer, or should it loop forever without configurable max retry value (perhaps logging a warning instead)? It seems sensible to me in a situation like this where we know that the lock will eventually make progress.

@tchaikov

Copy link
Copy Markdown
Contributor Author

This looks good and addresses all my concerns from #34566 (comment), but https://github.com/X0Ken/ceph/blob/23f8c323d2ba9133c3ef5834ae93115425c862d1/src/common/options.cc#L3998 now needs to mention that negative means unlimited, e.g.

    .set_long_description(
        "The number of times to retry on getting the block device lock. "
        "Programs such as systemd-udevd may compete with Ceph for this lock. "
        "A negative number means 'unlimited'."),

thank you. i split the wait-forever change into a separate commit, as it's not related to the OFD lock change. and incorporated your suggestion into that commit.

Independent question: Is 3 still the best default, should it be longer, or should it loop forever without configurable max retry value (perhaps logging a warning instead)? It seems sensible to me in a situation like this where we know that the lock will eventually make progress.

i cannot tell what is the best default. but by inspecting https://github.com/systemd/systemd/blob/ee0b9e721a368742ac6fa9c3d9a33e45dc3203a2/src/shared/lockfile-util.c#L45-L72 . i think 0.3 second should be enough for make_lock_file() to get its job done, unless the system is very busy.

and after a second thought, i don't think to loop forever is a good default. a small number for the max retry times is like

assert(systemd_should_finish_its_job_in_a_short_time)

where short time is, well, a magic number. if, systemd cannot finish in 0.3 second, we should be aware of this right away. as it very likely indicates a serious issue in system. a warning in log is not enough for this signal, IMHO.

@tchaikov
tchaikov requested a review from ifed01 September 16, 2020 01:45

@ifed01 ifed01 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just one nit - may be more straightforward processing when bdev_flock_retry is set to 0. Currently this means MAX_INT retries which isn't obvious for users...

@tchaikov

Copy link
Copy Markdown
Contributor Author

@ifed01 i don't follow you. do you mean we should retry forever if bdev_flock_retry is 0? that is exactly the behavior after this change. probably i should update the long_description accordingly.

@ifed01

ifed01 commented Sep 18, 2020

Copy link
Copy Markdown
Contributor

@ifed01 i don't follow you. do you mean we should retry forever if bdev_flock_retry is 0? that is exactly the behavior after this change. probably i should update the long_description accordingly.

Given prefix form for (++nr_tries) and initial setting nr_tries=0 it looks like the current behavior when bdev_flock_retry == 0 is to to repeat MAX_UINT times and stop. This is neither a "forever" loop nor "meaningful" behavior for such a setting.
IMO it's a bit confusing, it's better either use 0 as a major "forever" indicator (not negative value) or treat bdev_flock_retry explicitly as a RETRY counter assuming that one attempt is always performed. I.e. retry = 0 -> 1 attempt, retry = 1 -> 2 attempts, etc...

@tchaikov

Copy link
Copy Markdown
Contributor Author
max_retry > 0 && ++nr_tries == max_retry

if the setting (max_retry) is 0, this expression always evaluates to false, and the loop never ends unless r is 0.

but yeah, the setting is not retry anymore, it is actually nr_tries. will fix it.

instead of relying on utime_t, use standard library directly.

Signed-off-by: Kefu Chai <[email protected]>
also drop bdev_flock_retry and bdev_flock_retry_interval from
legacy_config_opts.h, as `KernelDevice::_lock()` is not in the critical
path, there is no need to access these settings via member variables --
get_val<> would just suffice.

Signed-off-by: Kefu Chai <[email protected]>
* use OFD lock if available. OFD is Linux specific, and only available
  on 3.15 kernels. OFD is able to synchronize both threads and
  processes. and has simpler semantics. this is just a cleanup.
  as we don't create threads for acquiring the flock.
* use BSD flock(2) as a fallback
* return the errno right away, without printing logging messages.
  for two reasons:
  - writing logging messages would reset the errno.
  - the caller of _lock() also prints the logging messages along
    with strerror(errno)

Fixes: https://tracker.ceph.com/issues/46124
Signed-off-by: Kefu Chai <[email protected]>
@tchaikov

Copy link
Copy Markdown
Contributor Author

@ifed01 fixed and repushed.

retry forever if cct->_conf->bdev_flock_retry is 0.
systemd-udevd is most likely the reason why ceph-osd fails to
acquire the flock when "mkfs", because systemd-udevd probes
all block devices when the device changes in the system using
libblkid, and when systemd-udevd starts looking at the device
it takes a `LOCK_SH|LOCK_NB` lock. and it releases the lock
right after done with it. so normally, it only takes a jiffy,
see
https://github.com/systemd/systemd/blob/ee0b9e721a368742ac6fa9c3d9a33e45dc3203a2/src/shared/lockfile-util.c#L18
so, we just need to retry couple times before acquiring the
lock.

Fixes: https://tracker.ceph.com/issues/46124
Signed-off-by: Kefu Chai <[email protected]>
@tchaikov
tchaikov merged commit bd7b671 into ceph:master Sep 27, 2020
@tchaikov
tchaikov deleted the wip-46124 branch September 27, 2020 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants