sstate: Add extra directory level
PATCH 1/4 sstate: Add extra directory level
We're having speed issues on the autobuilder due to the numbers of files in sstate directories. We previously split these by the first two characters of the hash. This change extends this to split by the next two characters as well, creating more layers of directories.
This should signifiantly speed up eSDK builds on the autobuilder as the current sstate layout simply isn't scaling there but addresses a general complaint.
gen-lockedsig-cache needed to be updated for the new split level sstate.
Also update tests for new layout.
--- meta/classes/sstate.bbclass | 4 ++-- meta/lib/oeqa/selftest/cases/signing.py | 4 ++-- meta/lib/oeqa/selftest/cases/sstate.py | 4 ++-- scripts/gen-lockedsig-cache | 13 ++++++++++--- 4 files changed, 16 insertions(+), 9 deletions(-)
meta/classes/sstate.bbclass +2 -2
@@ -6,7 +6,7 @@ SSTATE_MANFILEPREFIX = "${SSTATE_MANIFESTS}/manifest-${SSTATE_MANMACH}-${PN}" def generate_sstatefn(spec, hash, d): if not hash: hash = "INVALID" - return hash[:2] + "/" + spec + hash + return hash[:2] + "/" + hash[2:4] + "/" + spec + hash SSTATE_PKGARCH = "${PACKAGE_ARCH}" SSTATE_PKGSPEC = "sstate:${PN}:${PACKAGE_ARCH}${TARGET_VENDOR}-${TARGET_OS}:${PV}:${PR}:${SSTATE_PKGARCH}:${SSTATE_VERSION}:"
@@ -15,7 +15,7 @@ SSTATE_PKGNAME = "${SSTATE_EXTRAPATH}${@generate_sstatefn(d.getVar('SSTATE_PK SSTATE_PKG = "${SSTATE_DIR}/${SSTATE_PKGNAME}" SSTATE_EXTRAPATH = "" SSTATE_EXTRAPATHWILDCARD = "" -SSTATE_PATHSPEC = "${SSTATE_DIR}/${SSTATE_EXTRAPATHWILDCARD}*/${SSTATE_PKGSPEC}" +SSTATE_PATHSPEC = "${SSTATE_DIR}/${SSTATE_EXTRAPATHWILDCARD}*/*/${SSTATE_PKGSPEC}" # explicitly make PV to depend on evaluated value of PV variable PV[vardepvalue] = "${PV}"
meta/lib/oeqa/selftest/cases/signing.py +2 -2
@@ -157,8 +157,8 @@ class Signing(OESelftestTestCase): bitbake('-c clean %s' % test_recipe) bitbake('-c populate_lic %s' % test_recipe) - recipe_sig = glob.glob(sstatedir + '/*/*:ed:*_populate_lic.tgz.sig') - recipe_tgz = glob.glob(sstatedir + '/*/*:ed:*_populate_lic.tgz') + recipe_sig = glob.glob(sstatedir + '/*/*/*:ed:*_populate_lic.tgz.sig') + recipe_tgz = glob.glob(sstatedir + '/*/*/*:ed:*_populate_lic.tgz') self.assertEqual(len(recipe_sig), 1, 'Failed to find .sig file.') self.assertEqual(len(recipe_tgz), 1, 'Failed to find .tgz file.')
meta/lib/oeqa/selftest/cases/sstate.py +2 -2
@@ -56,11 +56,11 @@ class SStateBase(OESelftestTestCase): def search_sstate(self, filename_regex, distro_specific=True, distro_nonspecific=True): result = [] for root, dirs, files in os.walk(self.sstate_path): - if distro_specific and re.search("%s/[a-z0-9]{2}$" % self.hostdistro, root): + if distro_specific and re.search(r"%s/%s/[a-z0-9]{2}/[a-z0-9]{2}$" % (self.sstate_path, self.hostdistro), root): for f in files: if re.search(filename_regex, f): result.append(f) - if distro_nonspecific and re.search("%s/[a-z0-9]{2}$" % self.sstate_path, root): + if distro_nonspecific and re.search(r"%s/[a-z0-9]{2}/[a-z0-9]{2}$" % self.sstate_path, root): for f in files: if re.search(filename_regex, f): result.append(f)
scripts/gen-lockedsig-cache +10 -3
@@ -78,11 +78,18 @@ files = set() sstate_content_cache = {} for s in sigs: prefix = s[:2] + prefix2 = s[2:4] if prefix not in sstate_content_cache: sstate_content_cache[prefix] = build_sha_cache(prefix) - - for f in sstate_content_cache[prefix][s]: - files.add(f) + if prefix2 not in sstate_content_cache[prefix]: + sstate_content_cache[prefix][prefix2] = build_sha_cache(prefix + "/" + prefix2) + + if s in sstate_content_cache[prefix]: + for f in sstate_content_cache[prefix][s]: + files.add(f) + if s in sstate_content_cache[prefix][prefix2]: + for f in sstate_content_cache[prefix][prefix2][s]: + files.add(f) elapsed = time.perf_counter() - start_time print("Gathering file list took %.1fs" % elapsed)
Signature · 1 line
2.20.1
PATCH 2/4 sstate: Improve SSTATE_PKG handling
Move the task handling code into the SSTATE_PKGNAME variable using a temporary variable.
This makes the code more understandable as as well as allowing the length of the final sstate filename to be more easily accesses for following patches.
--- meta/classes/sstate.bbclass | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
meta/classes/sstate.bbclass +11 -10
@@ -11,11 +11,11 @@ def generate_sstatefn(spec, hash, d): SSTATE_PKGARCH = "${PACKAGE_ARCH}" SSTATE_PKGSPEC = "sstate:${PN}:${PACKAGE_ARCH}${TARGET_VENDOR}-${TARGET_OS}:${PV}:${PR}:${SSTATE_PKGARCH}:${SSTATE_VERSION}:" SSTATE_SWSPEC = "sstate:${PN}::${PV}:${PR}::${SSTATE_VERSION}:" -SSTATE_PKGNAME = "${SSTATE_EXTRAPATH}${@generate_sstatefn(d.getVar('SSTATE_PKGSPEC'), d.getVar('BB_UNIHASH'), d)}" +SSTATE_PKGNAME = "${SSTATE_EXTRAPATH}${@generate_sstatefn(d.getVar('SSTATE_PKGSPEC'), d.getVar('BB_UNIHASH'), d)}_${SSTATE_CURRTASK}.tgz" SSTATE_PKG = "${SSTATE_DIR}/${SSTATE_PKGNAME}" SSTATE_EXTRAPATH = "" SSTATE_EXTRAPATHWILDCARD = "" -SSTATE_PATHSPEC = "${SSTATE_DIR}/${SSTATE_EXTRAPATHWILDCARD}*/*/${SSTATE_PKGSPEC}" +SSTATE_PATHSPEC = "${SSTATE_DIR}/${SSTATE_EXTRAPATHWILDCARD}*/*/${SSTATE_PKGSPEC}*_${SSTATE_PATH_CURRTASK}.tgz*" # explicitly make PV to depend on evaluated value of PV variable PV[vardepvalue] = "${PV}"
@@ -317,8 +317,8 @@ def sstate_installpkg(ss, d): from oe.gpg_sign import get_signer sstateinst = d.expand("${WORKDIR}/sstate-install-%s/" % ss['task']) - sstatefetch = d.getVar('SSTATE_PKGNAME') + '_' + ss['task'] + ".tgz" - d.appendVar('SSTATE_PKG', '_'+ ss['task'] + ".tgz") + d.setVar("SSTATE_CURRTASK", ss['task']) + sstatefetch = d.getVar('SSTATE_PKGNAME') sstatepkg = d.getVar('SSTATE_PKG') if not os.path.exists(sstatepkg):
@@ -440,8 +440,9 @@ python sstate_hardcode_path_unpack () { def sstate_clean_cachefile(ss, d): import oe.path - sstatepkgfile = d.getVar('SSTATE_PATHSPEC') + "*_" + ss['task'] + ".tgz*" if d.getVarFlag('do_%s' % ss['task'], 'task'): + d.setVar("SSTATE_PATH_CURRTASK", ss['task']) + sstatepkgfile = d.getVar('SSTATE_PATHSPEC') bb.note("Removing %s" % sstatepkgfile) oe.path.remove(sstatepkgfile)
@@ -612,7 +613,7 @@ def sstate_package(ss, d): tmpdir = d.getVar('TMPDIR') sstatebuild = d.expand("${WORKDIR}/sstate-build-%s/" % ss['task']) - d.appendVar('SSTATE_PKG', '_'+ ss['task'] + ".tgz") + d.setVar("SSTATE_CURRTASK", ss['task']) bb.utils.remove(sstatebuild, recurse=True) bb.utils.mkdirhier(sstatebuild) for state in ss['dirs']:
@@ -1081,17 +1082,17 @@ addhandler sstate_eventhandler sstate_eventhandler[eventmask] = "bb.build.TaskSucceeded" python sstate_eventhandler() { d = e.data - # When we write an sstate package we rewrite the SSTATE_PKG - spkg = d.getVar('SSTATE_PKG') - if not spkg.endswith(".tgz"): + writtensstate = d.getVar('SSTATE_CURRTASK') + if not writtensstate: taskname = d.getVar("BB_RUNTASK")[3:] spec = d.getVar('SSTATE_PKGSPEC') swspec = d.getVar('SSTATE_SWSPEC') if taskname in ["fetch", "unpack", "patch", "populate_lic", "preconfigure"] and swspec: d.setVar("SSTATE_PKGSPEC", "${SSTATE_SWSPEC}") d.setVar("SSTATE_EXTRAPATH", "") + d.setVar("SSTATE_CURRTASK", taskname) sstatepkg = d.getVar('SSTATE_PKG') - bb.siggen.dump_this_task(sstatepkg + '_' + taskname + ".tgz" ".siginfo", d) + bb.siggen.dump_this_task(sstatepkg + ".siginfo", d) } SSTATE_PRUNE_OBSOLETEWORKDIR ?= "1"
Signature · 1 line
2.20.1
PATCH 3/4 sstate: Merge file name generation into single function
In reply to Richard PurdieMove the task handling and extension handling into one common filename construction function.
--- meta/classes/sstate.bbclass | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
meta/classes/sstate.bbclass +12 -10
@@ -3,15 +3,20 @@ SSTATE_VERSION = "3" SSTATE_MANIFESTS ?= "${TMPDIR}/sstate-control" SSTATE_MANFILEPREFIX = "${SSTATE_MANIFESTS}/manifest-${SSTATE_MANMACH}-${PN}" -def generate_sstatefn(spec, hash, d): +def generate_sstatefn(spec, hash, taskname, siginfo, d): + if taskname is None: + return "" + extension = ".tgz" + if siginfo: + extension = ".tgz.siginfo" if not hash: hash = "INVALID" - return hash[:2] + "/" + hash[2:4] + "/" + spec + hash + return hash[:2] + "/" + hash[2:4] + "/" + spec + hash + "_" + taskname + extension SSTATE_PKGARCH = "${PACKAGE_ARCH}" SSTATE_PKGSPEC = "sstate:${PN}:${PACKAGE_ARCH}${TARGET_VENDOR}-${TARGET_OS}:${PV}:${PR}:${SSTATE_PKGARCH}:${SSTATE_VERSION}:" SSTATE_SWSPEC = "sstate:${PN}::${PV}:${PR}::${SSTATE_VERSION}:" -SSTATE_PKGNAME = "${SSTATE_EXTRAPATH}${@generate_sstatefn(d.getVar('SSTATE_PKGSPEC'), d.getVar('BB_UNIHASH'), d)}_${SSTATE_CURRTASK}.tgz" +SSTATE_PKGNAME = "${SSTATE_EXTRAPATH}${@generate_sstatefn(d.getVar('SSTATE_PKGSPEC'), d.getVar('BB_UNIHASH'), d.getVar('SSTATE_CURRTASK'), False, d)}" SSTATE_PKG = "${SSTATE_DIR}/${SSTATE_PKGNAME}" SSTATE_EXTRAPATH = "" SSTATE_EXTRAPATHWILDCARD = ""
@@ -822,9 +827,6 @@ BB_HASHCHECK_FUNCTION = "sstate_checkhashes" def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True, **kwargs): found = set() missed = set() - extension = ".tgz" - if siginfo: - extension = extension + ".siginfo" def gethash(task): return sq_data['unihash'][task]
@@ -851,7 +853,7 @@ def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True, spec, extrapath, tname = getpathcomponents(tid, d) - sstatefile = d.expand("${SSTATE_DIR}/" + extrapath + generate_sstatefn(spec, gethash(tid), d) + "_" + tname + extension) + sstatefile = d.expand("${SSTATE_DIR}/" + extrapath + generate_sstatefn(spec, gethash(tid), tname, siginfo, d)) if os.path.exists(sstatefile): bb.debug(2, "SState: Found valid sstate file %s" % sstatefile)
@@ -914,7 +916,7 @@ def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True, if tid in found: continue spec, extrapath, tname = getpathcomponents(tid, d) - sstatefile = d.expand(extrapath + generate_sstatefn(spec, gethash(tid), d) + "_" + tname + extension) + sstatefile = d.expand(extrapath + generate_sstatefn(spec, gethash(tid), tname, siginfo, d)) tasklist.append((tid, sstatefile)) if tasklist:
@@ -944,11 +946,11 @@ def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True, evdata = {'missed': [], 'found': []}; for tid in missed: spec, extrapath, tname = getpathcomponents(tid, d) - sstatefile = d.expand(extrapath + generate_sstatefn(spec, gethash(tid), d) + "_" + tname + ".tgz") + sstatefile = d.expand(extrapath + generate_sstatefn(spec, gethash(tid), tname, False, d)) evdata['missed'].append((bb.runqueue.fn_from_tid(tid), bb.runqueue.taskname_from_tid(tid), gethash(tid), sstatefile ) ) for tid in found: spec, extrapath, tname = getpathcomponents(tid, d) - sstatefile = d.expand(extrapath + generate_sstatefn(spec, gethash(tid), d) + "_" + tname + ".tgz") + sstatefile = d.expand(extrapath + generate_sstatefn(spec, gethash(tid), tname, False, d)) evdata['found'].append((bb.runqueue.fn_from_tid(tid), bb.runqueue.taskname_from_tid(tid), gethash(tid), sstatefile ) ) bb.event.fire(bb.event.MetadataEvent("MissedSstate", evdata), d)
Signature · 1 line
2.20.1
PATCH 4/4 sstate: Handle sstate filenames longer than 255 characters
In reply to Richard PurdieMany filesystems can't cope with filenames longer that 255 characters. Add code to detect this and truncate non-essential elements of the filename to stay within the limit.
[YOCTO #13268]
--- meta/classes/sstate.bbclass | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
meta/classes/sstate.bbclass +18 -1
@@ -7,11 +7,28 @@ def generate_sstatefn(spec, hash, taskname, siginfo, d): if taskname is None: return "" extension = ".tgz" + # 8 chars reserved for siginfo + limit = 254 - 8 if siginfo: + limit = 254 extension = ".tgz.siginfo" if not hash: hash = "INVALID" - return hash[:2] + "/" + hash[2:4] + "/" + spec + hash + "_" + taskname + extension + fn = spec + hash + "_" + taskname + extension + # If the filename is too long, attempt to reduce it + if len(fn) > limit: + components = spec.split(":") + # Fields 0,5,6 are mandatory, 1 is most useful, 2,3,4 are just for information + # 7 is for the separators + avail = (254 - len(hash + "_" + taskname + extension) - len(components[0]) - len(components[1]) - len(components[5]) - len(components[6]) - 7) / 3 + components[2] = components[2][:avail] + components[3] = components[3][:avail] + components[4] = components[4][:avail] + spec = ":".join(components) + fn = spec + hash + "_" + taskname + extension + if len(fn) > limit: + bb.fatal("Unable to reduce sstate name to less than 255 chararacters") + return hash[:2] + "/" + hash[2:4] + "/" + fn SSTATE_PKGARCH = "${PACKAGE_ARCH}" SSTATE_PKGSPEC = "sstate:${PN}:${PACKAGE_ARCH}${TARGET_VENDOR}-${TARGET_OS}:${PV}:${PR}:${SSTATE_PKGARCH}:${SSTATE_VERSION}:"
Signature · 1 line
2.20.1
Quoted 9 lines · Richard Purdie
We're having speed issues on the autobuilder due to the numbers of files in sstate directories. We previously split these by the first two characters of the hash. This change extends this to split by the next two characters as well, creating more layers of directories.
This should signifiantly speed up eSDK builds on the autobuilder as the current sstate layout simply isn't scaling there but addresses a general complaint.
gen-lockedsig-cache needed to be updated for the new split level sstateI.
I assume zeus worthy?
Quoted 91 lines
Also update tests for new layout.
Signed-off-by Richard Purdie <[email protected]>--- meta/classes/sstate.bbclass | 4 ++-- meta/lib/oeqa/selftest/cases/signing.py | 4 ++-- meta/lib/oeqa/selftest/cases/sstate.py | 4 ++-- scripts/gen-lockedsig-cache | 13 ++++++++++--- 4 files changed, 16 insertions(+), 9 deletions(-)meta/classes/sstate.bbclass +2
-2@@ -6,7 +6,7 @@ SSTATE_MANFILEPREFIX = "${SSTATE_MANIFESTS}/manifest-${SSTATE_MANMACH}-${PN}" def generate_sstatefn(spec, hash, d): if not hash: hash = "INVALID" - return hash[:2] + "/" + spec + hash + return hash[:2] + "/" + hash[2:4] + "/" + spec + hash SSTATE_PKGARCH = "${PACKAGE_ARCH}" SSTATE_PKGSPEC = "sstate:${PN}:${PACKAGE_ARCH}${TARGET_VENDOR}-${TARGET_OS}:${PV}:${PR}:${SSTATE_PKGARCH}:${SSTATE_VERSION}:"@@ -15,7 +15,7 @@ SSTATE_PKGNAME = "${SSTATE_EXTRAPATH}${@generate_sstatefn(d.getVar('SSTATE_PK SSTATE_PKG = "${SSTATE_DIR}/${SSTATE_PKGNAME}" SSTATE_EXTRAPATH = "" SSTATE_EXTRAPATHWILDCARD = "" -SSTATE_PATHSPEC = "${SSTATE_DIR}/${SSTATE_EXTRAPATHWILDCARD}*/${SSTATE_PKGSPEC}" +SSTATE_PATHSPEC = "${SSTATE_DIR}/${SSTATE_EXTRAPATHWILDCARD}*/*/${SSTATE_PKGSPEC}" # explicitly make PV to depend on evaluated value of PV variable PV[vardepvalue] = "${PV}"meta/lib/oeqa/selftest/cases/signing.py +2
-2@@ -157,8 +157,8 @@ class Signing(OESelftestTestCase): bitbake('-c clean %s' % test_recipe) bitbake('-c populate_lic %s' % test_recipe) - recipe_sig = glob.glob(sstatedir + '/*/*:ed:*_populate_lic.tgz.sig') - recipe_tgz = glob.glob(sstatedir + '/*/*:ed:*_populate_lic.tgz') + recipe_sig = glob.glob(sstatedir + '/*/*/*:ed:*_populate_lic.tgz.sig') + recipe_tgz = glob.glob(sstatedir + '/*/*/*:ed:*_populate_lic.tgz') self.assertEqual(len(recipe_sig), 1, 'Failed to find .sig file.') self.assertEqual(len(recipe_tgz), 1, 'Failed to find .tgz file.')meta/lib/oeqa/selftest/cases/sstate.py +2
-2@@ -56,11 +56,11 @@ class SStateBase(OESelftestTestCase): def search_sstate(self, filename_regex, distro_specific=True, distro_nonspecific=True): result = [] for root, dirs, files in os.walk(self.sstate_path): - if distro_specific and re.search("%s/[a-z0-9]{2}$" % self.hostdistro, root): + if distro_specific and re.search(r"%s/%s/[a-z0-9]{2}/[a-z0-9]{2}$" % (self.sstate_path, self.hostdistro), root): for f in files: if re.search(filename_regex, f): result.append(f) - if distro_nonspecific and re.search("%s/[a-z0-9]{2}$" % self.sstate_path, root): + if distro_nonspecific and re.search(r"%s/[a-z0-9]{2}/[a-z0-9]{2}$" % self.sstate_path, root): for f in files: if re.search(filename_regex, f): result.append(f)scripts/gen-lockedsig-cache +10
-3@@ -78,11 +78,18 @@ files = set() sstate_content_cache = {} for s in sigs: prefix = s[:2] + prefix2 = s[2:4] if prefix not in sstate_content_cache: sstate_content_cache[prefix] = build_sha_cache(prefix) - - for f in sstate_content_cache[prefix][s]: - files.add(f) + if prefix2 not in sstate_content_cache[prefix]: + sstate_content_cache[prefix][prefix2] = build_sha_cache(prefix + "/" + prefix2) + + if s in sstate_content_cache[prefix]: + for f in sstate_content_cache[prefix][s]: + files.add(f) + if s in sstate_content_cache[prefix][prefix2]: + for f in sstate_content_cache[prefix][prefix2][s]: + files.add(f) elapsed = time.perf_counter() - start_time print("Gathering file list took %.1fs" % elapsed)
Quoted 14 lines · On Sun, 2020-01-05 at 16:41 -0800, akuster808 wrote:
Quoted 13 lines · Richard Purdie
We're having speed issues on the autobuilder due to the numbers of files in sstate
directories. We previously split these by the first two characters of the hash.
This change extends this to split by the next two characters as well, creating
more layers of directories.This should signifiantly speed up eSDK builds on the autobuilder as the current
sstate layout simply isn't scaling there but addresses a general complaint.
Quoted 4 lines
Quoted 2 lines
gen-lockedsig-cache needed to be updated for the new split level sstateI.
I assume zeus worthy?
I think we need to discuss that. It is a fairly significant change in behaviour.
Options are:
a) none of these
b) only this first change
c) all of them if we want to fix the 255 char sstate filename limit issue
Cheers,
Richard
Quoted 33 lines
-----Original Message-----
From: [email protected] <openembedded-core- [email protected]> On Behalf Of Richard Purdie
Sent: den 6 januari 2020 01:44
To: akuster808 <[email protected]>; openembedded- [email protected]
Subject: Re: [OE-core] [PATCH 1/4] sstate: Add extra directory levelQuoted 14 lines · On Sun, 2020-01-05 at 16:41 -0800, akuster808 wrote:
Quoted 13 lines · Richard Purdie
We're having speed issues on the autobuilder due to the numbers of files in sstate
directories. We previously split these by the first two characters of the hash.
This change extends this to split by the next two characters as well, creating
more layers of directories.This should signifiantly speed up eSDK builds on the autobuilder as the current
sstate layout simply isn't scaling there but addresses a general complaint.Quoted 4 lines
Quoted 2 lines
gen-lockedsig-cache needed to be updated for the new split level sstateI.
I assume zeus worthy?
I think we need to discuss that. It is a fairly significant change in behaviour.
Options are:
Quoted 8 lines
a) none of these
b) only this first change
c) all of them if we want to fix the 255 char sstate filename limit issueCheers,
Richard
I would like to see at least the first patch being backported. You are not alone with huge sstate-cache directories...
We have not had the problems solved by the other three patches so for us at least, they are not required. And they do seem somewhat invasive.
//Peter