Skip to content

pkg/system: move memory-info types to pkg/systeminfo, and minor refactor#44663

Merged
thaJeztah merged 4 commits intomoby:masterfrom
thaJeztah:move_meminfo
Dec 27, 2022
Merged

pkg/system: move memory-info types to pkg/systeminfo, and minor refactor#44663
thaJeztah merged 4 commits intomoby:masterfrom
thaJeztah:move_meminfo

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

pkg/sysinfo: unify NumCPU implementation

Use a single exported implementation, so that we can maintain the
GoDoc string in one place, and use non-exported functions for the
actual implementation (which were already in place).

pkg/system: move memory-info types to pkg/systeminfo

These types and functions are more closely related to the functionality
provided by pkg/systeminfo, and used in conjunction with the other functions
in that package, so moving them there.

pkg/sysinfo: remove github.com/docker/go-units dependency

It was only used in a test, and only for a single const; define
it locally.

pkg/sysinfo: unify ReadMemInfo implementation

Use a single exported implementation, so that we can maintain the
GoDoc string in one place, and use non-exported functions for the
actual implementation.

@thaJeztah thaJeztah added status/2-code-review kind/refactor PR's that refactor, or clean-up code labels Dec 16, 2022
@thaJeztah thaJeztah added this to the v-next milestone Dec 16, 2022
@thaJeztah
Copy link
Copy Markdown
Member Author

Failure in Jenkins; looks like the latest test-changes did not yet fix all things 😂

=== FAIL: libnetwork/ipam TestRequestReleaseAddressDuplicate (0.00s)
[2022-12-16T14:44:56.761Z]     allocator_test.go:1593: IP 198.168.0.75/23 was previously allocated

Use a single exported implementation, so that we can maintain the
GoDoc string in one place, and use non-exported functions for the
actual implementation (which were already in place).

Signed-off-by: Sebastiaan van Stijn <[email protected]>
These types and functions are more closely related to the functionality
provided by pkg/systeminfo, and used in conjunction with the other functions
in that package, so moving them there.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
It was only used in a test, and only for a single const; define
it locally.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Use a single exported implementation, so that we can maintain the
GoDoc string in one place, and use non-exported functions for the
actual implementation.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Copy link
Copy Markdown
Contributor

@corhere corhere left a comment

Choose a reason for hiding this comment

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

I spy another minor refactor opportunity: replace the popcnt function in pkg/sysinfo/numcpu_windows.go with https://pkg.go.dev/math/bits#OnesCount64

Comment thread pkg/sysinfo/meminfo.go
@@ -0,0 +1,24 @@
package sysinfo
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.

Suggested change
package sysinfo
package sysinfo // import "github.com/docker/docker/pkg/sysinfo"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah, probably should've mentioned that; so these import comments act at the package level; so technically, only a single file in the package needs to have it to enforce the import.

As we're planning to move to go modules (and thus rename the module), I'm preemptively removing these comments in files I move to other packages (if there's already at least one of those comments in the package) to reduce further code-churn a bit.

Overall the import comments are starting to lose value, as in many cases (if go mod is involved in any way), they're completely ignored.

@thaJeztah
Copy link
Copy Markdown
Member Author

I spy another minor refactor opportunity: replace the popcnt function in pkg/sysinfo/numcpu_windows.go with https://pkg.go.dev/math/bits#OnesCount64

Ah, nice find; yes, can look at that.

@thaJeztah
Copy link
Copy Markdown
Member Author

Thx! Let me bring this one in 👍

@thaJeztah thaJeztah merged commit c4ed09a into moby:master Dec 27, 2022
@thaJeztah thaJeztah deleted the move_meminfo branch December 27, 2022 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/refactor PR's that refactor, or clean-up code status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants