From owner-freebsd-hackers@FreeBSD.ORG Mon Oct 30 18:03:36 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1200816A527 for ; Mon, 30 Oct 2006 18:03:36 +0000 (UTC) (envelope-from rottled@gmail.com) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.172]) by mx1.FreeBSD.org (Postfix) with ESMTP id D89BC43D6B for ; Mon, 30 Oct 2006 18:03:29 +0000 (GMT) (envelope-from rottled@gmail.com) Received: by ug-out-1314.google.com with SMTP id m2so1027313uge for ; Mon, 30 Oct 2006 10:03:28 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=EpzfRtHDcICxedemcJJn7ss13yS89iQrFk2xd1J0JmXbaOjMhepT67pwjVWV0Qd5+LX/wxfJgiBgig5aVsj0H1QCQklO5OKvel02en6mtneYbrv8V0yEYn1LYiJe2f8YOlh5PeCAEov1ZQG3LETUbqFx36eMx4gyPwHrjqFKoVs= Received: by 10.82.101.3 with SMTP id y3mr808938bub; Mon, 30 Oct 2006 10:02:55 -0800 (PST) Received: by 10.82.101.19 with HTTP; Mon, 30 Oct 2006 10:02:55 -0800 (PST) Message-ID: <54b90fdf0610301002i1d988c80wf62d31645c38d683@mail.gmail.com> Date: Mon, 30 Oct 2006 13:02:55 -0500 From: Yan To: freebsd-hackers@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Subject: Obtaining used pages on process exit? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Oct 2006 18:03:36 -0000 Hello, I am currently writing my first kernel module to extract data from the kernel and bring it into user-space. As I understand, FreeBSD only loads pages of the text segment that it is about to use by registering its handler for page faults, and bringing in more pages from the binary as needed. I want to track this progress, and report the amount of pages it brought in on process exit. The current idea I have and the path I'm following is as follows: I register a callback in my module using EVENTHANDLER_REGISTER, using 'process_exit' name. That gives me the proc structure on exit, I then try to find the information I need using the p_vmspace member, and try using vm_tsize for the number of pages. But this is the number of pages in the virtual address space of the text segment, which does not correlate to how many pages were actually brought in. For the context of this, I am trying to write a tiny utility, that watches the execution of a process, and tracks how many pages were actually used during its execution. It passes that knowledge to a hopefully-to-be-written user-space utility that generates a new binary using only those pages for the text segment. (If an execution was to go outside that, a seg fault is okay.) Any help is appreciated. Thanks, Yan