def kmgtp_num(x):
    """ Return a string of a number in the MEM size format, Ie. "30 MB". """
    ends = [" ", "K", "M", "G", "T", "P"]
    while len(ends) and x > 1024:
        ends.pop(0)
        x /= 1024
    return "%u %s" % (x, ends[0])