Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753253AbbEHNW4 (ORCPT ); Fri, 8 May 2015 09:22:56 -0400 Received: from mx2.parallels.com ([199.115.105.18]:37218 "EHLO mx2.parallels.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752726AbbEHNWv (ORCPT ); Fri, 8 May 2015 09:22:51 -0400 Date: Fri, 8 May 2015 16:22:42 +0300 From: Vladimir Davydov To: Andrew Morton CC: Minchan Kim , Johannes Weiner , Michal Hocko , Greg Thelen , Michel Lespinasse , David Rientjes , Pavel Emelyanov , Cyrill Gorcunov , Jonathan Corbet , , , , , Subject: Re: [PATCH v4 0/3] idle memory tracking Message-ID: <20150508132242.GQ31732@esperanza> References: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2005 Lines: 79 On Thu, May 07, 2015 at 05:09:39PM +0300, Vladimir Davydov wrote: > ---- SCRIPT FOR COUNTING IDLE PAGES PER CGROUP ---- Oops, this script is stale. The correct one is here: --- #! /usr/bin/python # import os import stat import errno import struct CGROUP_MOUNT = "/sys/fs/cgroup/memory" BUFSIZE = 8 * 1024 # must be multiple of 8 def set_idle(): f = open("/proc/kpageidle", "wb", BUFSIZE) while True: try: f.write(struct.pack("Q", pow(2, 64) - 1)) except IOError as err: if err.errno == errno.ENXIO: break raise f.close() def count_idle(): f_flags = open("/proc/kpageflags", "rb", BUFSIZE) f_cgroup = open("/proc/kpagecgroup", "rb", BUFSIZE) f_idle = open("/proc/kpageidle", "rb", BUFSIZE) pfn = 0 nr_idle = {} while True: s = f_flags.read(8) if not s: break flags, = struct.unpack('Q', s) cgino, = struct.unpack('Q', f_cgroup.read(8)) bit = pfn % 64 if not bit: idle_bitmap, = struct.unpack('Q', f_idle.read(8)) idle = idle_bitmap >> bit & 1 pfn += 1 unevictable = flags >> 18 & 1 huge = flags >> 22 & 1 if idle and not unevictable: nr_idle[cgino] = nr_idle.get(cgino, 0) + (512 if huge else 1) f_flags.close() f_cgroup.close() f_idle.close() return nr_idle print "Setting the idle flag for each page..." set_idle() raw_input("Wait until the workload accesses its working set, then press Enter") print "Counting idle pages..." nr_idle = count_idle() for dir, subdirs, files in os.walk(CGROUP_MOUNT): ino = os.stat(dir)[stat.ST_INO] print dir + ": " + str(nr_idle.get(ino, 0) * 4) + " KB" -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/