All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov@parallels.com>
To: Andres Lagar-Cavilla <andreslc@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Minchan Kim <minchan@kernel.org>,
	Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Michal Hocko <mhocko@suse.cz>, Greg Thelen <gthelen@google.com>,
	Michel Lespinasse <walken@google.com>,
	David Rientjes <rientjes@google.com>,
	Pavel Emelyanov <xemul@parallels.com>,
	Cyrill Gorcunov <gorcunov@openvz.org>,
	Jonathan Corbet <corbet@lwn.net>,
	linux-api@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-mm@kvack.org, cgroups@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH -mm v7 5/6] proc: add kpageidle file
Date: Tue, 14 Jul 2015 14:05:28 +0300	[thread overview]
Message-ID: <20150714110527.GA1015@esperanza> (raw)
In-Reply-To: <CAJu=L59+7d_16zXZAFfJkr5HSwHsfYXi9EBu_9Sx1tAcJv2LOA@mail.gmail.com>

On Mon, Jul 13, 2015 at 12:02:57PM -0700, Andres Lagar-Cavilla wrote:
> On Sat, Jul 11, 2015 at 7:48 AM, Vladimir Davydov
> <vdavydov@parallels.com> wrote:
[...]
> > +static struct page *kpageidle_get_page(unsigned long pfn)
> > +{
> > +       struct page *page;
> > +       struct zone *zone;
> > +
> > +       if (!pfn_valid(pfn))
> > +               return NULL;
> > +
> > +       page = pfn_to_page(pfn);
> > +       if (!page || PageTail(page) || !PageLRU(page) ||
> > +           !get_page_unless_zero(page))
> 
> get_page_unless_zero does not succeed for Tail pages.

True. So we don't seem to need the PageTail checks here at all, because
if kpageidle_get_page succeeds, the page must be a head, so that we
won't dive into expensive rmap_walk for tail pages. Will remove it then.

> 
> > +               return NULL;
> > +
> > +       if (unlikely(PageTail(page))) {
> > +               put_page(page);
> > +               return NULL;
> > +       }
> > +
> > +       zone = page_zone(page);
> > +       spin_lock_irq(&zone->lru_lock);
> > +       if (unlikely(!PageLRU(page))) {
> > +               put_page(page);
> > +               page = NULL;
> > +       }
> > +       spin_unlock_irq(&zone->lru_lock);
> > +       return page;
> > +}
> > +
> > +static int kpageidle_clear_pte_refs_one(struct page *page,
> > +                                       struct vm_area_struct *vma,
> > +                                       unsigned long addr, void *arg)
> > +{
> > +       struct mm_struct *mm = vma->vm_mm;
> > +       spinlock_t *ptl;
> > +       pmd_t *pmd;
> > +       pte_t *pte;
> > +       bool referenced = false;
> > +
> > +       if (unlikely(PageTransHuge(page))) {
> 
> VM_BUG_ON(!PageHead)?

Don't think it's necessary, because PageTransHuge already does this sort
of check:

: static inline int PageTransHuge(struct page *page)
: {
: 	VM_BUG_ON_PAGE(PageTail(page), page);
: 	return PageHead(page);
: }

> 
> > +               pmd = page_check_address_pmd(page, mm, addr,
> > +                                            PAGE_CHECK_ADDRESS_PMD_FLAG, &ptl);
> > +               if (pmd) {
> > +                       referenced = pmdp_test_and_clear_young(vma, addr, pmd);
> 
> For any workload using MMU notifiers, this will lose significant
> information by not querying the secondary PTE. The most
> straightforward case is KVM. Once mappings are setup, all access
> activity is recorded through shadow PTEs. This interface will say
> "idle" even though the VM is blasting memory.

Hmm, interesting. It seems we have to introduce
mmu_notifier_ops.clear_young then, which, in contrast to
clear_flush_young, won't flush TLB. Looking back at your comment to v6,
now I see that you already mentioned it, but I missed your point :-(
OK, will do it in the next iteration.

Thanks a lot for the review!

Vladimir

WARNING: multiple messages have this Message-ID (diff)
From: Vladimir Davydov <vdavydov@parallels.com>
To: Andres Lagar-Cavilla <andreslc@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Minchan Kim <minchan@kernel.org>,
	Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Michal Hocko <mhocko@suse.cz>, Greg Thelen <gthelen@google.com>,
	Michel Lespinasse <walken@google.com>,
	David Rientjes <rientjes@google.com>,
	Pavel Emelyanov <xemul@parallels.com>,
	Cyrill Gorcunov <gorcunov@openvz.org>,
	Jonathan Corbet <corbet@lwn.net>,
	linux-api@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-mm@kvack.org, cgroups@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH -mm v7 5/6] proc: add kpageidle file
Date: Tue, 14 Jul 2015 14:05:28 +0300	[thread overview]
Message-ID: <20150714110527.GA1015@esperanza> (raw)
In-Reply-To: <CAJu=L59+7d_16zXZAFfJkr5HSwHsfYXi9EBu_9Sx1tAcJv2LOA@mail.gmail.com>

On Mon, Jul 13, 2015 at 12:02:57PM -0700, Andres Lagar-Cavilla wrote:
> On Sat, Jul 11, 2015 at 7:48 AM, Vladimir Davydov
> <vdavydov@parallels.com> wrote:
[...]
> > +static struct page *kpageidle_get_page(unsigned long pfn)
> > +{
> > +       struct page *page;
> > +       struct zone *zone;
> > +
> > +       if (!pfn_valid(pfn))
> > +               return NULL;
> > +
> > +       page = pfn_to_page(pfn);
> > +       if (!page || PageTail(page) || !PageLRU(page) ||
> > +           !get_page_unless_zero(page))
> 
> get_page_unless_zero does not succeed for Tail pages.

True. So we don't seem to need the PageTail checks here at all, because
if kpageidle_get_page succeeds, the page must be a head, so that we
won't dive into expensive rmap_walk for tail pages. Will remove it then.

> 
> > +               return NULL;
> > +
> > +       if (unlikely(PageTail(page))) {
> > +               put_page(page);
> > +               return NULL;
> > +       }
> > +
> > +       zone = page_zone(page);
> > +       spin_lock_irq(&zone->lru_lock);
> > +       if (unlikely(!PageLRU(page))) {
> > +               put_page(page);
> > +               page = NULL;
> > +       }
> > +       spin_unlock_irq(&zone->lru_lock);
> > +       return page;
> > +}
> > +
> > +static int kpageidle_clear_pte_refs_one(struct page *page,
> > +                                       struct vm_area_struct *vma,
> > +                                       unsigned long addr, void *arg)
> > +{
> > +       struct mm_struct *mm = vma->vm_mm;
> > +       spinlock_t *ptl;
> > +       pmd_t *pmd;
> > +       pte_t *pte;
> > +       bool referenced = false;
> > +
> > +       if (unlikely(PageTransHuge(page))) {
> 
> VM_BUG_ON(!PageHead)?

Don't think it's necessary, because PageTransHuge already does this sort
of check:

: static inline int PageTransHuge(struct page *page)
: {
: 	VM_BUG_ON_PAGE(PageTail(page), page);
: 	return PageHead(page);
: }

> 
> > +               pmd = page_check_address_pmd(page, mm, addr,
> > +                                            PAGE_CHECK_ADDRESS_PMD_FLAG, &ptl);
> > +               if (pmd) {
> > +                       referenced = pmdp_test_and_clear_young(vma, addr, pmd);
> 
> For any workload using MMU notifiers, this will lose significant
> information by not querying the secondary PTE. The most
> straightforward case is KVM. Once mappings are setup, all access
> activity is recorded through shadow PTEs. This interface will say
> "idle" even though the VM is blasting memory.

Hmm, interesting. It seems we have to introduce
mmu_notifier_ops.clear_young then, which, in contrast to
clear_flush_young, won't flush TLB. Looking back at your comment to v6,
now I see that you already mentioned it, but I missed your point :-(
OK, will do it in the next iteration.

Thanks a lot for the review!

Vladimir

--
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:"dont@kvack.org"> email@kvack.org </a>

WARNING: multiple messages have this Message-ID (diff)
From: Vladimir Davydov <vdavydov@parallels.com>
To: Andres Lagar-Cavilla <andreslc@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Minchan Kim <minchan@kernel.org>,
	Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Michal Hocko <mhocko@suse.cz>, "Greg Thelen" <gthelen@google.com>,
	Michel Lespinasse <walken@google.com>,
	"David Rientjes" <rientjes@google.com>,
	Pavel Emelyanov <xemul@parallels.com>,
	"Cyrill Gorcunov" <gorcunov@openvz.org>,
	Jonathan Corbet <corbet@lwn.net>, <linux-api@vger.kernel.org>,
	<linux-doc@vger.kernel.org>, <linux-mm@kvack.org>,
	<cgroups@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH -mm v7 5/6] proc: add kpageidle file
Date: Tue, 14 Jul 2015 14:05:28 +0300	[thread overview]
Message-ID: <20150714110527.GA1015@esperanza> (raw)
In-Reply-To: <CAJu=L59+7d_16zXZAFfJkr5HSwHsfYXi9EBu_9Sx1tAcJv2LOA@mail.gmail.com>

On Mon, Jul 13, 2015 at 12:02:57PM -0700, Andres Lagar-Cavilla wrote:
> On Sat, Jul 11, 2015 at 7:48 AM, Vladimir Davydov
> <vdavydov@parallels.com> wrote:
[...]
> > +static struct page *kpageidle_get_page(unsigned long pfn)
> > +{
> > +       struct page *page;
> > +       struct zone *zone;
> > +
> > +       if (!pfn_valid(pfn))
> > +               return NULL;
> > +
> > +       page = pfn_to_page(pfn);
> > +       if (!page || PageTail(page) || !PageLRU(page) ||
> > +           !get_page_unless_zero(page))
> 
> get_page_unless_zero does not succeed for Tail pages.

True. So we don't seem to need the PageTail checks here at all, because
if kpageidle_get_page succeeds, the page must be a head, so that we
won't dive into expensive rmap_walk for tail pages. Will remove it then.

> 
> > +               return NULL;
> > +
> > +       if (unlikely(PageTail(page))) {
> > +               put_page(page);
> > +               return NULL;
> > +       }
> > +
> > +       zone = page_zone(page);
> > +       spin_lock_irq(&zone->lru_lock);
> > +       if (unlikely(!PageLRU(page))) {
> > +               put_page(page);
> > +               page = NULL;
> > +       }
> > +       spin_unlock_irq(&zone->lru_lock);
> > +       return page;
> > +}
> > +
> > +static int kpageidle_clear_pte_refs_one(struct page *page,
> > +                                       struct vm_area_struct *vma,
> > +                                       unsigned long addr, void *arg)
> > +{
> > +       struct mm_struct *mm = vma->vm_mm;
> > +       spinlock_t *ptl;
> > +       pmd_t *pmd;
> > +       pte_t *pte;
> > +       bool referenced = false;
> > +
> > +       if (unlikely(PageTransHuge(page))) {
> 
> VM_BUG_ON(!PageHead)?

Don't think it's necessary, because PageTransHuge already does this sort
of check:

: static inline int PageTransHuge(struct page *page)
: {
: 	VM_BUG_ON_PAGE(PageTail(page), page);
: 	return PageHead(page);
: }

> 
> > +               pmd = page_check_address_pmd(page, mm, addr,
> > +                                            PAGE_CHECK_ADDRESS_PMD_FLAG, &ptl);
> > +               if (pmd) {
> > +                       referenced = pmdp_test_and_clear_young(vma, addr, pmd);
> 
> For any workload using MMU notifiers, this will lose significant
> information by not querying the secondary PTE. The most
> straightforward case is KVM. Once mappings are setup, all access
> activity is recorded through shadow PTEs. This interface will say
> "idle" even though the VM is blasting memory.

Hmm, interesting. It seems we have to introduce
mmu_notifier_ops.clear_young then, which, in contrast to
clear_flush_young, won't flush TLB. Looking back at your comment to v6,
now I see that you already mentioned it, but I missed your point :-(
OK, will do it in the next iteration.

Thanks a lot for the review!

Vladimir

  reply	other threads:[~2015-07-14 11:05 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-11 14:48 [PATCH -mm v7 0/6] idle memory tracking Vladimir Davydov
2015-07-11 14:48 ` Vladimir Davydov
2015-07-11 14:48 ` Vladimir Davydov
2015-07-11 14:48 ` [PATCH -mm v7 1/6] memcg: add page_cgroup_ino helper Vladimir Davydov
2015-07-11 14:48   ` Vladimir Davydov
2015-07-11 14:48   ` Vladimir Davydov
2015-07-11 14:48 ` [PATCH -mm v7 2/6] hwpoison: use page_cgroup_ino for filtering by memcg Vladimir Davydov
2015-07-11 14:48   ` Vladimir Davydov
2015-07-11 14:48 ` [PATCH -mm v7 3/6] memcg: zap try_get_mem_cgroup_from_page Vladimir Davydov
2015-07-11 14:48   ` Vladimir Davydov
2015-07-11 14:48 ` [PATCH -mm v7 4/6] proc: add kpagecgroup file Vladimir Davydov
2015-07-11 14:48   ` Vladimir Davydov
2015-07-11 14:48 ` [PATCH -mm v7 5/6] proc: add kpageidle file Vladimir Davydov
2015-07-11 14:48   ` Vladimir Davydov
2015-07-13 19:02   ` Andres Lagar-Cavilla
2015-07-13 19:02     ` Andres Lagar-Cavilla
2015-07-14 11:05     ` Vladimir Davydov [this message]
2015-07-14 11:05       ` Vladimir Davydov
2015-07-14 11:05       ` Vladimir Davydov
2015-07-14 20:27       ` Andres Lagar-Cavilla
2015-07-14 20:27         ` Andres Lagar-Cavilla
2015-07-14 20:27         ` Andres Lagar-Cavilla
2015-07-11 14:48 ` [PATCH -mm v7 6/6] proc: export idle flag via kpageflags Vladimir Davydov
2015-07-11 14:48   ` Vladimir Davydov

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=20150714110527.GA1015@esperanza \
    --to=vdavydov@parallels.com \
    --cc=akpm@linux-foundation.org \
    --cc=andreslc@google.com \
    --cc=cgroups@vger.kernel.org \
    --cc=corbet@lwn.net \
    --cc=gorcunov@openvz.org \
    --cc=gthelen@google.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.cz \
    --cc=minchan@kernel.org \
    --cc=raghavendra.kt@linux.vnet.ibm.com \
    --cc=rientjes@google.com \
    --cc=walken@google.com \
    --cc=xemul@parallels.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.