Skip to content

Lint Errors and spl_kmem_caches regression #236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion sdb/commands/spl/internal/kmem_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import drgn
import drgn.helpers.linux.list as drgn_list
import drgn.helpers.linux.percpu as drgn_percpu

import sdb
from sdb.commands.internal import p2
Expand Down Expand Up @@ -91,12 +92,25 @@ def object_size(cache: drgn.Object) -> int:
def nr_objects(cache: drgn.Object) -> int:
assert sdb.type_canonical_name(cache.type_) == 'struct spl_kmem_cache *'
if backed_by_linux_cache(cache):
return int(cache.skc_obj_alloc.value_())
return obj_alloc(cache)
return int(cache.skc_obj_total.value_())


def obj_alloc(cache: drgn.Object) -> int:
assert sdb.type_canonical_name(cache.type_) == 'struct spl_kmem_cache *'
if backed_by_linux_cache(cache):
try:
return int(drgn_percpu.percpu_counter_sum(cache.skc_linux_alloc))
except AttributeError:
#
# The percpu_counter referenced above wasn't in ZoL until the
# following commit: ec1fea4516ac2f0c08d31d6308929298d1b281d0
#
# Fall back to the old-mechanism of using skc_obj_alloc if that
# percpu_counter member doesn't exist (an AttributeError will
# be thrown).
#
pass
return int(cache.skc_obj_alloc.value_())
Copy link
Contributor

Choose a reason for hiding this comment

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

This line is equivalent to what we run in the except AttributeError case, so rather than duplicating the two, would it be better to use:

except AttributeError:
    pass

and let the code reach this line in that case?

Or perhaps we should more simply remove this line, since I think it's dead code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually thanks for pointing this out... this pointed out a bug in my code. We don't want to look at the percpu counter if this is not a linux_slub backed cache. I changed the code and retesting now.



Expand Down
1 change: 1 addition & 0 deletions tests/integration/test_core_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

# pylint: disable=missing-module-docstring
# pylint: disable=missing-function-docstring
# pylint: disable=not-callable

from typing import Any

Expand Down
1 change: 1 addition & 0 deletions tests/integration/test_linux_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# pylint: disable=missing-module-docstring
# pylint: disable=missing-function-docstring
# pylint: disable=line-too-long
# pylint: disable=not-callable

from typing import Any

Expand Down
1 change: 1 addition & 0 deletions tests/integration/test_spl_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# pylint: disable=missing-module-docstring
# pylint: disable=missing-function-docstring
# pylint: disable=line-too-long
# pylint: disable=not-callable

from typing import Any

Expand Down
1 change: 1 addition & 0 deletions tests/integration/test_zfs_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# pylint: disable=missing-module-docstring
# pylint: disable=missing-function-docstring
# pylint: disable=line-too-long
# pylint: disable=not-callable

from typing import Any

Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#

# pylint: disable=missing-docstring
# pylint: disable=not-callable

from typing import List, Tuple

Expand Down