kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: windtracekimo@gmail.com (Jui-Hao Chiang)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Question about page count
Date: Tue, 21 Jun 2011 10:25:44 -0400	[thread overview]
Message-ID: <BANLkTikojiQDN-6CJZ9+30pAfEJcdb9nGw@mail.gmail.com> (raw)
In-Reply-To: <BANLkTi=NqaNz-2uEPduwgidcm2bDEZeyMQ@mail.gmail.com>

Hi, Mulyadi:

My kernel module actually does something similar to the following

struct page *page = mem_map;
for (i = 0; i < 262144; i++, page++)
   printk("[%d] flags %x, count %x, mapcount %x, private %x, mapping %x, "
               "index %x, lrunext %x, lruprev %x\n",
               i, page->flags, page->_count,
               page->_mapcount, page->private, page->mapping,
               page->index, page->lru.next, page->lru.prev);

(1) no compound page has been found during this printing
(2) I seemed to figure out how to compute the free page as meminfo does
See the following 4 pages output
[20] flags 80000, count 0, mapcount ffffffff, private 2, mapping 0,
index 0, lrunext c069789c, lruprev c1001318
[21] flags 0, count 0, mapcount ffffffff, private 0, mapping 0, index
0, lrunext 100100, lruprev 200200
[22] flags 0, count 0, mapcount ffffffff, private 0, mapping 0, index
0, lrunext 100100, lruprev 200200
[23] flags 0, count 0, mapcount ffffffff, private 0, mapping 0, index
0, lrunext 100100, lruprev 200200

The 1st page (page frame 20) has PageBuddy(page)==1 from the flags,
and its field private==2 means there are 2^2 contiguous free pages in
the subsequent memory frames. So page 20,21, 22, 23 are actually a
group (buddy pages) in the zone allocator. There seems no special
flags in page 21, 22, 23, so the only way is to search for the
PageBuddy and look at the private field to deduce them.

With this rule to calculate the free pages, the result equals to
MemFree reported from nr_free_pages() or /proc/meminfo

(3) However there are some page frames that I can't not figure out the
buddy information from the rules found in (2).
For example, in the follow pages, I can't find any related buddy pages
before them, but their count is still 0.
[239339] flags c0000000, count 0, mapcount ffffffff, private 0,
mapping 0, index 155, lrunext c17eeb78, lruprev c17912f8
[239340] flags c0000000, count 0, mapcount ffffffff, private 0,
mapping 0, index ae, lrunext c178d8f8, lruprev c174e1b8
[239344] flags c0000000, count 0, mapcount ffffffff, private 0,
mapping 0, index 93f6, lrunext c069a18c, lruprev c17f5738

That's the part I don't understand.

Thanks,
Jui-Hao


On Tue, Jun 21, 2011 at 1:15 AM, Mulyadi Santosa
<mulyadi.santosa@gmail.com> wrote:
> Hi...
>
> On 20/06/2011, Jui-Hao Chiang <windtracekimo@gmail.com> wrote:
>> Hi,
>>
>> I am currently analyzing the memory pages footprint in 2.6.18.8 kernel (1GB
>> ram,
>> 32-bit, Flat model, no NUMA), and got a question. Does page_count(page)==0
>> really means the page is free because the source code says so?
>
> looking at how page_count implemented, it checks whether the related
> page is gonna be reclaimed or a compound page (not sure what it is).
> If so, returns the first page of that "page".
>
> by comparing the definition of free page as "really free, not being
> used for any purpose" versus the above perception, I guess it's not
> surprising to see the difference
>
> --
> regards,
>
> Mulyadi Santosa
> Freelance Linux trainer and consultant
>
> blog: the-hydra.blogspot.com
> training: mulyaditraining.blogspot.com
>

      parent reply	other threads:[~2011-06-21 14:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-20 13:10 Question about page count Jui-Hao Chiang
2011-06-21  1:46 ` Wick
2011-06-21  5:15 ` Mulyadi Santosa
2011-06-21 13:23   ` Dave Hylands
2011-06-21 16:34     ` Mulyadi Santosa
2011-06-21 14:25   ` Jui-Hao Chiang [this message]

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=BANLkTikojiQDN-6CJZ9+30pAfEJcdb9nGw@mail.gmail.com \
    --to=windtracekimo@gmail.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /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;
as well as URLs for NNTP newsgroup(s).