linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Ying Han <yinghan@google.com>
To: PINTU KUMAR <pintu_agarwal@yahoo.com>
Cc: "linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"pintu.k@samsung.com" <pintu.k@samsung.com>
Subject: Re: [NEW]: Introducing shrink_all_memory from user space
Date: Mon, 16 Apr 2012 11:50:31 -0700	[thread overview]
Message-ID: <CALWz4izONZq7gOz-h0MWqEgyuOF8PQEmP3FAMp_rKLcKx3X01Q@mail.gmail.com> (raw)
In-Reply-To: <1334483226.20721.YahooMailNeo@web162003.mail.bf1.yahoo.com>

On Sun, Apr 15, 2012 at 2:47 AM, PINTU KUMAR <pintu_agarwal@yahoo.com> wrote:
> Dear All,
>
> This is regarding a small proposal for shrink_all_memory( ) function which is found in mm/vmscan.c.
> For those who are not aware, this function helps in reclaiming specified amount of physical memory and returns number of freed pages.
>
> Currently this function is under CONFIG_HIBERNATION flag, so cannot be used by others without enabling hibernation.
> Moreover this function is not exported to the outside world, so no driver can use it directly without including EXPORT_SYMBOL(shrink_all_memory) and recompiling the kernel.
> The purpose of using it under hibernation(kernel/power/snapshot.c) is to regain enough physical pages to create hibernation image.
>
> The same can be useful for some drivers who wants to allocate large contiguous memory (in MBs) but his/her system is in very bad state and could not do so without rebooting.
> Due to this bad state of the system the user space application will be badly hurt on performance, and there could be a need to quickly reclaim all physical memory from user space.
> This could be very helpful for small embedded products and smart phones where rebooting is never a preferred choice.
>
> With this support in kernel, a small utility can be developed in user space which user can run and reclaim as many physical pages and noticed that his system performance is increased without rebooting.
>
> To make this work, I have performed a sample experiment on my ubuntu(10.x) machine running with kernel-3.3.0.
>
> Also I performed the similar experiment of one of our Samsung smart phones as well.
>
> Following are the results from Ubuntu:
>
> 1) I downloaded kernel3.3.0 and made the respective changes in mm/vmscan.c. That is added EXPORT_SYMBOL(shrink_all_memory) under the function shrink_all_memory( ).
>     (Note: CONFIG_HIBERNATION was already enabled for my system.)
>
> 2) Then I build the kernel and installed it on my Ubuntu PC.
>
> 3) After that I have developed a small kernel module (miscdevice: /dev/shrinkmem) to call shrink_all_memory( ) under my driver write( ) function.
>
> 4) Then from user space I just need to do this:
>
>     # echo 100 > /dev/shrinkmem   (To reclaim 100MB of physical memory without reboot)
>
>
> The results that were obtained with this experiment is as follows:
>
> 1) At some point of time, the buddyinfo and free pages on my Ubuntu were as follows:
> root@pintu-ubuntu:~/PintuHomeTest/KERNEL_ORG# cat /proc/buddyinfo ; free -tmNode 0, zone      DMA    468     23      0      0      0      0      0      0      0      0      0
> Node 0, zone   Normal    898    161     38      8      0      0      0      0      0      0      0
>                  total       used       free     shared    buffers     cached
> Mem:           497        489          7          0         37        405
> -/+ buffers/cache:         47        449
> Swap:         1458        158       1300
> Total:        1956        648       1308
>
>
> 2) After doing "echo 100 > /dev/shrinkmem" :
> [19653.833916] [SHRINKMEM]: memsize(in MB) = 100
> [19653.863618] <SHRINKMEM>: Number of Pages Freed: 26756
> [19653.863664] [SHRINKMEM] : Device is Closed....
>
> Node 0, zone      DMA    411    166     51      5      0      0      0      0      0      0      0
> Node 0, zone   Normal   2915   3792   2475   1335    730     23      0      0      0      0      0
>                  total       used       free     shared    buffers     cached
> Mem:           497        323        173          0         37        238
> -/+ buffers/cache:         47        449
> Swap:         1458        158       1300
> Total:        1956        481       1474
>
>
> 3) After running again with : echo 512 > /dev/shrinkmem
> [21961.064534] [SHRINKMEM]: memsize(in MB) = 512
> [21961.109497] <SHRINKMEM>: Number of Pages Freed: 61078
> [21961.109562] [SHRINKMEM] : Device is Closed....
> Node 0, zone      DMA    116     99     87     58     16      6      1      0      0      0      0
> Node 0, zone   Normal   6697   6939   5529   3756   1442    203     17      0      0      0      0
>                  total       used       free     shared    buffers     cached
> Mem:           497         87        410          0         37          9
> -/+ buffers/cache:         40        456
> Swap:         1458        158       1300
> Total:        1956        245       1711
>
>
> 4) Thus in both the cases huge number of free pages were reclaimed.
>
> 5) After running this on my system, the performance was improved quickly.
>
> 6) I performed the same experiment on our Samsung Smart phones as well. And I have seen a drastic improve in performance after running this for 3/4 times.
>     In case of phones it is more helpful as there is no swap space.
>
> 7) Your feedback and suggestion is important. Based on the feedback, I can plan to submit the patches officially after performing basic cleanups.
>
>
> Future Work
> ==========
> Our final goal is to use it during lowmem notifier where shrink_all_memory will be called automatically in background if the memory pressure falls below certain limit defined by the system.
> For example we can measure the percentage memory fragmentation level of the system across each zone and if the fragmentation percentage goes above say 80-85% during lowmem notifier, we can invoke shrink_all_memory() in background.

Does it make sense to let kswapd reclaim pages at background w/ user
configured watermark?

--Ying

>
> This can be used by some application which requires large mmap or shared memory mapping.
>
> This can be even using inside the multimedia drivers that requires large contiguous memory to check if that many memory pages can be reclaimed or not.
>
>
> Please provide your valuable feedback and suggestion.
>
>
> Thank you very much !
>
>
> With Regards,
> Pintu Kumar
>
> --
> 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/ .
> Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
> Don't email: <a hrefmailto:"dont@kvack.org"> email@kvack.org </a>

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2012-04-16 18:50 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-15  9:47 [NEW]: Introducing shrink_all_memory from user space PINTU KUMAR
2012-04-15 10:00 ` santosh
2012-04-15 10:38 ` richard -rw- weinberger
2012-04-15 11:47   ` PINTU KUMAR
2012-04-15 12:10     ` richard -rw- weinberger
2012-04-16  9:16       ` PINTU KUMAR
2012-04-18 20:10       ` Alan Cox
2012-04-19 13:42         ` PINTU KUMAR
2013-01-13 15:32           ` Introducing Aggressive Low Memory Booster [1] PINTU KUMAR
2013-01-14 11:00             ` Bartlomiej Zolnierkiewicz
2013-01-20 16:03             ` PINTU KUMAR
2012-04-16 18:50 ` Ying Han [this message]
2012-04-17 18:24 ` [NEW]: Introducing shrink_all_memory from user space KOSAKI Motohiro
2012-04-18 20:07 ` Alan Cox

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=CALWz4izONZq7gOz-h0MWqEgyuOF8PQEmP3FAMp_rKLcKx3X01Q@mail.gmail.com \
    --to=yinghan@google.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=pintu.k@samsung.com \
    --cc=pintu_agarwal@yahoo.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).