linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@intel.com>
To: Xiaokang <xiaokang.qin@intel.com>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>
Cc: "Yin, Fengwei" <fengwei.yin@intel.com>
Subject: Re: [PATCH] proc/smaps: add proportional size of anonymous page
Date: Tue, 11 Nov 2014 07:22:58 -0800	[thread overview]
Message-ID: <546229D2.6080202@intel.com> (raw)
In-Reply-To: <54621FDF.8090304@intel.com>

On 11/11/2014 06:40 AM, Xiaokang wrote:
> On 11/11/2014 01:03 AM, Dave Hansen wrote:
>> I'll agree that this definitely provides a bit of data that we didn't
>> have before, albeit a fairly obscure one.
>>
>> But, what's the goal of this patch?  Why are you doing this?  Was there
>> some application whose behavior you were not able to explain before, but
>> can after this patch?
> 
> Under Android, when user switches the application the previous
> application will not exit but switch to background so that next time
> this application could be resumed to foreground very quickly.
> So there may be many applications running at background and Android
> introduces lowmemory killer to kill processes to free memory according
> to oom_adj when memory is short. Some processes with high value of
> oom_adj will be killed first like the background running non-critical
> application. The memory used by these processes could be treated as
> "free" because it could be freed by killing. Hence under Android the
> "free" RAM is composed of: 1) memory using by non-critical application
> that could be killed easily, 2) page cache, 3) physical free page. We
> are using sum of Pss in smaps to measure the process consumed memory for
> 1) and get the info for 2) 3) from /proc/meminfo. Then we have the
> problem that file based memory will be double accounted in 1) and 2). To
> mitigate the double accounting issue here, we need to know the double
> accounting part - proportional page cache size, and do the deduction.

I see what you're trying to do, but I'm not convinced your approach is
effective.  Here's why:

The end goal is to say, for a given process, "If I kill $PID, I get back
X kB of memory."  You get back nothing for page cache, so you want to
subtract it out of the measurement.  You want to account for Anonymous
memory which you *do* get back, but you unfortunately *ALSO* get nothing
back for a shared anonymous page when you kill a single process.  You
need to kill *all* of the things sharing it.  If one of the things
sharing it is one of those critical applications, then you really can't
free it no matter how many non-critical apps you kill.

Let's also see some data.  How much of the memory on a system is
consumed by these pages?  How imprecise *is* the current method and how
much more precise does this make the Android OOM kills?

I think there also needs to be some level of root-cause analysis done
here.  These pages can only happen when you do:

	1. mmap(/some/file, MAP_PRIVATE);
	2. write to mmap()
	3. fork()
	4. run forever in child and never write again, and never exec()

Maybe the zygote thingy needs to be more aggressive about unmapping
things a child would never use.  Or, maybe it needs to set MADV_DONTFORK
on some things.

> If the goal is providing a "Proportional Page
>> cache size", why do that in an indirect way?  Have you explored doing
>> the same measurement with /proc/$pid/pagemap?  Is it possible with that
>> interface?
>>
> I checked the flags in /proc/kpageflags but have no idea about what
> flags should be used to identify the pagecache. It will be appreciated
> if you could provide some advice.

See Documentation/vm/pagemap.txt

If it is !ANON the it is page cache.

--
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>

  reply	other threads:[~2014-11-11 15:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-07  8:31 [PATCH] proc/smaps: add proportional size of anonymous page Xiaokang Qin
2014-11-07 21:34 ` Dave Hansen
2014-11-10  8:48   ` Qin, Xiaokang
2014-11-10 17:03     ` Dave Hansen
2014-11-11 14:40       ` Xiaokang
2014-11-11 15:22         ` Dave Hansen [this message]
2014-11-10  9:29   ` Xiaokang

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=546229D2.6080202@intel.com \
    --to=dave.hansen@intel.com \
    --cc=fengwei.yin@intel.com \
    --cc=linux-mm@kvack.org \
    --cc=xiaokang.qin@intel.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;
as well as URLs for NNTP newsgroup(s).