counting page tables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi.  I am creating a function that counts the number of pages used for
the page tables associated with an mm.

I thought it would be very easy, but I never see the debugging message
that is printed at function exit.  Can anyone see something that I'm
doing wrong?

This is 2.6.0-test11 on sparc64.  

The dbg_printk function is like printk except that it prints straight
to the terminal driver.


static unsigned long count_pt_pgs_mm(struct mm_struct *mm)
{
	unsigned long i, j;
	unsigned long int n = 0;

	/* loop over each pgd entry in the pgd
	 */
	for (i = 0; i < PTRS_PER_PGD; ++i) {
		/* loop over each entry in the second-level page table
		 */
		for (j = 0; j < REAL_PTRS_PER_PMD; ++j) {
			pgd_t *pgde;
			pmd_t *pmde;
			unsigned long addr = i << PGDIR_SHIFT | j << PMD_SHIFT;
			
			down_read(&mm->mmap_sem);
			spin_lock(&mm->page_table_lock);
			
			pgde = pgd_offset(mm, addr);
		
			if (pgd_none(*pgde) || pgd_bad(*pgde)) {
				dbg_printk(DBG_ADDR_KERNINFO, "%lu%s\n",
					   i, pgd_none(*pgde) ? "G" : "B");
				spin_unlock(&mm->page_table_lock);
				up_read(&mm->mmap_sem);
				break;
			}
			if (j == 0) {
				dbg_printk(DBG_ADDR_KERNINFO, "%lug\n", i);
				n += 1;	   /* count one page for the pmd that this
					    * pgd entry points to
					    */
			}

			pmde = pmd_offset(pgde, addr);

			if (pmd_none(*pmde)) {
				dbg_printk(DBG_ADDR_KERNINFO, "%luM ", j);
				goto cont;				
			}
			if (pmd_huge(*pmde)) {
				dbg_printk(DBG_ADDR_KERNINFO, "%luH ", j);
				goto cont;
			}
			if (pmd_bad(*pmde)) {
				dbg_printk(DBG_ADDR_KERNINFO, "%lub ", j);
				goto cont;
			}
			if (pmd_present(*pmde)) {
				n += 1; /* count one page for the PT */
				dbg_printk(DBG_ADDR_KERNINFO, "%lum ", j);
			} else {
				dbg_printk(DBG_ADDR_KERNINFO, "%luM ", j);
			}
		cont:
			spin_unlock(&mm->page_table_lock);
			up_read(&mm->mmap_sem);
		}
	}

	dbg_printk(DBG_ADDR_KERNINFO, " %s return %lu ", __FUNCTION__, n);

	return n;
}


-- 
--Ed L Cashin            |   PGP public key:
  ecashin@uga.edu        |   http://noserose.net/e/pgp/


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux