mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: KOSAKI Motohiro <kosaki.motohiro@gmail.com>
To: Trilok Soni <soni.trilok@gmail.com>
Cc: "Greg KH" <greg@kroah.com>, "Arve Hjønnevåg" <arve@android.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
Subject: Re: lowmemory android driver not needed?
Date: Fri, 16 Jan 2009 20:42:27 +0900	[thread overview]
Message-ID: <2f11576a0901160342x291267cn11b33d65ec9239b4@mail.gmail.com> (raw)
In-Reply-To: <5d5443650901150532r20a4c25q834afadde2f98a3@mail.gmail.com>

> And there is one more lowmem driver developed by Nokia for Nokia 8xx
> tablets it seems. CCed Tony Lindgren,  Juha and Viktor.
>
> http://git.kernel.org/?p=linux/kernel/git/tmlind/linux-omap-2.6.git;a=blob;f=security/lowmem.c;h=ae78a530af39703e335ad769f1e6f097f63ec6dd;hb=HEAD


quick review.

> 325 static struct security_operations lowmem_security_ops = {
> 326         /* Use the capability functions for some of the hooks */
> 327         .ptrace_may_access = cap_ptrace_may_access,
> 328         .ptrace_traceme = cap_ptrace_traceme,
> 329         .capget = cap_capget,
> 330         .capset_check = cap_capset_check,
> 331         .capset_set = cap_capset_set,
> 332         .capable = cap_capable,
> 333
> 334         .bprm_apply_creds = cap_bprm_apply_creds,
> 335         .bprm_set_security = cap_bprm_set_security,
> 336
> 337         .task_post_setuid = cap_task_post_setuid,
> 338         .task_reparent_to_init = cap_task_reparent_to_init,
> 339         .vm_enough_memory = low_vm_enough_memory,
> 340 };


.vm_enough_memory is the hook of virtual memory accounting, not rss.
modern almost linux application and glibc largely use virtual address space
than actual resident memory.

then, vm_enough_memory don't provide proper hook.


>  57 static ctl_table lowmem_table[] = {
> 58         {
> 59                 .ctl_name = VM_LOWMEM_DENY_PAGES,
> 60                 .procname = "lowmem_deny_watermark_pages",
> 61                 .data = &deny_pages,
> 62                 .maxlen = sizeof(long),
> 63                 .mode = 0644,
> 64                 .child = NULL,
> 65                 .proc_handler = &proc_dointvec,
> 66                 .strategy = &sysctl_intvec,
> 67         }, {

you can set .ctl_name to CTL_UNNUMBERED.


> 249 static int low_vm_enough_memory(struct mm_struct *mm, long pages)
> 250 {
> 251         unsigned long free, allowed;
> 252         int cap_sys_admin = 0, notify;
> 253
> 254         if (cap_capable(current, CAP_SYS_ADMIN) == 0)
> 255                 cap_sys_admin = 1;
> 256
> 257         allowed = totalram_pages - hugetlb_total_pages();
> 258         allowed_pages = allowed;
> 259
> 260         /* We activate ourselves only after both parameters have been
> 261          * configured. */
> 262         if (deny_pages == 0 || notify_low_pages == 0 || notify_high_pages == 0)
> 263                 return  __vm_enough_memory(mm, pages, cap_sys_admin);
> 264
> 265         vm_acct_memory(pages);
> 266
> 267         /* Easily freed pages when under VM pressure or direct reclaim */
> 268         free = global_page_state(NR_FILE_PAGES);

this line assume file page can evictable. but it is not true.
we should consider mlocked file page.


> 269         free += nr_swap_pages;
> 270         free += global_page_state(NR_SLAB_RECLAIMABLE);
> 271
> 272         if (likely(free > notify_low_pages))
> 273                 goto enough_memory;
> 274
> 275         /* No luck, lets make it more expensive and try again.. */
> 276         free += nr_free_pages();
> 277
> 278         if (free < deny_pages) {
> 279                 int i;
> 280
> 281                 lowmem_free_pages = free;
> 282                 low_watermark_state(1);
> 283                 high_watermark_state(1);
> 284                 /* Memory allocations by root are always allowed */
> 285                 if (cap_sys_admin)
> 286                         return 0;
> 287
> 288                 /* OOM unkillable process is allowed to consume memory */
> 289                 if (current->oomkilladj == OOM_DISABLE)
> 290                         return 0;

No generic assumption.

> 292                 /* uids from allowed_uids vector are also allowed no matter what */
> 293                 for (i = 0; i < LOWMEM_MAX_UIDS && allowed_uids[i]; i++)
> 294                         if (current->uid == allowed_uids[i])
> 295                                 return 0;

Oops, LOWMEM_MAX_UIDS is ugly restriction.


> 297                 vm_unacct_memory(pages);
> 298                 if (printk_ratelimit()) {
> 299                         printk(MY_NAME ": denying memory allocation to process %d (%s> )\n",
> 300                                current->pid, current->comm);
> 301                 }
> 302                 return -ENOMEM;
> 303         }
> 304
> 305 enough_memory:
> 306         /* See if we need to notify level 1 */
> 307         low_watermark_state(free < notify_low_pages);
> 308
> 309         /*
> 310          * In the level 2 notification case things are more complicated,
> 311          * as the level that we drop the state and send a notification
> 312          * should be lower than when it is first triggered. Having this
> 313          * on the same watermark level ends up bouncing back and forth
> 314          * when applications are being stupid.
> 315          */
> 316         notify = free < notify_high_pages;
> 317         if (notify || free - nr_decay_pages > notify_high_pages)
> 318                 high_watermark_state(notify);
> 319
> 320         /* We have plenty of memory */
> 321         lowmem_free_pages = free;

It seems racy.
if this code run on smp, lowmem_free_pages can hold unproper value.


> 322         return 0;
> 323 }


then, In my first look, this code deeply depend on embedded and nokia
process management policy.
I don't think it can merge mainline.

  parent reply	other threads:[~2009-01-16 11:42 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 [this message]
2009-01-16 13:18                       ` KOSAKI Motohiro
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=2f11576a0901160342x291267cn11b33d65ec9239b4@mail.gmail.com \
    --to=kosaki.motohiro@gmail.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

all inboxes | Powered by JetHome®