Openembedded Core Discussions
 help / color / mirror / Atom feed
From: Mike Crowe <mac@mcrowe.com>
To: Otavio Salvador <otavio.salvador@ossystems.com.br>
Cc: Mike Crowe <mac@mcrowe.com>,
	Patches and discussions about the oe-core layer
	<openembedded-core@lists.openembedded.org>
Subject: Re: Over-pruning the sstate cache
Date: Wed, 13 Apr 2016 16:27:04 +0100	[thread overview]
Message-ID: <20160413152704.GA19112@mcrowe.com> (raw)
In-Reply-To: <CAP9ODKpPEmPQuz7rJWfzCz5Rw4rpBHvBoRAg-FXktNd2nu6vRg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1150 bytes --]

On Wednesday 13 April 2016 at 11:11:11 -0300, Otavio Salvador wrote:
> On Wed, Apr 13, 2016 at 11:01 AM, Mike Crowe <mac@mcrowe.com> wrote:
> > On Wednesday 13 April 2016 at 10:47:13 -0300, Otavio Salvador wrote:
> >> Couldn't this to be done, similar to the fetchall task?
> >
> > That's the sort of thing I was thinking of with my "all_populate_sysroot"
> > task in my original question.
> >
> > But, I've a working script using Richard's method now. I'll share it once
> > I've tested it a bit more.
> 
> Having it as a task allows it to avoid races and like, when running
> inside of the BitBake. It also can reuse the metadata database
> information and ought to be faster. Once you share the script I will
> see if I can rework it to a task and see how it looks.

I'm not really sure how much my (not very pretty) script will have in
common with a task-based solution.

I agree that integrating it into Bitbake would be better though. At the
moment generating the locked-sigs.inc file is by far the slowest part of
the operation though.

Since you've requested it, here's the not-really-tested-properly script.

Mike.

[-- Attachment #2: touch-sstate --]
[-- Type: text/plain, Size: 3657 bytes --]

#!/usr/bin/python2
#
# touch-sstate
#
#  Update atime on sstate-cache files for locked-sigs.inc file.
#
# Mike Crowe <mac@mcrowe.com>
#
# If nothing needs recompiling when building an image then bitbake
# won't access the sstate files that are required to populate the
# sysroot. This means that they might be expired as being unused. To
# avoid the problem this script processes the "locked-sigs.inc" file
# generated by running "bitbake XXX --dump-signatures=none".

import glob
import os
import re
import sys
import time

# These variables may need tweaking when the build environment changes
native_lsb_string = "Debian-8"
target_vendor = ""
target_os = "oe-linux-gnueabi"
host_os = "linux"
sstate_version = "3"
native_arches = [ 'x86-64' ]

sstate_cache_dir = "sstate-cache/"

# The start of a variable declaration that tells us the arch
variable_re = re.compile('^SIGGEN_LOCKEDSIGS_t-([^ ]*) = \"\\\\$')

# A single hash for a task
sig_re = re.compile('^ *([^:]+):([^:]+):([^:]+) \\\\$')

# Ignore the trailing quote, the final line and blank lines
ignore_re = re.compile('^( *\")|(SIGGEN_LOCKEDSIGS_TYPES_)|$')

arch1 = "noarch"
arch2 = "noarch"

def TouchMatches(pattern, deadline):
    matches = glob.glob(pattern)
    for match in matches:
        # It's likely that we won't need to touch the file so it's
        # cheaper to do the stat to check first than to always open
        # the file for reading. The inode might be in cache but the
        # file contents not.
        if os.stat(match).st_atime < deadline:
            print match

            # We can't use os.utime for this since we may not own the
            # file.
            f = open(match, 'r')

            # We actually have to read something from the file in
            # order to update atime.
            f.read(1)
            f.close()
        
# In order to avoid unnecessarily thrashing the disk we only want to
# modify the atime of the file if the atime is more than a day ago.
# This matches the behaviour of the "relatime" mount option. We allow
# a bit of leeway in case we take a long time to run and the expiry
# script wants to expire stuff that's only more than a day old though.
deadline = time.time() - 23 * 3600

line_number = 0

for line in open("locked-sigs.inc", "r"):
    line_number += 1
    line = line.rstrip()
    variable_match = variable_re.match(line)
    if variable_match:
        arch = variable_match.group(1)
        arch_underscore = arch.replace("-", "_")
        if arch in native_arches:
            dir = sstate_cache_dir + native_lsb_string + "/"
            arch1 = arch_underscore + "-" + host_os
            arch2 = arch_underscore
        else:
            dir = sstate_cache_dir
            arch1 = arch_underscore + target_vendor + "-" + target_os
            arch2 = arch_underscore
    else:
        sig_match = sig_re.match(line)
        if sig_match:
            pn = sig_match.group(1)
            task = sig_match.group(2)[3:]
            sig = sig_match.group(3)

            arch_file = dir + sig[0:2] + "/sstate:" + pn + ":" + arch1 + ":*:*:" + arch2 + ":" + sstate_version + ":" + sig + "_" + task + ".tgz"
            noarch_file = dir + sig[0:2] + "/sstate:" + pn + "::*:*::" + sstate_version + ":" + sig + "_" + task + ".tgz"

            TouchMatches(arch_file, deadline)
            TouchMatches(noarch_file, deadline)
        elif ignore_re.match(line):
            pass
        else:
            sys.stderr.write('touch-sstate: Unparsed line %d\n' % line_number)
            sys.exit(1)
        
        

  reply	other threads:[~2016-04-13 15:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-29 12:56 Over-pruning the sstate cache Mike Crowe
2016-03-29 14:11 ` Richard Purdie
2016-03-30 13:05   ` Mike Crowe
2016-04-12 18:51   ` Mike Crowe
2016-04-12 20:50     ` Richard Purdie
2016-04-13 13:47       ` Otavio Salvador
2016-04-13 14:01         ` Mike Crowe
2016-04-13 14:11           ` Otavio Salvador
2016-04-13 15:27             ` Mike Crowe [this message]
2016-04-13 21:33             ` Paul Eggleton
2016-04-13 21:59               ` Richard Purdie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160413152704.GA19112@mcrowe.com \
    --to=mac@mcrowe.com \
    --cc=openembedded-core@lists.openembedded.org \
    --cc=otavio.salvador@ossystems.com.br \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox