linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: Nikita Danilov <nikita@clusterfs.com>
Cc: linux-mm@kvack.org, AKPM@osdl.org
Subject: Re: [PATCH]: VM 2/8 rmap.c cleanup
Date: Mon, 25 Apr 2005 20:37:39 -0700	[thread overview]
Message-ID: <20050425203739.5f653204.akpm@osdl.org> (raw)
In-Reply-To: <16994.40538.327768.911229@gargle.gargle.HOWL>

Nikita Danilov <nikita@clusterfs.com> wrote:
>
> mm/rmap.c:page_referenced_one() and mm/rmap.c:try_to_unmap_one() contain
>  identical code that
> 
>   - takes mm->page_table_lock;
> 
>   - drills through page tables;
> 
>   - checks that correct pte is reached.
> 
>  Coalesce this into page_check_address()
> 
> ...
>   /*
>  + * Check that @page is mapped at @address into @mm.
>  + *
>  + * On success returns with mapped pte and locked mm->page_table_lock.
>  + */
>  +static pte_t *page_check_address(struct page *page, struct mm_struct *mm,
>  +					unsigned long address)
>  +{
>  +	pgd_t *pgd;
>  +	pud_t *pud;
>  +	pmd_t *pmd;
>  +	pte_t *pte;
>  +
>  +	/*
>  +	 * We need the page_table_lock to protect us from page faults,
>  +	 * munmap, fork, etc...
>  +	 */
>  +	spin_lock(&mm->page_table_lock);
>  +	pgd = pgd_offset(mm, address);
>  +	if (likely(pgd_present(*pgd))) {
>  +		pud = pud_offset(pgd, address);
>  +		if (likely(pud_present(*pud))) {
>  +			pmd = pmd_offset(pud, address);
>  +			if (likely(pmd_present(*pmd))) {
>  +				pte = pte_offset_map(pmd, address);
>  +				if (likely(pte_present(*pte) &&
>  +					   page_to_pfn(page) == pte_pfn(*pte)))
>  +					return pte;
>  +				pte_unmap(pte);
>  +			}
>  +		}
>  +	}
>  +	spin_unlock(&mm->page_table_lock);
>  +	return ERR_PTR(-ENOENT);
>  +}

Can we not simply return NULL in the failure case?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org"> aart@kvack.org </a>

      reply	other threads:[~2005-04-26  3:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-17 17:35 Nikita Danilov
2005-04-26  3:37 ` Andrew Morton [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=20050425203739.5f653204.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=linux-mm@kvack.org \
    --cc=nikita@clusterfs.com \
    /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