Skip to content

Commit

Permalink
Drop -namespacesize option, related code, update related doc
Browse files Browse the repository at this point in the history
Maintaining multiple fixed-size namespaces does not add value,
so let's create a single namespace per namespace mode (fsdax, sector).
Modify DeviceMode diagrams of README to show less namespaces
  • Loading branch information
okartau committed Jun 3, 2019
1 parent 59a2771 commit c40aaa0
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 73 deletions.
1 change: 0 additions & 1 deletion DEVELOPMENT.md
Expand Up @@ -119,7 +119,6 @@ Specific arguments to pmem-ns-init

argument name | meaning | type | range
-------------------|--------------------------------------------------------|------|---
-namespacesize in | Namespace size in GB (default 32) | int | set to 2 if less than 2
-useforfsdax int | Percentage of total to use in Fsdax mode (default 100) | int | 0..100
-useforsector int | Percentage of total to use in Sector mode (default 0) | int | 0..100

Expand Down
6 changes: 2 additions & 4 deletions README.md
Expand Up @@ -76,10 +76,8 @@ initialization stages and a third API-serving stage.

During startup, the driver scans persistent memory for regions and
namespaces, and tries to create more namespaces using all or part
(selectable via option) of the remaining available space. The
namespace size can be specified as a driver parameter and defaults to
32 GB. This first stage is performed by a separate entity
_pmem-ns-init_.
(selectable via option) of the remaining available space. This first
stage is performed by a separate entity _pmem-ns-init_.

The second stage of initialization arranges physical volumes provided
by namespaces into LVM volume groups. This is performed by a separate
Expand Down
1 change: 0 additions & 1 deletion deploy/kubernetes-1.13/pmem-csi-lvm-testing.yaml
Expand Up @@ -350,7 +350,6 @@ spec:
initContainers:
- args:
- -v=3
- -namespacesize=9
- -v=5
- -coverprofile=/var/lib/pmem-csi-coverage/pmem-ns-init-*.out
command:
Expand Down
1 change: 0 additions & 1 deletion deploy/kubernetes-1.13/pmem-csi-lvm.yaml
Expand Up @@ -268,7 +268,6 @@ spec:
initContainers:
- args:
- -v=3
- -namespacesize=9
command:
- /go/bin/pmem-ns-init
env:
Expand Down
1 change: 0 additions & 1 deletion deploy/kubernetes-1.14/pmem-csi-lvm-testing.yaml
Expand Up @@ -370,7 +370,6 @@ spec:
initContainers:
- args:
- -v=3
- -namespacesize=9
- -v=5
- -coverprofile=/var/lib/pmem-csi-coverage/pmem-ns-init-*.out
command:
Expand Down
1 change: 0 additions & 1 deletion deploy/kubernetes-1.14/pmem-csi-lvm.yaml
Expand Up @@ -288,7 +288,6 @@ spec:
initContainers:
- args:
- -v=3
- -namespacesize=9
command:
- /go/bin/pmem-ns-init
env:
Expand Down
2 changes: 1 addition & 1 deletion deploy/kustomize/patches/lvm-patch.yaml
Expand Up @@ -11,7 +11,7 @@
imagePullPolicy: Always
image: PMEM_REGISTRY/pmem-csi-driver:canary
command: ["/go/bin/pmem-ns-init"]
args: [ "-v=3", "-namespacesize=9" ]
args: [ "-v=3" ]
env:
- name: TERMINATION_LOG_PATH
value: /tmp/pmem-ns-init-termination-log
Expand Down
Binary file modified docs/diagrams/pmem-csi.dia
Binary file not shown.
Binary file modified docs/images/devicemodes/pmem-csi-direct.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/devicemodes/pmem-csi-lvm.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 25 additions & 47 deletions pkg/pmem-ns-init/main.go
Expand Up @@ -15,10 +15,9 @@ var (
/* generic options */
//TODO: reading name configuration not yet supported
//configFile = flag.String("configfile", "/etc/pmem-csi/config", "PMEM CSI driver namespace configuration file")
namespacesize = flag.Int("namespacesize", 32, "Namespace size in GB")
useforfsdax = flag.Int("useforfsdax", 100, "Percentage of total to use in Fsdax mode")
useforsector = flag.Int("useforsector", 0, "Percentage of total to use in Sector mode")
showVersion = flag.Bool("version", false, "Show release version and exit")
useforfsdax = flag.Int("useforfsdax", 100, "Percentage of total to use in Fsdax mode")
useforsector = flag.Int("useforsector", 0, "Percentage of total to use in Sector mode")
showVersion = flag.Bool("version", false, "Show release version and exit")

version = "unknown"
)
Expand All @@ -36,7 +35,7 @@ func Main() int {

glog.V(3).Info("Version: ", version)

if err := CheckArgs(*namespacesize, *useforfsdax, *useforsector); err != nil {
if err := CheckArgs(*useforfsdax, *useforsector); err != nil {
pmemcommon.ExitError("invalid arguments", err)
return 1
}
Expand All @@ -46,11 +45,11 @@ func Main() int {
return 1
}

initNVdimms(ctx, *namespacesize, *useforfsdax, *useforsector)
initNVdimms(ctx, *useforfsdax, *useforsector)
return 0
}

func CheckArgs(namespacesize int, useforfsdax int, useforsector int) error {
func CheckArgs(useforfsdax int, useforsector int) error {
if useforfsdax < 0 || useforfsdax > 100 {
return fmt.Errorf("useforfsdax value must be 0..100")
}
Expand All @@ -60,25 +59,19 @@ func CheckArgs(namespacesize int, useforfsdax int, useforsector int) error {
if useforfsdax+useforsector > 100 {
return fmt.Errorf("useforfsdax and useforsector combined must not exceed 100")
}
if namespacesize < 2 {
return fmt.Errorf("namespacesize has to be at least 2 GB")
}
return nil
}

func initNVdimms(ctx *ndctl.Context, namespacesize int, useforfsdax int, useforsector int) {
glog.V(4).Infof("Configured namespacesize; %v GB", namespacesize)
// we get 1GB smaller than we ask so lets ask for 1GB more
nsSize := uint64(namespacesize+1) * 1024 * 1024 * 1024
func initNVdimms(ctx *ndctl.Context, useforfsdax int, useforsector int) {
for _, bus := range ctx.GetBuses() {
for _, r := range bus.ActiveRegions() {
createNS(r, nsSize, useforfsdax, ndctl.FsdaxMode)
createNS(r, nsSize, useforsector, ndctl.SectorMode)
createNS(r, useforfsdax, ndctl.FsdaxMode)
createNS(r, useforsector, ndctl.SectorMode)
}
}
}

func createNS(r *ndctl.Region, nsSize uint64, uselimit int, nsmode ndctl.NamespaceMode) {
func createNS(r *ndctl.Region, uselimit int, nsmode ndctl.NamespaceMode) {
// uselimit is the percentage we can use
canUse := uint64(uselimit) * r.Size() / 100
glog.V(3).Infof("Create %s-namespaces in %v, allowed %d %%:\ntotal : %16d\navail : %16d\ncan use : %16d",
Expand All @@ -90,43 +83,28 @@ func createNS(r *ndctl.Region, nsSize uint64, uselimit int, nsmode ndctl.Namespa
canUse -= ns.Size()
}
}
glog.V(4).Infof("%v bytes calculated available after scan for existing %s-mode namespaces", canUse, nsmode)
// cast to signed, otherwise can never be negative and risks forever-looping,
// broken only by break stmt below which happens after a failed creation attempt
for int64(canUse) > 0 {
if nsSize > canUse {
// this creates one last smaller namespace in leftover space
nsSize = canUse
glog.V(4).Infof("Less than configured namespacesize remaining, change desired size to %v", nsSize)
}
glog.V(4).Infof("Calculated canUse:%v, available by Region info:%v", canUse, r.AvailableSize())
// Because of overhead by alignement and extra space for page mapping, calculated available may show more than actual
if r.AvailableSize() < nsSize {
glog.V(4).Infof("Available in Region:%v is less than desired nsSize, limit nsSize to that", r.AvailableSize())
nsSize = r.AvailableSize()
}
// Should not happen easily, fragmented space could lead to r.MaxAvailableExtent() being less than r.AvailableSize()
if r.MaxAvailableExtent() < nsSize {
glog.V(4).Infof("MaxAvailableExtent in Region:%v is less than desired nsSize, limit nsSize to that", r.MaxAvailableExtent())
nsSize = r.MaxAvailableExtent()
}
// If NSize drops to less than 2GB, stop as creation would fail
if nsSize < 2*1024*1024*1024 {
glog.V(4).Infof("nsSize:%v is less then 2 GB, stop creating", nsSize)
break
}
glog.V(3).Infof("Create next %v-bytes %s-namespace", nsSize, nsmode)
glog.V(4).Infof("Calculated canUse:%v, available by Region info:%v", canUse, r.AvailableSize())
// Because of overhead by alignement and extra space for page mapping, calculated available may show more than actual
if r.AvailableSize() < canUse {
glog.V(4).Infof("Available in Region:%v is less than desired size, limit to that", r.AvailableSize())
canUse = r.AvailableSize()
}
// Should not happen often: fragmented space could lead to r.MaxAvailableExtent() being less than r.AvailableSize()
if r.MaxAvailableExtent() < canUse {
glog.V(4).Infof("MaxAvailableExtent in Region:%v is less than desired size, limit to that", r.MaxAvailableExtent())
canUse = r.MaxAvailableExtent()
}
// If less than 2GB usable, don't attempt as creation would fail
if canUse >= 2*1024*1024*1024 {
glog.V(3).Infof("Create %v-bytes %s-namespace", canUse, nsmode)
_, err := r.CreateNamespace(ndctl.CreateNamespaceOpts{
Name: "pmem-csi",
Mode: nsmode,
Size: nsSize,
Size: canUse,
Align: 1024 * 1024 * 1024,
})
if err != nil {
glog.Warning("Failed to create namespace:", err.Error())
/* ??? something went wrong, leave this region ??? */
break
}
canUse -= nsSize
}
}
29 changes: 13 additions & 16 deletions pkg/pmem-ns-init/main_test.go
Expand Up @@ -26,37 +26,34 @@ var _ = AfterSuite(func() {
var _ = Describe("pmem-ns-init", func() {
Context("Check arguments", func() {
type cases struct {
name string
namespacesize, useforfsdax, useforsector int
name string
useforfsdax, useforsector int
}
goodcases := []cases{
{"namespacesize ok", 32, 0, 0},
{"useforfsdax ok", 32, 50, 0},
{"useforsector ok", 32, 0, 50},
{"useforfsdax and useforsector combined 100", 32, 70, 30},
{"useforfsdax and useforsector combined less than 100", 32, 40, 30},
{"useforfsdax ok", 50, 0},
{"useforsector ok", 0, 50},
{"useforfsdax and useforsector combined 100", 70, 30},
{"useforfsdax and useforsector combined less than 100", 40, 30},
}
badcases := []cases{
{"namespacesize negative", -1, 0, 0},
{"namespacesize too small", 1, 0, 0},
{"useforfsdax negative", 32, -1, 0},
{"useforsector negative", 32, 0, -1},
{"useforfsdax too large", 32, 101, 0},
{"useforsector too large", 32, 0, 101},
{"useforfsdax and useforsector combined too large", 32, 51, 51},
{"useforfsdax negative", -1, 0},
{"useforsector negative", 0, -1},
{"useforfsdax too large", 101, 0},
{"useforsector too large", 0, 101},
{"useforfsdax and useforsector combined too large", 51, 51},
}

for _, c := range goodcases {
c := c
It(c.name, func() {
err := pmemnsinit.CheckArgs(c.namespacesize, c.useforfsdax, c.useforsector)
err := pmemnsinit.CheckArgs(c.useforfsdax, c.useforsector)
Expect(err).NotTo(HaveOccurred())
})
}
for _, c := range badcases {
c := c
It(c.name, func() {
err := pmemnsinit.CheckArgs(c.namespacesize, c.useforfsdax, c.useforsector)
err := pmemnsinit.CheckArgs(c.useforfsdax, c.useforsector)
Expect(err).To(HaveOccurred())
})
}
Expand Down

0 comments on commit c40aaa0

Please sign in to comment.