mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
To: "Arve Hjønnevåg" <arve@android.com>
Cc: "Greg KH" <greg@kroah.com>, "Alan Cox" <alan@lxorguk.ukuu.org.uk>,
	"Pavel Machek" <pavel@suse.cz>,
	"Brian Swetland" <swetland@google.com>,
	arve@google.com, "San Mehat" <san@android.com>,
	"Robert Love" <rlove@google.com>,
	linux-kernel@vger.kernel.org,
	"linux-omap@vger.kernel.org" <linux-omap@vger.kernel.org>,
	"Tony Lindgren" <tony@atomide.com>,
	"ext Juha Yrjölä" <juha.yrjola@solidboot.com>,
	viktor.rosendahl@nokia.com, "Trilok Soni" <soni.trilok@gmail.com>
Subject: Re: lowmemory android driver not needed?
Date: Fri, 16 Jan 2009 22:18:13 +0900	[thread overview]
Message-ID: <2f11576a0901160518g52a3e70endc98fe4792a98b9b@mail.gmail.com> (raw)
In-Reply-To: <2f11576a0901160342x291267cn11b33d65ec9239b4@mail.gmail.com>

also quick review to lowmemorykiller.c

> #include <linux/module.h>
> #include <linux/kernel.h>
> #include <linux/mm.h>
> #include <linux/oom.h>
> #include <linux/sched.h>
>
> static int lowmem_shrink(int nr_to_scan, gfp_t gfp_mask);
>
> static struct shrinker lowmem_shrinker = {
>         .shrink = lowmem_shrink,
>         .seeks = DEFAULT_SEEKS * 16
> };

why do you choice *16?


> static uint32_t lowmem_debug_level = 2;
> static int lowmem_adj[6] = {

why do you choice [6]?

>         0,
>         1,
>         6,
>         12,
> };
>
> static int lowmem_adj_size = 4;
> static size_t lowmem_minfree[6] = {
>         3*512, // 6MB
>         2*1024, // 8MB
>         4*1024, // 16MB
>         16*1024, // 64MB
> };
> static int lowmem_minfree_size = 4;
>
> #define lowmem_print(level, x...) do { if(lowmem_debug_level >= (level)) printk(x); } while(0)
>
> module_param_named(cost, lowmem_shrinker.seeks, int, S_IRUGO | S_IWUSR);
> module_param_array_named(adj, lowmem_adj, int, &lowmem_adj_size, S_IRUGO | S_IWUSR);
> module_param_array_named(minfree, lowmem_minfree, uint, &lowmem_minfree_size, S_IRUGO | S_IWUSR);
> module_param_named(debug_level, lowmem_debug_level, uint, S_IRUGO | S_IWUSR);
>
> static int lowmem_shrink(int nr_to_scan, gfp_t gfp_mask)
> {
>         struct task_struct *p;
>         struct task_struct *selected = NULL;
>         int rem = 0;
>         int tasksize;
>         int i;
>         int min_adj = OOM_ADJUST_MAX + 1;
>         int selected_tasksize = 0;
>         int array_size = ARRAY_SIZE(lowmem_adj);
>         int other_free = global_page_state(NR_FREE_PAGES) + global_page_state(NR_FILE_PAGES);

I think you don't consider mlocked page (and/or other unevictable page).
if much mlocked file page exist, other_free can become large value.
then, this routine don't kill any process.


>         if(lowmem_adj_size < array_size)
>                 array_size = lowmem_adj_size;
>         if(lowmem_minfree_size < array_size)
>                 array_size = lowmem_minfree_size;
>         for(i = 0; i < array_size; i++) {
>                 if(other_free < lowmem_minfree[i]) {
>                         min_adj = lowmem_adj[i];
>                         break;
>                 }
>         }
>
>
>         if(nr_to_scan > 0)
>                 lowmem_print(3, "lowmem_shrink %d, %x, ofree %d, ma %d\n", nr_to_scan, gfp_mask, other_fr> ee, min_adj);
>         read_lock(&tasklist_lock);
>         for_each_process(p) {

Oops. too long locking.
shrink_slab() is freqentlly called function. I don't like costly operation.

>                 if(p->oomkilladj >= 0 && p->mm) {
>                         tasksize = get_mm_rss(p->mm);
>                         if(nr_to_scan > 0 && tasksize > 0 && p->oomkilladj >= min_adj) {
>                                 if(selected == NULL ||
>                                    p->oomkilladj > selected->oomkilladj ||
>                                    (p->oomkilladj == selected->oomkilladj &&
>                                     tasksize > selected_tasksize)) {
>                                         selected = p;
>                                         selected_tasksize = tasksize;
>                                         lowmem_print(2, "select %d (%s), adj %d, size %d, to kill\n",
>                                                      p->pid, p->comm, p->oomkilladj, tasksize);
>                                 }
>                         }
>                         rem += tasksize;

this code mean,
shrinker->shrink(0, gfp_mask) indicate to recalculate total rss every time.
it is too CPU and battery wasting.


>                 }
>         }
>         if(selected != NULL) {
>                 lowmem_print(1, "send sigkill to %d (%s), adj %d, size %d\n",
>                              selected->pid, selected->comm,
>                              selected->oomkilladj, selected_tasksize);
>                 force_sig(SIGKILL, selected);
>                 rem -= selected_tasksize;
>         }
>         lowmem_print(4, "lowmem_shrink %d, %x, return %d\n", nr_to_scan, gfp_mask, rem);
>         read_unlock(&tasklist_lock);
>         return rem;
> }

  reply	other threads:[~2009-01-16 13:18 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-14  1:02 Greg KH
2009-01-14  2:18 ` Brian Swetland
2009-01-14  2:30   ` Arve Hjønnevåg
2009-01-14  3:52     ` Greg KH
2009-01-14 10:43       ` Pavel Machek
2009-01-14 10:48         ` Alan Cox
2009-01-14 12:18           ` MinChan Kim
2009-01-14 22:26           ` Arve Hjønnevåg
2009-01-14 23:17             ` Greg KH
2009-01-14 23:32               ` Arve Hjønnevåg
2009-01-15  0:12                 ` Greg KH
2009-01-15  0:54                   ` [PATCH] Staging: android: Add lowmemorykiller documentation Arve Hjønnevåg
2009-01-15  0:59                     ` Greg KH
2009-01-15 13:32                   ` lowmemory android driver not needed? Trilok Soni
2009-01-15 23:44                     ` Greg KH
2009-01-16  9:02                       ` Paul Mundt
2009-01-16 11:16                         ` KOSAKI Motohiro
2009-01-16 15:23                           ` Greg KH
2009-01-21  2:50                             ` KOSAKI Motohiro
2009-01-21  3:05                               ` Paul Mundt
2009-01-21  3:29                               ` KAMEZAWA Hiroyuki
2009-04-01 18:38                               ` Trilok Soni
2009-04-01 19:33                                 ` David Rientjes
2009-02-03 20:55                         ` Tony Lindgren
2009-01-16 11:42                     ` KOSAKI Motohiro
2009-01-16 13:18                       ` KOSAKI Motohiro [this message]
2009-01-22  6:13                         ` Arve Hjønnevåg
2009-01-29  1:48                           ` KOSAKI Motohiro
2009-01-29  2:51                             ` Arve Hjønnevåg
2009-01-29  3:45                               ` KAMEZAWA Hiroyuki
2009-01-29  4:27                                 ` Greg KH
2009-01-29  4:43                                   ` KOSAKI Motohiro
2009-01-29  4:59                                     ` Greg KH
2009-01-29  5:29                                       ` KOSAKI Motohiro
2009-01-30  6:20                                         ` Greg KH
2009-01-30  6:41                                           ` Brian Swetland
2009-02-03 13:40                                             ` KOSAKI Motohiro
2009-01-29 22:06                               ` Pavel Machek
2009-02-03 14:08                                 ` KOSAKI Motohiro
2009-01-15  7:55           ` David Rientjes
2009-01-14  6:45     ` MinChan Kim

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=2f11576a0901160518g52a3e70endc98fe4792a98b9b@mail.gmail.com \
    --to=kosaki.motohiro@jp.fujitsu.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=arve@android.com \
    --cc=arve@google.com \
    --cc=greg@kroah.com \
    --cc=juha.yrjola@solidboot.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=pavel@suse.cz \
    --cc=rlove@google.com \
    --cc=san@android.com \
    --cc=soni.trilok@gmail.com \
    --cc=swetland@google.com \
    --cc=tony@atomide.com \
    --cc=viktor.rosendahl@nokia.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

Powered by JetHome